修改路由
This commit is contained in:
1871
docs/docs.go
1871
docs/docs.go
File diff suppressed because it is too large
Load Diff
1842
docs/swagger.json
1842
docs/swagger.json
File diff suppressed because it is too large
Load Diff
1193
docs/swagger.yaml
1193
docs/swagger.yaml
File diff suppressed because it is too large
Load Diff
@@ -204,7 +204,7 @@ func (a *API) setupRoutes() {
|
||||
a.logger.Info("计划相关接口注册成功 (需要认证和审计)")
|
||||
|
||||
// 猪舍相关路由组
|
||||
pigHouseGroup := authGroup.Group("/pighouses")
|
||||
pigHouseGroup := authGroup.Group("/pig-houses")
|
||||
{
|
||||
pigHouseGroup.POST("", a.pigFarmController.CreatePigHouse)
|
||||
pigHouseGroup.GET("", a.pigFarmController.ListPigHouses)
|
||||
|
||||
@@ -38,7 +38,7 @@ func NewPigFarmController(logger *logs.Logger, service service.PigFarmService) *
|
||||
// @Produce json
|
||||
// @Param body body dto.CreatePigHouseRequest true "猪舍信息"
|
||||
// @Success 201 {object} controller.Response{data=dto.PigHouseResponse} "创建成功"
|
||||
// @Router /api/v1/pighouses [post]
|
||||
// @Router /api/v1/pig-houses [post]
|
||||
func (c *PigFarmController) CreatePigHouse(ctx *gin.Context) {
|
||||
const action = "创建猪舍"
|
||||
var req dto.CreatePigHouseRequest
|
||||
@@ -69,7 +69,7 @@ func (c *PigFarmController) CreatePigHouse(ctx *gin.Context) {
|
||||
// @Produce json
|
||||
// @Param id path int true "猪舍ID"
|
||||
// @Success 200 {object} controller.Response{data=dto.PigHouseResponse} "获取成功"
|
||||
// @Router /api/v1/pighouses/{id} [get]
|
||||
// @Router /api/v1/pig-houses/{id} [get]
|
||||
func (c *PigFarmController) GetPigHouse(ctx *gin.Context) {
|
||||
const action = "获取猪舍"
|
||||
id, err := strconv.ParseUint(ctx.Param("id"), 10, 32)
|
||||
@@ -103,7 +103,7 @@ func (c *PigFarmController) GetPigHouse(ctx *gin.Context) {
|
||||
// @Tags 猪场管理
|
||||
// @Produce json
|
||||
// @Success 200 {object} controller.Response{data=[]dto.PigHouseResponse} "获取成功"
|
||||
// @Router /api/v1/pighouses [get]
|
||||
// @Router /api/v1/pig-houses [get]
|
||||
func (c *PigFarmController) ListPigHouses(ctx *gin.Context) {
|
||||
const action = "获取猪舍列表"
|
||||
houses, err := c.service.ListPigHouses()
|
||||
@@ -134,7 +134,7 @@ func (c *PigFarmController) ListPigHouses(ctx *gin.Context) {
|
||||
// @Param id path int true "猪舍ID"
|
||||
// @Param body body dto.UpdatePigHouseRequest true "猪舍信息"
|
||||
// @Success 200 {object} controller.Response{data=dto.PigHouseResponse} "更新成功"
|
||||
// @Router /api/v1/pighouses/{id} [put]
|
||||
// @Router /api/v1/pig-houses/{id} [put]
|
||||
func (c *PigFarmController) UpdatePigHouse(ctx *gin.Context) {
|
||||
const action = "更新猪舍"
|
||||
id, err := strconv.ParseUint(ctx.Param("id"), 10, 32)
|
||||
@@ -175,7 +175,7 @@ func (c *PigFarmController) UpdatePigHouse(ctx *gin.Context) {
|
||||
// @Produce json
|
||||
// @Param id path int true "猪舍ID"
|
||||
// @Success 200 {object} controller.Response "删除成功"
|
||||
// @Router /api/v1/pighouses/{id} [delete]
|
||||
// @Router /api/v1/pig-houses/{id} [delete]
|
||||
func (c *PigFarmController) DeletePigHouse(ctx *gin.Context) {
|
||||
const action = "删除猪舍"
|
||||
id, err := strconv.ParseUint(ctx.Param("id"), 10, 32)
|
||||
@@ -216,7 +216,7 @@ func (c *PigFarmController) CreatePen(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pen, err := c.service.CreatePen(req.PenNumber, req.HouseID, req.Capacity, req.Status)
|
||||
pen, err := c.service.CreatePen(req.PenNumber, req.HouseID, req.Capacity)
|
||||
if err != nil {
|
||||
c.logger.Errorf("%s: 业务逻辑失败: %v", action, err)
|
||||
controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "创建猪栏失败", action, "业务逻辑失败", req)
|
||||
|
||||
@@ -26,7 +26,7 @@ type PigFarmService interface {
|
||||
DeletePigHouse(id uint) error
|
||||
|
||||
// Pen methods
|
||||
CreatePen(penNumber string, houseID uint, capacity int, status models.PenStatus) (*models.Pen, error)
|
||||
CreatePen(penNumber string, houseID uint, capacity int) (*models.Pen, error)
|
||||
GetPenByID(id uint) (*models.Pen, error)
|
||||
ListPens() ([]models.Pen, error)
|
||||
UpdatePen(id uint, penNumber string, houseID uint, capacity int, status models.PenStatus) (*models.Pen, error)
|
||||
@@ -99,7 +99,7 @@ func (s *pigFarmService) DeletePigHouse(id uint) error {
|
||||
|
||||
// --- Pen Implementation ---
|
||||
|
||||
func (s *pigFarmService) CreatePen(penNumber string, houseID uint, capacity int, status models.PenStatus) (*models.Pen, error) {
|
||||
func (s *pigFarmService) CreatePen(penNumber string, houseID uint, capacity int) (*models.Pen, error) {
|
||||
// 业务逻辑:验证所属猪舍是否存在
|
||||
_, err := s.repo.GetPigHouseByID(houseID)
|
||||
if err != nil {
|
||||
@@ -113,7 +113,7 @@ func (s *pigFarmService) CreatePen(penNumber string, houseID uint, capacity int,
|
||||
PenNumber: penNumber,
|
||||
HouseID: houseID,
|
||||
Capacity: capacity,
|
||||
Status: status,
|
||||
Status: models.PenStatusEmpty,
|
||||
}
|
||||
err = s.repo.CreatePen(pen)
|
||||
return pen, err
|
||||
|
||||
Reference in New Issue
Block a user