增加发布的图形的接口

This commit is contained in:
joylink_zhangsai 2023-07-18 17:19:03 +08:00
parent 9a1de49e01
commit 19c00c3fb5
8 changed files with 1877 additions and 7 deletions

View File

@ -14,7 +14,7 @@ import (
func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/drafting").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/drafting").Use(authMiddleware.MiddlewareFunc())
authed.GET("/paging", pageQueryUser) authed.GET("/paging", pageQueryDrafting)
authed.POST("", createDrafting) authed.POST("", createDrafting)
authed.POST("/:id/saveAs", saveAsDrafting) authed.POST("/:id/saveAs", saveAsDrafting)
authed.GET("/:id", queryDraftingInfo) authed.GET("/:id", queryDraftingInfo)
@ -61,7 +61,7 @@ func pageQueryDrafting(c *gin.Context) {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id query dto.DraftingDto true "草稿信息" // @Param id query dto.DraftingDto true "草稿信息"
// @Success 200 {object} // @Success 200 {object} nil
// @Failure 401 {object} dto.ErrorDto // @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto // @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
@ -88,7 +88,7 @@ func createDrafting(c *gin.Context) {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id query dto.DraftingDto true "指定name" // @Param id query dto.DraftingDto true "指定name"
// @Success 200 {object} // @Success 200 {object} nil
// @Failure 401 {object} dto.ErrorDto // @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto // @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
@ -145,7 +145,7 @@ func queryDraftingInfo(c *gin.Context) {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id query dto.DraftingDto true "指定name" // @Param id query dto.DraftingDto true "指定name"
// @Success 200 {object} // @Success 200 {object} nil
// @Failure 401 {object} dto.ErrorDto // @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto // @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto

173
api/publishedGi.go Normal file
View File

@ -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)
}

View File

@ -16,6 +16,242 @@ const docTemplate = `{
"host": "{{.Host}}", "host": "{{.Host}}",
"basePath": "{{.BasePath}}", "basePath": "{{.BasePath}}",
"paths": { "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": { "/api/v1/drafting/paging": {
"get": { "get": {
"security": [ "security": [
@ -31,7 +267,7 @@ const docTemplate = `{
"application/json" "application/json"
], ],
"tags": [ "tags": [
"用户Api" "草稿Api"
], ],
"summary": "分页查询草稿", "summary": "分页查询草稿",
"parameters": [ "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": { "/api/v1/user/login": {
"post": { "post": {
"description": "用户登录", "description": "用户登录",
@ -287,6 +838,66 @@ const docTemplate = `{
"type": "string" "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": { "securityDefinitions": {

View File

@ -9,6 +9,242 @@
"host": "localhost:8080", "host": "localhost:8080",
"basePath": "/", "basePath": "/",
"paths": { "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": { "/api/v1/drafting/paging": {
"get": { "get": {
"security": [ "security": [
@ -24,7 +260,7 @@
"application/json" "application/json"
], ],
"tags": [ "tags": [
"用户Api" "草稿Api"
], ],
"summary": "分页查询草稿", "summary": "分页查询草稿",
"parameters": [ "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": { "/api/v1/user/login": {
"post": { "post": {
"description": "用户登录", "description": "用户登录",
@ -280,6 +831,66 @@
"type": "string" "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": { "securityDefinitions": {

View File

@ -59,6 +59,49 @@ definitions:
token: token:
type: string type: string
type: object 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 host: localhost:8080
info: info:
contact: {} contact: {}
@ -66,6 +109,154 @@ info:
title: CBTC测试系统API title: CBTC测试系统API
version: "1.0" version: "1.0"
paths: 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: /api/v1/drafting/paging:
get: get:
consumes: consumes:
@ -110,7 +301,210 @@ paths:
- JwtAuth: [] - JwtAuth: []
summary: 分页查询草稿 summary: 分页查询草稿
tags: 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: /api/v1/user/login:
post: post:
consumes: consumes:

15
dto/publishedGi.go Normal file
View File

@ -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"`
}

View File

@ -29,6 +29,7 @@ func main() {
router := engine.Group("/api") router := engine.Group("/api")
api.InitUserRouter(router, authMiddleware) api.InitUserRouter(router, authMiddleware)
api.InitDraftingRouter(router, authMiddleware) api.InitDraftingRouter(router, authMiddleware)
api.InitPublishedGiRouter(router, authMiddleware)
docs.SwaggerInfo.Title = "CBTC测试系统API" docs.SwaggerInfo.Title = "CBTC测试系统API"
engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

65
service/publishedGi.go Normal file
View File

@ -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()
}