diff --git a/docs/admin/admin_docs.go b/docs/admin/admin_docs.go index 7998b8a..5f6fb28 100644 --- a/docs/admin/admin_docs.go +++ b/docs/admin/admin_docs.go @@ -2019,6 +2019,144 @@ const docTemplateadmin = `{ } } }, + "/admin/my/share_record/batchDelete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "批量删除我的分享记录", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "我的" + ], + "summary": "批量删除我的分享记录", + "parameters": [ + { + "description": "id", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/admin.PeerShareRecordBatchDeleteForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/admin/my/share_record/delete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "分享记录删除", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "我的" + ], + "summary": "分享记录删除", + "parameters": [ + { + "description": "分享记录信息", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/admin.ShareRecordForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/admin/my/share_record/list": { + "get": { + "security": [ + { + "token": [] + } + ], + "description": "分享记录列表", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "我的" + ], + "summary": "分享记录列表", + "parameters": [ + { + "type": "integer", + "description": "页码", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "页大小", + "name": "page_size", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, "/admin/oauth/create": { "post": { "security": [ @@ -2727,6 +2865,150 @@ const docTemplateadmin = `{ } } }, + "/admin/share_record/batchDelete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "批量分享记录", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "分享记录" + ], + "summary": "批量分享记录", + "parameters": [ + { + "description": "id", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/admin.PeerShareRecordBatchDeleteForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/admin/share_record/delete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "分享记录删除", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "分享记录" + ], + "summary": "分享记录删除", + "parameters": [ + { + "description": "分享记录信息", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/admin.ShareRecordForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/admin/share_record/list": { + "get": { + "security": [ + { + "token": [] + } + ], + "description": "分享记录列表", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "分享记录" + ], + "summary": "分享记录列表", + "parameters": [ + { + "type": "integer", + "description": "用户ID", + "name": "user_id", + "in": "query" + }, + { + "type": "integer", + "description": "页码", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "页大小", + "name": "page_size", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, "/admin/tag/create": { "post": { "security": [ @@ -3562,7 +3844,7 @@ const docTemplateadmin = `{ } } }, - "/admin/user_token/delete": { + "/admin/user_token/batchDelete": { "post": { "security": [ { @@ -3607,6 +3889,51 @@ const docTemplateadmin = `{ } } }, + "/admin/user_token/delete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "登录凭证删除", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "登录凭证" + ], + "summary": "登录凭证删除", + "parameters": [ + { + "description": "登录凭证信息", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.UserToken" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, "/admin/user_token/list": { "get": { "security": [ @@ -3949,6 +4276,20 @@ const docTemplateadmin = `{ } } }, + "admin.PeerShareRecordBatchDeleteForm": { + "type": "object", + "required": [ + "ids" + ], + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "admin.ShareByWebClientForm": { "type": "object", "required": [ @@ -3976,6 +4317,17 @@ const docTemplateadmin = `{ } } }, + "admin.ShareRecordForm": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "user_id": { + "type": "integer" + } + } + }, "admin.TagForm": { "type": "object", "required": [ diff --git a/docs/admin/admin_swagger.json b/docs/admin/admin_swagger.json index b8fa451..532b3fc 100644 --- a/docs/admin/admin_swagger.json +++ b/docs/admin/admin_swagger.json @@ -2012,6 +2012,144 @@ } } }, + "/admin/my/share_record/batchDelete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "批量删除我的分享记录", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "我的" + ], + "summary": "批量删除我的分享记录", + "parameters": [ + { + "description": "id", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/admin.PeerShareRecordBatchDeleteForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/admin/my/share_record/delete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "分享记录删除", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "我的" + ], + "summary": "分享记录删除", + "parameters": [ + { + "description": "分享记录信息", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/admin.ShareRecordForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/admin/my/share_record/list": { + "get": { + "security": [ + { + "token": [] + } + ], + "description": "分享记录列表", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "我的" + ], + "summary": "分享记录列表", + "parameters": [ + { + "type": "integer", + "description": "页码", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "页大小", + "name": "page_size", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, "/admin/oauth/create": { "post": { "security": [ @@ -2720,6 +2858,150 @@ } } }, + "/admin/share_record/batchDelete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "批量分享记录", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "分享记录" + ], + "summary": "批量分享记录", + "parameters": [ + { + "description": "id", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/admin.PeerShareRecordBatchDeleteForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/admin/share_record/delete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "分享记录删除", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "分享记录" + ], + "summary": "分享记录删除", + "parameters": [ + { + "description": "分享记录信息", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/admin.ShareRecordForm" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/admin/share_record/list": { + "get": { + "security": [ + { + "token": [] + } + ], + "description": "分享记录列表", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "分享记录" + ], + "summary": "分享记录列表", + "parameters": [ + { + "type": "integer", + "description": "用户ID", + "name": "user_id", + "in": "query" + }, + { + "type": "integer", + "description": "页码", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "页大小", + "name": "page_size", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, "/admin/tag/create": { "post": { "security": [ @@ -3555,7 +3837,7 @@ } } }, - "/admin/user_token/delete": { + "/admin/user_token/batchDelete": { "post": { "security": [ { @@ -3600,6 +3882,51 @@ } } }, + "/admin/user_token/delete": { + "post": { + "security": [ + { + "token": [] + } + ], + "description": "登录凭证删除", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "登录凭证" + ], + "summary": "登录凭证删除", + "parameters": [ + { + "description": "登录凭证信息", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.UserToken" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, "/admin/user_token/list": { "get": { "security": [ @@ -3942,6 +4269,20 @@ } } }, + "admin.PeerShareRecordBatchDeleteForm": { + "type": "object", + "required": [ + "ids" + ], + "properties": { + "ids": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "admin.ShareByWebClientForm": { "type": "object", "required": [ @@ -3969,6 +4310,17 @@ } } }, + "admin.ShareRecordForm": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "user_id": { + "type": "integer" + } + } + }, "admin.TagForm": { "type": "object", "required": [ diff --git a/docs/admin/admin_swagger.yaml b/docs/admin/admin_swagger.yaml index 627ac01..270ee15 100644 --- a/docs/admin/admin_swagger.yaml +++ b/docs/admin/admin_swagger.yaml @@ -182,6 +182,15 @@ definitions: version: type: string type: object + admin.PeerShareRecordBatchDeleteForm: + properties: + ids: + items: + type: integer + type: array + required: + - ids + type: object admin.ShareByWebClientForm: properties: expire: @@ -201,6 +210,13 @@ definitions: - password - password_type type: object + admin.ShareRecordForm: + properties: + id: + type: integer + user_id: + type: integer + type: object admin.TagForm: properties: collection_id: @@ -1959,6 +1975,92 @@ paths: summary: 登出 tags: - 登录 + /admin/my/share_record/batchDelete: + post: + consumes: + - application/json + description: 批量删除我的分享记录 + parameters: + - description: id + in: body + name: body + required: true + schema: + $ref: '#/definitions/admin.PeerShareRecordBatchDeleteForm' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + security: + - token: [] + summary: 批量删除我的分享记录 + tags: + - 我的 + /admin/my/share_record/delete: + post: + consumes: + - application/json + description: 分享记录删除 + parameters: + - description: 分享记录信息 + in: body + name: body + required: true + schema: + $ref: '#/definitions/admin.ShareRecordForm' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + security: + - token: [] + summary: 分享记录删除 + tags: + - 我的 + /admin/my/share_record/list: + get: + consumes: + - application/json + description: 分享记录列表 + parameters: + - description: 页码 + in: query + name: page + type: integer + - description: 页大小 + in: query + name: page_size + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + security: + - token: [] + summary: 分享记录列表 + tags: + - 我的 /admin/oauth/create: post: consumes: @@ -2381,6 +2483,96 @@ paths: summary: RUSTDESK服务配置 tags: - ADMIN + /admin/share_record/batchDelete: + post: + consumes: + - application/json + description: 批量分享记录 + parameters: + - description: id + in: body + name: body + required: true + schema: + $ref: '#/definitions/admin.PeerShareRecordBatchDeleteForm' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + security: + - token: [] + summary: 批量分享记录 + tags: + - 分享记录 + /admin/share_record/delete: + post: + consumes: + - application/json + description: 分享记录删除 + parameters: + - description: 分享记录信息 + in: body + name: body + required: true + schema: + $ref: '#/definitions/admin.ShareRecordForm' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + security: + - token: [] + summary: 分享记录删除 + tags: + - 分享记录 + /admin/share_record/list: + get: + consumes: + - application/json + description: 分享记录列表 + parameters: + - description: 用户ID + in: query + name: user_id + type: integer + - description: 页码 + in: query + name: page + type: integer + - description: 页大小 + in: query + name: page_size + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + security: + - token: [] + summary: 分享记录列表 + tags: + - 分享记录 /admin/tag/create: post: consumes: @@ -2876,7 +3068,7 @@ paths: summary: 修改密码 tags: - 用户 - /admin/user_token/delete: + /admin/user_token/batchDelete: post: consumes: - application/json @@ -2904,6 +3096,34 @@ paths: summary: 登录凭证批量删除 tags: - 登录凭证 + /admin/user_token/delete: + post: + consumes: + - application/json + description: 登录凭证删除 + parameters: + - description: 登录凭证信息 + in: body + name: body + required: true + schema: + $ref: '#/definitions/model.UserToken' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + security: + - token: [] + summary: 登录凭证删除 + tags: + - 登录凭证 /admin/user_token/list: get: consumes: diff --git a/docs/api/api_docs.go b/docs/api/api_docs.go index 69f2fc6..2e980a3 100644 --- a/docs/api/api_docs.go +++ b/docs/api/api_docs.go @@ -1042,6 +1042,40 @@ const docTemplateapi = `{ } }, "/server-config": { + "get": { + "security": [ + { + "token": [] + } + ], + "description": "服务配置,给webclient提供api-server", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "WEBCLIENT" + ], + "summary": "服务配置", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/server-config-v2": { "get": { "security": [ { diff --git a/docs/api/api_swagger.json b/docs/api/api_swagger.json index 13b8153..8f32707 100644 --- a/docs/api/api_swagger.json +++ b/docs/api/api_swagger.json @@ -1035,6 +1035,40 @@ } }, "/server-config": { + "get": { + "security": [ + { + "token": [] + } + ], + "description": "服务配置,给webclient提供api-server", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "WEBCLIENT" + ], + "summary": "服务配置", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/response.Response" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/response.Response" + } + } + } + } + }, + "/server-config-v2": { "get": { "security": [ { diff --git a/docs/api/api_swagger.yaml b/docs/api/api_swagger.yaml index 1c9cebe..e84a22f 100644 --- a/docs/api/api_swagger.yaml +++ b/docs/api/api_swagger.yaml @@ -850,6 +850,27 @@ paths: tags: - 群组 /server-config: + get: + consumes: + - application/json + description: 服务配置,给webclient提供api-server + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/response.Response' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/response.Response' + security: + - token: [] + summary: 服务配置 + tags: + - WEBCLIENT + /server-config-v2: get: consumes: - application/json diff --git a/http/controller/admin/my/shareRecord.go b/http/controller/admin/my/shareRecord.go new file mode 100644 index 0000000..1218c64 --- /dev/null +++ b/http/controller/admin/my/shareRecord.go @@ -0,0 +1,119 @@ +package my + +import ( + "Gwen/global" + "Gwen/http/request/admin" + "Gwen/http/response" + "Gwen/service" + "github.com/gin-gonic/gin" + "gorm.io/gorm" +) + +type ShareRecord struct { +} + +// List 分享记录列表 +// @Tags 我的 +// @Summary 分享记录列表 +// @Description 分享记录列表 +// @Accept json +// @Produce json +// @Param page query int false "页码" +// @Param page_size query int false "页大小" +// @Success 200 {object} response.Response +// @Failure 500 {object} response.Response +// @Router /admin/my/share_record/list [get] +// @Security token +func (sr *ShareRecord) List(c *gin.Context) { + query := &admin.PageQuery{} + if err := c.ShouldBindQuery(query); err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + u := service.AllService.UserService.CurUser(c) + res := service.AllService.ShareRecordService.List(query.Page, query.PageSize, func(tx *gorm.DB) { + tx.Where("user_id = ?", u.Id) + }) + response.Success(c, res) +} + +// Delete 分享记录删除 +// @Tags 我的 +// @Summary 分享记录删除 +// @Description 分享记录删除 +// @Accept json +// @Produce json +// @Param body body admin.ShareRecordForm true "分享记录信息" +// @Success 200 {object} response.Response +// @Failure 500 {object} response.Response +// @Router /admin/my/share_record/delete [post] +// @Security token +func (sr *ShareRecord) Delete(c *gin.Context) { + f := &admin.ShareRecordForm{} + if err := c.ShouldBindJSON(f); err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + id := f.Id + errList := global.Validator.ValidVar(c, id, "required,gt=0") + if len(errList) > 0 { + response.Fail(c, 101, errList[0]) + return + } + u := service.AllService.UserService.CurUser(c) + i := service.AllService.ShareRecordService.InfoById(f.Id) + if i.UserId != u.Id { + response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) + return + } + if i.Id == 0 { + response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) + return + } + err := service.AllService.ShareRecordService.Delete(i) + if err == nil { + response.Success(c, nil) + return + } + response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error()) +} + +// BatchDelete 批量删除我的分享记录 +// @Tags 我的 +// @Summary 批量删除我的分享记录 +// @Description 批量删除我的分享记录 +// @Accept json +// @Produce json +// @Param body body admin.PeerShareRecordBatchDeleteForm true "id" +// @Success 200 {object} response.Response +// @Failure 500 {object} response.Response +// @Router /admin/my/share_record/batchDelete [post] +// @Security token +func (sr *ShareRecord) BatchDelete(c *gin.Context) { + f := &admin.PeerShareRecordBatchDeleteForm{} + if err := c.ShouldBindJSON(f); err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + if len(f.Ids) == 0 { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")) + return + } + u := service.AllService.UserService.CurUser(c) + var l int64 + l = int64(len(f.Ids)) + res := service.AllService.ShareRecordService.List(1, uint(l), func(tx *gorm.DB) { + tx.Where("user_id = ?", u.Id) + tx.Where("id in ?", f.Ids) + }) + if res.Total != l { + response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) + return + } + err := service.AllService.ShareRecordService.BatchDelete(f.Ids) + if err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error()) + return + } + response.Success(c, nil) +} diff --git a/http/controller/admin/shareRecord.go b/http/controller/admin/shareRecord.go new file mode 100644 index 0000000..6585b83 --- /dev/null +++ b/http/controller/admin/shareRecord.go @@ -0,0 +1,105 @@ +package admin + +import ( + "Gwen/global" + "Gwen/http/request/admin" + "Gwen/http/response" + "Gwen/service" + "github.com/gin-gonic/gin" + "gorm.io/gorm" +) + +type ShareRecord struct { +} + +// List 列表 +// @Tags 分享记录 +// @Summary 分享记录列表 +// @Description 分享记录列表 +// @Accept json +// @Produce json +// @Param user_id query int false "用户ID" +// @Param page query int false "页码" +// @Param page_size query int false "页大小" +// @Success 200 {object} response.Response +// @Failure 500 {object} response.Response +// @Router /admin/share_record/list [get] +// @Security token +func (sr *ShareRecord) List(c *gin.Context) { + query := &admin.ShareRecordQuery{} + if err := c.ShouldBindQuery(query); err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + res := service.AllService.ShareRecordService.List(query.Page, query.PageSize, func(tx *gorm.DB) { + if query.UserId > 0 { + tx.Where("user_id = ?", query.UserId) + } + }) + response.Success(c, res) +} + +// Delete 删除 +// @Tags 分享记录 +// @Summary 分享记录删除 +// @Description 分享记录删除 +// @Accept json +// @Produce json +// @Param body body admin.ShareRecordForm true "分享记录信息" +// @Success 200 {object} response.Response +// @Failure 500 {object} response.Response +// @Router /admin/share_record/delete [post] +// @Security token +func (sr *ShareRecord) Delete(c *gin.Context) { + f := &admin.ShareRecordForm{} + if err := c.ShouldBindJSON(f); err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + id := f.Id + errList := global.Validator.ValidVar(c, id, "required,gt=0") + if len(errList) > 0 { + response.Fail(c, 101, errList[0]) + return + } + i := service.AllService.ShareRecordService.InfoById(f.Id) + if i.Id > 0 { + err := service.AllService.ShareRecordService.Delete(i) + if err == nil { + response.Success(c, nil) + return + } + response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error()) + return + } + response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) +} + +// BatchDelete 批量删除 +// @Tags 分享记录 +// @Summary 批量分享记录 +// @Description 批量分享记录 +// @Accept json +// @Produce json +// @Param body body admin.PeerShareRecordBatchDeleteForm true "id" +// @Success 200 {object} response.Response +// @Failure 500 {object} response.Response +// @Router /admin/share_record/batchDelete [post] +// @Security token +func (sr *ShareRecord) BatchDelete(c *gin.Context) { + f := &admin.PeerShareRecordBatchDeleteForm{} + if err := c.ShouldBindJSON(f); err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) + return + } + if len(f.Ids) == 0 { + response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")) + return + } + err := service.AllService.ShareRecordService.BatchDelete(f.Ids) + if err != nil { + response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error()) + return + } + response.Success(c, nil) +} diff --git a/http/controller/admin/userToken.go b/http/controller/admin/userToken.go index 23e88e2..46e680a 100644 --- a/http/controller/admin/userToken.go +++ b/http/controller/admin/userToken.go @@ -91,7 +91,7 @@ func (ct *UserToken) Delete(c *gin.Context) { // @Param body body admin.UserTokenBatchDeleteForm true "登录凭证信息" // @Success 200 {object} response.Response // @Failure 500 {object} response.Response -// @Router /admin/user_token/delete [post] +// @Router /admin/user_token/batchDelete [post] // @Security token func (ct *UserToken) BatchDelete(c *gin.Context) { f := &admin.UserTokenBatchDeleteForm{} diff --git a/http/request/admin/shareRecord.go b/http/request/admin/shareRecord.go new file mode 100644 index 0000000..d8df471 --- /dev/null +++ b/http/request/admin/shareRecord.go @@ -0,0 +1,15 @@ +package admin + +type ShareRecordQuery struct { + UserId uint `json:"user_id" form:"user_id"` + PageQuery +} + +type ShareRecordForm struct { + Id uint `json:"id" form:"id"` + UserId uint `json:"user_id" form:"user_id"` +} + +type PeerShareRecordBatchDeleteForm struct { + Ids []uint `json:"ids" validate:"required"` +} diff --git a/http/response/admin/user.go b/http/response/admin/user.go index d441106..7f85975 100644 --- a/http/response/admin/user.go +++ b/http/response/admin/user.go @@ -4,8 +4,8 @@ import "Gwen/model" type LoginPayload struct { Username string `json:"username"` - Email string `json:"email"` - Avatar string `json:"avatar"` + Email string `json:"email"` + Avatar string `json:"avatar"` Token string `json:"token"` RouteNames []string `json:"route_names"` Nickname string `json:"nickname"` @@ -19,13 +19,13 @@ func (lp *LoginPayload) FromUser(user *model.User) { } var UserRouteNames = []string{ - "MyTagList", "MyAddressBookList", "MyInfo", "MyAddressBookCollection", "MyPeer", + "MyTagList", "MyAddressBookList", "MyInfo", "MyAddressBookCollection", "MyPeer", "MyShareRecordList", } var AdminRouteNames = []string{"*"} type UserOauthItem struct { - Op string `json:"op"` - Status int `json:"status"` + Op string `json:"op"` + Status int `json:"status"` } type GroupUsersPayload struct { diff --git a/http/router/admin.go b/http/router/admin.go index 4977aa2..6f7fba1 100644 --- a/http/router/admin.go +++ b/http/router/admin.go @@ -3,6 +3,7 @@ package router import ( _ "Gwen/docs/admin" "Gwen/http/controller/admin" + "Gwen/http/controller/admin/my" "Gwen/http/middleware" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" @@ -34,11 +35,14 @@ func Init(g *gin.Engine) { ConfigBind(adg) //deprecated by ConfigBind - rs := &admin.Rustdesk{} - adg.GET("/server-config", rs.ServerConfig) - adg.GET("/app-config", rs.AppConfig) + //rs := &admin.Rustdesk{} + //adg.GET("/server-config", rs.ServerConfig) + //adg.GET("/app-config", rs.AppConfig) //deprecated end + ShareRecordBind(adg) + MyBind(adg) + //访问静态文件 //g.StaticFS("/upload", http.Dir(global.Config.Gin.ResourcesPath+"/upload")) } @@ -220,3 +224,23 @@ func FileBind(rg *gin.RouterGroup) { aR.POST("/upload", cont.Upload) } }*/ + +func MyBind(rg *gin.RouterGroup) { + { + sr := &my.ShareRecord{} + rg.GET("/my/share_record/list", sr.List) + rg.POST("/my/share_record/delete", sr.Delete) + rg.POST("/my/share_record/batchDelete", sr.BatchDelete) + } +} + +func ShareRecordBind(rg *gin.RouterGroup) { + aR := rg.Group("/share_record").Use(middleware.AdminPrivilege()) + { + cont := &admin.ShareRecord{} + aR.GET("/list", cont.List) + aR.POST("/delete", cont.Delete) + aR.POST("/batchDelete", cont.BatchDelete) + } + +} diff --git a/model/shareRecord.go b/model/shareRecord.go index 7417eb6..845659f 100644 --- a/model/shareRecord.go +++ b/model/shareRecord.go @@ -10,3 +10,9 @@ type ShareRecord struct { Expire int64 `json:"expire" gorm:"default:0;not null;"` TimeModel } + +// ShareRecordList 分享记录列表 +type ShareRecordList struct { + ShareRecords []*ShareRecord `json:"list,omitempty"` + Pagination +} diff --git a/service/service.go b/service/service.go index 013ebc2..4e06280 100644 --- a/service/service.go +++ b/service/service.go @@ -16,6 +16,7 @@ type Service struct { *OauthService *LoginLogService *AuditService + *ShareRecordService } func New() *Service { diff --git a/service/shareRecord.go b/service/shareRecord.go new file mode 100644 index 0000000..81036f4 --- /dev/null +++ b/service/shareRecord.go @@ -0,0 +1,49 @@ +package service + +import ( + "Gwen/global" + "Gwen/model" + "gorm.io/gorm" +) + +type ShareRecordService struct { +} + +// InfoById 根据用户id取用户信息 +func (srs *ShareRecordService) InfoById(id uint) *model.ShareRecord { + u := &model.ShareRecord{} + global.DB.Where("id = ?", id).First(u) + return u +} + +func (srs *ShareRecordService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.ShareRecordList) { + res = &model.ShareRecordList{} + res.Page = int64(page) + res.PageSize = int64(pageSize) + tx := global.DB.Model(&model.ShareRecord{}) + if where != nil { + where(tx) + } + tx.Count(&res.Total) + tx.Scopes(Paginate(page, pageSize)) + tx.Find(&res.ShareRecords) + return +} + +// Create 创建 +func (srs *ShareRecordService) Create(u *model.ShareRecord) error { + res := global.DB.Create(u).Error + return res +} +func (srs *ShareRecordService) Delete(u *model.ShareRecord) error { + return global.DB.Delete(u).Error +} + +// Update 更新 +func (srs *ShareRecordService) Update(u *model.ShareRecord) error { + return global.DB.Model(u).Updates(u).Error +} + +func (srs *ShareRecordService) BatchDelete(ids []uint) error { + return global.DB.Where("id in (?)", ids).Delete(&model.ShareRecord{}).Error +}