feat: swag.

This commit is contained in:
2026-05-04 16:20:46 +08:00
parent 3fbbbbc6a8
commit b7843641ca
24 changed files with 9376 additions and 19 deletions
+40
View File
@@ -26,6 +26,14 @@ func NewKindergartenAdminController() *KindergartenAdminController {
return &KindergartenAdminController{DB: config.DB}
}
// @Summary 获取幼儿园列表
// @Description 查询幼儿园列表,支持按名称/地址模糊搜索
// @Tags 幼儿园管理
// @Produce json
// @Param keyword query string false "关键词(名称/地址模糊搜索)"
// @Security BearerAuth
// @Success 200 {object} SwagAPIResponse "查询成功"
// @Router /admin/kindergartens [get]
func (kc *KindergartenAdminController) List(c *gin.Context) {
var items []models.Kindergarten
query := kc.DB.Model(&models.Kindergarten{}).Order("region_id ASC, id ASC")
@@ -42,6 +50,16 @@ func (kc *KindergartenAdminController) List(c *gin.Context) {
writeSuccess(c, http.StatusOK, "query success", items)
}
// @Summary 创建幼儿园
// @Description 创建新的幼儿园记录
// @Tags 幼儿园管理
// @Accept json
// @Produce json
// @Param kindergarten body kindergartenPayload true "幼儿园信息"
// @Security BearerAuth
// @Success 201 {object} SwagAPIResponse "创建成功"
// @Failure 400 {object} SwagAPIResponse "请求参数错误"
// @Router /admin/kindergartens [post]
func (kc *KindergartenAdminController) Create(c *gin.Context) {
var payload kindergartenPayload
if err := c.ShouldBindJSON(&payload); err != nil {
@@ -65,6 +83,18 @@ func (kc *KindergartenAdminController) Create(c *gin.Context) {
writeSuccess(c, http.StatusCreated, "create success", record)
}
// @Summary 更新幼儿园信息
// @Description 更新指定幼儿园的名称、地址和区域
// @Tags 幼儿园管理
// @Accept json
// @Produce json
// @Param id path int true "幼儿园ID"
// @Param kindergarten body kindergartenPayload true "更新信息"
// @Security BearerAuth
// @Success 200 {object} SwagAPIResponse "更新成功"
// @Failure 400 {object} SwagAPIResponse "请求参数错误"
// @Failure 404 {object} SwagAPIResponse "幼儿园不存在"
// @Router /admin/kindergartens/{id} [put]
func (kc *KindergartenAdminController) Update(c *gin.Context) {
record, err := kc.findByID(c.Param("id"))
if err != nil {
@@ -93,6 +123,16 @@ func (kc *KindergartenAdminController) Update(c *gin.Context) {
writeSuccess(c, http.StatusOK, "update success", record)
}
// @Summary 删除幼儿园
// @Description 删除指定幼儿园,如果被用户绑定则无法删除
// @Tags 幼儿园管理
// @Produce json
// @Param id path int true "幼儿园ID"
// @Security BearerAuth
// @Success 200 {object} SwagAPIResponse "删除成功"
// @Failure 404 {object} SwagAPIResponse "幼儿园不存在"
// @Failure 409 {object} SwagAPIResponse "已绑定用户无法删除"
// @Router /admin/kindergartens/{id} [delete]
func (kc *KindergartenAdminController) Delete(c *gin.Context) {
record, err := kc.findByID(c.Param("id"))
if err != nil {