From 8562d390711f287e8dc5fa636d290557ca1949bb Mon Sep 17 00:00:00 2001 From: Tran Anh Tuan Date: Fri, 8 May 2026 18:16:40 +0700 Subject: [PATCH] fix(delete): update delete operations to return affected rows for cabinets, rooms, and warehouses --- internal/services/cabinet_service.go | 8 ++++---- internal/services/room_service.go | 8 ++++---- internal/services/warehouse_service.go | 9 +++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/services/cabinet_service.go b/internal/services/cabinet_service.go index 442db2b..693f516 100644 --- a/internal/services/cabinet_service.go +++ b/internal/services/cabinet_service.go @@ -173,13 +173,13 @@ func CabinetDelete(c *gin.Context) error { } rowsAffected, err := repositories.DeleteCabinet(c.Request.Context(), global.Queries, id) if err != nil { - if rowsAffected == 0 { - response.NotFoundError(c, http.StatusNotFound, "Cabinet not found") - return nil - } response.InternalServerError(c, http.StatusInternalServerError, "Failed to delete cabinet") return nil } + if rowsAffected == 0 { + response.NotFoundError(c, http.StatusNotFound, "Cabinet not found") + return nil + } response.Ok(c, "Delete Success", nil) return nil diff --git a/internal/services/room_service.go b/internal/services/room_service.go index 21674f7..6f2fc61 100644 --- a/internal/services/room_service.go +++ b/internal/services/room_service.go @@ -175,13 +175,13 @@ func RoomDelete(c *gin.Context) error { rowsAffected, err := repositories.DeleteRoom(c.Request.Context(), global.Queries, id) if err != nil { log.Error().Err(err).Msgf("Failed to delete room with ID: %d", id) - if rowsAffected == 0 { - response.NotFoundError(c, http.StatusNotFound, "Room not found") - return nil - } response.InternalServerError(c, http.StatusInternalServerError, "Failed to delete room") return nil } + if rowsAffected == 0 { + response.NotFoundError(c, http.StatusNotFound, "Room not found") + return nil + } response.Ok(c, "Delete Success", nil) return nil } diff --git a/internal/services/warehouse_service.go b/internal/services/warehouse_service.go index 30822e4..e897c6b 100644 --- a/internal/services/warehouse_service.go +++ b/internal/services/warehouse_service.go @@ -165,13 +165,14 @@ func WareHouseDelete(c *gin.Context) error { rowsAffected, err := repositories.DeleteWarehouse(c.Request.Context(), global.Queries, id) if err != nil { log.Error().Err(err).Msgf("Failed to delete warehouse with ID: %d", id) - if rowsAffected == 0 { - response.NotFoundError(c, http.StatusNotFound, "Warehouse not found") - return nil - } + response.InternalServerError(c, http.StatusInternalServerError, "Failed to delete warehouse") return nil } + if rowsAffected == 0 { + response.NotFoundError(c, http.StatusNotFound, "Warehouse not found") + return nil + } response.Ok(c, "Delete Success", nil) return nil }