Skip to content

Commit

Permalink
[ORG-91] Set status in applications (#97)
Browse files Browse the repository at this point in the history
* application model and orm

* migration

* update tests
  • Loading branch information
carlotacb authored Jan 11, 2024
1 parent 752749d commit 520f433
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 11 deletions.
6 changes: 5 additions & 1 deletion organizator_api/app/applications/application/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
from typing import Any

from app.applications.domain.models.application import Application
from app.applications.domain.models.application import Application, ApplicationStatus
from app.events.application.response import EventResponse
from app.events.domain.models.event import Event
from app.users.application.response import UserResponse
Expand All @@ -14,6 +14,7 @@ class ApplicationResponse:
id: str
user: User
event: Event
status: ApplicationStatus
created_at: datetime
updated_at: datetime

Expand All @@ -23,6 +24,7 @@ def from_application(application: Application) -> "ApplicationResponse":
id=str(application.id),
user=application.user,
event=application.event,
status=application.status,
created_at=application.created_at,
updated_at=application.updated_at,
)
Expand All @@ -31,6 +33,7 @@ def to_dict_without_user(self) -> dict[str, Any]:
return {
"id": self.id,
"event": EventResponse.from_event(self.event).to_dict(),
"status": self.status.value,
"created_at": self.created_at.strftime("%Y-%m-%dT%H:%M:%SZ"),
"updated_at": self.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ"),
}
Expand All @@ -39,6 +42,7 @@ def to_dict_without_event(self) -> dict[str, Any]:
return {
"id": self.id,
"user": UserResponse.from_user(self.user).to_dict(),
"status": self.status.value,
"created_at": self.created_at.strftime("%Y-%m-%dT%H:%M:%SZ"),
"updated_at": self.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ"),
}
17 changes: 16 additions & 1 deletion organizator_api/app/applications/domain/models/application.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import uuid
from dataclasses import dataclass
from datetime import datetime
from typing import Optional
from enum import Enum

from app.events.domain.models.event import Event
from app.users.domain.models.user import User


class ApplicationStatus(Enum):
PENDING = "Under review"
INVITED = "Invited"
CONFIRMED = "Confirmed"
CANCELLED = "Cancelled"
INVALID = "Invalid"
REJECTED = "Rejected"
WAIT_LIST = "Wait list"

@classmethod
def choices(cls) -> tuple[tuple[str, str], ...]:
return tuple((i.name, i.value) for i in cls)


@dataclass
class Application:
id: uuid.UUID
user: User
event: Event
status: ApplicationStatus
created_at: datetime
updated_at: datetime
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
UserIsNotStudent,
UserIsTooYoung,
)
from app.applications.domain.models.application import Application
from app.applications.domain.models.application import Application, ApplicationStatus
from app.applications.infrastructure.repository_factories import (
ApplicationRepositoryFactory,
)
Expand Down Expand Up @@ -54,6 +54,7 @@ def execute(self, token: uuid.UUID, event_id: uuid.UUID) -> None:
id=uuid.uuid4(),
user=user,
event=event,
status=ApplicationStatus.PENDING,
created_at=datetime.now(tz=timezone.utc),
updated_at=datetime.now(tz=timezone.utc),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.db import models

from app.applications.domain.models.application import ApplicationStatus


class ORMEventApplication(models.Model):
class Meta:
Expand All @@ -9,5 +11,10 @@ class Meta:
id = models.UUIDField(primary_key=True)
user = models.ForeignKey("ORMUser", on_delete=models.CASCADE)
event = models.ForeignKey("ORMEvent", on_delete=models.CASCADE)
status = models.CharField(
max_length=255,
choices=ApplicationStatus.choices(),
default=ApplicationStatus.PENDING.name,
)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.db import IntegrityError

from app.applications.domain.exceptions import ApplicationAlreadyExists
from app.applications.domain.models.application import Application
from app.applications.domain.models.application import Application, ApplicationStatus
from app.applications.domain.repositories import ApplicationRepository
from app.applications.infrastructure.persistence.models.orm_application import (
ORMEventApplication,
Expand Down Expand Up @@ -84,6 +84,7 @@ def _to_domain_model(self, orm_application: ORMEventApplication) -> Application:
students_only=orm_application.event.students_only,
age_restrictions=orm_application.event.age_restrictions,
),
status=ApplicationStatus[orm_application.status],
created_at=orm_application.created_at,
updated_at=orm_application.updated_at,
)
29 changes: 29 additions & 0 deletions organizator_api/app/migrations/0015_ormeventapplication_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.7 on 2024-01-11 18:44

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("app", "0014_alter_ormevent_age_restrictions_and_more"),
]

