-
Notifications
You must be signed in to change notification settings - Fork 3
/
cleanup.go
63 lines (53 loc) · 1.4 KB
/
cleanup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package controllers
import (
"net/http"
"github.com/envelope-zero/backend/pkg/httperrors"
"github.com/envelope-zero/backend/pkg/models"
"github.com/gin-gonic/gin"
)
// DeleteAll permanently deletes all resources in the database
//
// @Summary Delete everything
// @Description Permanently deletes all resources
// @Tags v1
// @Success 204
// @Failure 500 {object} httperrors.HTTPError
// @Router /v1 [delete]
func (co Controller) DeleteAll(c *gin.Context) {
err := co.DB.Unscoped().Where("true").Delete(&models.Transaction{}).Error
if err != nil {
httperrors.Handler(c, err)
return
}
err = co.DB.Unscoped().Where("true").Delete(&models.Allocation{}).Error
if err != nil {
httperrors.Handler(c, err)
return
}
err = co.DB.Unscoped().Where("true").Delete(&models.Envelope{}).Error
if err != nil {
httperrors.Handler(c, err)
return
}
err = co.DB.Unscoped().Where("true").Delete(&models.Category{}).Error
if err != nil {
httperrors.Handler(c, err)
return
}
err = co.DB.Unscoped().Where("true").Delete(&models.Account{}).Error
if err != nil {
httperrors.Handler(c, err)
return
}
err = co.DB.Unscoped().Where("true").Delete(&models.Budget{}).Error
if err != nil {
httperrors.Handler(c, err)
return
}
err = co.DB.Unscoped().Where("true").Delete(&models.MonthConfig{}).Error
if err != nil {
httperrors.Handler(c, err)
return
}
c.JSON(http.StatusNoContent, gin.H{})
}