Skip to content

Commit

Permalink
add interface to grewhistory service
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed May 24, 2024
1 parent 1752a56 commit 555f7d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
16 changes: 4 additions & 12 deletions app/history/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from app.projects.service import ProjectService
from .service import HistoryService
from .schema import GrewHistorySchema
from .interface import GrewHistoryInterface

api = Namespace(
"History",
Expand All @@ -25,7 +26,7 @@ def get(self, project_name):
@responds(schema=GrewHistorySchema, api=api)
def post(self, project_name):
project = ProjectService.get_by_name(project_name)
data = request.get_json()
data: GrewHistoryInterface = request.parsed_obj
data["project_id"] = project.id
data["user_id"] = current_user.id
new_history_record = HistoryService.create(data)
Expand All @@ -42,7 +43,7 @@ class HistoryRecordResource(Resource):

@responds(schema=GrewHistorySchema, api=api)
def put(self, project_name, history_uuid):
changes = request.get_json()
changes: GrewHistoryInterface = request.get_json()
project = ProjectService.get_by_name(project_name)
history_record = HistoryService.get_by_uuid(project.id, history_uuid)
updated_record = HistoryService.update(history_record, changes)
Expand All @@ -54,13 +55,4 @@ def delete(self, project_name, history_uuid):
HistoryService.delete_by_id(history_record.id)
return { "status": "ok" }












11 changes: 11 additions & 0 deletions app/history/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from mypy_extensions import TypedDict

class GrewHistoryInterface(TypedDict, total=False):
id: int
uuid: str
request: str
type: str
favorite: bool
date: int
modified_sentences: int

2 changes: 1 addition & 1 deletion app/history/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class GrewHistorySchema(Schema):
type = fields.String(attribute="type")
favorite = fields.Boolean(attribute="favorite")
date = fields.Integer(attribute="date")
modified_sentences = fields.Integer(attribute="modified_sentences")
modifiedSentences = fields.Integer(attribute="modified_sentences")

0 comments on commit 555f7d0

Please sign in to comment.