修改按名称查询发布地图数据接口

This commit is contained in:
joylink_zhangsai 2023-10-17 11:29:08 +08:00
parent 891df5237b
commit be6f84b923
3 changed files with 19 additions and 6 deletions

View File

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

View File

@ -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,

View File

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