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
+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")