This commit is contained in:
+28
-12
@@ -43,10 +43,7 @@ func (s *Server) AddUser(ctx context.Context, req *proto.AddUserReq) (*proto.Use
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &proto.User{
|
||||
Id: int32(user.Id),
|
||||
Username: req.Username,
|
||||
}, nil
|
||||
return mapUser(user), nil
|
||||
}
|
||||
|
||||
func (s *Server) Login(ctx context.Context, req *proto.LoginReq) (*proto.User, error) {
|
||||
@@ -60,10 +57,14 @@ func (s *Server) Login(ctx context.Context, req *proto.LoginReq) (*proto.User, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapUser(user), nil
|
||||
}
|
||||
|
||||
func mapUser(user *user.UserEntity) *proto.User {
|
||||
return &proto.User{
|
||||
Id: int32(user.Id),
|
||||
Username: req.Username,
|
||||
}, nil
|
||||
Username: user.Username,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) AddBudget(ctx context.Context, req *proto.AddBudgetReq) (*proto.Budget, error) {
|
||||
@@ -78,12 +79,32 @@ func (s *Server) AddBudget(ctx context.Context, req *proto.AddBudgetReq) (*proto
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapBudget(budget), nil
|
||||
}
|
||||
|
||||
func (s *Server) GetBudgets(ctx context.Context, req *proto.GetBudgetsReq) (*proto.Budgets, error) {
|
||||
budgets, err := s.budgetService.GetBudgets(
|
||||
ctx,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make([]*proto.Budget, 0, len(budgets))
|
||||
for _, budget := range budgets {
|
||||
res = append(res, mapBudget(budget))
|
||||
}
|
||||
return &proto.Budgets{
|
||||
Budgets: res,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func mapBudget(budget *budget.BudgetEntity) *proto.Budget {
|
||||
return &proto.Budget{
|
||||
Id: int32(budget.Id),
|
||||
Name: budget.Name,
|
||||
StartDay: int32(budget.StartDay),
|
||||
MonthlyLimit: int32(budget.MonthlyLimit),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// AddCategory implements proto.SmmCoreServer.
|
||||
@@ -121,11 +142,6 @@ func (s *Server) GetBudgetUsers(context.Context, *proto.GetBudgetUsersReq) (*pro
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetBudgets implements proto.SmmCoreServer.
|
||||
func (s *Server) GetBudgets(context.Context, *proto.GetBudgetsReq) (*proto.Budgets, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetCategories implements proto.SmmCoreServer.
|
||||
func (s *Server) GetCategories(context.Context, *proto.GetCategoriesReq) (*proto.Categories, error) {
|
||||
panic("unimplemented")
|
||||
|
||||
Reference in New Issue
Block a user