|
@@ -4,7 +4,7 @@ from typing import List,Optional,Union
|
|
|
from fastapi.responses import FileResponse
|
|
|
from random import randint
|
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
|
-from app.models.models import Registration,User,User_information,Class_list,Class_name,Schools,Class_date
|
|
|
+from app.models.models import Registration,User,User_information,Class_list,Class_name,Schools,Class_date,User_resume
|
|
|
from app.api import deps
|
|
|
from sqlalchemy.orm import Session
|
|
|
from typing import Any, Dict
|
|
@@ -21,6 +21,24 @@ from app.api.users import manager
|
|
|
|
|
|
registration = APIRouter()
|
|
|
|
|
|
+IMAGEDIR = "/var/www/ntcri/assets/resume_pic/"
|
|
|
+IMAGEDIR_short = "assets/resume_pic/"
|
|
|
+
|
|
|
+
|
|
|
+@registration.post("/upload_user_resume_imgs")
|
|
|
+async def create_upload_files(files:Optional[List[UploadFile]] = File(None)):
|
|
|
+ files_url = []
|
|
|
+ if files :
|
|
|
+ for file in files:
|
|
|
+ contents = await file.read()
|
|
|
+
|
|
|
+ #save the file
|
|
|
+ with open(f"{IMAGEDIR}{file.filename}", "wb") as f:
|
|
|
+ f.write(contents)
|
|
|
+ files_url.append(f"{IMAGEDIR_short}{file.filename}" )
|
|
|
+
|
|
|
+ return files_url
|
|
|
+
|
|
|
async def check_token(access_token: str):
|
|
|
|
|
|
result = await User.filter(token=access_token).first()
|
|
@@ -390,4 +408,89 @@ async def delete_registration(
|
|
|
|
|
|
return {"msg": msg , "code": 200}
|
|
|
except Exception as e:
|
|
|
- return {"msg": str(e), "code": 500}
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@registration.post("/input_user_resume")
|
|
|
+async def input_user_resume(
|
|
|
+ user_id = Depends(check_token),
|
|
|
+ teacher_name : str = Form(default=''),
|
|
|
+ work_type : str = Form(default=''),
|
|
|
+ experience : str = Form(default=''),
|
|
|
+ expertise : str = Form(default=''),
|
|
|
+ license : str = Form(default=''),
|
|
|
+ media : str = Form(default=''),
|
|
|
+ imgs : str = Form(default='[]'),
|
|
|
+ introduction: str = Form(default='')
|
|
|
+):
|
|
|
+ try:
|
|
|
+ if not user_id :
|
|
|
+ return {"msg": "please log in", "code": 200}
|
|
|
+
|
|
|
+ msg = ''
|
|
|
+
|
|
|
+ user_resume, created = await User_resume.get_or_create(
|
|
|
+ user_id = user_id,
|
|
|
+ defaults = {
|
|
|
+ "teacher_name": teacher_name,
|
|
|
+ "work_type": work_type,
|
|
|
+ "experience": experience,
|
|
|
+ "expertise": expertise,
|
|
|
+ "license": license,
|
|
|
+ "media": media,
|
|
|
+ "imgs": imgs,
|
|
|
+ "introduction": introduction
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if not created:
|
|
|
+
|
|
|
+ if teacher_name.strip() != '' :
|
|
|
+ user_resume.teacher_name = teacher_name
|
|
|
+
|
|
|
+ if work_type.strip() != '' :
|
|
|
+ user_resume.work_type= work_type
|
|
|
+
|
|
|
+ if experience.strip() != '' :
|
|
|
+ user_resume.experience= experience
|
|
|
+
|
|
|
+ if license.strip() != '' :
|
|
|
+ user_resume.license= license
|
|
|
+
|
|
|
+ if media.strip() != '' :
|
|
|
+ user_resume.media= media
|
|
|
+
|
|
|
+ if imgs | imgs.strip() != '[]' :
|
|
|
+ user_resume.imgs= imgs
|
|
|
+
|
|
|
+ if introduction.strip() != '' :
|
|
|
+ user_resume.introduction= introduction
|
|
|
+
|
|
|
+ await user_resume.save()
|
|
|
+
|
|
|
+ msg = "Update success"
|
|
|
+
|
|
|
+ else :
|
|
|
+ msg = "input success"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return {"msg": msg , "code": 200}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+
|
|
|
+@registration.get("/get_user_resume")
|
|
|
+async def get_user_resume(
|
|
|
+ user_id = Depends(check_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ if not user_id :
|
|
|
+ return {"msg": "please log in", "code": 200}
|
|
|
+
|
|
|
+ user_resume = await User_resume.get(user_id = user_id)
|
|
|
+
|
|
|
+ data = user_resume.show_data()
|
|
|
+
|
|
|
+ return {"msg": "success" , "code": 200,"user_resume":data}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|