Ver Fonte

新增課程報名時間Table

Mia Cheng há 1 ano atrás
pai
commit
b9fdc49c6c
4 ficheiros alterados com 89 adições e 33 exclusões
  1. 3 3
      app/api/article.py
  2. 76 27
      app/api/classes.py
  3. 1 1
      app/api/news.py
  4. 9 2
      app/models/models.py

+ 3 - 3
app/api/article.py

@@ -18,7 +18,7 @@ from fastapi.responses import HTMLResponse
 
 article = APIRouter()
 
-IMAGEDIR = "/var/www/ntcri/ntcri/assets/article_files/"
+IMAGEDIR = "/var/www/ntcri/assets/article_files/"
 IMAGEDIR_short = "assets/article_files/"
 
 async def create_upload_files(files:Optional[List[UploadFile]] = File(None)):
@@ -84,7 +84,7 @@ async def get_article(
             "depiction" : article_obj.depiction,
             "content" : article_obj.content,
             "files" : article_obj.files,
-            "vedio_url" : article_obj.vedio_url,
+            "video_url" : article_obj.vedio_url,
             "tags" : article_obj.tags,
             "cover_img": article_obj.cover_img,
             "url" : article_obj.url
@@ -267,7 +267,7 @@ async def search_article_like(keyword: str,page_num : Optional[int] = None,
             "depiction" : article_obj.depiction,
             "content" : article_obj.content,
             "files" : article_obj.files,
-            "vedio_url" : article_obj.vedio_url,
+            "video_url" : article_obj.vedio_url,
             "tags" : article_obj.tags,
             "cover_img": article_obj.cover_img,
             "url" : article_obj.url

+ 76 - 27
app/api/classes.py

@@ -3,7 +3,7 @@ from typing import List,Optional
 from fastapi.responses import FileResponse
 from random import randint
 from fastapi.security import OAuth2PasswordRequestForm
-from app.models.models import User,Favorite_course,Article_list
+from app.models.models import User,Favorite_course,Article_list,Class_date
 from app.models.models import Class_list,Schools,Class_detail,Class_name,Registration,Group_name,Online_course
 from app.api import deps
 from sqlalchemy.orm import Session
@@ -35,7 +35,7 @@ async def check_token(access_token: str):
 
     return user_id
 
-IMAGEDIR = "/var/www/ntcri/ntcri/assets/"
+IMAGEDIR = "/var/www/ntcri/assets/"
 IMAGEDIR_short = "assets/"
 
 async def update_location_time(location_id: int):
@@ -117,7 +117,9 @@ async def insert_event(
     people : str = Form(default=''),
     fee_method: str = Form(default=''),
     registration_way: str = Form(default=''),
-    registration_day: str = Form(default=''),
+    registration_start:  datetime = Form(default=datetime.now()),
+    registration_end:  datetime = Form(default=datetime.now()),
+    number_limit: int = Form(default=0),
     remark : str = Form(default='')
 ):    
     try:
@@ -140,10 +142,17 @@ async def insert_event(
             people=people,
             fee_method=fee_method,
             registration_way=registration_way,
-            registration_day=registration_day,
             remark=remark
         )
 
+        await Class_date.create(
+            class_list_id = new_class.id,
+            registration_start = registration_start,
+            registration_end = registration_end,
+            number_limit = number_limit,
+            amount_left = number_limit
+        )
+
         return {"msg": "success", "code": 200, "class_id": new_class.id}
     except Exception as e:
         return {"msg": str(e), "code": 500}
@@ -272,7 +281,9 @@ async def update_event(
     people : str = Form(default=''),
     fee_method: str = Form(default=''),
     registration_way: str = Form(default=''),
-    registration_day:  str = Form(default=''),
+    registration_start:  datetime = Form(default=datetime.now()),
+    registration_end:  datetime = Form(default=datetime.now()),
+    number_limit: int = Form(default=0),
     remark :  str = Form(default='')
 ):
     try:
@@ -314,13 +325,23 @@ async def update_event(
         if registration_way.strip() != '':
             class_obj.registration_way = registration_way
 
-        if registration_day.strip() != '':
-            class_obj.registration_day = registration_day
-
         if remark.strip() != '':
             class_obj.remark = remark
+
+        class_date_obj = await Class_date.get(class_list_id=id)
+
+        if registration_start != datetime.now():
+            class_date_obj.registration_start = registration_start
+
+        if registration_end != datetime.now():
+            class_date_obj.registration_end = registration_end
+
+        if number_limit != 0:
+            class_date_obj.number_limit = number_limit
         
         await class_obj.save()
+        await class_date_obj.save()
+
         return {"msg": "success", "code": 200}
     except Exception as e:
         return {"msg": str(e), "code": 500}
@@ -374,6 +395,7 @@ async def delete(id: int):
     if id:
         await Class_detail.filter(class_list_id=id).delete()
         await Class_list.filter(id=id).delete()
+        await Class_date.filter(class_list_id=id).delete()
         return {"msg": "success", "code": 200}
     
 @classes.post("/delete_class_name")
@@ -382,9 +404,11 @@ async def delete(id: int):
         class_event_list = await Class_list.filter(name_id=id).all()
         for class_event_obj in class_event_list:
             await Class_detail.filter(class_list_id=class_event_obj.id).delete()
+            await Class_date.filter(class_list_id=class_event_obj.id).delete()
 
         await Class_list.filter(name_id=id).delete()
         await Class_name.filter(id=id).delete()
+        
         return {"msg": "success", "code": 200}
 
 @classes.get("/get_event")
@@ -405,25 +429,50 @@ async def search_event(
             class_name_obj = await Class_name.get(id=class_obj.name_id)
             class_name = class_name_obj.name
 
-            class_data = {
-            "class_name" : class_name,
-            "event_id": class_obj.id,
-            "name_id": class_obj.name_id,
-            "event": class_obj.event,
-            "start_time": class_obj.start_time,
-            "end_time": class_obj.end_time,
-            "location": class_obj.location,
-            "lecturer": class_obj.lecturer,
-            "contact": class_obj.contact,
-            "content": class_obj.content,
-            "URL": class_obj.URL,
-            "people": class_obj.people,
-            "fee_method": class_obj.fee_method,
-            "registration_way": class_obj.registration_way,
-            "registration_day": class_obj.registration_day,
-            "remark": class_obj.remark
-        }
-            classes.append(class_data)
+            try:
+                class_date_obj = await Class_date.get(class_list_id=class_obj.id)
+                class_data = {
+                    "class_name" : class_name,
+                    "event_id": class_obj.id,
+                    "name_id": class_obj.name_id,
+                    "event": class_obj.event,
+                    "start_time": class_obj.start_time,
+                    "end_time": class_obj.end_time,
+                    "location": class_obj.location,
+                    "lecturer": class_obj.lecturer,
+                    "contact": class_obj.contact,
+                    "content": class_obj.content,
+                    "URL": class_obj.URL,
+                    "people": class_obj.people,
+                    "fee_method": class_obj.fee_method,
+                    "registration_way": class_obj.registration_way,
+                    "registration_start": class_date_obj.registration_start,
+                    "registration_end": class_date_obj.registration_end,
+                    "number_limit": class_date_obj.number_limit,
+                    "amount_left": class_date_obj.amount_left,
+                    "remark": class_obj.remark
+                }
+                classes.append(class_data)
+            except:
+
+                class_data = {
+                    "class_name" : class_name,
+                    "event_id": class_obj.id,
+                    "name_id": class_obj.name_id,
+                    "event": class_obj.event,
+                    "start_time": class_obj.start_time,
+                    "end_time": class_obj.end_time,
+                    "location": class_obj.location,
+                    "lecturer": class_obj.lecturer,
+                    "contact": class_obj.contact,
+                    "content": class_obj.content,
+                    "URL": class_obj.URL,
+                    "people": class_obj.people,
+                    "fee_method": class_obj.fee_method,
+                    "registration_way": class_obj.registration_way,
+                    "remark": class_obj.remark
+                }
+                classes.append(class_data)
 
         return {"msg": "success", "code": 200, "classes": classes}
     except Exception as e:

+ 1 - 1
app/api/news.py

@@ -18,7 +18,7 @@ from fastapi.responses import HTMLResponse
 
 news = APIRouter()
 
-IMAGEDIR = "/var/www/ntcri/ntcri/assets/news_files/"
+IMAGEDIR = "/var/www/ntcri/assets/news_files/"
 IMAGEDIR_short = "assets/news_files/"
 
 @news.get("/get_news")

+ 9 - 2
app/models/models.py

@@ -78,7 +78,6 @@ class Class_list(Model):
     fee_method = fields.CharField(max_length=255, description="收費方式")
     registration_way = fields.CharField(max_length=255, description="報名方式")
     remark = fields.TextField(description="備註")
-    registration_day = fields.CharField(max_length=255, description="報名時間")
 
 
 class Class_detail(Model):
@@ -168,4 +167,12 @@ class User_information(Model):
     gender = fields.CharField(max_length=45, description="性別")
     phone = fields.CharField(max_length=45, description="電話")
     email = fields.CharField(max_length=45, description="信箱")
-    is_default = fields.IntField(description="是否為預設")
+    is_default = fields.IntField(description="是否為預設")
+
+class Class_date(Model):
+    id = fields.IntField(pk=True)
+    class_list_id = fields.IntField(description="場次ID")
+    registration_start = fields.DatetimeField(description="報名時間開始")
+    registration_end = fields.DatetimeField(description="報名時間結束")
+    number_limit = fields.IntField(description="名額")
+    amount_left = fields.IntField(description="剩餘名額")