Compare commits

..

No commits in common. "8807235dada9b31409245850e1f89b9aed222e08" and "d55ba5c3c74ce22bad9aeda0bf65a92f3ecfd689" have entirely different histories.

3 changed files with 7 additions and 20 deletions

View File

@ -39,6 +39,9 @@ var (
)
func (c *Category) BeforeSave(tx *gorm.DB) error {
if c.ParentID == c.ID {
return ERROR_CATEGORY_SELF_REFERENCING
}
if c.ParentID != 0 {
var parent Category
if err := tx.Find(&parent, c.ParentID).Error; err != nil {
@ -60,10 +63,3 @@ func (c *Category) BeforeSave(tx *gorm.DB) error {
}
return nil
}
func (c *Category) AfterCreate(tx *gorm.DB) error {
if c.ParentID == c.ID {
return ERROR_CATEGORY_SELF_REFERENCING
}
return nil
}

View File

@ -1,23 +1,16 @@
package handlers
import (
"fmt"
"git.qowevisa.me/Qowevisa/fin-check-api/db"
"git.qowevisa.me/Qowevisa/fin-check-api/types"
"github.com/gin-gonic/gin"
)
var categoryTransform func(*db.Category) types.DbCategory = func(inp *db.Category) types.DbCategory {
nameWithParent := inp.Name
if inp.Parent != nil {
nameWithParent = fmt.Sprintf("%s -> %s", inp.Parent.Name, inp.Name)
}
return types.DbCategory{
ID: inp.ID,
Name: inp.Name,
ParentID: inp.ParentID,
NameWithParent: nameWithParent,
ID: inp.ID,
Name: inp.Name,
ParentID: inp.ParentID,
}
}
@ -57,7 +50,7 @@ func CategoryGetAll(c *gin.Context) {
}
dbc := db.Connect()
var entities []*db.Category
if err := dbc.Preload("Parent").Find(&entities, db.Category{UserID: userID}).Error; err != nil {
if err := dbc.Find(&entities, db.Category{UserID: userID}).Error; err != nil {
c.JSON(500, types.ErrorResponse{Message: err.Error()})
return
}

View File

@ -42,8 +42,6 @@ type DbCategory struct {
// Parent is used as a infinite sub-category structure
// Can be 0
ParentID uint `json:"parent_id" example:"0"`
// Purely UI things
NameWithParent string `json:"name_with_parent" example:"World -> Moldova"`
}
type DbDebt struct {