---
# System prepended metadata

title: API
tags: [' API', backend]

---

---
tags: backend, API
---
# API
## 取得請假紀錄
- [name=brian]

Path: `/api/v1/record`
Request:
| Method | Header                                |
|:------:|:------------------------------------- |
|  POST   | authorization: Bearer "\<JWT TOKEN\>" |


body:
```
{
  "paging": {
    "offset": 0,
    "limit": 0
  },
  "search": {},
  "filter": {
    "status": all、approved、pending、refused
  },
  "order": {
    "column": "created_at",
    "direction": "ASC"
  }
}
```


Response:
- Status code 200
```json!
{
   "code":0,
   "msg":"SUCCESS",
   "data":{
      "hasNextPage":true,
      "records":[
         {
            "uuid":"3c4ea096-e04f-40f1-8911-6846f1084979",
            "name":"資料庫",
            "code":"1234",
            "date":"2022/10/18",
            "weekday":4,
            "sessions":[
               5,
               6,
               7
            ],
            "teacher":"大衛",
            "leaveType":"病假",
            "status":"approved",
            "sendTime":"2022/10/17 12:30"
         }
      ]
   }
}
``` 
status:
approved
pending
refused
            


## 判斷登入
- [name=yaya]

Path: `/api/v1/login`
Request:
| Method | Header                                                                  |request body                                  |
|:------:|:-----------------------:|:---------------------------------------------------------------------------------------------|
|  POST  |     |```{"studentId": "test1","password": "1"}   ```|


Response:
- Status code 200
```json!
{
    "code": 0, 
    "msg": "SUCCESS", 
    "data": 
      { 
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZDRlOGQ5YTA2MWMxYTJjMDIxY2JlMTgiLCJpYXQiOjE1NjU4NTczMjAsImV4cCI6MTU2NTk0MzcyMH0.GQVyQJLmwXd2jQZsjZ8n6cAWD0HQGjvlp2Mk8kAsGy8", 
        "studentId": "U10816014", 
      }
    
}
``` 
- Status code 401
```json!
{
  "code": 11002,
  "msg": "帳號或密碼錯誤，請重新輸入",
  "data": []
}
{
  "code": 11006, 
  "msg": "帳號或密碼為空，請重新輸入",
  "data": []
}
``` 
- Status code 403
```json!
{
  "code": 11003,
  "msg": "Suspended account",
  "data": []
}
```  
- Status code 504
```json!
{
  "code": 11004,
  "msg": "Timeout",
  "data": []
}
```  
- Status code 500
```json!
{
  "code": 11005,
  "msg": "Other",
  "data": []
}
```

## 取得請假類別
- [name=nick]

Path: `/api/v1/leave-type`
Request:
| Method | Header |
|:------:|:------ |
|  GET   |        |

Response:
- Status code 200
```json!
{
    "code": 0,
    "msg": "SUCCESS",
    "data": {
        "11": {
            "name": "早退",
            "shortName": "退"
        },
        "21": {
            "name": "事假",
            "shortName": "事"
        },
        "22": {
            "name": "病假",
            "shortName": "病"
        }, ...
    }
}
``` 



## 取得課程
- [name=brian]

Path: `/api/v1/course?search_date=2022/10/18`
Request:
| Method | Header                                | Params                    |
|:------:|:------------------------------------- |:------------------------- |
|  GET   | authorization: Bearer "\<JWT TOKEN\>" | search_date: "2022/10/18" |

Response:
- Status code 200
```json!
{
   "code":0,
   "msg":"SUCCESS",
   "data":[
       {
            "name":"資料庫",
            "academic_year":"111",
            "semester":"1",
            "code":"1234",
            "date":"2022/10/18",
            "weekday":4,
            "sessions":[
               5,
               6,
               7
            ],
         }
   ]
}
``` 

- semester:學期
    - 上學期: 1 
    - 下學期: 2
    - 暑假: 5
    - 寒假: 6
- year: 學年
- leave_type code mapping:

| 假別代碼 | 假別名稱 | 假別簡稱 |
|:--------:|:-------- |:-------- |
|    0     |          |          |
|    11    | 早退     | 退       |
|    21    | 事假     | 事       |
|    22    | 病假     | 病       |
|    23    | 公假     | 公       |
|    24    | 喪假     | 喪       |
|    25    | 婚假     | 婚       |
|    26    | 孕(產)假 | 產       |
|    27    | 哺育假   | 哺       |
|    28    | 防疫假   | 疫       |
|    29    | 公傷假   | 傷       |
|    30    | 生理假   | 生       |
|    51    | 請假     | 假       |
|    52    | 疫苗假   | 苗       |


## post leave apply
- [name=yaya]
Path: `/api/v1/leave-apply`
Request:

| Method | Header |
|:------:|:------ |
|  POST  | authorization: Bearer “<JWT TOKEN>”   |

```json!
{
  "course": {
    "name": "string",
    "academicYear": 111,
    "semester": 1,
    "courseCode": "0010",
    "sessions": [
      0
    ]
  },
  "date": "202/12/28",
  "leaveType": "公傷假",
  "reason": "string"
}
```

Response:
- Status code 200
```json!
{
  "code": 0,
  "msg": "SUCCESS",
  "data": []
}
```
- Status code 500
```json!
{
  "code": 8,
  "msg": "已經有該天該節課申請資料",
  "data": []
}
```
備註:
- code:8
    -msg:"已經有該天該節課申請資料" 
    -msg:"session not matched" 
    -msg:"course not matched" 
    -msg:"leave type not matched" 
   
    
## logout
    
- [name=yaya]
Path: `/api/v1/logout`
    
Request:
    
| Method | Header |
|:------:|:------ |
|  POST  | authorization:“<JWT TOKEN>”   |

Response:
- Status code 200
```json!
{
  "code": 0,
  "msg": "SUCCESS",
  "data": []
}
```    
    

    

