diff --git a/Makefile b/Makefile index 3c74de8..0ea1e6f 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ # Custom configuration | 独立配置 # Service name | 项目名称 SERVICE=core +FILE_SERVICE=file TEMPLATE_REMOTE=https://git.noahlan.cn/noahlan/goctls-template.git TEMPLATE_BRANCH=v1.5.17 @@ -50,6 +51,17 @@ gen-rpc: # Generate RPC files from proto | 生成 RPC 的代码 --branch $(TEMPLATE_BRANCH) @echo "Generate RPC files successfully" +.PHONY: gen-rpc-file +gen-rpc-file: # Generate RPC files from proto | 生成 RPC 的代码 + goctls rpc protoc ./rpc/$(FILE_SERVICE)/$(FILE_SERVICE).proto \ + --style=$(PROJECT_STYLE) \ + --go_out=./rpc/$(FILE_SERVICE)/types \ + --go-grpc_out=./rpc/$(FILE_SERVICE)/types \ + --zrpc_out=./rpc/$(FILE_SERVICE) \ + --remote $(TEMPLATE_REMOTE) \ + --branch $(TEMPLATE_BRANCH) + @echo "Generate RPC files successfully" + .PHONY: gen-ent gen-ent: # Generate Ent codes | 生成 Ent 的代码 go run -mod=mod entgo.io/ent/cmd/ent generate \ diff --git a/api/desc/all.api b/api/desc/all.api index 77055eb..5e4f49f 100644 --- a/api/desc/all.api +++ b/api/desc/all.api @@ -1 +1,3 @@ -import "base.api" \ No newline at end of file +import "base.api" +import "core/model.api" +import "core/user.api" \ No newline at end of file diff --git a/api/desc/base.api b/api/desc/base.api index 91ee52d..017dce3 100644 --- a/api/desc/base.api +++ b/api/desc/base.api @@ -42,39 +42,31 @@ type TimeInfo { } // Basic ID Request | 基础ID结构 -type IDReq { +type BaseID { // Id | 序号 - Id uint64 `json:"id,string,optional" form:"id,string,optional"` + ID int64 `json:"id,string,optional" form:"id,string,optional"` } // Basic ID request (path) | 基础ID结构,地址参数 -type IDPathReq { +type PathID { // ID | 序号 // // In: path - Id uint64 `json:"id,optional,string" path:"id,optional,string"` + ID int64 `json:"id,optional,string" path:"id,optional,string"` } // Basic ID List request | 基础ID列表结构,用于Post -// swagger:model IDsReq -type IDsReq { +// swagger:model BaseIDs +type BaseIDs { // 主键列表 - Ids []uint64 `json:"ids,optional" form:"ids,optional"` -} - -// The base ID response data | 基础ID信息 -type BaseIDInfo { - // Id | 序号 - Id uint64 `json:"id,string,optional"` - - TimeInfo + Ids []int64 `json:"ids,optional" form:"ids,optional"` } @server( group: base prefix: /api/base ) -service Test { +service api { // Initialize database | 初始化数据库 @handler initDatabase get /initDatabase diff --git a/api/desc/core/model.api b/api/desc/core/model.api new file mode 100644 index 0000000..a5133a3 --- /dev/null +++ b/api/desc/core/model.api @@ -0,0 +1,16 @@ +syntax = "v1" + +info( + title: "Model" + desc: "API basic" + author: "NorthLan" + email: "lan6995@gmail.com" + version: "v1.0" +) + +import "../base.api" + +type UserInfo { + BaseID + TimeInfo +} \ No newline at end of file diff --git a/api/desc/core/user.api b/api/desc/core/user.api new file mode 100644 index 0000000..0f33063 --- /dev/null +++ b/api/desc/core/user.api @@ -0,0 +1,28 @@ +//import "model.api" + +type ( + UserReq { + BaseID + *Pagination + } +) + +@server( + group: user_admin + prefix: /api/admin/user + jwt: Auth + middleware: Authority +) +service api { + // Create user | 创建用户 + @handler createUserAdmin + post /create (UserInfo) returns (BaseID) + + // Get user | 获取用户 + @handler getUserAdmin + get / (UserReq) returns (UserInfo) + + // Delete user | 删除用户 + @handler deleteUserAdmin + post / (BaseID) +} \ No newline at end of file diff --git a/n-admin-server.yml b/n-admin-server.yml index 4941bea..20ed5f3 100644 --- a/n-admin-server.yml +++ b/n-admin-server.yml @@ -2,54 +2,23 @@ basePath: / consumes: - application/json definitions: - BaseIDInfo: - description: The base ID response data | 基础ID信息 - properties: - createdAt: - description: Create Time | 创建时间 - type: string - x-go-name: CreatedAt - id: - description: Id | 序号 - format: uint64 - type: string - x-go-name: Id - updatedAt: - description: Update Time | 更新时间 - type: string - x-go-name: UpdatedAt - type: object - x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types - IDPathReq: - description: Basic ID request (path) | 基础ID结构,地址参数 - properties: - id: - description: |- - ID | 序号 - - In: path - format: uint64 - type: string - x-go-name: Id - type: object - x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types - IDReq: + BaseID: description: Basic ID Request | 基础ID结构 properties: id: description: Id | 序号 - format: uint64 + format: int64 type: string - x-go-name: Id + x-go-name: ID type: object x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types - IDsReq: + BaseIDs: description: Basic ID List request | 基础ID列表结构,用于Post properties: ids: description: 主键列表 items: - format: uint64 + format: int64 type: integer type: array x-go-name: Ids @@ -94,12 +63,107 @@ definitions: x-go-name: UpdatedAt type: object x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + UserInfo: + properties: + createdAt: + description: Create Time | 创建时间 + type: string + x-go-name: CreatedAt + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + updatedAt: + description: Update Time | 更新时间 + type: string + x-go-name: UpdatedAt + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types + UserReq: + properties: + current: + description: Current Page | 当前页 + example: 1 + format: uint64 + maximum: 100000 + minimum: 1 + type: integer + x-go-name: Current + id: + description: Id | 序号 + format: int64 + type: string + x-go-name: ID + size: + description: Page Size | 每页大小 + example: 10 + format: uint64 + maximum: 9999 + minimum: 0 + type: integer + x-go-name: Size + total: + description: Total Number | 数据总数 + format: uint64 + type: integer + x-go-name: Total + type: object + x-go-package: git.noahlan.cn/n-admin/n-admin-server/api/internal/types host: localhost:0 info: - description: 'Description: test service' - title: test + description: 'Description: api service' + title: api version: 0.0.1 paths: + /api/admin/user: + get: + description: Get user | 获取用户 + operationId: GetUserAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/UserReq' + type: object + responses: + "200": + description: UserInfo + schema: + $ref: '#/definitions/UserInfo' + summary: Get user | 获取用户 + tags: + - user_admin + post: + description: Delete user | 删除用户 + operationId: DeleteUserAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/BaseID' + type: object + summary: Delete user | 删除用户 + tags: + - user_admin + /api/admin/user/create: + post: + description: Create user | 创建用户 + operationId: CreateUserAdmin + parameters: + - in: body + name: body + schema: + $ref: '#/definitions/UserInfo' + type: object + responses: + "200": + description: BaseID + schema: + $ref: '#/definitions/BaseID' + summary: Create user | 创建用户 + tags: + - user_admin /api/base/initDatabase: get: description: Initialize database | 初始化数据库 diff --git a/rpc/file/.gitkeep b/rpc/file/.gitkeep deleted file mode 100644 index e69de29..0000000