109 lines
3.0 KiB
Go
Executable File
109 lines
3.0 KiB
Go
Executable File
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.zhouxhere.com/zhouxhere/maptile/model"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// ListFeature 获取要素列表
|
|
// @Summary 获取要素列表
|
|
// @Description 获取要素列表
|
|
// @Tags feature
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param page query int false "页码"
|
|
// @Param size query int false "每页数量"
|
|
// @Success 200 {object} Pagination[FeaturePublic]
|
|
// @Router /features [get]
|
|
func (a *API) GetFeatures(c echo.Context) error {
|
|
var featureList model.FeatureList
|
|
if err := BindAndValidate(c, &featureList); err != nil {
|
|
return Error(c, http.StatusBadRequest, err.Error())
|
|
}
|
|
features, total, err := a.store.ListFeature(&featureList)
|
|
if err != nil {
|
|
return Error(c, http.StatusInternalServerError, err.Error())
|
|
}
|
|
// 将 features 转换为 FeaturePublic
|
|
featurePublics := make([]model.FeaturePublic, len(features))
|
|
for i, feature := range features {
|
|
featurePublics[i] = feature.ToPublic()
|
|
}
|
|
return Paginate(c, featurePublics, featureList.Page, featureList.Size, total, "获取要素列表成功")
|
|
}
|
|
|
|
// CreateFeature 创建要素
|
|
// @Summary 创建要素
|
|
// @Description 创建要素
|
|
// @Tags feature
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param feature body store.FeatureCreate true "要素"
|
|
// @Success 200 {object} Response[FeaturePublic]
|
|
// @Router /feature [post]
|
|
func (a *API) PostFeature(c echo.Context) error {
|
|
var featureCreate model.FeatureCreate
|
|
if err := BindAndValidate(c, &featureCreate); err != nil {
|
|
return Error(c, http.StatusBadRequest, err.Error())
|
|
}
|
|
feature, err := a.store.CreateFeature(&featureCreate)
|
|
if err != nil {
|
|
return Error(c, http.StatusInternalServerError, err.Error())
|
|
}
|
|
return Success(c, feature.ToPublic(), "创建要素成功")
|
|
}
|
|
|
|
// GetFeatureByID 获取要素
|
|
// @Summary 获取要素
|
|
// @Description 获取要素
|
|
// @Tags feature
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "要素 ID"
|
|
// @Success 200 {object} Response[FeaturePublic]
|
|
// @Router /feature/{id} [get]
|
|
func (a *API) GetFeatureByID(c echo.Context) error {
|
|
return nil
|
|
}
|
|
|
|
// UpdateFeature 更新要素
|
|
// @Summary 更新要素
|
|
// @Description 更新要素
|
|
// @Tags feature
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param feature body store.FeatureUpdate true "要素"
|
|
// @Success 200 {object} Response[FeaturePublic]
|
|
// @Router /feature [put]
|
|
func (a *API) PutFeature(c echo.Context) error {
|
|
return nil
|
|
}
|
|
|
|
// DeleteFeature 删除要素
|
|
// @Summary 删除要素
|
|
// @Description 删除要素
|
|
// @Tags feature
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param feature body store.FeatureDeleteOrBanned true "要素"
|
|
// @Success 200 {object} Response[FeaturePublic]
|
|
// @Router /feature/{id} [delete]
|
|
func (a *API) DeleteFeature(c echo.Context) error {
|
|
return nil
|
|
}
|
|
|
|
// BannedFeature 禁用要素
|
|
// @Summary 禁用要素
|
|
// @Description 禁用要素
|
|
// @Tags feature
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param feature body store.FeatureDeleteOrBanned true "要素"
|
|
// @Success 200 {object} Response[FeaturePublic]
|
|
// @Router /feature/banned/{id} [post]
|
|
func (a *API) BannedFeature(c echo.Context) error {
|
|
return nil
|
|
}
|