remane vars
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-11-21 15:11:21 +07:00
parent 66df21c6c9
commit f2011b953c
8 changed files with 517 additions and 471 deletions
+70 -37
View File
@@ -2,14 +2,10 @@ package app
import (
"context"
"errors"
"git.3crabs.ru/save_my_money/smm_core/internal/services/category"
"git.3crabs.ru/save_my_money/smm_core/internal/services/context_utils"
"git.3crabs.ru/save_my_money/smm_core/internal/services/user"
proto "git.3crabs.ru/save_my_money/smm_core/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type Server struct {
@@ -28,12 +24,13 @@ func NewServer(
}
}
func (s *Server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, error) {
func (s *Server) Ping(context.Context, *proto.PingReq) (*proto.PingRsp, error) {
return &proto.PingRsp{}, nil
}
func (s *Server) AddUser(ctx context.Context, req *proto.CreateUserReq) (*proto.User, error) {
res, err := s.userService.AddUser(
// AddUser implements proto.SmmCoreServer.
func (s *Server) AddUser(ctx context.Context, req *proto.AddUserReq) (*proto.User, error) {
user, err := s.userService.AddUser(
ctx,
&user.UserEntity{
Username: req.Username,
@@ -41,45 +38,81 @@ func (s *Server) AddUser(ctx context.Context, req *proto.CreateUserReq) (*proto.
},
)
if err != nil {
if errors.Is(err, &user.UsernameAlreadyExistsErr{}) {
return nil, status.Error(codes.AlreadyExists, "Пользователь с таким username уже существует")
}
return nil, err
}
return &proto.User{
Id: int32(res.Id),
Username: res.Username,
Id: int32(user.Id),
Username: req.Username,
}, nil
}
func (s *Server) AddCategory(ctx context.Context, req *proto.CreateCategoryReq) (*proto.Category, error) {
res, err := s.categoryService.AddCategory(
ctx,
&category.CategoryEntity{
Name: req.Name,
Favorite: req.Favorite,
MonthlyLimit: int(req.MonthlyLimit),
},
)
if err != nil {
if errors.Is(err, &context_utils.UnauthorizedErr{}) {
return nil, status.Error(codes.Unauthenticated, "Клиент не авторизован")
}
if errors.Is(err, &category.CategoryAlreadyExistsErr{}) {
return nil, status.Error(codes.AlreadyExists, "Категория с таким именеи уже существует")
}
return nil, err
}
return &proto.Category{
Id: int32(res.Id),
Name: res.Name,
Favorite: res.Favorite,
MonthlyLimit: req.MonthlyLimit,
}, nil
// Login implements proto.SmmCoreServer.
func (s *Server) Login(context.Context, *proto.LoginReq) (*proto.User, error) {
panic("unimplemented")
}
// AddBudget implements proto.SmmCoreServer.
func (s *Server) AddBudget(context.Context, *proto.AddBudgetReq) (*proto.Budget, error) {
panic("unimplemented")
}
// AddCategory implements proto.SmmCoreServer.
func (s *Server) AddCategory(context.Context, *proto.AddCategoryReq) (*proto.Category, error) {
panic("unimplemented")
}
// AddUserToBudget implements proto.SmmCoreServer.
func (s *Server) AddUserToBudget(context.Context, *proto.AddUserToBudgetReq) (*proto.Budget, error) {
panic("unimplemented")
}
// AddWaste implements proto.SmmCoreServer.
func (s *Server) AddWaste(context.Context, *proto.AddWasteReq) (*proto.Waste, error) {
panic("unimplemented")
}
// DeleteBudget implements proto.SmmCoreServer.
func (s *Server) DeleteBudget(context.Context, *proto.DeleteBudgetReq) (*proto.Budget, error) {
panic("unimplemented")
}
// DeleteCategories implements proto.SmmCoreServer.
func (s *Server) DeleteCategories(context.Context, *proto.DeleteCategoriesReq) (*proto.Category, error) {
panic("unimplemented")
}
// DeleteWaste implements proto.SmmCoreServer.
func (s *Server) DeleteWaste(context.Context, *proto.DeleteWasteReq) (*proto.Waste, error) {
panic("unimplemented")
}
// GetBudgetUsers implements proto.SmmCoreServer.
func (s *Server) GetBudgetUsers(context.Context, *proto.GetBudgetUsersReq) (*proto.Users, error) {
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.CategoryFilterReq) (*proto.Categories, error) {
func (s *Server) GetCategories(context.Context, *proto.GetCategoriesReq) (*proto.Categories, error) {
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")
}
// UpdateBudget implements proto.SmmCoreServer.
func (s *Server) UpdateBudget(context.Context, *proto.UpdateBudgetReq) (*proto.Budget, error) {
panic("unimplemented")
}