fix(zone): register domain delete/update APIs and drop edit UI

补全 Zone 与 Zone 域名的 update/delete 路由与业务逻辑,修复删除域名
404;前端域名列表移除编辑入口,仅保留添加与删除。
This commit is contained in:
ryan
2026-07-12 15:56:45 +08:00
parent 7ef84cce52
commit 8afd103751
11 changed files with 987 additions and 51 deletions
+110
View File
@@ -87,6 +87,56 @@ func GetOverviewHandler(c *gin.Context) {
c.JSON(http.StatusOK, response.OK(item))
}
// UpdateHandler updates a Zone.
// @Summary 更新 Zone
// @Tags openflare-zone
// @Accept json
// @Produce json
// @Security SessionCookie
// @Param id path int true "Zone ID"
// @Param body body zone.Input true "Zone 参数"
// @Success 200 {object} response.Any{data=model.Zone}
// @Failure 400 {object} response.Any
// @Failure 404 {object} response.Any
// @Failure 409 {object} response.Any
// @Router /api/v1/d/zones/{id}/update [post]
func UpdateHandler(c *gin.Context) {
id, ok := apiutil.IDParam(c)
if !ok {
return
}
var input Input
if !apiutil.BindJSON(c, &input) {
return
}
item, err := Update(c.Request.Context(), id, input)
if abort(c, err, errZoneNotFound) {
return
}
c.JSON(http.StatusOK, response.OK(item))
}
// DeleteHandler deletes a Zone with no remaining domains.
// @Summary 删除 Zone
// @Tags openflare-zone
// @Produce json
// @Security SessionCookie
// @Param id path int true "Zone ID"
// @Success 200 {object} response.Any
// @Failure 400 {object} response.Any
// @Failure 404 {object} response.Any
// @Router /api/v1/d/zones/{id}/delete [post]
func DeleteHandler(c *gin.Context) {
id, ok := apiutil.IDParam(c)
if !ok {
return
}
if err := Delete(c.Request.Context(), id); abort(c, err, errZoneNotFound) {
return
}
c.JSON(http.StatusOK, response.OKNil())
}
// CreateDomainHandler creates an explicit FQDN under a Zone.
// @Summary 创建 Zone 域名
// @Tags openflare-zone
@@ -115,3 +165,63 @@ func CreateDomainHandler(c *gin.Context) {
}
c.JSON(http.StatusOK, response.OK(item))
}
// UpdateDomainHandler updates a Zone domain.
// @Summary 更新 Zone 域名
// @Tags openflare-zone
// @Accept json
// @Produce json
// @Security SessionCookie
// @Param id path int true "Zone ID"
// @Param domainId path int true "域名 ID"
// @Param body body zone.DomainInput true "域名参数"
// @Success 200 {object} response.Any{data=model.ZoneDomain}
// @Failure 400 {object} response.Any
// @Failure 404 {object} response.Any
// @Failure 409 {object} response.Any
// @Router /api/v1/d/zones/{id}/domains/{domainId}/update [post]
func UpdateDomainHandler(c *gin.Context) {
zoneID, ok := apiutil.IDParam(c)
if !ok {
return
}
domainID, ok := apiutil.NamedIDParam(c, "domainId")
if !ok {
return
}
var input DomainInput
if !apiutil.BindJSON(c, &input) {
return
}
item, err := UpdateDomain(c.Request.Context(), zoneID, domainID, input)
if abort(c, err, errDomainNotFound) {
return
}
c.JSON(http.StatusOK, response.OK(item))
}
// DeleteDomainHandler deletes a Zone domain not bound to a proxy route.
// @Summary 删除 Zone 域名
// @Tags openflare-zone
// @Produce json
// @Security SessionCookie
// @Param id path int true "Zone ID"
// @Param domainId path int true "域名 ID"
// @Success 200 {object} response.Any
// @Failure 400 {object} response.Any
// @Failure 404 {object} response.Any
// @Router /api/v1/d/zones/{id}/domains/{domainId}/delete [post]
func DeleteDomainHandler(c *gin.Context) {
zoneID, ok := apiutil.IDParam(c)
if !ok {
return
}
domainID, ok := apiutil.NamedIDParam(c, "domainId")
if !ok {
return
}
if err := DeleteDomain(c.Request.Context(), zoneID, domainID); abort(c, err, errDomainNotFound) {
return
}
c.JSON(http.StatusOK, response.OKNil())
}