feat(park):已完成删除指定园区的功能。
This commit is contained in:
parent
cd98d0917a
commit
04417c0fca
|
@ -31,6 +31,7 @@ func InitializeParkController(router *gin.Engine) {
|
||||||
ParkController.Router.PUT("/park/:pid", security.EnterpriseAuthorize, modifyPark)
|
ParkController.Router.PUT("/park/:pid", security.EnterpriseAuthorize, modifyPark)
|
||||||
ParkController.Router.GET("/park/:pid", security.EnterpriseAuthorize, fetchParkDetail)
|
ParkController.Router.GET("/park/:pid", security.EnterpriseAuthorize, fetchParkDetail)
|
||||||
ParkController.Router.PUT("/park/:pid/enabled", security.EnterpriseAuthorize, changeParkEnableState)
|
ParkController.Router.PUT("/park/:pid/enabled", security.EnterpriseAuthorize, changeParkEnableState)
|
||||||
|
ParkController.Router.DELETE("/park/:pid", security.EnterpriseAuthorize, deleteSpecificPark)
|
||||||
}
|
}
|
||||||
|
|
||||||
func listAllParksUnderSessionUser(c *gin.Context) {
|
func listAllParksUnderSessionUser(c *gin.Context) {
|
||||||
|
@ -192,3 +193,23 @@ func changeParkEnableState(c *gin.Context) {
|
||||||
}
|
}
|
||||||
result.Updated("指定园区的可用性状态已成功更新。")
|
result.Updated("指定园区的可用性状态已成功更新。")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteSpecificPark(c *gin.Context) {
|
||||||
|
result := response.NewResult(c)
|
||||||
|
session, exists := c.Get("session")
|
||||||
|
if !exists {
|
||||||
|
result.Error(http.StatusUnauthorized, "用户会话无效。")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userSession, ok := session.(*model.Session)
|
||||||
|
if !ok {
|
||||||
|
result.Failure(http.StatusInternalServerError, "内部缓存错误,需要重新登录。")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
requestParkId := c.Param("pid")
|
||||||
|
err := service.ParkService.DeletePark(userSession.Uid, requestParkId)
|
||||||
|
if err != nil {
|
||||||
|
result.Error(http.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
result.Deleted("指定园区已成功删除。")
|
||||||
|
}
|
||||||
|
|
|
@ -49,3 +49,17 @@ func (_ParkService) ChangeParkState(uid, pid string, state bool) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_ParkService) DeletePark(uid, pid string) error {
|
||||||
|
rows, err := global.DBConn.
|
||||||
|
Where(builder.Eq{"id": pid, "user_id": uid}).
|
||||||
|
Delete(&model.Park{})
|
||||||
|
if err != nil {
|
||||||
|
if rows == 0 {
|
||||||
|
return exceptions.NewNotFoundError("未能找到符合条件的园区。")
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user