operations = [
migrations.AddField(
model_name="ormeventapplication",
name="status",
field=models.CharField(
choices=[
("PENDING", "Under review"),
("INVITED", "Invited"),
("CONFIRMED", "Confirmed"),
("CANCELLED", "Cancelled"),
("INVALID", "Invalid"),
("REJECTED", "Rejected"),
("WAIT_LIST", "Wait list"),
],
default="PENDING",
max_length=255,
),
),
]
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import uuid
from datetime import datetime
from typing import Optional

from app.applications.domain.models.application import Application
from app.applications.domain.models.application import Application, ApplicationStatus
from app.events.domain.models.event import Event
from app.users.domain.models.user import User
from tests.events.domain.EventFactory import EventFactory
Expand All @@ -15,13 +14,15 @@ def create(
new_id: uuid.UUID = uuid.UUID("ef6f6fb3-ba12-43dd-a0da-95de8125b1cc"),
user: User = UserFactory().create(),
event: Event = EventFactory().create(),
status: ApplicationStatus = ApplicationStatus.PENDING,
created_at: datetime = datetime.now(),
updated_at: datetime = datetime.now(),
) -> Application:
return Application(
id=new_id,
user=user,
event=event,
status=status,
created_at=created_at,
updated_at=updated_at,
)
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ def test__given_a_organizer_user_and_a_existing_event_with_participants__when_ge
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.content,
b'[{"id": "eb41b762-5988-4fa3-8942-7a91ccb00686", "user": {"id": "eb41b762-5988-4fa3-8942-7a91ccb00686", "username": "john", "email": "john@test.com", "first_name": "Carlota", "last_name": "Catot", "bio": "The user that is using this application", "profile_image": "profile_picture.png", "role": "Participant", "date_of_birth": "07/05/1996", "study": true, "work": false, "university": "Universitat Polit\\u00e8cnica de Catalunya", "degree": "Computer Science", "expected_graduation": "01/05/2024", "current_job_role": "", "tshirt": "", "gender": "", "alimentary_restrictions": "", "github": "", "linkedin": "", "devpost": "", "webpage": ""}, "created_at": "2024-01-09T10:47:00Z", "updated_at": "2024-01-09T10:47:00Z"}, {"id": "eb41b762-5988-4fa3-8942-7a91ccb00687", "user": {"id": "ef6f6fb3-ba12-43dd-a0da-95de8125b1cc", "username": "carlotacb", "email": "carlota@hackupc.com", "first_name": "Carlota", "last_name": "Catot", "bio": "The user that is using this application", "profile_image": "profile_picture.png", "role": "Participant", "date_of_birth": "07/05/1996", "study": true, "work": false, "university": "Universitat Polit\\u00e8cnica de Catalunya", "degree": "Computer Science", "expected_graduation": "01/05/2024", "current_job_role": "", "tshirt": "", "gender": "", "alimentary_restrictions": "", "github": "", "linkedin": "", "devpost": "", "webpage": ""}, "created_at": "2024-01-09T10:47:00Z", "updated_at": "2024-01-09T10:47:00Z"}]',
b'[{"id": "eb41b762-5988-4fa3-8942-7a91ccb00686", "user": {"id": "eb41b762-5988-4fa3-8942-7a91ccb00686", "username": "john", "email": "john@test.com", "first_name": "Carlota", "last_name": "Catot", "bio": "The user that is using this application", "profile_image": "profile_picture.png", "role": "Participant", "date_of_birth": "07/05/1996", "study": true, "work": false, "university": "Universitat Polit\\u00e8cnica de Catalunya", "degree": "Computer Science", "expected_graduation": "01/05/2024", "current_job_role": "", "tshirt": "", "gender": "", "alimentary_restrictions": "", "github": "", "linkedin": "", "devpost": "", "webpage": ""}, "status": "Under review", "created_at": "2024-01-09T10:47:00Z", "updated_at": "2024-01-09T10:47:00Z"}, {"id": "eb41b762-5988-4fa3-8942-7a91ccb00687", "user": {"id": "ef6f6fb3-ba12-43dd-a0da-95de8125b1cc", "username": "carlotacb", "email": "carlota@hackupc.com", "first_name": "Carlota", "last_name": "Catot", "bio": "The user that is using this application", "profile_image": "profile_picture.png", "role": "Participant", "date_of_birth": "07/05/1996", "study": true, "work": false, "university": "Universitat Polit\\u00e8cnica de Catalunya", "degree": "Computer Science", "expected_graduation": "01/05/2024", "current_job_role": "", "tshirt": "", "gender": "", "alimentary_restrictions": "", "github": "", "linkedin": "", "devpost": "", "webpage": ""}, "status": "Under review", "created_at": "2024-01-09T10:47:00Z", "updated_at": "2024-01-09T10:47:00Z"}]',
)
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ def test__given_a_valid_token_and_some_applications_for_a_user__when_get_user_ev
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.content,
b'[{"id": "ef6f6fb3-ba12-43dd-a0da-95de8125b1cc", "event": {"id": "eb41b762-5988-4fa3-8942-7a91ccb00686", "name": "HackUPC 2024", "url": "https://www.hackupc.com/", "description": "The biggest student hackathon in Europe", "start_date": "2023-05-12T16:00:00Z", "end_date": "2023-05-14T18:00:00Z", "location": "UPC Campus Nord", "header_image": "https://hackupc.com/ogimage.png", "deleted": false, "open_for_participants": true, "max_participants": 100, "expected_attrition_rate": 0.1, "students_only": true, "age_restrictions": 16}, "created_at": "2024-01-09T00:52:29Z", "updated_at": "2024-01-09T00:52:29Z"}, {"id": "eb41b762-5988-4fa3-8942-7a91ccb00687", "event": {"id": "ef6f6fb3-ba12-43dd-a0da-95de8125b1cc", "name": "HackUPC 2023", "url": "https://www.hackupc.com/", "description": "The biggest student hackathon in Europe", "start_date": "2023-05-12T16:00:00Z", "end_date": "2023-05-14T18:00:00Z", "location": "UPC Campus Nord", "header_image": "https://hackupc.com/ogimage.png", "deleted": false, "open_for_participants": true, "max_participants": 100, "expected_attrition_rate": 0.1, "students_only": true, "age_restrictions": 16}, "created_at": "2024-01-09T00:52:29Z", "updated_at": "2024-01-09T00:52:29Z"}]',
b'[{"id": "ef6f6fb3-ba12-43dd-a0da-95de8125b1cc", "event": {"id": "eb41b762-5988-4fa3-8942-7a91ccb00686", "name": "HackUPC 2024", "url": "https://www.hackupc.com/", "description": "The biggest student hackathon in Europe", "start_date": "2023-05-12T16:00:00Z", "end_date": "2023-05-14T18:00:00Z", "location": "UPC Campus Nord", "header_image": "https://hackupc.com/ogimage.png", "deleted": false, "open_for_participants": true, "max_participants": 100, "expected_attrition_rate": 0.1, "students_only": true, "age_restrictions": 16}, "status": "Under review", "created_at": "2024-01-09T00:52:29Z", "updated_at": "2024-01-09T00:52:29Z"}, {"id": "eb41b762-5988-4fa3-8942-7a91ccb00687", "event": {"id": "ef6f6fb3-ba12-43dd-a0da-95de8125b1cc", "name": "HackUPC 2023", "url": "https://www.hackupc.com/", "description": "The biggest student hackathon in Europe", "start_date": "2023-05-12T16:00:00Z", "end_date": "2023-05-14T18:00:00Z", "location": "UPC Campus Nord", "header_image": "https://hackupc.com/ogimage.png", "deleted": false, "open_for_participants": true, "max_participants": 100, "expected_attrition_rate": 0.1, "students_only": true, "age_restrictions": 16}, "status": "Under review", "created_at": "2024-01-09T00:52:29Z", "updated_at": "2024-01-09T00:52:29Z"}]',
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime, timezone

