smm_core/internal/app/server.go

57 lines
1.4 KiB
Go
Raw Normal View History

2024-11-09 11:18:51 +00:00
package app
import (
"context"
2024-11-19 15:45:31 +00:00
"git.3crabs.ru/save_my_money/smm_core/internal/services/category"
2024-11-09 11:18:51 +00:00
proto "git.3crabs.ru/save_my_money/smm_core/proto"
)
type Server struct {
proto.UnsafeSmmCoreServer
2024-11-19 15:45:31 +00:00
categoryService *category.CategoryService
2024-11-09 11:18:51 +00:00
}
2024-11-19 15:45:31 +00:00
func NewServer(
categoryService *category.CategoryService,
) proto.SmmCoreServer {
return &Server{
categoryService: categoryService,
}
2024-11-09 11:18:51 +00:00
}
func (s *Server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, error) {
return &proto.PingRsp{}, nil
}
2024-11-19 08:16:01 +00:00
2024-11-19 15:45:31 +00:00
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
2024-11-19 08:16:01 +00:00
}
// GetCategories implements proto.SmmCoreServer.
func (s *Server) GetCategories(context.Context, *proto.CategoryFilterReq) (*proto.Categories, error) {
panic("unimplemented")
}
// UpdateCategory implements proto.SmmCoreServer.
func (s *Server) UpdateCategory(context.Context, *proto.UpdateCategoryReq) (*proto.Category, error) {
panic("unimplemented")
}