---
# System prepended metadata

title: Backend Flow
tags: [' flow', backend]

---

---
tags: backend, flow
---

# Backend Flow

```plantuml
@startuml
==/POST Login API==
Frontend->Backend:student_id, password
Backend->DB:write login record
Backend->Server:student_id, password
alt succes
    Server->Backend:Login Success: token, ...
    Backend->DB:write user table
    Backend->Frontend:Login Success: token, studentId, name, code, msg
else failed
    Server->Backend:http 401 | 403 | 504 | 500
    Backend->Frontend:msg, detail
end
==when server is shutdown==
Frontend->Backend:student_id, password
Backend->DB:write login record
Backend->x Server:student, password
Backend->Frontend:http 503 Service Unavailable
==/GET get record API==
Frontend->Backend:token
DB->Backend:get user info
Backend->Backend:check user
alt valid
    DB->Backend:get 最後更新時間
    Backend->Server:get record by token
    Server->Backend:record
    Backend->DB:update record table
    DB->Backend:get record from DB
    Backend->Backend:組合校務系統和DB的資料、排序、分頁、過濾status
    Backend->Frontend:record, code, msg
else invalid
    Backend->Frontend:http 401
end
==when server is shutdown==
Frontend->Backend:token
DB->Backend:get user info
Backend->Backend:check user
alt valid
    DB->Backend:get 最後更新時間
    Backend->x Server:get record by token
    DB->Backend:get record from DB 註明未驗證
    Backend->Backend:組合校務系統和DB的資料、排序、分頁、過濾status
    Backend->Frontend:record, code, msg
else invalid
    Backend->Frontend:http 401
end
@enduml
```
```plantuml
@startuml
participant Frontend order 10
participant Backend order 20
participant DB order 25
participant Server order 30
==/POST Leave application API==
Frontend->Backend:請假紀錄
DB->Backend:get user info
Backend->Backend:check user
alt valid
    Backend->Server:token, 請假紀錄
    Backend->DB:write 請假紀錄
    Server->Backend:http 200 Success: data, ...
    Backend->DB:write status to record
    Backend->Frontend:code, msg
else invalid
    Backend->Frontend:http 401
end
==when server is shutdown==
Frontend->Backend:請假紀錄
DB->Backend:get user info
Backend->Backend:check user
alt valid
    Backend->DB:write 請假紀錄
    Backend->x Server:token, 請假紀錄
    Backend->DB:write status to record
    Backend->Frontend:code, msg: 告訴使用者校務系統無法\n使用，將來排程送出請假
else invalid
    Backend->Frontend:http 401
end
==/GET getCourse API==
Frontend->Backend:token
DB->Backend:get user info
Backend->Backend:check user
alt valid
    Backend->Server:token
    Server->Backend:http 200: courses, ...
    Backend->DB:write courses to DB
    Backend->Frontend:courses, code, msg
else invalid
    Backend->Frontend:http 401
end
==when server is shutdown==
Frontend->Backend:token
DB->Backend:get user info
Backend->Backend:check user
alt valid
    Backend->x Server:token
    DB->Backend:get exsited course
    alt have courses in DB
        Backend->Frontend:courses
    else no saved courses
        Backend->Frontend:http 503 Service Unavailable
    end
else invalid
    Backend->Frontend:http 401
end
@enduml
```