Skip to content

Commit

Permalink
fix(software): properly remove associations on DELETE (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabio authored Sep 10, 2022
1 parent c664f42 commit c73780d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 1 addition & 3 deletions internal/handlers/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ func (p *Software) PatchSoftware(ctx *fiber.Ctx) error {

// DeleteSoftware deletes the software with the given ID.
func (p *Software) DeleteSoftware(ctx *fiber.Ctx) error {
var software models.Software

if err := p.db.Delete(&software, "id = ?", ctx.Params("id")).Error; err != nil {
if err := p.db.Select("Aliases").Delete(&models.Software{ID: ctx.Params("id")}).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return common.Error(fiber.StatusNotFound, "can't delete Software", "Software was not found")
}
Expand Down
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@ func TestSoftwareEndpoints(t *testing.T) {
expectedBody: "",
expectedContentType: "application/json",
},
// TODO: check there are no dangling software_urls

// GET /software/:id/logs
{
Expand Down

0 comments on commit c73780d

Please sign in to comment.