add category insert
This commit is contained in:
+27
-5
@@ -3,24 +3,46 @@ package app
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.3crabs.ru/save_my_money/smm_core/internal/services/category"
|
||||
proto "git.3crabs.ru/save_my_money/smm_core/proto"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
proto.UnsafeSmmCoreServer
|
||||
categoryService *category.CategoryService
|
||||
}
|
||||
|
||||
func NewServer() proto.SmmCoreServer {
|
||||
return &Server{}
|
||||
func NewServer(
|
||||
categoryService *category.CategoryService,
|
||||
) proto.SmmCoreServer {
|
||||
return &Server{
|
||||
categoryService: categoryService,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, error) {
|
||||
return &proto.PingRsp{}, nil
|
||||
}
|
||||
|
||||
// AddCategory implements proto.SmmCoreServer.
|
||||
func (s *Server) AddCategory(context.Context, *proto.CreateCategoryReq) (*proto.Category, error) {
|
||||
panic("unimplemented")
|
||||
func (s *Server) AddCategory(ctx context.Context, req *proto.CreateCategoryReq) (*proto.Category, error) {
|
||||
res, err := s.categoryService.AddCategory(
|
||||
ctx,
|
||||
&category.CategoryEntity{
|
||||
Name: req.Name,
|
||||
UserId: int(req.UserId),
|
||||
Favorite: req.Favorite,
|
||||
MonthlyLimit: int(req.MonthlyLimit),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &proto.Category{
|
||||
Id: int32(res.Id),
|
||||
Name: res.Name,
|
||||
Favorite: res.Favorite,
|
||||
MonthlyLimit: req.MonthlyLimit,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetCategories implements proto.SmmCoreServer.
|
||||
|
||||
Reference in New Issue
Block a user