Implement new budget with transaction to be able to satisfy not null columns

This commit is contained in:
2021-12-11 20:19:52 +00:00
parent 935499e3a8
commit 40a299141d
3 changed files with 40 additions and 0 deletions

View File

@ -22,5 +22,24 @@ func (s *Database) NewBudget(context context.Context, name string, userID uuid.U
return nil, err
}
group, err := q.CreateCategoryGroup(context, CreateCategoryGroupParams{
Name: "Inflow",
BudgetID: budget.ID,
})
if err != nil {
return nil, err
}
cat, err := q.CreateCategory(context, CreateCategoryParams{
Name: "Ready to assign",
CategoryGroupID: group.ID,
})
q.SetInflowCategory(context, SetInflowCategoryParams{
IncomeCategoryID: cat.ID,
ID: budget.ID,
})
tx.Commit()
return &budget, nil
}