Skip to content

Commit

Permalink
Modifica funcao para alterar o historico
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielhrlima committed Aug 8, 2024
1 parent d9894c0 commit 27dae8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/controller/recordController.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

@Record.post("/")
def add_to_record(record: recordSchema.RecordCreate, db: Session = Depends(get_db)):
return recordRepository.create_record(db=db, record=record)
record_user = recordSchema.RecordGet(user_id =record.user_id)
videos = recordRepository.get_record(db = db , record = record_user)
if videos:
return recordRepository.create_record(db=db, record=record, is_creat= False)

return recordRepository.create_record(db=db, record=record, is_creat= True)

@Record.get("/get_record")
def check_record(user_id: str =Query(...) , db: Session = Depends(get_db)):
Expand Down
25 changes: 19 additions & 6 deletions src/repository/recordRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@
from model import recordModel
from fastapi import HTTPException

def create_record(db: Session, record: recordSchema.RecordCreate):
db_record = recordModel.Record(
user_id=record.user_id.strip(),
videos=record.videos
)
db.add(db_record)
def create_record(db: Session, record: recordSchema.RecordCreate, is_creat):
if is_creat == True:
db_record = recordModel.Record(
user_id=record.user_id.strip(),
videos=record.videos
)
db.add(db_record)
else:
db_record = db.query(recordModel.Record).filter(recordModel.Record.user_id == record.user_id).first()

id_video = list(record.videos.keys())[0]
timestamp_video = list(record.videos.values())[0]

video_append = db_record.videos.copy()
video_append[id_video] = timestamp_video
print(video_append)

db_record.videos = video_append

db.commit()
db.refresh(db_record)
print(f"Created record: user_id={db_record.user_id}")
Expand Down

0 comments on commit 27dae8a

Please sign in to comment.