|
@@ -11,6 +11,7 @@ import time
|
|
|
from datetime import datetime
|
|
|
from PIL import Image
|
|
|
import io
|
|
|
+from typing import List
|
|
|
|
|
|
app = FastAPI()
|
|
|
origins = [
|
|
@@ -94,22 +95,30 @@ class Course(BaseModel):
|
|
|
teacher_img: str #teacher user image url form
|
|
|
price: int
|
|
|
price_discount: int
|
|
|
- hours: int
|
|
|
+ hours: float
|
|
|
units: int
|
|
|
-'''
|
|
|
-@app.get("/courses")
|
|
|
+
|
|
|
+@app.post("/get_courses")
|
|
|
async def get_courses(tags:List[int]):
|
|
|
-
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
|
|
|
+ tag_str = '('
|
|
|
+ for t in tags:
|
|
|
+ tag_str = tag_str + str(t) +','
|
|
|
+ tag_str = tag_str[:-1]+')'
|
|
|
+
|
|
|
+
|
|
|
courses = []
|
|
|
-
|
|
|
+ statement = 'SELECT * FROM course_tag '\
|
|
|
+ 'INNER JOIN course on course_tag.course_id=course.id '\
|
|
|
+ 'INNER JOIN tag on course_tag.tag_id = tag.id '\
|
|
|
+ 'WHERE tag.id IN'+tag_str
|
|
|
|
|
|
- statement = 'SELECT * from course_table where id IN'+course_id_string
|
|
|
for row in db.query(statement):
|
|
|
- courses.append({'id':row['id'],'title':row['title'],'url':row['url'],'img':row['img']
|
|
|
- ,'teacher_name':['teacher_name'],'teacher_img':row['teacher_img'],'price':row['price']
|
|
|
- ,'hours':row['hours'],'units':row['units']})
|
|
|
+ courses.append({'id':row['course_id'],'title':row['title'],'url':row['url'],'cover_img':row['cover_img']
|
|
|
+ ,'teacher_name':['teacher_name'],'price':row['price'],'price_discount':row['price_discount'],'profile':row['profile']
|
|
|
+ ,'cover_img':row['cover_img'],'hours':row['hours'],'units':row['units']})
|
|
|
return courses
|
|
|
-'''
|
|
|
+
|
|
|
@app.post("/courses")
|
|
|
async def create_courses(tags: list,course:Course):
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
|
|
@@ -124,25 +133,7 @@ async def create_courses(tags: list,course:Course):
|
|
|
return {'msg':'新增成功'}
|
|
|
|
|
|
|
|
|
-@app.delete("/courses/{course_id}")
|
|
|
-async def delete_course(course_id:int):
|
|
|
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
|
|
|
- sqls = 'DELETE FROM course_table WHERE id = '+str(course_id)
|
|
|
- db.query(sqls)
|
|
|
- sqls = 'DELETE FROM course_tag WHERE course_id = '+str(course_id)
|
|
|
- db.query(sqls)
|
|
|
- return "success"
|
|
|
-
|
|
|
-@app.put("/courses/{course_id}")
|
|
|
-async def update_course(course_id,course:Course):
|
|
|
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/openTalk?charset=utf8mb4')
|
|
|
- sqls = 'UPDATE course_table\
|
|
|
- SET title="'+course.title+'", url="'+course.url+'", hours='+str(course.hours)+',\
|
|
|
- teacher_name="'+course.teacher_name+'", price='+str(course.price)+', units='+str(course.units)+'\
|
|
|
- WHERE id='+str(course_id)+';'
|
|
|
- db.query(sqls)
|
|
|
- course.id=course_id
|
|
|
- return course
|
|
|
+
|
|
|
|
|
|
|
|
|
|