add auth
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
@@ -55,12 +56,17 @@ func (s *Server) AddCategory(ctx context.Context, req *proto.CreateCategoryReq)
|
||||
ctx,
|
||||
&category.CategoryEntity{
|
||||
Name: req.Name,
|
||||
UserId: int(req.UserId),
|
||||
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{
|
||||
|
||||
Reference in New Issue
Block a user