from app.applications.domain.exceptions import ApplicationAlreadyExists
from app.applications.domain.models.application import Application
from app.applications.domain.models.application import Application, ApplicationStatus
from app.applications.infrastructure.persistence.models.orm_application import (
ORMEventApplication,
)
Expand Down Expand Up @@ -30,6 +30,7 @@ def test__given_a_application_with_a_valid_user_and_event__when_create__then_app
id=uuid.UUID("ef6f6fb3-ba12-43dd-a0da-95de8125b1cc"),
user=user,
event=event,
status=ApplicationStatus.PENDING,
created_at=datetime.now(tz=timezone.utc),
updated_at=datetime.now(tz=timezone.utc),
)
Expand All @@ -56,6 +57,7 @@ def test__given_a_application_in_orm_and_another_application_with_the_same_event
id=uuid.UUID("ef6f6fb3-ba12-43dd-a0da-95de8125b1cc"),
user=user,
event=event,
status=ApplicationStatus.PENDING,
created_at=datetime.now(tz=timezone.utc),
updated_at=datetime.now(tz=timezone.utc),
)
Expand All @@ -65,6 +67,7 @@ def test__given_a_application_in_orm_and_another_application_with_the_same_event
id=uuid.UUID("ef6f6fb3-ba14-43dd-a0da-95de8125b1cc"),
user=user,
event=event,
status=ApplicationStatus.PENDING,
created_at=datetime.now(tz=timezone.utc),
updated_at=datetime.now(tz=timezone.utc),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from datetime import datetime, timezone

