This commit is contained in:
@@ -4,6 +4,7 @@ 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"
|
||||
"git.3crabs.ru/save_my_money/smm_core/internal/services/waste"
|
||||
proto "git.3crabs.ru/save_my_money/smm_core/proto"
|
||||
)
|
||||
|
||||
@@ -40,3 +41,12 @@ func mapCategories(categories []*category.CategoryEntity) []*proto.Category {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func mapWaste(waste *waste.WasteEntity) *proto.Waste {
|
||||
return &proto.Waste{
|
||||
Id: int32(waste.Id),
|
||||
Name: waste.Name,
|
||||
Price: int32(waste.Price),
|
||||
Amount: waste.Amount,
|
||||
}
|
||||
}
|
||||
|
||||
+22
-7
@@ -6,6 +6,7 @@ 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"
|
||||
"git.3crabs.ru/save_my_money/smm_core/internal/services/waste"
|
||||
proto "git.3crabs.ru/save_my_money/smm_core/proto"
|
||||
)
|
||||
|
||||
@@ -14,17 +15,20 @@ type Server struct {
|
||||
categoryService *category.CategoryService
|
||||
userService *user.UserService
|
||||
budgetService *budget.BudgetService
|
||||
wasteService *waste.WasteService
|
||||
}
|
||||
|
||||
func NewServer(
|
||||
categoryService *category.CategoryService,
|
||||
userService *user.UserService,
|
||||
budgetService *budget.BudgetService,
|
||||
wasteService *waste.WasteService,
|
||||
) proto.SmmCoreServer {
|
||||
return &Server{
|
||||
categoryService: categoryService,
|
||||
userService: userService,
|
||||
budgetService: budgetService,
|
||||
wasteService: wasteService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,8 +140,24 @@ func (s *Server) GetBudgetCategories(ctx context.Context, req *proto.GetBudgetCa
|
||||
}, nil
|
||||
}
|
||||
|
||||
// AddWaste implements proto.SmmCoreServer.
|
||||
func (s *Server) AddWaste(context.Context, *proto.AddWasteReq) (*proto.Waste, error) {
|
||||
func (s *Server) AddWaste(ctx context.Context, req *proto.AddWasteReq) (*proto.Waste, error) {
|
||||
waste, err := s.wasteService.AddWaste(
|
||||
ctx,
|
||||
&waste.WasteEntity{
|
||||
Name: req.Name,
|
||||
Price: int(req.Price),
|
||||
Amount: req.Amount,
|
||||
CategoryId: int(req.CategoryId),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapWaste(waste), nil
|
||||
}
|
||||
|
||||
// GetCategoriesStat implements proto.SmmCoreServer.
|
||||
func (s *Server) GetCategoriesStat(context.Context, *proto.GetCategoriesStatReq) (*proto.CategoriesStat, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
@@ -161,11 +181,6 @@ func (s *Server) GetBudgetUsers(context.Context, *proto.GetBudgetUsersReq) (*pro
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetCategoriesStat implements proto.SmmCoreServer.
|
||||
func (s *Server) GetCategoriesStat(context.Context, *proto.GetCategoriesStatReq) (*proto.CategoriesStat, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// RemoveUserFromBudget implements proto.SmmCoreServer.
|
||||
func (s *Server) RemoveUserFromBudget(context.Context, *proto.RemoveUserFromBudgetReq) (*proto.Budget, error) {
|
||||
panic("unimplemented")
|
||||
|
||||
Reference in New Issue
Block a user