diff --git a/api/publishedGi.go b/api/publishedGi.go index e93b4d2..d53c250 100644 --- a/api/publishedGi.go +++ b/api/publishedGi.go @@ -22,7 +22,7 @@ func InitPublishedGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl authed.POST("/publish", publishFromDraft) authed.DELETE("/:id", deletePublishedGiById) authed.POST("/saveAsDrafting/:id", saveAsDraftingFromPublish) - authed.GET("/name/:name", getPublishedGiByName) + authed.GET("/name", getPublishedGiByName) } // 分页查询发布的图形数据 @@ -213,9 +213,10 @@ func saveAsDraftingFromPublish(c *gin.Context) { func getPublishedGiByName(c *gin.Context) { user, _ := c.Get(middleware.IdentityKey) slog.Debug("name查询发布的图形数据", user) - name := c.Param("name") - slog.Debug("name查询发布的图形数据", name) - entity, err := service.GetPublishedGiByCode(name) + param := &publishedGi.PublishedGiSingleQueryDto{} + err := c.ShouldBind(param) + slog.Debug("name查询发布的图形数据", param.Name) + entity, err := service.GetPublishedGiByName(param) if err != nil { panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) } diff --git a/dto/publishedGi/publishedGi.go b/dto/publishedGi/publishedGi.go index 53b86be..381e0c8 100644 --- a/dto/publishedGi/publishedGi.go +++ b/dto/publishedGi/publishedGi.go @@ -41,6 +41,12 @@ type PublishedGiDto struct { PublishAt dto.JsonTime `json:"publishAt" time_format:"2006-01-02 15:04:05"` } +// PublishedGiSingleQueryDto 单个查询发布地图数据 +type PublishedGiSingleQueryDto struct { + Name string `json:"name" form:"name"` + Detail bool `json:"detail" form:"detail"` +} + func ConvertFrom(gi *model.PublishedGi) *PublishedGiDto { return &PublishedGiDto{ ID: gi.ID, diff --git a/service/publishedGi.go b/service/publishedGi.go index 286702a..ef08656 100644 --- a/service/publishedGi.go +++ b/service/publishedGi.go @@ -146,6 +146,12 @@ func QueryProjectPublishedGi(id int32) []*model.PublishedGi { return publishedGis } -func GetPublishedGiByCode(name string) (*model.PublishedGi, error) { - return dbquery.PublishedGi.Where(dbquery.PublishedGi.Name.Eq(name)).Debug().First() +func GetPublishedGiByName(param *publishedGi.PublishedGiSingleQueryDto) (*model.PublishedGi, error) { + where := dbquery.PublishedGi. + Where(dbquery.PublishedGi.Name.Eq(param.Name)). + Where(dbquery.PublishedGi.Status.Eq(1)) + if !param.Detail { + where = where.Omit(dbquery.PublishedGi.Proto) + } + return where.Debug().First() }