from app.applications.domain.models.application import Application
from app.applications.domain.models.application import Application, ApplicationStatus
from app.applications.infrastructure.persistence.orm_applications_respository import (
ORMApplicationRepository,
)
Expand Down Expand Up @@ -39,6 +39,7 @@ def test__given_a_application_for_the_event__when_get_by_event__then_return_the_
id=uuid.UUID("ef6f6fb3-ba46-43dd-a0da-95de8125b1cc"),
user=user,
event=event,
status=ApplicationStatus.PENDING,
created_at=datetime.now(tz=timezone.utc),
updated_at=datetime.now(tz=timezone.utc),
)
Expand All @@ -53,5 +54,6 @@ def test__given_a_application_for_the_event__when_get_by_event__then_return_the_
self.assertEqual(application.id, response[0].id)
self.assertEqual(application.user.id, response[0].user.id)
self.assertEqual(application.event.id, response[0].event.id)
self.assertEqual(application.status, response[0].status)
self.assertEqual(application.created_at, response[0].created_at)
self.assertEqual(application.updated_at, response[0].updated_at)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from datetime import timezone, datetime

from app.applications.domain.models.application import Application
from app.applications.domain.models.application import Application, ApplicationStatus
from app.applications.infrastructure.persistence.orm_applications_respository import (
ORMApplicationRepository,
)
Expand Down Expand Up @@ -41,6 +41,7 @@ def test__given_a_application_for_the_user__when_get_by_user__then_return_the_ap
id=uuid.UUID("ef6f6fb3-ba46-43dd-a0da-95de8125b1cc"),
user=user,
event=event,
status=ApplicationStatus.PENDING,
created_at=datetime.now(tz=timezone.utc),
updated_at=datetime.now(tz=timezone.utc),
)
Expand All @@ -55,6 +56,7 @@ def test__given_a_application_for_the_user__when_get_by_user__then_return_the_ap
self.assertEqual(application.id, response[0].id)
self.assertEqual(application.user.id, response[0].user.id)
self.assertEqual(application.event.id, response[0].event.id)
self.assertEqual(application.status, response[0].status)
self.assertEqual(application.created_at, response[0].created_at)
self.assertEqual(application.updated_at, response[0].updated_at)

Expand All @@ -80,6 +82,7 @@ def test__given_a_application_for_the_user_and_another_application_for_another_u
id=uuid.UUID("ef6f6fb3-ba46-43dd-a0da-95de8125b1cc"),
user=user,
event=event,
status=ApplicationStatus.PENDING,
created_at=datetime.now(tz=timezone.utc),
updated_at=datetime.now(tz=timezone.utc),
)
Expand All @@ -88,6 +91,7 @@ def test__given_a_application_for_the_user_and_another_application_for_another_u
id=uuid.UUID("ef6f6fb3-ba46-43dd-a0da-95de8125b1cd"),
user=user2,
event=event,
status=ApplicationStatus.PENDING,
created_at=datetime.now(tz=timezone.utc),
updated_at=datetime.now(tz=timezone.utc),
)
Expand All @@ -103,5 +107,6 @@ def test__given_a_application_for_the_user_and_another_application_for_another_u
self.assertEqual(application.id, response[0].id)
self.assertEqual(application.user.id, response[0].user.id)
self.assertEqual(application.event.id, response[0].event.id)
self.assertEqual(application.status, response[0].status)
self.assertEqual(application.created_at, response[0].created_at)
self.assertEqual(application.updated_at, response[0].updated_at)

0 comments on commit 520f433

Please sign in to comment.