Skip to content

Commit

Permalink
Merge pull request #53 from Maker-Management-Platform/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
EduardoOliveira authored Jan 16, 2024
2 parents ca8319d + 83142c4 commit 6b7ba8c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/data/database/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ func GetProjectNames() (rtn []*models.Project, err error) {
func GetProject(uuid string) (rtn *models.Project, err error) {
return rtn, DB.Where(&models.Project{UUID: uuid}).Preload("Tags").First(&rtn).Error
}

func DeleteProject(uuid string) (err error) {
return DB.Where(&models.Project{UUID: uuid}).Delete(&models.Project{}).Error
}
29 changes: 29 additions & 0 deletions core/projects/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,32 @@ func setMainImageHandler(c echo.Context) error {
Path string `json:"path"`
}{project.UUID, project.DefaultImageID})
}

func deleteHandler(c echo.Context) error {

uuid := c.Param("uuid")

if uuid == "" {
return c.NoContent(http.StatusBadRequest)
}
project, err := database.GetProject(uuid)

if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return echo.NewHTTPError(http.StatusNotFound, err.Error())
}
log.Println(err)
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}

err = os.RemoveAll(utils.ToLibPath(project.FullPath()))
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

if err := database.DeleteProject(uuid); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.NoContent(http.StatusOK)
}
1 change: 1 addition & 0 deletions core/projects/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ func Register(e *echo.Group) {
group.POST("/:uuid", save)
group.POST("/:uuid/move", moveHandler)
group.POST("/:uuid/image", setMainImageHandler)
group.POST("/:uuid/delete", deleteHandler)
group.POST("", new)
}

0 comments on commit 6b7ba8c

Please sign in to comment.