meta/user/user.proto

syntax = "proto3";

package jsgenerate_kb2022.meta.user;
option go_package = "gateway/protocol/meta/user";

import "google/api/annotations.proto";
import "adadd52b-e7a2-4fe2-9f15-356ceddbd4f6/utils/utils.proto";

// 用戶相關
service User {
    // 添加一個用戶
    rpc Add (AddRequest) returns (AddResponse){
        option (google.api.http) = {
            post: "/api/v1/meta/user"
            body: "*"
        };
    }
    // 用戶修改自己的密碼,一旦修改成功所有此用戶的 session 都將失效
    rpc Password (PasswordRequest) returns (PasswordResponse){
        option (google.api.http) = {
            patch: "/api/v1/meta/user/password"
            body: "*"
        };
    }
    // 只有管理員可調用,用於修改用戶密碼,一旦修改成功所有此用戶的 session 都將失效
    rpc SetPassword (SetPasswordRequest) returns (SetPasswordResponse){
        option (google.api.http) = {
            patch: "/api/v1/meta/user/set_password"
            body: "*"
        };
    }
    // 用戶修改自己的昵稱
    rpc Nickname (NicknameRequest) returns (NicknameResponse){
        option (google.api.http) = {
            patch: "/api/v1/meta/user/nickname"
            body: "*"
        };
    }
    // 用戶修改自己的頭像
    rpc Avatar (AvatarRequest) returns (AvatarResponse){
        option (google.api.http) = {
            patch: "/api/v1/meta/user/avatar"
            body: "*"
        };
    }
    // 管理員修改用戶的所在組,一旦修改成功所有此用戶的 session 都將失效
    rpc Groups (GroupsRequest) returns (GroupsResponse){
        option (google.api.http) = {
            patch: "/api/v1/meta/user/groups"
            body: "*"
        };
    }
    // 管理員修改用戶管轄區域,一旦修改成功所有此用戶的 session 都將失效
    rpc Areas (AreasRequest) returns (AreasResponse){
        option (google.api.http) = {
            patch: "/api/v1/meta/user/areas"
            body: "*"
        };
    }
    // 管理員修改用戶優先級,一旦修改成功所有此用戶的 session 都將失效
    rpc Priority (PriorityRequest) returns (PriorityResponse){
        option (google.api.http) = {
            patch: "/api/v1/meta/user/priority"
            body: "*"
        };
    }
    // 管理員修改用戶等級,一旦修改成功所有此用戶的 session 都將失效
    rpc Level (LevelRequest) returns (LevelResponse){
        option (google.api.http) = {
            patch: "/api/v1/meta/user/level"
            body: "*"
        };
    }
    // 停用用戶,所有此用戶的 session 都將失效
    rpc Disable (DisableRequest) returns (DisableResponse){
        option (google.api.http) = {
            delete: "/api/v1/meta/user/{id}"
        };
    }
    // 將禁用的用戶重新啓用
    rpc Enable (EnableRequest) returns (EnableResponse){
        option (google.api.http) = {
            post: "/api/v1/meta/user/enable/{id}"
        };
    }
    // 返回指定 id 的用戶,僅用於顯示歷史數據
    rpc ID (IDRequest) returns (IDResponse){
        option (google.api.http) = {
            get: "/api/v1/meta/user/by_id"
        };
    }
    // 查找用戶
    rpc Find (FindRequest) returns (FindResponse){
        option (google.api.http) = {
            get: "/api/v1/meta/user/find"
        };
    }
}

message AddRequest{
    // 用戶名 ^[a-zA-Z][a-zA-Z0-9]+$
    // 長度需要在 [4,20] 個字符之間
    string name = 1;
    // 登入密碼,不能傳輸用戶設置的元密碼,爲了安全必須加鹽 hash 
    // password = md5(input_password+".kb2022").lowerHex()
    string password = 2;
    // 用戶昵稱
    string nickname = 3;
    // 用戶綁定手機
    string phone = 4;
    // 用戶所在組
    repeated int32 groups = 5;
    // 用戶管轄區域邏輯碼
    repeated string areas = 6;
    // 用戶優先級,可設置任務 優先級 只能小於等於此值
    int32 priority = 7;
    // 用戶等級,可設置任務 等級 只能小於等於此值
    int32 level = 8;
}
message AddResponse{
    // 用戶 id
    int64 id = 1;
    // 用戶權限
    repeated int32 permission = 2;
}

message PasswordRequest{
    // 原密碼 md5(input_password+".kb2022").lowerHex()
    string old = 1;
    // 新密碼 md5(input_password+".kb2022").lowerHex()
    string current = 2;
}
message PasswordResponse{
}
message SetPasswordRequest{
    // 要修改的用戶 id
    int64 id = 1;
    // 新密碼 md5(input_password+".kb2022").lowerHex()
    string password = 2;
}
message SetPasswordResponse{
}
message NicknameRequest{
    string nickname = 1;
}
message NicknameResponse{
}
message AvatarRequest{
    string avatar = 1;
}
message AvatarResponse{
}
message GroupsRequest{
    // 要修改的用戶 id
    int64 id = 1;
    // 新的組信息
    repeated int32 values = 5;
}
message GroupsResponse{
}
message AreasRequest{
    // 要修改的用戶 id
    int64 id = 1;
    // 新的區域信息
    repeated string values = 5;
}
message AreasResponse{
}
message PriorityRequest{
    // 要修改的用戶 id
    int64 id = 1;
    // 新的用戶優先級
    int32 value = 5;
}
message PriorityResponse{
}
message LevelRequest{
    // 要修改的用戶 id
    int64 id = 1;
    // 新的用戶優先級
    int32 value = 5;
}
message LevelResponse{
}
message DisableRequest{
    // 要停用的用戶
    int64 id = 1;
}
message DisableResponse{
}
message EnableRequest{
    // 要重新啓用的用戶
    int64 id = 1;
}
message EnableResponse{
}
message IDRequest{
    repeated int64 id = 1;
}
message Data{
    // 用戶唯一識別代碼
    int64 id = 1;
    // 用戶名
    string name = 2;
    // hash 後的密碼 md5(input_password+".kb2022").lowerHex()
    // string password = 3;
    // 用戶昵稱
    string nickname = 4;
    // 綁定電話
    string phone = 5;
    // 用戶頭像
    string avatar = 6;
    // 用戶所在組
    repeated int32 groups = 7;
    // 用戶管理區域
    repeated string areas = 8;
    // 用戶優先級,可設置任務 優先級 只能小於等於此值
    int32 priority = 9;
    // 用戶等級,可設置任務 等級 只能小於等於此值
    int32 level = 10;

    // 是否被停用
    bool disabled = 11;
    // 被停用的時間
    int64 disabledAt = 12;
}
message IDResponse{
    repeated Data data = 1;
}
message FindRequest{
    jsgenerate_kb2022.utils.FindLimit limit = 1;
    // id not in (...)
    repeated int64 notID = 50;
    // 查找 id id in 
    repeated int64 id = 2;
    // 名稱 like
    string name = 3;
    // 昵稱 like
    string nickname = 4;
    // 電話 like
    string phone = 5;
    // 用戶組 has
    repeated int32 group = 6;
    // 區域 has
    repeated string area = 7;
    // 大於0時有效 用戶優先級 <=
    int32 lePriority = 8;
    // 大於0時有效 用戶優先級 >=
    int32 gePriority = 9;
    // 大於0時有效 用戶等級 <=
    int32 leLevel = 10;
    // 大於0時有效 用戶等級 >=
    int32 geLevel = 11;

    // <0 查找 有效用戶
    // 0 忽略此參數,將查找所有用戶(包括啓用和禁用)
    // >0 查找 被禁用的用戶
    int32 disabled = 12;
}
message FindResponse{
    jsgenerate_kb2022.utils.FindResult result = 1;
    repeated Data data = 2;
}