feat: add delete method for both trash domain
This commit is contained in:
parent
9a99f4f03b
commit
fec1ec8e36
|
@ -17,12 +17,12 @@ func AppRouter(app *fiber.App) {
|
|||
|
||||
// # userinfo
|
||||
app.Get("/user", middleware.AuthMiddleware, controllers.GetUserInfo)
|
||||
app.Put("/update-user", middleware.AuthMiddleware, controllers.UpdateUser)
|
||||
app.Post("/user/update-password", middleware.AuthMiddleware, controllers.UpdatePassword)
|
||||
app.Put("/update-user", middleware.AuthMiddleware, controllers.UpdateUser)
|
||||
|
||||
// # user set pin
|
||||
app.Post("/user/set-pin", middleware.AuthMiddleware, controllers.CreatePin)
|
||||
app.Get("/user/get-pin", middleware.AuthMiddleware, controllers.GetPin)
|
||||
app.Post("/user/set-pin", middleware.AuthMiddleware, controllers.CreatePin)
|
||||
app.Put("/user/update-pin", middleware.AuthMiddleware, controllers.UpdatePin)
|
||||
|
||||
// # address routing
|
||||
|
@ -33,9 +33,9 @@ func AppRouter(app *fiber.App) {
|
|||
app.Delete("/address/:id", middleware.AuthMiddleware, controllers.DeleteAddress)
|
||||
|
||||
// # article
|
||||
app.Post("/articles", middleware.AuthMiddleware, controllers.CreateArticle)
|
||||
app.Get("/articles", middleware.AuthMiddleware, controllers.GetArticles)
|
||||
app.Get("/articles/:id", middleware.AuthMiddleware, controllers.GetArticleByID)
|
||||
app.Post("/articles", middleware.AuthMiddleware, controllers.CreateArticle)
|
||||
app.Put("/articles/:id", middleware.AuthMiddleware, controllers.UpdateArticle)
|
||||
app.Delete("/articles/:id", middleware.AuthMiddleware, controllers.DeleteArticle)
|
||||
|
||||
|
@ -46,4 +46,6 @@ func AppRouter(app *fiber.App) {
|
|||
app.Post("/addtrash-categorydetail", controllers.CreateTrashDetail)
|
||||
app.Put("/updatetrash-category/:id", controllers.UpdateTrashCategory)
|
||||
app.Put("/updatetrash-detail/:id", controllers.UpdateTrashDetail)
|
||||
app.Delete("/deletetrash-category/:id", controllers.DeleteTrashCategory)
|
||||
app.Delete("/deletetrash-detail/:id", controllers.DeleteTrashDetail)
|
||||
}
|
||||
|
|
|
@ -251,3 +251,43 @@ func UpdateTrashDetail(c *fiber.Ctx) error {
|
|||
response,
|
||||
))
|
||||
}
|
||||
|
||||
func DeleteTrashCategory(c *fiber.Ctx) error {
|
||||
id := c.Params("id")
|
||||
|
||||
err := services.DeleteTrashCategory(id)
|
||||
if err != nil {
|
||||
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(utils.FormatResponse(
|
||||
fiber.StatusInternalServerError,
|
||||
"Failed to delete trash category",
|
||||
nil,
|
||||
))
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||
fiber.StatusOK,
|
||||
"Trash category deleted successfully",
|
||||
nil,
|
||||
))
|
||||
}
|
||||
|
||||
func DeleteTrashDetail(c *fiber.Ctx) error {
|
||||
id := c.Params("id")
|
||||
|
||||
err := services.DeleteTrashDetail(id)
|
||||
if err != nil {
|
||||
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(utils.FormatResponse(
|
||||
fiber.StatusInternalServerError,
|
||||
"Failed to delete trash detail",
|
||||
nil,
|
||||
))
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||
fiber.StatusOK,
|
||||
"Trash detail deleted successfully",
|
||||
nil,
|
||||
))
|
||||
}
|
||||
|
|
|
@ -57,3 +57,25 @@ func UpdateTrashDetail(detail *domain.TrashDetail) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteTrashCategory(id string) error {
|
||||
|
||||
if err := config.DB.Where("category_id = ?", id).Delete(&domain.TrashDetail{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := config.DB.Where("id = ?", id).Delete(&domain.TrashCategory{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteTrashDetail(id string) error {
|
||||
|
||||
if err := config.DB.Where("id = ?", id).Delete(&domain.TrashDetail{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -65,3 +65,21 @@ func UpdateTrashDetail(id, description string, price int) (domain.TrashDetail, e
|
|||
|
||||
return detail, nil
|
||||
}
|
||||
|
||||
func DeleteTrashCategory(id string) error {
|
||||
|
||||
err := repositories.DeleteTrashCategory(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteTrashDetail(id string) error {
|
||||
|
||||
err := repositories.DeleteTrashDetail(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue