From 19c00c3fb512109f9f15ae9586f833caabd7cbb4 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Tue, 18 Jul 2023 17:19:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=91=E5=B8=83=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E5=BD=A2=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/drafting.go | 8 +- api/publishedGi.go | 173 ++++++++++++ docs/docs.go | 613 ++++++++++++++++++++++++++++++++++++++++- docs/swagger.json | 613 ++++++++++++++++++++++++++++++++++++++++- docs/swagger.yaml | 396 +++++++++++++++++++++++++- dto/publishedGi.go | 15 + main.go | 1 + service/publishedGi.go | 65 +++++ 8 files changed, 1877 insertions(+), 7 deletions(-) create mode 100644 api/publishedGi.go create mode 100644 dto/publishedGi.go create mode 100644 service/publishedGi.go diff --git a/api/drafting.go b/api/drafting.go index 7f793bc..f2b91ae 100644 --- a/api/drafting.go +++ b/api/drafting.go @@ -14,7 +14,7 @@ import ( func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { authed := api.Group("/v1/drafting").Use(authMiddleware.MiddlewareFunc()) - authed.GET("/paging", pageQueryUser) + authed.GET("/paging", pageQueryDrafting) authed.POST("", createDrafting) authed.POST("/:id/saveAs", saveAsDrafting) authed.GET("/:id", queryDraftingInfo) @@ -61,7 +61,7 @@ func pageQueryDrafting(c *gin.Context) { // @Accept json // @Produce json // @Param id query dto.DraftingDto true "草稿信息" -// @Success 200 {object} +// @Success 200 {object} nil // @Failure 401 {object} dto.ErrorDto // @Failure 404 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto @@ -88,7 +88,7 @@ func createDrafting(c *gin.Context) { // @Accept json // @Produce json // @Param id query dto.DraftingDto true "指定name" -// @Success 200 {object} +// @Success 200 {object} nil // @Failure 401 {object} dto.ErrorDto // @Failure 404 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto @@ -145,7 +145,7 @@ func queryDraftingInfo(c *gin.Context) { // @Accept json // @Produce json // @Param id query dto.DraftingDto true "指定name" -// @Success 200 {object} +// @Success 200 {object} nil // @Failure 401 {object} dto.ErrorDto // @Failure 404 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto diff --git a/api/publishedGi.go b/api/publishedGi.go new file mode 100644 index 0000000..b047278 --- /dev/null +++ b/api/publishedGi.go @@ -0,0 +1,173 @@ +package api + +import ( + jwt "github.com/appleboy/gin-jwt/v2" + "github.com/gin-gonic/gin" + "go.uber.org/zap" + "joylink.club/bj-rtsts-server/db/model" + "joylink.club/bj-rtsts-server/dto" + "joylink.club/bj-rtsts-server/middleware" + "joylink.club/bj-rtsts-server/service" + "net/http" + "strconv" +) + +func InitPublishedGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { + authed := api.Group("/v1/publishedGi").Use(authMiddleware.MiddlewareFunc()) + authed.GET("/paging", pageQueryPublishedGi) + authed.GET("/list", listQueryPublishedGi) + authed.GET("/:id", getPublishedGiById) + authed.POST("/publish", publishFromDraft) + authed.DELETE("/:id", deletePublishedGiById) +} + +// 分页查询发布的图形数据 +// +// @Summary 分页查询发布的图形数据 +// +// @Security JwtAuth +// +// @Description 可以通过名称过滤 +// @Tags 发布的图形数据Api +// @Accept json +// @Produce json +// @Param pagePublishedGiReqDto query dto.PublishedGiReqDto true "分页查询参数" +// @Success 200 {object} dto.PageDto +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/publishedGi/paging [get] +func pageQueryPublishedGi(c *gin.Context) { + user, _ := c.Get(middleware.IdentityKey) + zap.S().Debug("分页查询发布的图形数据", user) + req := dto.PublishedGiReqDto{} + if err := c.ShouldBind(&req); err != nil { + //zap.S().Warn("分页查询参数绑定错误,使用默认参数", err) + req.Default() + } + zap.S().Debug("分页查询发布的图形数据", req) + page, err := service.PageQueryPublishedGi(&req) + if err != nil { + panic(err) + } + c.JSON(http.StatusOK, page) +} + +// 列表查询发布的图形数据 +// +// @Summary 列表查询发布的图形数据 +// +// @Security JwtAuth +// +// @Description 可以通过名称过滤 +// @Tags 发布的图形数据Api +// @Accept json +// @Produce json +// @Param token query string true "JWT Token" +// @Param pagePublishedGiReqDto query dto.PublishedGiReqDto true "查询参数" +// @Success 200 {object} []model.PublishedGi +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/publishedGi/list [get] +func listQueryPublishedGi(c *gin.Context) { + user, _ := c.Get(middleware.IdentityKey) + zap.S().Debug("列表查询发布的图形数据", user) + req := dto.PublishedGiReqDto{} + if err := c.ShouldBind(&req); err != nil { + zap.S().Warn("列表查询参数绑定错误", err) + } + zap.S().Debug("列表查询发布的图形数据", req) + list, err := service.ListQueryPublishedGi(&req) + if err != nil { + panic(err) + } + c.JSON(http.StatusOK, list) +} + +// 从草稿发布数据 +// +// @Summary 从草稿发布数据 +// +// @Security JwtAuth +// +// @Description +// @Tags 发布的图形数据Api +// @Accept json +// @Produce json +// @Param PublishReqDto query dto.PublishReqDto true "查询参数" +// @Success 200 {object} nil +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/publishedGi/publish [post] +func publishFromDraft(c *gin.Context) { + user, _ := c.Get(middleware.IdentityKey) + zap.S().Debug("发布图形数据", user) + req := dto.PublishReqDto{} + if err := c.ShouldBind(&req); err != nil { + zap.S().Warn("发布图形数据参数绑定错误", err) + } + zap.S().Debug("发布图形数据请求参数", req) + service.PublishFormDraft(&req, user.(model.User)) +} + +// id 查询发布的图形数据 +// +// @Summary id查询发布的图形数据 +// +// @Security JwtAuth +// +// @Description 可以通过名称过滤 +// @Tags 发布的图形数据Api +// @Accept json +// @Produce json +// @Param id path int true "id" +// @Success 200 {object} model.PublishedGi +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/publishedGi/{id} [get] +func getPublishedGiById(c *gin.Context) { + user, _ := c.Get(middleware.IdentityKey) + zap.S().Debug("id查询发布的图形数据", user) + idStr := c.Param("id") + id, err := strconv.Atoi(idStr) + if err != nil { + panic("id参数解析错误") + } + zap.S().Debug("id查询发布的图形数据", id) + entity, err := service.GetPublishedGiById(id) + if err != nil { + panic(err) + } + c.JSON(http.StatusOK, entity) +} + +// id 查询发布的图形数据 +// +// @Summary id查询发布的图形数据 +// +// @Security JwtAuth +// +// @Description 可以通过名称过滤 +// @Tags 发布的图形数据Api +// @Accept json +// @Produce json +// @Param id path int true "id" +// @Success 200 {object} nil +// @Failure 401 {object} dto.ErrorDto +// @Failure 404 {object} dto.ErrorDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/publishedGi/{id} [delete] +func deletePublishedGiById(c *gin.Context) { + user, _ := c.Get(middleware.IdentityKey) + zap.S().Debug("id删除发布的图形数据", user) + idStr := c.Param("id") + id, err := strconv.Atoi(idStr) + if err != nil { + panic("id参数解析错误") + } + zap.S().Debug("id查询发布的图形数据", id) + service.DeletePublishedGiById(id) +} diff --git a/docs/docs.go b/docs/docs.go index b14ba99..ad319c2 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -16,6 +16,242 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/api/v1/drafting": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "创建草稿数据", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "草稿Api" + ], + "summary": "创建草稿", + "parameters": [ + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "name": "proto", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/drafting/:id": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "查询草稿详情", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "草稿Api" + ], + "summary": "查询草稿详情", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/model.Drafting" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + }, + "put": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "草稿另存为", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "草稿Api" + ], + "summary": "草稿另存为", + "parameters": [ + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "name": "proto", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/drafting/:id/saveAs": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "草稿另存为", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "草稿Api" + ], + "summary": "草稿另存为", + "parameters": [ + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "name": "proto", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, "/api/v1/drafting/paging": { "get": { "security": [ @@ -31,7 +267,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "用户Api" + "草稿Api" ], "summary": "分页查询草稿", "parameters": [ @@ -85,6 +321,321 @@ const docTemplate = `{ } } }, + "/api/v1/publishedGi/list": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过名称过滤", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "列表查询发布的图形数据", + "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "token", + "in": "query", + "required": true + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "example": 1, + "description": "页码", + "name": "page", + "in": "query", + "required": true + }, + { + "type": "integer", + "example": 10, + "description": "页面行数", + "name": "size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/model.PublishedGi" + } + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/publishedGi/paging": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过名称过滤", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "分页查询发布的图形数据", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "example": 1, + "description": "页码", + "name": "page", + "in": "query", + "required": true + }, + { + "type": "integer", + "example": 10, + "description": "页面行数", + "name": "size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.PageDto" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/publishedGi/publish": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "从草稿发布数据", + "parameters": [ + { + "type": "integer", + "description": "草稿数据的id", + "name": "draftId", + "in": "query" + }, + { + "type": "string", + "description": "发布后的名称", + "name": "name", + "in": "query" + }, + { + "type": "boolean", + "description": "是否覆盖同名数据", + "name": "overwrite", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/publishedGi/{id}": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过名称过滤", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "id查询发布的图形数据", + "parameters": [ + { + "type": "integer", + "description": "id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/model.PublishedGi" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + }, + "delete": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过名称过滤", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "id查询发布的图形数据", + "parameters": [ + { + "type": "integer", + "description": "id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, "/api/v1/user/login": { "post": { "description": "用户登录", @@ -287,6 +838,66 @@ const docTemplate = `{ "type": "string" } } + }, + "model.Drafting": { + "type": "object", + "properties": { + "created_at": { + "description": "创建时间", + "type": "string" + }, + "creator_id": { + "description": "创建人id", + "type": "integer" + }, + "id": { + "description": "id", + "type": "integer" + }, + "name": { + "description": "草稿图名称", + "type": "string" + }, + "proto": { + "description": "绘图数据", + "type": "array", + "items": { + "type": "integer" + } + }, + "update_at": { + "description": "修改时间", + "type": "string" + } + } + }, + "model.PublishedGi": { + "type": "object", + "properties": { + "id": { + "description": "id", + "type": "integer" + }, + "name": { + "description": "发布图形界面名称", + "type": "string" + }, + "proto": { + "description": "图形界面数据", + "type": "array", + "items": { + "type": "integer" + } + }, + "publish_at": { + "description": "发布时间", + "type": "string" + }, + "user_id": { + "description": "发布用户id", + "type": "integer" + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.json b/docs/swagger.json index 34f7a86..352ee80 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -9,6 +9,242 @@ "host": "localhost:8080", "basePath": "/", "paths": { + "/api/v1/drafting": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "创建草稿数据", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "草稿Api" + ], + "summary": "创建草稿", + "parameters": [ + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "name": "proto", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/drafting/:id": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "查询草稿详情", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "草稿Api" + ], + "summary": "查询草稿详情", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/model.Drafting" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + }, + "put": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "草稿另存为", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "草稿Api" + ], + "summary": "草稿另存为", + "parameters": [ + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "name": "proto", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/drafting/:id/saveAs": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "草稿另存为", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "草稿Api" + ], + "summary": "草稿另存为", + "parameters": [ + { + "type": "integer", + "name": "id", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "name": "proto", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, "/api/v1/drafting/paging": { "get": { "security": [ @@ -24,7 +260,7 @@ "application/json" ], "tags": [ - "用户Api" + "草稿Api" ], "summary": "分页查询草稿", "parameters": [ @@ -78,6 +314,321 @@ } } }, + "/api/v1/publishedGi/list": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过名称过滤", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "列表查询发布的图形数据", + "parameters": [ + { + "type": "string", + "description": "JWT Token", + "name": "token", + "in": "query", + "required": true + }, + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "example": 1, + "description": "页码", + "name": "page", + "in": "query", + "required": true + }, + { + "type": "integer", + "example": 10, + "description": "页面行数", + "name": "size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/model.PublishedGi" + } + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/publishedGi/paging": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过名称过滤", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "分页查询发布的图形数据", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "query" + }, + { + "type": "integer", + "example": 1, + "description": "页码", + "name": "page", + "in": "query", + "required": true + }, + { + "type": "integer", + "example": 10, + "description": "页面行数", + "name": "size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/dto.PageDto" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/publishedGi/publish": { + "post": { + "security": [ + { + "JwtAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "从草稿发布数据", + "parameters": [ + { + "type": "integer", + "description": "草稿数据的id", + "name": "draftId", + "in": "query" + }, + { + "type": "string", + "description": "发布后的名称", + "name": "name", + "in": "query" + }, + { + "type": "boolean", + "description": "是否覆盖同名数据", + "name": "overwrite", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, + "/api/v1/publishedGi/{id}": { + "get": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过名称过滤", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "id查询发布的图形数据", + "parameters": [ + { + "type": "integer", + "description": "id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/model.PublishedGi" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + }, + "delete": { + "security": [ + { + "JwtAuth": [] + } + ], + "description": "可以通过名称过滤", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "发布的图形数据Api" + ], + "summary": "id查询发布的图形数据", + "parameters": [ + { + "type": "integer", + "description": "id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/dto.ErrorDto" + } + } + } + } + }, "/api/v1/user/login": { "post": { "description": "用户登录", @@ -280,6 +831,66 @@ "type": "string" } } + }, + "model.Drafting": { + "type": "object", + "properties": { + "created_at": { + "description": "创建时间", + "type": "string" + }, + "creator_id": { + "description": "创建人id", + "type": "integer" + }, + "id": { + "description": "id", + "type": "integer" + }, + "name": { + "description": "草稿图名称", + "type": "string" + }, + "proto": { + "description": "绘图数据", + "type": "array", + "items": { + "type": "integer" + } + }, + "update_at": { + "description": "修改时间", + "type": "string" + } + } + }, + "model.PublishedGi": { + "type": "object", + "properties": { + "id": { + "description": "id", + "type": "integer" + }, + "name": { + "description": "发布图形界面名称", + "type": "string" + }, + "proto": { + "description": "图形界面数据", + "type": "array", + "items": { + "type": "integer" + } + }, + "publish_at": { + "description": "发布时间", + "type": "string" + }, + "user_id": { + "description": "发布用户id", + "type": "integer" + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 6ccdc9d..22a72fd 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -59,6 +59,49 @@ definitions: token: type: string type: object + model.Drafting: + properties: + created_at: + description: 创建时间 + type: string + creator_id: + description: 创建人id + type: integer + id: + description: id + type: integer + name: + description: 草稿图名称 + type: string + proto: + description: 绘图数据 + items: + type: integer + type: array + update_at: + description: 修改时间 + type: string + type: object + model.PublishedGi: + properties: + id: + description: id + type: integer + name: + description: 发布图形界面名称 + type: string + proto: + description: 图形界面数据 + items: + type: integer + type: array + publish_at: + description: 发布时间 + type: string + user_id: + description: 发布用户id + type: integer + type: object host: localhost:8080 info: contact: {} @@ -66,6 +109,154 @@ info: title: CBTC测试系统API version: "1.0" paths: + /api/v1/drafting: + post: + consumes: + - application/json + description: 创建草稿数据 + parameters: + - in: query + name: id + type: integer + - in: query + name: name + type: string + - collectionFormat: csv + in: query + items: + type: integer + name: proto + type: array + produces: + - application/json + responses: + "200": + description: OK + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: 创建草稿 + tags: + - 草稿Api + /api/v1/drafting/:id: + get: + consumes: + - application/json + description: 查询草稿详情 + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/model.Drafting' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: 查询草稿详情 + tags: + - 草稿Api + put: + consumes: + - application/json + description: 草稿另存为 + parameters: + - in: query + name: id + type: integer + - in: query + name: name + type: string + - collectionFormat: csv + in: query + items: + type: integer + name: proto + type: array + produces: + - application/json + responses: + "200": + description: OK + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: 草稿另存为 + tags: + - 草稿Api + /api/v1/drafting/:id/saveAs: + post: + consumes: + - application/json + description: 草稿另存为 + parameters: + - in: query + name: id + type: integer + - in: query + name: name + type: string + - collectionFormat: csv + in: query + items: + type: integer + name: proto + type: array + produces: + - application/json + responses: + "200": + description: OK + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: 草稿另存为 + tags: + - 草稿Api /api/v1/drafting/paging: get: consumes: @@ -110,7 +301,210 @@ paths: - JwtAuth: [] summary: 分页查询草稿 tags: - - 用户Api + - 草稿Api + /api/v1/publishedGi/{id}: + delete: + consumes: + - application/json + description: 可以通过名称过滤 + parameters: + - description: id + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: id查询发布的图形数据 + tags: + - 发布的图形数据Api + get: + consumes: + - application/json + description: 可以通过名称过滤 + parameters: + - description: id + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/model.PublishedGi' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: id查询发布的图形数据 + tags: + - 发布的图形数据Api + /api/v1/publishedGi/list: + get: + consumes: + - application/json + description: 可以通过名称过滤 + parameters: + - description: JWT Token + in: query + name: token + required: true + type: string + - in: query + name: name + type: string + - description: 页码 + example: 1 + in: query + name: page + required: true + type: integer + - description: 页面行数 + example: 10 + in: query + name: size + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/model.PublishedGi' + type: array + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: 列表查询发布的图形数据 + tags: + - 发布的图形数据Api + /api/v1/publishedGi/paging: + get: + consumes: + - application/json + description: 可以通过名称过滤 + parameters: + - in: query + name: name + type: string + - description: 页码 + example: 1 + in: query + name: page + required: true + type: integer + - description: 页面行数 + example: 10 + in: query + name: size + required: true + type: integer + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/dto.PageDto' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: 分页查询发布的图形数据 + tags: + - 发布的图形数据Api + /api/v1/publishedGi/publish: + post: + consumes: + - application/json + parameters: + - description: 草稿数据的id + in: query + name: draftId + type: integer + - description: 发布后的名称 + in: query + name: name + type: string + - description: 是否覆盖同名数据 + in: query + name: overwrite + type: boolean + produces: + - application/json + responses: + "200": + description: OK + "401": + description: Unauthorized + schema: + $ref: '#/definitions/dto.ErrorDto' + "404": + description: Not Found + schema: + $ref: '#/definitions/dto.ErrorDto' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/dto.ErrorDto' + security: + - JwtAuth: [] + summary: 从草稿发布数据 + tags: + - 发布的图形数据Api /api/v1/user/login: post: consumes: diff --git a/dto/publishedGi.go b/dto/publishedGi.go new file mode 100644 index 0000000..fdfbb16 --- /dev/null +++ b/dto/publishedGi.go @@ -0,0 +1,15 @@ +package dto + +type PublishedGiReqDto struct { + PageQueryDto + Name string `json:"name" form:"name"` +} + +type PublishReqDto struct { + //发布后的名称 + Name string `json:"name" form:"name"` + //草稿数据的id + DraftId int32 `json:"draftId" form:"draftId"` + //是否覆盖同名数据 + Overwrite bool `json:"overwrite" form:"overwrite"` +} diff --git a/main.go b/main.go index 2f9ccab..d842fd4 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ func main() { router := engine.Group("/api") api.InitUserRouter(router, authMiddleware) api.InitDraftingRouter(router, authMiddleware) + api.InitPublishedGiRouter(router, authMiddleware) docs.SwaggerInfo.Title = "CBTC测试系统API" engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) diff --git a/service/publishedGi.go b/service/publishedGi.go new file mode 100644 index 0000000..390e794 --- /dev/null +++ b/service/publishedGi.go @@ -0,0 +1,65 @@ +package service + +import ( + "fmt" + "gorm.io/gorm/clause" + "joylink.club/bj-rtsts-server/db/dbquery" + "joylink.club/bj-rtsts-server/db/model" + "joylink.club/bj-rtsts-server/dto" + "time" +) + +func PageQueryPublishedGi(req *dto.PublishedGiReqDto) (*dto.PageDto, error) { + where := dbquery.PublishedGi.Where() + if req.Name != "" { + where.Where(dbquery.PublishedGi.Name.Like(fmt.Sprintf("%%%s%%", req.Name))) + } + result, count, err := where.Debug().FindByPage(req.Offset(), req.Size) + return &dto.PageDto{ + Total: int(count), + PageQueryDto: req.PageQueryDto, + Records: result, + }, err +} + +func ListQueryPublishedGi(req *dto.PublishedGiReqDto) ([]*model.PublishedGi, error) { + where := dbquery.PublishedGi.Where() + if req.Name != "" { + where.Where(dbquery.PublishedGi.Name.Like(fmt.Sprintf("%%%s%%", req.Name))) + } + return where.Debug().Find() +} + +func GetPublishedGiById(id int) (*model.PublishedGi, error) { + return dbquery.PublishedGi.Where(dbquery.PublishedGi.ID.Eq(int32(id))).Debug().First() +} + +func PublishFormDraft(req *dto.PublishReqDto, user model.User) { + draft := QueryDrafting(req.DraftId) + if draft.Proto == nil || len(draft.Proto) == 0 { + panic(fmt.Sprintf("草稿[%v]绘图数据信息为空", req.DraftId)) + } + entity := model.PublishedGi{ + Name: req.Name, + Proto: draft.Proto, + UserID: user.ID, + PublishAt: time.Now(), + } + + query := dbquery.PublishedGi.Debug() + if req.Overwrite { + query.Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "name"}}, + UpdateAll: true, + }) + } else { + query.Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "name"}}, + }) + } + _ = query.Create(&entity) +} + +func DeletePublishedGiById(id int) { + _, _ = dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.ID.Eq(int32(id))).Delete() +}