shri-jai commited on
Commit
f5bcfa6
·
1 Parent(s): 853fb59

feat: updated emotion tag

Browse files
Files changed (3) hide show
  1. src/core/models.py +20 -7
  2. src/home/schemas.py +7 -9
  3. src/home/service.py +1 -0
src/core/models.py CHANGED
@@ -7,7 +7,7 @@ from typing import List, Optional
7
 
8
 
9
  from sqlalchemy.dialects.postgresql import UUID
10
- from sqlalchemy import CheckConstraint, UniqueConstraint, ForeignKey
11
  from sqlmodel import Field, Relationship, SQLModel
12
 
13
 
@@ -17,6 +17,14 @@ class AssetStatus(str, Enum):
17
  ON_REQUEST = "On Request"
18
  IN_SERVICE = "In Service"
19
 
 
 
 
 
 
 
 
 
20
 
21
  class Users(SQLModel, table=True):
22
  __tablename__ = "users"
@@ -81,23 +89,28 @@ class Assets(SQLModel, table=True):
81
  name: str = Field(nullable=False)
82
  type: str = Field(nullable=False)
83
  status: AssetStatus = Field(default=AssetStatus.UNAVAILABLE)
84
- user: "Users" = Relationship(back_populates="asset")
85
 
86
 
87
  class EmotionLogs(SQLModel, table=True):
88
  __tablename__ = "emotion_logs"
89
  __table_args__ = (
90
  UniqueConstraint("user_id", "log_date"),
91
- CheckConstraint("morning_emotion BETWEEN 1 AND 7 or morning_emotion IS NULL"),
92
- CheckConstraint("evening_emotion BETWEEN 1 AND 7 or evening_emotion IS NULL"),
93
  )
94
  id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
95
  user_id: uuid.UUID = Field(
96
- sa_column=Column(UUID(as_uuid=True),
 
97
  ForeignKey("users.id", ondelete="CASCADE"),
98
  nullable=False
99
  )
100
  )
101
- morning_emotion: Optional[int] = Field(default=None, ge=1, le=7)
102
- evening_emotion: Optional[int] = Field(default=None, ge=1, le=7)
 
 
 
 
 
 
103
  log_date: date = Field(default_factory=date.today)
 
7
 
8
 
9
  from sqlalchemy.dialects.postgresql import UUID
10
+ from sqlalchemy import CheckConstraint, UniqueConstraint, ForeignKey, SAEnum
11
  from sqlmodel import Field, Relationship, SQLModel
12
 
13
 
 
17
  ON_REQUEST = "On Request"
18
  IN_SERVICE = "In Service"
19
 
20
+ class Emotion(str, Enum):
21
+ JOYFUL = "joyful"
22
+ HAPPY = "happy"
23
+ CALM = "calm"
24
+ NEUTRAL = "neutral"
25
+ ANXIOUS = "anxious"
26
+ SAD = "sad"
27
+ FRUSTRATED = "frustrated"
28
 
29
  class Users(SQLModel, table=True):
30
  __tablename__ = "users"
 
89
  name: str = Field(nullable=False)
90
  type: str = Field(nullable=False)
91
  status: AssetStatus = Field(default=AssetStatus.UNAVAILABLE)
92
+ user: "Users" = Relationship(back_populatealmosts="asset")
93
 
94
 
95
  class EmotionLogs(SQLModel, table=True):
96
  __tablename__ = "emotion_logs"
97
  __table_args__ = (
98
  UniqueConstraint("user_id", "log_date"),
 
 
99
  )
100
  id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
101
  user_id: uuid.UUID = Field(
102
+ sa_column=Column(
103
+ UUID(as_uuid=True),
104
  ForeignKey("users.id", ondelete="CASCADE"),
105
  nullable=False
106
  )
107
  )
108
+ morning_emotion: Optional[Emotion] = Field(
109
+ default=None,
110
+ sa_column=Column(SAEnum(Emotion, native_enum=False), nullable=True)
111
+ )
112
+ evening_emotion: Optional[Emotion] = Field(
113
+ default=None,
114
+ sa_column=Column(SAEnum(Emotion, native_enum=False), nullable=True)
115
+ )
116
  log_date: date = Field(default_factory=date.today)
src/home/schemas.py CHANGED
@@ -1,22 +1,19 @@
1
- # pylint: disable=no-name-in-module
2
- # pylint: disable=no-self-argument
3
  from datetime import date
4
- from typing import List, Optional, Union
5
-
6
  from pydantic import BaseModel
7
-
8
 
9
  class EmotionLogCreate(BaseModel):
10
  user_id: str
11
- morning_emotion: Optional[int] = None
12
- evening_emotion: Optional[int] = None
13
  log_date: date
14
 
15
 
16
  class EmotionLogResponse(BaseModel):
17
  log_date: date
18
- morning_emotion: Optional[int]
19
- evening_emotion: Optional[int]
20
 
21
 
22
  class HomeResponseData(BaseModel):
@@ -25,6 +22,7 @@ class HomeResponseData(BaseModel):
25
  philosophy_text: str
26
  recent_emotions: List[EmotionLogResponse]
27
 
 
28
  class BroadcastNotificationRequest(BaseModel):
29
  title: str
30
  body: str
 
 
 
1
  from datetime import date
2
+ from typing import List, Optional
 
3
  from pydantic import BaseModel
4
+ from src.core.enums import Emotion
5
 
6
  class EmotionLogCreate(BaseModel):
7
  user_id: str
8
+ morning_emotion: Optional[Emotion] = None
9
+ evening_emotion: Optional[Emotion] = None
10
  log_date: date
11
 
12
 
13
  class EmotionLogResponse(BaseModel):
14
  log_date: date
15
+ morning_emotion: Optional[Emotion]
16
+ evening_emotion: Optional[Emotion]
17
 
18
 
19
  class HomeResponseData(BaseModel):
 
22
  philosophy_text: str
23
  recent_emotions: List[EmotionLogResponse]
24
 
25
+
26
  class BroadcastNotificationRequest(BaseModel):
27
  title: str
28
  body: str
src/home/service.py CHANGED
@@ -46,6 +46,7 @@ async def get_home_data(user_id: str, session: AsyncSession) -> HomeResponseData
46
  async def add_or_update_emotion(
47
  data: EmotionLogCreate, session: AsyncSession
48
  ) -> EmotionLogResponse:
 
49
  user_exists = await session.exec(select(Users).where(Users.id == data.user_id))
50
  if not user_exists.first():
51
  raise ValueError("User not found. Cannot add emotion log.")
 
46
  async def add_or_update_emotion(
47
  data: EmotionLogCreate, session: AsyncSession
48
  ) -> EmotionLogResponse:
49
+
50
  user_exists = await session.exec(select(Users).where(Users.id == data.user_id))
51
  if not user_exists.first():
52
  raise ValueError("User not found. Cannot add emotion log.")