From bd6b5fe4a8a51fdb4e833ba4bd2ee888d97a2c44 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Wed, 20 Nov 2024 15:32:43 +0700 Subject: [PATCH] add create user method --- api/smm_core.proto | 17 ++ cmd/smm_core/main.go | 4 +- internal/app/server.go | 26 +++ internal/services/user/requests.restbook | 1 + internal/services/user/user_service.go | 51 ++++ migrations/20241109180651_add_user.sql | 2 +- proto/smm_core.pb.go | 283 ++++++++++++++++------- proto/smm_core.pb.gw.go | 77 ++++++ proto/smm_core_grpc.pb.go | 40 ++++ resources/smm_core.swagger.json | 53 +++++ 10 files changed, 467 insertions(+), 87 deletions(-) create mode 100644 internal/services/user/requests.restbook create mode 100644 internal/services/user/user_service.go diff --git a/api/smm_core.proto b/api/smm_core.proto index 52ca71a..8593ada 100644 --- a/api/smm_core.proto +++ b/api/smm_core.proto @@ -16,6 +16,14 @@ service SmmCore { }; } + // users + rpc AddUser(CreateUserReq) returns (User) { + option (google.api.http) = { + post: "/users", + body: "*" + }; + } + // categories rpc AddCategory(CreateCategoryReq) returns (Category) { option (google.api.http) = { @@ -39,6 +47,15 @@ message PingReq {} message PingRsp {} +message CreateUserReq { + string username = 1; +} + +message User { + int32 id = 1; + string username = 2; +} + message CreateCategoryReq { string name = 1; int32 user_id = 2; diff --git a/cmd/smm_core/main.go b/cmd/smm_core/main.go index 4af93d0..d9b7b75 100644 --- a/cmd/smm_core/main.go +++ b/cmd/smm_core/main.go @@ -10,6 +10,7 @@ import ( "git.3crabs.ru/save_my_money/smm_core/internal/app" "git.3crabs.ru/save_my_money/smm_core/internal/services/category" + "git.3crabs.ru/save_my_money/smm_core/internal/services/user" "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/jackc/pgx/v5/pgxpool" "google.golang.org/grpc" @@ -33,11 +34,12 @@ func main() { defer dbpool.Close() categoryService := category.NewCategoryService(dbpool) + userService := user.NewUserService(dbpool) // Create a gRPC server object s := grpc.NewServer() // Attach the Greeter service to the server - proto.RegisterSmmCoreServer(s, app.NewServer(categoryService)) + proto.RegisterSmmCoreServer(s, app.NewServer(categoryService, userService)) // Serve gRPC server log.Println("Serving gRPC on 0.0.0.0:8080") go func() { diff --git a/internal/app/server.go b/internal/app/server.go index 29822a6..339c796 100644 --- a/internal/app/server.go +++ b/internal/app/server.go @@ -2,21 +2,28 @@ 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/user" proto "git.3crabs.ru/save_my_money/smm_core/proto" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) type Server struct { proto.UnsafeSmmCoreServer categoryService *category.CategoryService + userService *user.UserService } func NewServer( categoryService *category.CategoryService, + userService *user.UserService, ) proto.SmmCoreServer { return &Server{ categoryService: categoryService, + userService: userService, } } @@ -24,6 +31,25 @@ func (s *Server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, erro return &proto.PingRsp{}, nil } +func (s *Server) AddUser(ctx context.Context, req *proto.CreateUserReq) (*proto.User, error) { + res, err := s.userService.AddUser( + ctx, + &user.UserEntity{ + Username: req.Username, + }, + ) + 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, + }, nil +} + func (s *Server) AddCategory(ctx context.Context, req *proto.CreateCategoryReq) (*proto.Category, error) { res, err := s.categoryService.AddCategory( ctx, diff --git a/internal/services/user/requests.restbook b/internal/services/user/requests.restbook new file mode 100644 index 0000000..da2d570 --- /dev/null +++ b/internal/services/user/requests.restbook @@ -0,0 +1 @@ +[{"kind":1,"language":"markdown","value":"# Добавление пользователя","outputs":[]},{"kind":2,"language":"rest-book","value":"POST http://localhost:8090/users\n\n{\n \"username\": \"foo\"\n}","outputs":[{"mime":"x-application/rest-book","value":{"status":409,"statusText":"Conflict","headers":{"Date":"Wed, 20 Nov 2024 08:30:32 GMT","Content-Type":"application/json","Content-Length":"111"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Agent":"rest-book","Content-Length":18}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost:8090/users","timeout":10000,"headers":{"User-Agent":"rest-book"},"data":{"username":"bar"}},"data":{"code":6,"message":"Пользователь с таким username уже существует","details":[]}}},{"mime":"text/x-json","value":{"status":409,"statusText":"Conflict","headers":{"Date":"Wed, 20 Nov 2024 08:30:32 GMT","Content-Type":"application/json","Content-Length":"111"},"config":{"timeout":10000,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","User-Agent":"rest-book","Content-Length":18}},"request":{"method":"POST","httpVersion":"1.1","responseUrl":"http://localhost:8090/users","timeout":10000,"headers":{"User-Agent":"rest-book"},"data":{"username":"bar"}},"data":{"code":6,"message":"Пользователь с таким username уже существует","details":[]}}},{"mime":"text/html","value":"[object Object]"}]}] \ No newline at end of file diff --git a/internal/services/user/user_service.go b/internal/services/user/user_service.go new file mode 100644 index 0000000..7276e71 --- /dev/null +++ b/internal/services/user/user_service.go @@ -0,0 +1,51 @@ +package user + +import ( + "context" + "errors" + "fmt" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgconn" + "github.com/jackc/pgx/v5/pgxpool" +) + +type UserEntity struct { + Id int + Username string +} + +type UsernameAlreadyExistsErr struct{} + +func (e *UsernameAlreadyExistsErr) Error() string { + return "username already exists error" +} + +type UserService struct { + db *pgxpool.Pool +} + +func NewUserService( + db *pgxpool.Pool, +) *UserService { + return &UserService{ + db: db, + } +} + +func (s *UserService) AddUser(ctx context.Context, user *UserEntity) (*UserEntity, error) { + query := `INSERT INTO users (username) VALUES (@username) RETURNING id` + args := pgx.NamedArgs{ + "username": user.Username, + } + if err := s.db.QueryRow(ctx, query, args).Scan(&user.Id); err != nil { + var pgErr *pgconn.PgError + if errors.As(err, &pgErr) { + if pgErr.Code == "23505" && pgErr.ConstraintName == "users_username_key" { // unique_violation + return nil, &UsernameAlreadyExistsErr{} + } + } + return nil, fmt.Errorf("unable to insert row: %w", err) + } + return user, nil +} diff --git a/migrations/20241109180651_add_user.sql b/migrations/20241109180651_add_user.sql index a590932..19fe2f3 100644 --- a/migrations/20241109180651_add_user.sql +++ b/migrations/20241109180651_add_user.sql @@ -2,7 +2,7 @@ -- +goose StatementBegin CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, - chat_id TEXT NOT NULL + username TEXT UNIQUE NOT NULL ); -- +goose StatementEnd diff --git a/proto/smm_core.pb.go b/proto/smm_core.pb.go index d9f77e9..1ce7439 100644 --- a/proto/smm_core.pb.go +++ b/proto/smm_core.pb.go @@ -94,6 +94,104 @@ func (*PingRsp) Descriptor() ([]byte, []int) { return file_smm_core_proto_rawDescGZIP(), []int{1} } +type CreateUserReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` +} + +func (x *CreateUserReq) Reset() { + *x = CreateUserReq{} + mi := &file_smm_core_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateUserReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateUserReq) ProtoMessage() {} + +func (x *CreateUserReq) ProtoReflect() protoreflect.Message { + mi := &file_smm_core_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateUserReq.ProtoReflect.Descriptor instead. +func (*CreateUserReq) Descriptor() ([]byte, []int) { + return file_smm_core_proto_rawDescGZIP(), []int{2} +} + +func (x *CreateUserReq) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +type User struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"` +} + +func (x *User) Reset() { + *x = User{} + mi := &file_smm_core_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *User) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*User) ProtoMessage() {} + +func (x *User) ProtoReflect() protoreflect.Message { + mi := &file_smm_core_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use User.ProtoReflect.Descriptor instead. +func (*User) Descriptor() ([]byte, []int) { + return file_smm_core_proto_rawDescGZIP(), []int{3} +} + +func (x *User) GetId() int32 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *User) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + type CreateCategoryReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -107,7 +205,7 @@ type CreateCategoryReq struct { func (x *CreateCategoryReq) Reset() { *x = CreateCategoryReq{} - mi := &file_smm_core_proto_msgTypes[2] + mi := &file_smm_core_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -119,7 +217,7 @@ func (x *CreateCategoryReq) String() string { func (*CreateCategoryReq) ProtoMessage() {} func (x *CreateCategoryReq) ProtoReflect() protoreflect.Message { - mi := &file_smm_core_proto_msgTypes[2] + mi := &file_smm_core_proto_msgTypes[4] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -132,7 +230,7 @@ func (x *CreateCategoryReq) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateCategoryReq.ProtoReflect.Descriptor instead. func (*CreateCategoryReq) Descriptor() ([]byte, []int) { - return file_smm_core_proto_rawDescGZIP(), []int{2} + return file_smm_core_proto_rawDescGZIP(), []int{4} } func (x *CreateCategoryReq) GetName() string { @@ -176,7 +274,7 @@ type UpdateCategoryReq struct { func (x *UpdateCategoryReq) Reset() { *x = UpdateCategoryReq{} - mi := &file_smm_core_proto_msgTypes[3] + mi := &file_smm_core_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -188,7 +286,7 @@ func (x *UpdateCategoryReq) String() string { func (*UpdateCategoryReq) ProtoMessage() {} func (x *UpdateCategoryReq) ProtoReflect() protoreflect.Message { - mi := &file_smm_core_proto_msgTypes[3] + mi := &file_smm_core_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -201,7 +299,7 @@ func (x *UpdateCategoryReq) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateCategoryReq.ProtoReflect.Descriptor instead. func (*UpdateCategoryReq) Descriptor() ([]byte, []int) { - return file_smm_core_proto_rawDescGZIP(), []int{3} + return file_smm_core_proto_rawDescGZIP(), []int{5} } func (x *UpdateCategoryReq) GetId() int32 { @@ -245,7 +343,7 @@ type Category struct { func (x *Category) Reset() { *x = Category{} - mi := &file_smm_core_proto_msgTypes[4] + mi := &file_smm_core_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -257,7 +355,7 @@ func (x *Category) String() string { func (*Category) ProtoMessage() {} func (x *Category) ProtoReflect() protoreflect.Message { - mi := &file_smm_core_proto_msgTypes[4] + mi := &file_smm_core_proto_msgTypes[6] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -270,7 +368,7 @@ func (x *Category) ProtoReflect() protoreflect.Message { // Deprecated: Use Category.ProtoReflect.Descriptor instead. func (*Category) Descriptor() ([]byte, []int) { - return file_smm_core_proto_rawDescGZIP(), []int{4} + return file_smm_core_proto_rawDescGZIP(), []int{6} } func (x *Category) GetId() int32 { @@ -311,7 +409,7 @@ type CategoryFilterReq struct { func (x *CategoryFilterReq) Reset() { *x = CategoryFilterReq{} - mi := &file_smm_core_proto_msgTypes[5] + mi := &file_smm_core_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -323,7 +421,7 @@ func (x *CategoryFilterReq) String() string { func (*CategoryFilterReq) ProtoMessage() {} func (x *CategoryFilterReq) ProtoReflect() protoreflect.Message { - mi := &file_smm_core_proto_msgTypes[5] + mi := &file_smm_core_proto_msgTypes[7] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -336,7 +434,7 @@ func (x *CategoryFilterReq) ProtoReflect() protoreflect.Message { // Deprecated: Use CategoryFilterReq.ProtoReflect.Descriptor instead. func (*CategoryFilterReq) Descriptor() ([]byte, []int) { - return file_smm_core_proto_rawDescGZIP(), []int{5} + return file_smm_core_proto_rawDescGZIP(), []int{7} } func (x *CategoryFilterReq) GetFavorite() bool { @@ -356,7 +454,7 @@ type Categories struct { func (x *Categories) Reset() { *x = Categories{} - mi := &file_smm_core_proto_msgTypes[6] + mi := &file_smm_core_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -368,7 +466,7 @@ func (x *Categories) String() string { func (*Categories) ProtoMessage() {} func (x *Categories) ProtoReflect() protoreflect.Message { - mi := &file_smm_core_proto_msgTypes[6] + mi := &file_smm_core_proto_msgTypes[8] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -381,7 +479,7 @@ func (x *Categories) ProtoReflect() protoreflect.Message { // Deprecated: Use Categories.ProtoReflect.Descriptor instead. func (*Categories) Descriptor() ([]byte, []int) { - return file_smm_core_proto_rawDescGZIP(), []int{6} + return file_smm_core_proto_rawDescGZIP(), []int{8} } func (x *Categories) GetCategories() []*Category { @@ -402,63 +500,74 @@ var file_smm_core_proto_rawDesc = []byte{ 0x70, 0x69, 0x76, 0x32, 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x09, 0x0a, 0x07, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x22, 0x09, 0x0a, 0x07, 0x50, 0x69, 0x6e, - 0x67, 0x52, 0x73, 0x70, 0x22, 0x81, 0x01, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, - 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x17, - 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, - 0x69, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, - 0x69, 0x74, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x5f, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x6d, 0x6f, 0x6e, 0x74, - 0x68, 0x6c, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x78, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x12, 0x23, 0x0a, - 0x0d, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x4c, 0x69, 0x6d, - 0x69, 0x74, 0x22, 0x6f, 0x0a, 0x08, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x0e, + 0x67, 0x52, 0x73, 0x70, 0x22, 0x2b, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, + 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, + 0x65, 0x22, 0x32, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x81, 0x01, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, 0x6f, + 0x72, 0x69, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x66, 0x61, 0x76, 0x6f, + 0x72, 0x69, 0x74, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x5f, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x6d, 0x6f, 0x6e, + 0x74, 0x68, 0x6c, 0x79, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x78, 0x0a, 0x11, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x18, 0x04, + 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x4c, 0x69, - 0x6d, 0x69, 0x74, 0x22, 0x2f, 0x0a, 0x11, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x46, - 0x69, 0x6c, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, 0x6f, - 0x72, 0x69, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x66, 0x61, 0x76, 0x6f, - 0x72, 0x69, 0x74, 0x65, 0x22, 0x46, 0x0a, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, - 0x65, 0x73, 0x12, 0x38, 0x0a, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, - 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, - 0x52, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x32, 0x84, 0x03, 0x0a, - 0x07, 0x53, 0x6d, 0x6d, 0x43, 0x6f, 0x72, 0x65, 0x12, 0x47, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, - 0x12, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, - 0x65, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, - 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, - 0x73, 0x70, 0x22, 0x0d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x07, 0x12, 0x05, 0x2f, 0x70, 0x69, 0x6e, - 0x67, 0x12, 0x62, 0x0a, 0x0b, 0x41, 0x64, 0x64, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, - 0x12, 0x21, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, - 0x65, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, - 0x52, 0x65, 0x71, 0x1a, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, - 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x22, 0x16, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, 0x22, 0x0b, 0x2f, 0x63, 0x61, 0x74, 0x65, 0x67, - 0x6f, 0x72, 0x69, 0x65, 0x73, 0x12, 0x67, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, - 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x21, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, - 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, - 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x18, 0x2e, 0x63, 0x72, 0x61, - 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x61, 0x74, 0x65, - 0x67, 0x6f, 0x72, 0x79, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x1a, 0x10, 0x2f, 0x63, - 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x63, - 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x12, - 0x21, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, - 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x52, - 0x65, 0x71, 0x1a, 0x1a, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, - 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x22, 0x13, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x12, 0x0b, 0x2f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, - 0x69, 0x65, 0x73, 0x42, 0x0e, 0x92, 0x41, 0x00, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x4c, 0x69, + 0x6d, 0x69, 0x74, 0x22, 0x6f, 0x0a, 0x08, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x66, 0x61, 0x76, 0x6f, 0x72, 0x69, 0x74, 0x65, 0x12, + 0x23, 0x0a, 0x0d, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x6d, 0x6f, 0x6e, 0x74, 0x68, 0x6c, 0x79, 0x4c, + 0x69, 0x6d, 0x69, 0x74, 0x22, 0x2f, 0x0a, 0x11, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, + 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x61, 0x76, + 0x6f, 0x72, 0x69, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x66, 0x61, 0x76, + 0x6f, 0x72, 0x69, 0x74, 0x65, 0x22, 0x46, 0x0a, 0x0a, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, + 0x69, 0x65, 0x73, 0x12, 0x38, 0x0a, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, + 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, + 0x79, 0x52, 0x0a, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x32, 0xd7, 0x03, + 0x0a, 0x07, 0x53, 0x6d, 0x6d, 0x43, 0x6f, 0x72, 0x65, 0x12, 0x47, 0x0a, 0x04, 0x50, 0x69, 0x6e, + 0x67, 0x12, 0x17, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, + 0x72, 0x65, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x63, 0x72, 0x61, + 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x50, 0x69, 0x6e, 0x67, + 0x52, 0x73, 0x70, 0x22, 0x0d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x07, 0x12, 0x05, 0x2f, 0x70, 0x69, + 0x6e, 0x67, 0x12, 0x51, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x55, 0x73, 0x65, 0x72, 0x12, 0x1d, 0x2e, + 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x14, 0x2e, 0x63, + 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x55, 0x73, + 0x65, 0x72, 0x22, 0x11, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0b, 0x3a, 0x01, 0x2a, 0x22, 0x06, 0x2f, + 0x75, 0x73, 0x65, 0x72, 0x73, 0x12, 0x62, 0x0a, 0x0b, 0x41, 0x64, 0x64, 0x43, 0x61, 0x74, 0x65, + 0x67, 0x6f, 0x72, 0x79, 0x12, 0x21, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, + 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x61, 0x74, 0x65, + 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x18, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, + 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, + 0x79, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, 0x22, 0x0b, 0x2f, 0x63, + 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x12, 0x67, 0x0a, 0x0e, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x21, 0x2e, 0x63, 0x72, + 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x18, + 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, + 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, + 0x1a, 0x10, 0x2f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x2f, 0x7b, 0x69, + 0x64, 0x7d, 0x12, 0x63, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, + 0x69, 0x65, 0x73, 0x12, 0x21, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, 0x6d, 0x6d, 0x5f, + 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x46, 0x69, 0x6c, + 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x1a, 0x2e, 0x63, 0x72, 0x61, 0x62, 0x73, 0x2e, 0x73, + 0x6d, 0x6d, 0x5f, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x69, + 0x65, 0x73, 0x22, 0x13, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x12, 0x0b, 0x2f, 0x63, 0x61, 0x74, + 0x65, 0x67, 0x6f, 0x72, 0x69, 0x65, 0x73, 0x42, 0x0e, 0x92, 0x41, 0x00, 0x5a, 0x09, 0x70, 0x6b, + 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -473,28 +582,32 @@ func file_smm_core_proto_rawDescGZIP() []byte { return file_smm_core_proto_rawDescData } -var file_smm_core_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_smm_core_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_smm_core_proto_goTypes = []any{ (*PingReq)(nil), // 0: crabs.smm_core.PingReq (*PingRsp)(nil), // 1: crabs.smm_core.PingRsp - (*CreateCategoryReq)(nil), // 2: crabs.smm_core.CreateCategoryReq - (*UpdateCategoryReq)(nil), // 3: crabs.smm_core.UpdateCategoryReq - (*Category)(nil), // 4: crabs.smm_core.Category - (*CategoryFilterReq)(nil), // 5: crabs.smm_core.CategoryFilterReq - (*Categories)(nil), // 6: crabs.smm_core.Categories + (*CreateUserReq)(nil), // 2: crabs.smm_core.CreateUserReq + (*User)(nil), // 3: crabs.smm_core.User + (*CreateCategoryReq)(nil), // 4: crabs.smm_core.CreateCategoryReq + (*UpdateCategoryReq)(nil), // 5: crabs.smm_core.UpdateCategoryReq + (*Category)(nil), // 6: crabs.smm_core.Category + (*CategoryFilterReq)(nil), // 7: crabs.smm_core.CategoryFilterReq + (*Categories)(nil), // 8: crabs.smm_core.Categories } var file_smm_core_proto_depIdxs = []int32{ - 4, // 0: crabs.smm_core.Categories.categories:type_name -> crabs.smm_core.Category + 6, // 0: crabs.smm_core.Categories.categories:type_name -> crabs.smm_core.Category 0, // 1: crabs.smm_core.SmmCore.Ping:input_type -> crabs.smm_core.PingReq - 2, // 2: crabs.smm_core.SmmCore.AddCategory:input_type -> crabs.smm_core.CreateCategoryReq - 3, // 3: crabs.smm_core.SmmCore.UpdateCategory:input_type -> crabs.smm_core.UpdateCategoryReq - 5, // 4: crabs.smm_core.SmmCore.GetCategories:input_type -> crabs.smm_core.CategoryFilterReq - 1, // 5: crabs.smm_core.SmmCore.Ping:output_type -> crabs.smm_core.PingRsp - 4, // 6: crabs.smm_core.SmmCore.AddCategory:output_type -> crabs.smm_core.Category - 4, // 7: crabs.smm_core.SmmCore.UpdateCategory:output_type -> crabs.smm_core.Category - 6, // 8: crabs.smm_core.SmmCore.GetCategories:output_type -> crabs.smm_core.Categories - 5, // [5:9] is the sub-list for method output_type - 1, // [1:5] is the sub-list for method input_type + 2, // 2: crabs.smm_core.SmmCore.AddUser:input_type -> crabs.smm_core.CreateUserReq + 4, // 3: crabs.smm_core.SmmCore.AddCategory:input_type -> crabs.smm_core.CreateCategoryReq + 5, // 4: crabs.smm_core.SmmCore.UpdateCategory:input_type -> crabs.smm_core.UpdateCategoryReq + 7, // 5: crabs.smm_core.SmmCore.GetCategories:input_type -> crabs.smm_core.CategoryFilterReq + 1, // 6: crabs.smm_core.SmmCore.Ping:output_type -> crabs.smm_core.PingRsp + 3, // 7: crabs.smm_core.SmmCore.AddUser:output_type -> crabs.smm_core.User + 6, // 8: crabs.smm_core.SmmCore.AddCategory:output_type -> crabs.smm_core.Category + 6, // 9: crabs.smm_core.SmmCore.UpdateCategory:output_type -> crabs.smm_core.Category + 8, // 10: crabs.smm_core.SmmCore.GetCategories:output_type -> crabs.smm_core.Categories + 6, // [6:11] is the sub-list for method output_type + 1, // [1:6] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension extendee 0, // [0:1] is the sub-list for field type_name @@ -511,7 +624,7 @@ func file_smm_core_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_smm_core_proto_rawDesc, NumEnums: 0, - NumMessages: 7, + NumMessages: 9, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/smm_core.pb.gw.go b/proto/smm_core.pb.gw.go index 5097028..a003627 100644 --- a/proto/smm_core.pb.gw.go +++ b/proto/smm_core.pb.gw.go @@ -49,6 +49,32 @@ func local_request_SmmCore_Ping_0(ctx context.Context, marshaler runtime.Marshal } +func request_SmmCore_AddUser_0(ctx context.Context, marshaler runtime.Marshaler, client SmmCoreClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateUserReq + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.AddUser(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_SmmCore_AddUser_0(ctx context.Context, marshaler runtime.Marshaler, server SmmCoreServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateUserReq + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.AddUser(ctx, &protoReq) + return msg, metadata, err + +} + func request_SmmCore_AddCategory_0(ctx context.Context, marshaler runtime.Marshaler, client SmmCoreClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq CreateCategoryReq var metadata runtime.ServerMetadata @@ -213,6 +239,31 @@ func RegisterSmmCoreHandlerServer(ctx context.Context, mux *runtime.ServeMux, se }) + mux.Handle("POST", pattern_SmmCore_AddUser_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.smm_core.SmmCore/AddUser", runtime.WithHTTPPathPattern("/users")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_SmmCore_AddUser_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_SmmCore_AddUser_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("POST", pattern_SmmCore_AddCategory_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -351,6 +402,28 @@ func RegisterSmmCoreHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl }) + mux.Handle("POST", pattern_SmmCore_AddUser_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.smm_core.SmmCore/AddUser", runtime.WithHTTPPathPattern("/users")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_SmmCore_AddUser_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_SmmCore_AddUser_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("POST", pattern_SmmCore_AddCategory_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -423,6 +496,8 @@ func RegisterSmmCoreHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl var ( pattern_SmmCore_Ping_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"ping"}, "")) + pattern_SmmCore_AddUser_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"users"}, "")) + pattern_SmmCore_AddCategory_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"categories"}, "")) pattern_SmmCore_UpdateCategory_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"categories", "id"}, "")) @@ -433,6 +508,8 @@ var ( var ( forward_SmmCore_Ping_0 = runtime.ForwardResponseMessage + forward_SmmCore_AddUser_0 = runtime.ForwardResponseMessage + forward_SmmCore_AddCategory_0 = runtime.ForwardResponseMessage forward_SmmCore_UpdateCategory_0 = runtime.ForwardResponseMessage diff --git a/proto/smm_core_grpc.pb.go b/proto/smm_core_grpc.pb.go index 9b5a7b7..fea0317 100644 --- a/proto/smm_core_grpc.pb.go +++ b/proto/smm_core_grpc.pb.go @@ -20,6 +20,7 @@ const _ = grpc.SupportPackageIsVersion9 const ( SmmCore_Ping_FullMethodName = "/crabs.smm_core.SmmCore/Ping" + SmmCore_AddUser_FullMethodName = "/crabs.smm_core.SmmCore/AddUser" SmmCore_AddCategory_FullMethodName = "/crabs.smm_core.SmmCore/AddCategory" SmmCore_UpdateCategory_FullMethodName = "/crabs.smm_core.SmmCore/UpdateCategory" SmmCore_GetCategories_FullMethodName = "/crabs.smm_core.SmmCore/GetCategories" @@ -30,6 +31,8 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type SmmCoreClient interface { Ping(ctx context.Context, in *PingReq, opts ...grpc.CallOption) (*PingRsp, error) + // users + AddUser(ctx context.Context, in *CreateUserReq, opts ...grpc.CallOption) (*User, error) // categories AddCategory(ctx context.Context, in *CreateCategoryReq, opts ...grpc.CallOption) (*Category, error) UpdateCategory(ctx context.Context, in *UpdateCategoryReq, opts ...grpc.CallOption) (*Category, error) @@ -54,6 +57,16 @@ func (c *smmCoreClient) Ping(ctx context.Context, in *PingReq, opts ...grpc.Call return out, nil } +func (c *smmCoreClient) AddUser(ctx context.Context, in *CreateUserReq, opts ...grpc.CallOption) (*User, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(User) + err := c.cc.Invoke(ctx, SmmCore_AddUser_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *smmCoreClient) AddCategory(ctx context.Context, in *CreateCategoryReq, opts ...grpc.CallOption) (*Category, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Category) @@ -89,6 +102,8 @@ func (c *smmCoreClient) GetCategories(ctx context.Context, in *CategoryFilterReq // for forward compatibility. type SmmCoreServer interface { Ping(context.Context, *PingReq) (*PingRsp, error) + // users + AddUser(context.Context, *CreateUserReq) (*User, error) // categories AddCategory(context.Context, *CreateCategoryReq) (*Category, error) UpdateCategory(context.Context, *UpdateCategoryReq) (*Category, error) @@ -106,6 +121,9 @@ type UnimplementedSmmCoreServer struct{} func (UnimplementedSmmCoreServer) Ping(context.Context, *PingReq) (*PingRsp, error) { return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented") } +func (UnimplementedSmmCoreServer) AddUser(context.Context, *CreateUserReq) (*User, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddUser not implemented") +} func (UnimplementedSmmCoreServer) AddCategory(context.Context, *CreateCategoryReq) (*Category, error) { return nil, status.Errorf(codes.Unimplemented, "method AddCategory not implemented") } @@ -154,6 +172,24 @@ func _SmmCore_Ping_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _SmmCore_AddUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateUserReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SmmCoreServer).AddUser(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: SmmCore_AddUser_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SmmCoreServer).AddUser(ctx, req.(*CreateUserReq)) + } + return interceptor(ctx, in, info, handler) +} + func _SmmCore_AddCategory_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(CreateCategoryReq) if err := dec(in); err != nil { @@ -219,6 +255,10 @@ var SmmCore_ServiceDesc = grpc.ServiceDesc{ MethodName: "Ping", Handler: _SmmCore_Ping_Handler, }, + { + MethodName: "AddUser", + Handler: _SmmCore_AddUser_Handler, + }, { MethodName: "AddCategory", Handler: _SmmCore_AddCategory_Handler, diff --git a/resources/smm_core.swagger.json b/resources/smm_core.swagger.json index a197eaa..377238d 100644 --- a/resources/smm_core.swagger.json +++ b/resources/smm_core.swagger.json @@ -148,6 +148,39 @@ "SmmCore" ] } + }, + "/users": { + "post": { + "summary": "users", + "operationId": "SmmCore_AddUser", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/smm_coreUser" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/smm_coreCreateUserReq" + } + } + ], + "tags": [ + "SmmCore" + ] + } } }, "definitions": { @@ -229,8 +262,28 @@ } } }, + "smm_coreCreateUserReq": { + "type": "object", + "properties": { + "username": { + "type": "string" + } + } + }, "smm_corePingRsp": { "type": "object" + }, + "smm_coreUser": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int32" + }, + "username": { + "type": "string" + } + } } } }