---
# System prepended metadata

title: 東毅中 User Service - SDD
tags: [software-docs]

---

# 東毅中 User Service - SDD

## Version

| 版本  | 內容           | 日期   | 負責人 |
| ---- | -------------- | ----- | ----- |
| 1.0  | Tech Stack     | 12/05 | Ateto |
| 1.1  | Model Design   | 12/08 | Ateto |
| 1.2  | Arch Design    | 12/10 | Ateto |
| 1.3  | Test Cases     | 12/12 | Ateto |
| 1.4  | OTP Verify     | 12/27 | 劉長諺 |
| 1.5  | Get favorites     | 12/31 | 劉長諺 |

## A. Tech Stack
- FastAPI (Python)
- MySQL
- Redis (Good to Have)

## B. Architecture

- Clean Architecture

### Product Structure
```
- .github/workflows/main.yml
- api/
    - __init__.py
    - account_controller.py
    - auth_controller.py
- domain/
    - __init__.py
    - account_entity.py
    - models.py
- infrastructure/
    - __init__.py
    - database.py
    - mongoDB.py
- repository/
    - __init__.py
    - account_repository.py
    - account_repository_impl.py
    - auth_repository.py
- usecases/
    - __init__.py
    - account_usecase.py
    - auth_usecase.py
- test/
    - __init__.py
    - test_auth.py
- __init__.py
- main.py
- requirement.txt
```

## C. Model


### 1. Account Model
- id: string
    - email
- name: string
    - user name
- orders: List[str]
    - the list of user's order id
- created_at: str
    - the account created time
- updated_at: str
    - the last updated time
- liked:
    - add products into favorites


## D. API
- Gateway Prefix: `user/`

### 1. create_account
- ID: `user-01`
- Description: 使用 otp 驗證後創建 account
- Method: `POST`
- URI: `/account/account-create`
- Status Code: 
    - `200`: OK
    - `404`: Not Found - Owner 不存在
- Body
    :::spoiler Request
    ```json
    {
        "OTP": "demo-otp"
        "email": "user email"
    }
    ```
    :::
    :::spoiler Reponse
    ```json
    {
        "message": "result of create account"
    }
    ```
    :::

### 2. get_account
- ID: `user-02`
- Description: 使用 Order ID 來取得 Order Info，並使用 Owner ID 驗證身份。
- Method: `POST`
- URI: `/account/account-get`
- State Code: 
    - `200`: OK
    - `401`: Unauthorized - Owner 未授權
    - `404`: Not Found - Order 或 Owner 不存在
- Body
    :::spoiler Request
    ```json
    {
        "id":"user@example.com"
    }
    ```
    :::
    :::spoiler Response
    ```json
    {
        "id": "user@example.com",
        "name": "Demo User",
        "cart": null,
        "orders": [],
        "created_at": "2024-12-16 03:09:32",
        "updated_at": "2024-12-16 08:58:55",
        "liked": []
    }
    ```
    :::

### 3. add_order
- ID: `user-03`
- Description: 新增 User 的 Order Info。
- Method: `PATCH`
- URI: `/account/order-add`
- Body
    :::spoiler Request
    ```json
    {
        "id":"user@example.com",
        "order":"demo-order-id"
    }
    ```
    :::
    :::spoiler Response
    ```json
    {
        "id": "user@example.com",
        "name": "Demo User",
        "cart": null,
        "orders": [
            "demo-order-id"
        ],
        "created_at": "2024-12-16 03:09:32",
        "updated_at": "2024-12-16 08:58:55"
    }
    ```
    :::

### 4. auth_google
- ID: `user-04`
- Description: 取得 Google OAuth URL
- Method: `GET`
- URI: `/auth/login`
- Body
    :::spoiler Response
    ```json
    {
        "auth_url": "http://example.com"
    }
    ```
    :::

### 5. auth_google_callback
- ID: `user-05`
- Description: 前端提供 Auth Code，後端使用 Auth Code 和 Access Token 向 OAuth Provider 請求 User Info
- Method: `POST`
- URI: `auth/callback`

### 6. add_liked
- ID: `user-06`
- Description: 提供使用者收藏功能
- Method: `PATCH`
- URI: `/account/liked-update`
- Body
    :::spoiler Request
    ```JSON
    {
        "id": "user mail"
        "liked": product id
    }
    ```
    :::
    :::spoiler Response
    ```JSON
    {
        "message": "the liked updated successfully"
    }
    ```
    :::

### 7. isAdmin
- ID: `user-07`
- Description: 判斷是否為管理員
- Method: `GET`
- URI: `/account/isAdmin?id={admin email}`
- Body:
    :::spoiler Response
    ```JSON
    {
        boolean // true or false
    }
    ```
    :::

### 8. SendOtp
- ID: `user-08`
- Description: 使用 email, username 生成 otp 並發送至信箱
- Method: `POST`
- URI: `/account/otp-send`
- Body:
    :::spoiler Request
    ```JSON
	{
	  "id": "string", //user email
	  "name": "string",
	}
    ```
    :::
    :::spoiler Response
    ```JSON
    {
        "message": "successful or failed"
    }
    ```
    :::
### 9. Get user favorites
- ID: `user-09`
- Description: 取得使用者收藏商品
- Method: `GET`
- URI: `/account/get-favorites/{id}`
- Body:
    :::spoiler Response
    ```JSON
    {
        "{user} favorites": [product id]
    }
    ```
    :::

## E. Test Cases

### 1. Create Order

### 2. Get Order

### 3. Order Not Found

### 4. Order Unauthorized
