|
@@ -0,0 +1,118 @@
|
|
|
+from fastapi import APIRouter, Form, Depends, HTTPException, File, UploadFile
|
|
|
+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 Guidance_group
|
|
|
+from app.api import deps
|
|
|
+from sqlalchemy.orm import Session
|
|
|
+from typing import Any, Dict
|
|
|
+import secrets
|
|
|
+from fastapi_login.exceptions import InvalidCredentialsException
|
|
|
+from fastapi_login import LoginManager
|
|
|
+from datetime import timedelta,datetime
|
|
|
+from jose import jwt
|
|
|
+from emails.template import JinjaTemplate
|
|
|
+from tortoise.queryset import Q
|
|
|
+from fastapi.responses import HTMLResponse
|
|
|
+
|
|
|
+guidance = APIRouter()
|
|
|
+
|
|
|
+@guidance.get("/get_guidance_group")
|
|
|
+async def get_guidance_group(
|
|
|
+ guidance_group_id : Optional[int] = None
|
|
|
+):
|
|
|
+ try:
|
|
|
+ if guidance_group_id :
|
|
|
+ news_list = await Guidance_group.filter(id=guidance_group_id).all()
|
|
|
+ else:
|
|
|
+ news_list = await Guidance_group.all()
|
|
|
+
|
|
|
+ news_objs = []
|
|
|
+ for news_obj in news_list:
|
|
|
+ news_tmp = {
|
|
|
+ "guidance_group_id": news_obj.id,
|
|
|
+ "name": news_obj.name,
|
|
|
+ "contact_person": news_obj.contact_person,
|
|
|
+ "contact_phone" : news_obj.contact_phone,
|
|
|
+ "line" : news_obj.line,
|
|
|
+ "online_meet" : news_obj.online_meet,
|
|
|
+ "remark" : news_obj.remark
|
|
|
+ }
|
|
|
+ news_objs.append(news_tmp)
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200, "Guidance groups": news_objs}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@guidance.post("/insert_guidance_group")
|
|
|
+async def insert_news(
|
|
|
+ name : str = Form(default=''),
|
|
|
+ contact_person : str = Form(default=''),
|
|
|
+ contact_phone :str = Form(default=''),
|
|
|
+ line : int = Form(default=0),
|
|
|
+ online_meet : int = Form(default=0),
|
|
|
+ remark : str = Form(default='')
|
|
|
+):
|
|
|
+ try:
|
|
|
+
|
|
|
+ new_news = await Guidance_group.create(
|
|
|
+ name=name,
|
|
|
+ contact_person=contact_person,
|
|
|
+ contact_phone=contact_phone,
|
|
|
+ line = line,
|
|
|
+ online_meet = online_meet,
|
|
|
+ remark =remark
|
|
|
+ )
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200, "new_Guidance_group": new_news.id}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@guidance.post("/update_guidance_group")
|
|
|
+async def update_news(
|
|
|
+ guidance_group_id : int = Form(default=None),
|
|
|
+ name : str = Form(default=''),
|
|
|
+ contact_person : str = Form(default=''),
|
|
|
+ contact_phone :str = Form(default=''),
|
|
|
+ line : int = Form(default=None),
|
|
|
+ online_meet : int = Form(default=None),
|
|
|
+ remark : str = Form(default='')
|
|
|
+):
|
|
|
+ try:
|
|
|
+ if not guidance_group_id :
|
|
|
+ return {"msg": "no ID"}
|
|
|
+
|
|
|
+ news_obj = await Guidance_group.get(id=guidance_group_id)
|
|
|
+
|
|
|
+ if name.strip() != '':
|
|
|
+ news_obj.name = name
|
|
|
+
|
|
|
+ if contact_person.strip() != '':
|
|
|
+ news_obj.contact_person = contact_person
|
|
|
+
|
|
|
+ if contact_phone.strip() != '':
|
|
|
+ news_obj.contact_phone = contact_phone
|
|
|
+
|
|
|
+ if line != None:
|
|
|
+ news_obj.line = line
|
|
|
+
|
|
|
+ if online_meet != None:
|
|
|
+ news_obj.online_meet = online_meet
|
|
|
+
|
|
|
+ if remark.strip() != '':
|
|
|
+ news_obj.remark = remark
|
|
|
+
|
|
|
+ await news_obj.save()
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@guidance.post("/delete_guidance_group")
|
|
|
+async def delete_guidance_group(guidance_group_id: Optional[int] = None):
|
|
|
+ if guidance_group_id :
|
|
|
+ await Guidance_group.filter(id=guidance_group_id).delete()
|
|
|
+ return {"msg": "success", "code": 200}
|
|
|
+ else :
|
|
|
+ return {"msg": "please input ID", "code": 200}
|