+70
-37
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
[{"kind":1,"language":"markdown","value":"# Добавление пользователя","outputs":[]},{"kind":2,"language":"rest-book","value":"POST http://localhost:8090/users\nauthorization: Y3JhYjpjcmFi\n\n{\n \"username\": \"foo\",\n \"password\": \"bar\"\n}","outputs":[{"mime":"application/vnd.code.notebook.error","value":{"name":"Error","message":"timeout of 10000ms exceeded"}}]},{"kind":1,"language":"markdown","value":"# Добавление категории","outputs":[]},{"kind":2,"language":"rest-book","value":"POST http://localhost:8090/categories\nUser-Id: 1\n\n{\n \"name\": \"Продукты питания\"\n}","outputs":[{"mime":"x-application/rest-book","value":{"status":500,"statusText":"Internal Server Error","headers":{"Date":"Wed, 20 Nov 2024 16:25:26 GMT","Content-Type":"application/json","Content-Length":"184"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Id":"2","User-Agent":"axios/0.21.4","Content-Length":42}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost:8090/categories","timeout":10000,"headers":{"User-Id":"2"},"data":{"name":"Продукты питания"}},"data":{"code":2,"message":"unable to insert row: ERROR: insert or update on table \"categories\" violates foreign key constraint \"categories_user_id_fkey\" (SQLSTATE 23503)","details":[]}}},{"mime":"text/x-json","value":{"status":500,"statusText":"Internal Server Error","headers":{"Date":"Wed, 20 Nov 2024 16:25:26 GMT","Content-Type":"application/json","Content-Length":"184"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Id":"2","User-Agent":"axios/0.21.4","Content-Length":42}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost:8090/categories","timeout":10000,"headers":{"User-Id":"2"},"data":{"name":"Продукты питания"}},"data":{"code":2,"message":"unable to insert row: ERROR: insert or update on table \"categories\" violates foreign key constraint \"categories_user_id_fkey\" (SQLSTATE 23503)","details":[]}}},{"mime":"text/html","value":"[object Object]"}]}]
|
||||
[{"kind":1,"language":"markdown","value":"# Добавление пользователя","outputs":[]},{"kind":2,"language":"rest-book","value":"POST http://localhost:8090/users\nauthorization: Y3JhYjpjcmFi\n\n{\n \"username\": \"foo\",\n \"password\": \"bar\"\n}","outputs":[{"mime":"x-application/rest-book","value":{"status":500,"statusText":"Internal Server Error","headers":{"Date":"Thu, 21 Nov 2024 08:10:55 GMT","Content-Type":"application/json","Content-Length":"65"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","authorization":"Y3JhYjpjcmFi","User-Agent":"axios/0.21.4","Content-Length":35}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost:8090/users","timeout":10000,"headers":{"authorization":"Y3JhYjpjcmFi"},"data":{"username":"foo","password":"bar"}},"data":{"code":2,"message":"username already exists error","details":[]}}},{"mime":"text/x-json","value":{"status":500,"statusText":"Internal Server Error","headers":{"Date":"Thu, 21 Nov 2024 08:10:55 GMT","Content-Type":"application/json","Content-Length":"65"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","authorization":"Y3JhYjpjcmFi","User-Agent":"axios/0.21.4","Content-Length":35}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost:8090/users","timeout":10000,"headers":{"authorization":"Y3JhYjpjcmFi"},"data":{"username":"foo","password":"bar"}},"data":{"code":2,"message":"username already exists error","details":[]}}},{"mime":"text/html","value":"[object Object]"}]},{"kind":1,"language":"markdown","value":"# Добавление категории","outputs":[]},{"kind":2,"language":"rest-book","value":"POST http://localhost:8090/categories\nUser-Id: 1\n\n{\n \"name\": \"Продукты питания\"\n}","outputs":[{"mime":"x-application/rest-book","value":{"status":500,"statusText":"Internal Server Error","headers":{"Date":"Wed, 20 Nov 2024 16:25:26 GMT","Content-Type":"application/json","Content-Length":"184"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Id":"2","User-Agent":"axios/0.21.4","Content-Length":42}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost:8090/categories","timeout":10000,"headers":{"User-Id":"2"},"data":{"name":"Продукты питания"}},"data":{"code":2,"message":"unable to insert row: ERROR: insert or update on table \"categories\" violates foreign key constraint \"categories_user_id_fkey\" (SQLSTATE 23503)","details":[]}}},{"mime":"text/x-json","value":{"status":500,"statusText":"Internal Server Error","headers":{"Date":"Wed, 20 Nov 2024 16:25:26 GMT","Content-Type":"application/json","Content-Length":"184"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Id":"2","User-Agent":"axios/0.21.4","Content-Length":42}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost:8090/categories","timeout":10000,"headers":{"User-Id":"2"},"data":{"name":"Продукты питания"}},"data":{"code":2,"message":"unable to insert row: ERROR: insert or update on table \"categories\" violates foreign key constraint \"categories_user_id_fkey\" (SQLSTATE 23503)","details":[]}}},{"mime":"text/html","value":"[object Object]"}]}]
|
||||
Reference in New Issue
Block a user