add create categories route
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-11-25 13:36:14 +07:00
parent 130a3236e0
commit 675c2884b7
12 changed files with 621 additions and 518 deletions
+19
View File
@@ -2,6 +2,7 @@ package app
import (
"git.3crabs.ru/save_my_money/smm_core/internal/services/budget"
"git.3crabs.ru/save_my_money/smm_core/internal/services/category"
"git.3crabs.ru/save_my_money/smm_core/internal/services/user"
proto "git.3crabs.ru/save_my_money/smm_core/proto"
)
@@ -19,5 +20,23 @@ func mapBudget(budget *budget.BudgetEntity) *proto.Budget {
Name: budget.Name,
StartDay: int32(budget.StartDay),
MonthlyLimit: int32(budget.MonthlyLimit),
Categories: mapCategories(budget.Categories),
}
}
func mapCategory(category *category.CategoryEntity) *proto.Category {
return &proto.Category{
Id: int32(category.Id),
Name: category.Name,
Favorite: category.Favorite,
MonthlyLimit: int32(category.MonthlyLimit),
}
}
func mapCategories(categories []*category.CategoryEntity) []*proto.Category {
res := make([]*proto.Category, 0, len(categories))
for _, item := range categories {
res = append(res, mapCategory(item))
}
return res
}
+31 -8
View File
@@ -103,9 +103,37 @@ func (s *Server) AddUserToBudget(ctx context.Context, req *proto.AddUserToBudget
return &proto.OK{}, nil
}
// AddCategory implements proto.SmmCoreServer.
func (s *Server) AddCategory(context.Context, *proto.AddCategoryReq) (*proto.Category, error) {
panic("unimplemented")
func (s *Server) AddCategory(ctx context.Context, req *proto.AddCategoryReq) (*proto.Category, error) {
category, err := s.categoryService.AddCategory(
ctx,
&category.CategoryEntity{
Name: req.Name,
BudgetId: int(req.BudgetId),
Favorite: req.Favorite,
MonthlyLimit: int(req.MonthlyLimit),
},
)
if err != nil {
return nil, err
}
return mapCategory(category), nil
}
func (s *Server) GetBudgetCategories(ctx context.Context, req *proto.GetBudgetCategoriesReq) (*proto.Categories, error) {
categories, err := s.budgetService.GetBudgetCategories(
ctx,
int(req.BudgetId),
)
if err != nil {
return nil, err
}
res := make([]*proto.Category, 0, len(categories))
for _, category := range categories {
res = append(res, mapCategory(category))
}
return &proto.Categories{
Categories: res,
}, nil
}
// AddWaste implements proto.SmmCoreServer.
@@ -133,11 +161,6 @@ func (s *Server) GetBudgetUsers(context.Context, *proto.GetBudgetUsersReq) (*pro
panic("unimplemented")
}
// GetCategories implements proto.SmmCoreServer.
func (s *Server) GetCategories(context.Context, *proto.GetCategoriesReq) (*proto.Categories, error) {
panic("unimplemented")
}
// GetCategoriesStat implements proto.SmmCoreServer.
func (s *Server) GetCategoriesStat(context.Context, *proto.GetCategoriesStatReq) (*proto.CategoriesStat, error) {
panic("unimplemented")