173 lines
5.8 KiB
Plaintext
173 lines
5.8 KiB
Plaintext
syntax = "v1"
|
||
|
||
info(
|
||
title: "Portal-Api-Gateway (PGW)"
|
||
desc: "digimon web portal api gateway"
|
||
author: "daniel Wang"
|
||
email: "igs170911@gmail.com"
|
||
version: "0.0.1"
|
||
)
|
||
|
||
type Status {
|
||
Code int64 `json:"code"` // 狀態碼
|
||
Message string `json:"message"` // 訊息
|
||
Data interface{} `json:"data,omitempty"` // 可選的數據,當有返回時才出現
|
||
Error interface{} `json:"error,omitempty"` // 可選的錯誤信息
|
||
}
|
||
|
||
type BaseResponse {
|
||
Status Status `json:"status"` // 狀態
|
||
}
|
||
|
||
// -------------------------------------------
|
||
type CreateAccountRequest {
|
||
Account string `json:"account" validate:"required, account"` // 帳號名稱
|
||
Token string `json:"token"` // 密碼或平台token,密碼請 sha256 轉碼
|
||
TokenCheck string `json:"token_check"` // 密碼或平台token,密碼請 sha256 轉碼
|
||
Platform string `json:"platform" validate:"oneof=digimon google twitter"` // 平台名稱 digimon, google, twitter
|
||
AccountType string `json:"account_type" validate:"oneof=1 2 3"`// 帳號類型 1 Email 2. 台灣手機 3. 任意
|
||
}
|
||
|
||
type CreateAccountItem {
|
||
UID string `json:"uid"` // 使用者UID
|
||
}
|
||
|
||
type CreateAccountResp {
|
||
Status Status `json:"status"` // 狀態
|
||
Data CreateAccountItem `json:"data"`
|
||
}
|
||
// -------------------------------------------
|
||
|
||
type LoginResp {
|
||
Status Status `json:"status"` // 狀態
|
||
Data LoginItem `json:"data"`
|
||
}
|
||
|
||
type LoginItem {
|
||
AccessToken string `json:"access_token"` // 訪問令牌 預設 5 分鐘過期
|
||
RefreshToken string `json:"refresh_token"` // 刷新令牌 (預設一天過期,只能用一次),當呼叫更新token api 時,會自動把舊的失效,變成新的 refresh_token ,前端要記得過其實協助刷新,刷新不過表示全失效了(重新登入)
|
||
TokenType string `json:"token_type"` // Bearer
|
||
}
|
||
|
||
type LoginReq {
|
||
Account string `json:"account" validate:"required, account"` // 帳號名稱
|
||
Token string `json:"token"` // 密碼或平台token,密碼請 sha256 轉碼
|
||
Platform string `json:"platform" validate:"oneof=digimon google twitter"` // 平台名稱 digimon, google, twitter
|
||
AccountType string `json:"account_type" validate:"oneof=1 2 3"` // 帳號類型 1 Email 2. 台灣手機 3. 任意
|
||
}
|
||
// -------------------------------------------
|
||
|
||
type ForgetPasswordCodeReq {
|
||
Account string `json:"account" validate:"required, account"` // 帳號名稱
|
||
AccountType string `json:"account_type" validate:"oneof=1 2 3"` // 帳號類型 1 Email 2. 台灣手機 3. 任意
|
||
}
|
||
// -------------------------------------------
|
||
|
||
type CheckoutVerifyReq {
|
||
Account string `form:"account"m:"account" validate:"required, account"` // 帳號名稱
|
||
VerifyCode string `form:"verify_code" validate:"required,len=6"` // 驗證碼,長度為6
|
||
}
|
||
// -------------------------------------------
|
||
type UpdatePasswordReq {
|
||
Account string `json:"account" validate:"required, account"` // 帳號名稱
|
||
VerifyCode string `json:"verify_code" validate:"required,len=6"` // 驗證碼,長度為6
|
||
Token string `json:"token" validate:"required"` // 密碼或平台token,密碼請 sha256 轉碼
|
||
TokenCheck string `json:"token_check" validate:"required"` // 密碼或平台token,密碼請 sha256 轉碼
|
||
}
|
||
|
||
|
||
@server(
|
||
group: member
|
||
prefix: /api/v1
|
||
schemes: https
|
||
timeout: 3s
|
||
)
|
||
service gateway {
|
||
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
||
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
||
@doc(
|
||
summary:"創建新會員"
|
||
description: "創建一個全新的帳號"
|
||
)
|
||
@handler createAccount
|
||
post /member (CreateAccountRequest) returns (CreateAccountResp)
|
||
|
||
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
||
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
||
@doc(
|
||
summary:"登入"
|
||
description: "會員登入"
|
||
)
|
||
@handler Login
|
||
post /member/login (LoginReq) returns (LoginResp)
|
||
|
||
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
||
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
||
@doc(
|
||
summary:"發送忘記密碼驗證"
|
||
description: "發送忘記密碼驗證(三分鐘內只能發一次信)"
|
||
)
|
||
@handler ForgetPassworCode
|
||
post /member/forget-password-code (ForgetPasswordCodeReq) returns (BaseResponse)
|
||
|
||
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
||
/* @respdoc-403 (BaseResponse) // 無效的驗證碼 */
|
||
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
||
@doc(
|
||
summary:"確認驗證碼是否有效"
|
||
description: "確認驗證碼是否有效"
|
||
)
|
||
@handler CheckVerifyCode
|
||
get /member/check-verify-code (CheckoutVerifyReq) returns (BaseResponse)
|
||
|
||
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
||
/* @respdoc-403 (BaseResponse) // 無效的驗證碼 */
|
||
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
||
@doc(
|
||
summary:"更新密碼"
|
||
description: "更新密碼"
|
||
)
|
||
@handler UpadtePassword
|
||
put /member/update-password (UpdatePasswordReq) returns (BaseResponse)
|
||
}
|
||
|
||
type Header {
|
||
Uid string `header:"uid"`
|
||
Token string `header:"token"`
|
||
}
|
||
|
||
type UserInfoResp {
|
||
Status Status `json:"status"` // 狀態
|
||
Data UserInfo `json:"data"`
|
||
}
|
||
|
||
type UserInfo {}
|
||
|
||
@server(
|
||
group: member
|
||
prefix: /api/v1
|
||
schemes: https
|
||
timeout: 3s
|
||
middleware: AuthMiddleware
|
||
)
|
||
|
||
service gateway {
|
||
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
||
/* @respdoc-403 (BaseResponse) // 無效的Token */
|
||
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
||
@doc(
|
||
summary: "會員登出"
|
||
)
|
||
@handler Logout
|
||
get /member/logout (Header) returns (BaseResponse)
|
||
|
||
/* @respdoc-400 (BaseResponse) // 輸入的參數錯誤 */
|
||
/* @respdoc-403 (BaseResponse) // 無效的Token */
|
||
/* @respdoc-500 (BaseResponse) // 伺服器出錯 */
|
||
@doc(
|
||
summary: "取得會員資訊"
|
||
)
|
||
@handler Info
|
||
get /member/info (Header) returns (UserInfoResp)
|
||
}
|