Skip to content

Commit

Permalink
Migrated by manually
Browse files Browse the repository at this point in the history
Signed-off-by: Toomore Chiang <[email protected]>
  • Loading branch information
toomore committed Jan 23, 2025
1 parent 7b86617 commit df3363d
Show file tree
Hide file tree
Showing 27 changed files with 262 additions and 275 deletions.
12 changes: 6 additions & 6 deletions api/routers/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def members_past(
_user = chiefs_infos[uid]
h_msg = hashlib.md5()
h_msg.update(_user['oauth']['email'].encode('utf-8'))
data_chiefs.append(MembersInfo.parse_obj({
data_chiefs.append(MembersInfo.model_validate({
'name': _user['profile']['badge_name'],
'email_hash': h_msg.hexdigest(),
}))
Expand All @@ -60,12 +60,12 @@ async def members_past(
for _user in User.get_info(uids=list(uids)).values():
h_msg = hashlib.md5()
h_msg.update(_user['oauth']['email'].encode('utf-8'))
data_members.append(MembersInfo.parse_obj({
data_members.append(MembersInfo.model_validate({
'name': _user['profile']['badge_name'],
'email_hash': h_msg.hexdigest(),
}))

result.data.append(MembersTeams.parse_obj(
result.data.append(MembersTeams.model_validate(
{'name': team.name, 'tid': team.id,
'chiefs': data_chiefs, 'members': data_members}
))
Expand Down Expand Up @@ -103,7 +103,7 @@ async def members(
user = chiefs_infos[uid]
h_msg = hashlib.md5()
h_msg.update(user['oauth']['email'].encode('utf-8'))
data_chiefs.append(MembersInfo.parse_obj({
data_chiefs.append(MembersInfo.model_validate({
'name': user['profile']['badge_name'],
'email_hash': h_msg.hexdigest(),
}))
Expand All @@ -119,12 +119,12 @@ async def members(
for user in User.get_info(uids=list(uids)).values():
h_msg = hashlib.md5()
h_msg.update(user['oauth']['email'].encode('utf-8'))
data_members.append(MembersInfo.parse_obj({
data_members.append(MembersInfo.model_validate({
'name': user['profile']['badge_name'],
'email_hash': h_msg.hexdigest(),
}))

result.data.append(MembersTeams.parse_obj(
result.data.append(MembersTeams.model_validate(
{'name': team.name, 'tid': team.id,
'chiefs': data_chiefs, 'members': data_members}
))
Expand Down
39 changes: 18 additions & 21 deletions api/routers/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
from fastapi import APIRouter, Depends, HTTPException, Path, status

from api.apistructs.items import ProjectItem, TeamItem
from api.apistructs.projects import (ProjectAllOut, ProjectCreateInput,
ProjectCreateOutput,
ProjectItemUpdateInput,
ProjectItemUpdateOutput,
from api.apistructs.projects import (ProjectAllOut, ProjectCreateInput, ProjectCreateOutput,
ProjectItemUpdateInput, ProjectItemUpdateOutput,
ProjectSettingTrafficSubsidyInput,
ProjectSettingTrafficSubsidyOutput,
ProjectTeamDietaryHabitOutput,
ProjectTeamsOutput)
ProjectTeamDietaryHabitOutput, ProjectTeamsOutput)
from api.apistructs.teams import TeamCreateInput, TeamCreateOutput
from api.dependencies import get_current_user
from module.dietary_habit import DietaryHabitItemsName, DietaryHabitItemsValue
Expand Down Expand Up @@ -41,10 +38,10 @@ async def projects_all(current_user: dict[str, Any] = Depends(get_current_user))
datas = []
for data in Project.all():
if current_user['uid'] in data.owners:
datas.append(ProjectItem.parse_obj(data))
datas.append(ProjectItem.model_validate(data))
else:
datas.append(
ProjectItem.parse_obj({
ProjectItem.model_validate({
'id': data.id,
'name': data.name,
'desc': data.desc,
Expand All @@ -68,10 +65,10 @@ async def projects_create(
if current_user['uid'] not in API_DEFAULT_OWNERS:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)

data = create_date.dict()
data = create_date.model_dump()
data['owners'] = API_DEFAULT_OWNERS
result = Project.create(**data)
return ProjectCreateOutput.parse_obj(result)
return ProjectCreateOutput.model_validate(result)


@router.patch('/{pid}',
Expand Down Expand Up @@ -105,9 +102,9 @@ async def projects_one_update(
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)

result = Project.update(pid=pid,
data=ProjectBaseUpdate.parse_obj(update_data))
data=ProjectBaseUpdate.model_validate(update_data))

return ProjectItemUpdateOutput.parse_obj(result)
return ProjectItemUpdateOutput.model_validate(result)


@router.get('/{pid}/teams',
Expand All @@ -125,9 +122,9 @@ async def projects_teams(
''' Lists of teams in project '''
teams = []
for team in Team.list_by_pid(pid=pid):
teams.append(TeamItem.parse_obj(team))
teams.append(TeamItem.model_validate(team))

return ProjectTeamsOutput.parse_obj({'teams': teams})
return ProjectTeamsOutput.model_validate({'teams': teams})


@router.post('/{pid}/teams',
Expand Down Expand Up @@ -155,7 +152,7 @@ async def projects_teams_create(
result = Team.create(
pid=pid, tid=create_date.id, name=create_date.name, owners=project.owners)

return TeamCreateOutput.parse_obj(result)
return TeamCreateOutput.model_validate(result)


@router.get('/{pid}/teams/dietary_habit',
Expand Down Expand Up @@ -199,10 +196,10 @@ async def projects_teams_dietary_habit(
datas = []
for habit, count in habit_count.items():
datas.append(
ProjectTeamDietaryHabitOutput.parse_obj({'name': dietary_habit_info[habit],
'count': count,
'code': habit,
}))
ProjectTeamDietaryHabitOutput.model_validate({'name': dietary_habit_info[habit],
'count': count,
'code': habit,
}))

return datas

Expand Down Expand Up @@ -235,7 +232,7 @@ async def projects_traffic(
if current_user['uid'] not in project.owners:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)

return ProjectSettingTrafficSubsidyOutput.parse_obj({
return ProjectSettingTrafficSubsidyOutput.model_validate({
'datas': FormTrafficFeeMapping.get(pid=pid)})


Expand Down Expand Up @@ -270,4 +267,4 @@ async def projects_traffic_update(

result = FormTrafficFeeMapping.save(pid=pid, datas=update_data.datas)

return ProjectSettingTrafficSubsidyOutput.parse_obj({'datas': result})
return ProjectSettingTrafficSubsidyOutput.model_validate({'datas': result})
19 changes: 9 additions & 10 deletions api/routers/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import io
from typing import Any

from fastapi import (APIRouter, Depends, File, HTTPException, Path, UploadFile,
status)
from fastapi import APIRouter, Depends, File, HTTPException, Path, UploadFile, status
from pydantic import BaseModel, Field

from api.apistructs.sender import SenderCampaignLists
Expand Down Expand Up @@ -37,15 +36,15 @@ async def sender_all(
if not team:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)

teamusers = TeamUsers.parse_obj(team)
teamusers = TeamUsers.model_validate(team)
if current_user['uid'] not in (teamusers.owners + teamusers.chiefs + teamusers.members):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)

campaigns = []
for campaign in SenderCampaign.get_list(pid=pid, tid=tid):
campaigns.append(campaign)

return SenderCampaignLists.parse_obj({'datas': campaigns})
return SenderCampaignLists.model_validate({'datas': campaigns})


class UploadReceiverOutput(BaseModel):
Expand Down Expand Up @@ -98,14 +97,14 @@ async def sender_upload_receiver_lists_replace(
if not team:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)

teamusers = TeamUsers.parse_obj(team)
teamusers = TeamUsers.model_validate(team)
if current_user['uid'] not in (teamusers.owners + teamusers.chiefs + teamusers.members):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)

csv_rows = await sender_upload_receiver(pid=pid, tid=tid, cid=cid,
file=file, upload_type='replace')

return UploadReceiverOutput.parse_obj({'rows': csv_rows})
return UploadReceiverOutput.model_validate({'rows': csv_rows})


@router.patch('/{pid}/{tid}/{cid}/receiver/lists',
Expand All @@ -128,14 +127,14 @@ async def sender_upload_receiver_lists_update(
if not team:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)

teamusers = TeamUsers.parse_obj(team)
teamusers = TeamUsers.model_validate(team)
if current_user['uid'] not in (teamusers.owners + teamusers.chiefs + teamusers.members):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)

csv_rows = await sender_upload_receiver(pid=pid, tid=tid, cid=cid,
file=file, upload_type='update')

return UploadReceiverOutput.parse_obj({'rows': csv_rows})
return UploadReceiverOutput.model_validate({'rows': csv_rows})


@router.delete('/{pid}/{tid}/{cid}/receiver/lists',
Expand All @@ -156,9 +155,9 @@ async def sender_upload_receiver_lists_delete(
if not team:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)

teamusers = TeamUsers.parse_obj(team)
teamusers = TeamUsers.model_validate(team)
if current_user['uid'] not in (teamusers.owners + teamusers.chiefs + teamusers.members):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)

return UploadReceiverOutput.parse_obj({
return UploadReceiverOutput.model_validate({
'rows': SenderReceiver.remove(pid=pid, cid=cid)})
27 changes: 13 additions & 14 deletions api/routers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
from fastapi import APIRouter, Depends, HTTPException, Path, Request, status

from api.apistructs.items import UserItem
from api.apistructs.tasks import (TaskAttendeeInput, TaskCreateInput,
TaskCreateOutput, TaskGetAttendeeOutput,
TaskGetOutput, TaskMeJoinOutput,
from api.apistructs.tasks import (TaskAttendeeInput, TaskCreateInput, TaskCreateOutput,
TaskGetAttendeeOutput, TaskGetOutput, TaskMeJoinOutput,
TasksGetAllOutput, TaskUpdateInput)
from api.dependencies import get_current_user
from module.project import Project
Expand Down Expand Up @@ -50,13 +49,13 @@ async def tasks_all(

datas = []
for task in Tasks.get_by_pid(pid=pid):
task_data = TaskItem.parse_obj(task)
task_data = TaskItem.model_validate(task)
if not is_in_project:
task_data.people = []

datas.append(task_data)

return TasksGetAllOutput.parse_obj({'datas': datas})
return TasksGetAllOutput.model_validate({'datas': datas})


@router.post('/{pid}',
Expand Down Expand Up @@ -90,14 +89,14 @@ async def tasks_create(
if not project:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)

data = update_data.dict()
data = update_data.model_dump()
data['pid'] = pid
data['created_by'] = current_user['uid']
task_item = TaskItem.parse_obj(data)
task_item = TaskItem.model_validate(data)
raw = Tasks.add(pid=pid,
body=task_item.dict(by_alias=True))
body=task_item.model_dump(by_alias=True))

return TaskCreateOutput.parse_obj(raw)
return TaskCreateOutput.model_validate(raw)


@router.get('/{pid}/{task_id}',
Expand Down Expand Up @@ -134,7 +133,7 @@ async def tasks_get(
if not is_in_project:
task_data['people'] = []

return TaskGetOutput.parse_obj(task_data)
return TaskGetOutput.model_validate(task_data)


@router.patch('/{pid}/{task_id}',
Expand Down Expand Up @@ -172,13 +171,13 @@ async def tasks_update(
if not is_in_project:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)

data = update_data.dict(exclude_none=True)
data = update_data.model_dump(exclude_none=True)
data['_id'] = task_id
data['pid'] = pid

if data:
raw = Tasks.add(pid=pid, body=data)
return TaskGetOutput.parse_obj(raw)
return TaskGetOutput.model_validate(raw)

raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE)

Expand Down Expand Up @@ -292,13 +291,13 @@ async def tasks_users_add(
if user_infos:
for uid in task_data['people']:
if uid in user_infos:
result.append(UserItem.parse_obj({
result.append(UserItem.model_validate({
'id': uid,
'badge_name': user_infos[uid]['profile']['badge_name'],
'avatar': user_infos[uid]['oauth']['picture'],
}))

return TaskGetAttendeeOutput.parse_obj({'datas': result})
return TaskGetAttendeeOutput.model_validate({'datas': result})

if update_data is not None:
if request.method == 'PATCH':
Expand Down
Loading

0 comments on commit df3363d

Please sign in to comment.