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

This commit is contained in:
2024-11-24 16:02:13 +07:00
parent 866009cf09
commit bf85f31056
9 changed files with 104 additions and 10 deletions
+22 -3
View File
@@ -3,6 +3,7 @@ package app
import (
"context"
"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"
@@ -12,15 +13,18 @@ type Server struct {
proto.UnsafeSmmCoreServer
categoryService *category.CategoryService
userService *user.UserService
budgetService *budget.BudgetService
}
func NewServer(
categoryService *category.CategoryService,
userService *user.UserService,
budgetService *budget.BudgetService,
) proto.SmmCoreServer {
return &Server{
categoryService: categoryService,
userService: userService,
budgetService: budgetService,
}
}
@@ -62,9 +66,24 @@ func (s *Server) Login(ctx context.Context, req *proto.LoginReq) (*proto.User, e
}, nil
}
// AddBudget implements proto.SmmCoreServer.
func (s *Server) AddBudget(context.Context, *proto.AddBudgetReq) (*proto.Budget, error) {
panic("unimplemented")
func (s *Server) AddBudget(ctx context.Context, req *proto.AddBudgetReq) (*proto.Budget, error) {
budget, err := s.budgetService.AddBudget(
ctx,
&budget.BudgetEntity{
Name: req.Name,
StartDay: int(req.StartDay),
MonthlyLimit: int(req.MonthlyLimit),
},
)
if err != nil {
return nil, err
}
return &proto.Budget{
Id: int32(budget.Id),
Name: budget.Name,
StartDay: int32(budget.StartDay),
MonthlyLimit: int32(budget.MonthlyLimit),
}, nil
}
// AddCategory implements proto.SmmCoreServer.