diff --git a/api/main.proto b/api/main.proto index 2d1ad50..7bc693d 100644 --- a/api/main.proto +++ b/api/main.proto @@ -252,7 +252,7 @@ service EveningDetectiveServer { rpc AddScenarioPlace(AddScenarioPlaceReq) returns (AddScenarioPlaceRsp) { option (google.api.http) = { - post: "/api/scenarios/places" + post: "/api/scenarios/{id}/places" body: "*" }; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { @@ -263,7 +263,7 @@ service EveningDetectiveServer { rpc UpdateScenarioPlace(UpdateScenarioPlaceReq) returns (UpdateScenarioPlaceRsp) { option (google.api.http) = { - put : "/api/scenarios/places/{code}" + put : "/api/scenarios/{id}/places/{code}" body: "*" }; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { @@ -274,7 +274,7 @@ service EveningDetectiveServer { rpc DeleteScenarioPlace(DeleteScenarioPlaceReq) returns (DeleteScenarioPlaceRsp) { option (google.api.http) = { - delete: "/api/scenarios/places/{code}" + delete: "/api/scenarios/{id}/places/{code}" }; option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { tags : "Точки сценария"; @@ -425,7 +425,7 @@ message GetScenarioReq { } message GetScenarioRsp { - string error = 1; + string error = 1; Scenario scenario = 2; } @@ -491,7 +491,8 @@ message DeleteScenarioRsp { } message AddScenarioPlaceReq { - Place place = 1; + int32 id = 1; + Place place = 2; } message AddScenarioPlaceRsp { @@ -499,8 +500,9 @@ message AddScenarioPlaceRsp { } message UpdateScenarioPlaceReq { - string code = 1; - Place place = 2; + int32 id = 1; + string code = 2; + Place place = 3; } message UpdateScenarioPlaceRsp { @@ -508,7 +510,8 @@ message UpdateScenarioPlaceRsp { } message DeleteScenarioPlaceReq { - string code = 1; + int32 id = 1; + string code = 2; } message DeleteScenarioPlaceRsp { diff --git a/cmd/evening_detective_server/main.swagger.json b/cmd/evening_detective_server/main.swagger.json index d286135..64c7e55 100644 --- a/cmd/evening_detective_server/main.swagger.json +++ b/cmd/evening_detective_server/main.swagger.json @@ -288,107 +288,6 @@ ] } }, - "/api/scenarios/places": { - "post": { - "summary": "Создать точку сценария", - "operationId": "EveningDetectiveServer_AddScenarioPlace", - "responses": { - "200": { - "description": "A successful response.", - "schema": { - "$ref": "#/definitions/evening_detective_serverAddScenarioPlaceRsp" - } - }, - "default": { - "description": "An unexpected error response.", - "schema": { - "$ref": "#/definitions/rpcStatus" - } - } - }, - "parameters": [ - { - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/evening_detective_serverAddScenarioPlaceReq" - } - } - ], - "tags": [ - "Точки сценария" - ] - } - }, - "/api/scenarios/places/{code}": { - "delete": { - "summary": "Удалить точку сценария", - "operationId": "EveningDetectiveServer_DeleteScenarioPlace", - "responses": { - "200": { - "description": "A successful response.", - "schema": { - "$ref": "#/definitions/evening_detective_serverDeleteScenarioPlaceRsp" - } - }, - "default": { - "description": "An unexpected error response.", - "schema": { - "$ref": "#/definitions/rpcStatus" - } - } - }, - "parameters": [ - { - "name": "code", - "in": "path", - "required": true, - "type": "string" - } - ], - "tags": [ - "Точки сценария" - ] - }, - "put": { - "summary": "Обновить точку сценария", - "operationId": "EveningDetectiveServer_UpdateScenarioPlace", - "responses": { - "200": { - "description": "A successful response.", - "schema": { - "$ref": "#/definitions/evening_detective_serverUpdateScenarioPlaceRsp" - } - }, - "default": { - "description": "An unexpected error response.", - "schema": { - "$ref": "#/definitions/rpcStatus" - } - } - }, - "parameters": [ - { - "name": "code", - "in": "path", - "required": true, - "type": "string" - }, - { - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/EveningDetectiveServerUpdateScenarioPlaceBody" - } - } - ], - "tags": [ - "Точки сценария" - ] - } - }, "/api/scenarios/{id}": { "get": { "summary": "Получить сценарий по id", @@ -489,6 +388,128 @@ ] } }, + "/api/scenarios/{id}/places": { + "post": { + "summary": "Создать точку сценария", + "operationId": "EveningDetectiveServer_AddScenarioPlace", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/evening_detective_serverAddScenarioPlaceRsp" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "type": "integer", + "format": "int32" + }, + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/EveningDetectiveServerAddScenarioPlaceBody" + } + } + ], + "tags": [ + "Точки сценария" + ] + } + }, + "/api/scenarios/{id}/places/{code}": { + "delete": { + "summary": "Удалить точку сценария", + "operationId": "EveningDetectiveServer_DeleteScenarioPlace", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/evening_detective_serverDeleteScenarioPlaceRsp" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "type": "integer", + "format": "int32" + }, + { + "name": "code", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "Точки сценария" + ] + }, + "put": { + "summary": "Обновить точку сценария", + "operationId": "EveningDetectiveServer_UpdateScenarioPlace", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/evening_detective_serverUpdateScenarioPlaceRsp" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "type": "integer", + "format": "int32" + }, + { + "name": "code", + "in": "path", + "required": true, + "type": "string" + }, + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/EveningDetectiveServerUpdateScenarioPlaceBody" + } + } + ], + "tags": [ + "Точки сценария" + ] + } + }, "/api/test/echo": { "post": { "summary": "Проверить обработку данных", @@ -736,6 +757,14 @@ } }, "definitions": { + "EveningDetectiveServerAddScenarioPlaceBody": { + "type": "object", + "properties": { + "place": { + "$ref": "#/definitions/evening_detective_serverPlace" + } + } + }, "EveningDetectiveServerAddUserRoleBody": { "type": "object", "properties": { @@ -797,14 +826,6 @@ }, "description": "Message that represents an arbitrary HTTP body. It should only be used for\npayload formats that can't be represented as JSON, such as raw binary or\nan HTML page.\n\n\nThis message can be used both in streaming and non-streaming API methods in\nthe request as well as the response.\n\nIt can be used as a top-level request field, which is convenient if one\nwants to extract parameters from either the URL or HTTP template into the\nrequest fields and also want access to the raw HTTP body.\n\nExample:\n\n message GetResourceRequest {\n // A unique request id.\n string request_id = 1;\n\n // The raw HTTP body is bound to this field.\n google.api.HttpBody http_body = 2;\n\n }\n\n service ResourceService {\n rpc GetResource(GetResourceRequest)\n returns (google.api.HttpBody);\n rpc UpdateResource(google.api.HttpBody)\n returns (google.protobuf.Empty);\n\n }\n\nExample with streaming methods:\n\n service CaldavService {\n rpc GetCalendar(stream google.api.HttpBody)\n returns (stream google.api.HttpBody);\n rpc UpdateCalendar(stream google.api.HttpBody)\n returns (stream google.api.HttpBody);\n\n }\n\nUse of this type only changes how the request and response bodies are\nhandled, all other features will continue to work unchanged." }, - "evening_detective_serverAddScenarioPlaceReq": { - "type": "object", - "properties": { - "place": { - "$ref": "#/definitions/evening_detective_serverPlace" - } - } - }, "evening_detective_serverAddScenarioPlaceRsp": { "type": "object", "properties": { diff --git a/internal/app/server.go b/internal/app/server.go index 1b1ae92..a123d44 100644 --- a/internal/app/server.go +++ b/internal/app/server.go @@ -307,7 +307,18 @@ func (s *server) AddScenarioPlace(ctx context.Context, req *proto.AddScenarioPla return nil, status.Errorf(codes.PermissionDenied, "permission denied") } - panic("unimplemented") + err := s.scenarioService.AddScenarioPlace( + ctx, + int(req.Id), + convertPlace(req.Place), + ) + if err != nil { + return &proto.AddScenarioPlaceRsp{ + Error: err.Error(), + }, nil + } + + return &proto.AddScenarioPlaceRsp{}, nil } func (s *server) UpdateScenarioPlace(ctx context.Context, req *proto.UpdateScenarioPlaceReq) (*proto.UpdateScenarioPlaceRsp, error) { @@ -316,7 +327,19 @@ func (s *server) UpdateScenarioPlace(ctx context.Context, req *proto.UpdateScena return nil, status.Errorf(codes.PermissionDenied, "permission denied") } - panic("unimplemented") + err := s.scenarioService.UpdateScenarioPlace( + ctx, + int(req.Id), + req.Code, + convertPlace(req.Place), + ) + if err != nil { + return &proto.UpdateScenarioPlaceRsp{ + Error: err.Error(), + }, nil + } + + return &proto.UpdateScenarioPlaceRsp{}, nil } func (s *server) DeleteScenarioPlace(ctx context.Context, req *proto.DeleteScenarioPlaceReq) (*proto.DeleteScenarioPlaceRsp, error) { @@ -325,5 +348,16 @@ func (s *server) DeleteScenarioPlace(ctx context.Context, req *proto.DeleteScena return nil, status.Errorf(codes.PermissionDenied, "permission denied") } - panic("unimplemented") + err := s.scenarioService.DeleteScenarioPlace( + ctx, + int(req.Id), + req.Code, + ) + if err != nil { + return &proto.DeleteScenarioPlaceRsp{ + Error: err.Error(), + }, nil + } + + return &proto.DeleteScenarioPlaceRsp{}, nil } diff --git a/internal/app/story_mapper.go b/internal/app/story_mapper.go index 6846d3a..ab47b36 100644 --- a/internal/app/story_mapper.go +++ b/internal/app/story_mapper.go @@ -1,6 +1,7 @@ package app import ( + "evening_detective_server/internal/modules/formatter_utils" "evening_detective_server/internal/modules/storytelling" "evening_detective_server/internal/services/scenarios_service" proto "evening_detective_server/proto" @@ -105,3 +106,61 @@ func mapKey(o *storytelling.Key) *proto.Key { Name: o.Name, } } + +func convertPlace(o *proto.Place) *storytelling.Place { + return &storytelling.Place{ + Code: o.Code, + Name: formatter_utils.FormatString(o.Name), + Text: formatter_utils.FormatText(o.Text), + Image: o.Image, + Hidden: o.Hidden, + Applications: convertApplications(o.Applications), + Doors: convertDoors(o.Doors), + Keys: convertKeys(o.Keys), + } +} + +func convertApplications(o []*proto.Application) []*storytelling.Application { + res := make([]*storytelling.Application, 0, len(o)) + for _, item := range o { + res = append(res, convertApplication(item)) + } + return res +} + +func convertDoors(o []*proto.Door) []*storytelling.Door { + res := make([]*storytelling.Door, 0, len(o)) + for _, item := range o { + res = append(res, convertDoor(item)) + } + return res +} + +func convertKeys(o []*proto.Key) []*storytelling.Key { + res := make([]*storytelling.Key, 0, len(o)) + for _, item := range o { + res = append(res, convertKey(item)) + } + return res +} + +func convertApplication(o *proto.Application) *storytelling.Application { + return &storytelling.Application{ + Name: formatter_utils.FormatString(o.Name), + Image: o.Image, + } +} + +func convertDoor(o *proto.Door) *storytelling.Door { + return &storytelling.Door{ + Code: o.Code, + Name: formatter_utils.FormatString(o.Name), + Keys: convertKeys(o.Keys), + } +} + +func convertKey(o *proto.Key) *storytelling.Key { + return &storytelling.Key{ + Name: formatter_utils.FormatString(o.Name), + } +} diff --git a/internal/modules/formatter/interface.go b/internal/modules/formatter/interface.go deleted file mode 100644 index 3fd0ec0..0000000 --- a/internal/modules/formatter/interface.go +++ /dev/null @@ -1,6 +0,0 @@ -package formatter - -type IFormatter interface { - FormatText(text string) string - FormatString(text string) string -} diff --git a/internal/modules/formatter/service.go b/internal/modules/formatter_utils/service.go similarity index 78% rename from internal/modules/formatter/service.go rename to internal/modules/formatter_utils/service.go index 2639a77..9a330de 100644 --- a/internal/modules/formatter/service.go +++ b/internal/modules/formatter_utils/service.go @@ -1,17 +1,11 @@ -package formatter +package formatter_utils import ( "bufio" "strings" ) -type service struct{} - -func NewFormatter() IFormatter { - return &service{} -} - -func (s *service) FormatText(text string) string { +func FormatText(text string) string { scanner := bufio.NewScanner(strings.NewReader(text)) scanner.Split(bufio.ScanLines) @@ -41,7 +35,7 @@ func (s *service) FormatText(text string) string { return res.String() } -func (s *service) FormatString(text string) string { +func FormatString(text string) string { l := strings.TrimSpace(text) if strings.HasPrefix(l, "--") { l = strings.Replace(l, "--", "—", 1) diff --git a/internal/modules/formatter/service_test.go b/internal/modules/formatter_utils/service_test.go similarity index 91% rename from internal/modules/formatter/service_test.go rename to internal/modules/formatter_utils/service_test.go index c474684..221af7b 100644 --- a/internal/modules/formatter/service_test.go +++ b/internal/modules/formatter_utils/service_test.go @@ -1,4 +1,4 @@ -package formatter +package formatter_utils import "testing" @@ -31,8 +31,7 @@ func Test_service_FormatText(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - var s service - got := s.FormatText(tt.text) + got := FormatText(tt.text) if got != tt.want { t.Errorf("FormatText() = %v, want %v", got, tt.want) } diff --git a/internal/repos/scenarios_repo/repo.go b/internal/repos/scenarios_repo/repo.go index 975d848..7fcebe8 100644 --- a/internal/repos/scenarios_repo/repo.go +++ b/internal/repos/scenarios_repo/repo.go @@ -204,3 +204,53 @@ func (s *ScenariosRepo) DeleteScenarioByID( } return nil } + +func (s *ScenariosRepo) GetStoryByScenarioID( + ctx context.Context, + id int, +) (string, error) { + story := "" + row := s.pool.QueryRow( + ctx, + `SELECT + scenario + FROM scenarios + WHERE scenarios.id = $1`, + id, + ) + err := row.Scan( + &story, + ) + if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + return "", ErrScenarioNotFound + } + return "", err + } + + return story, nil +} + +func (s *ScenariosRepo) UpdateStoryByScenarioID( + ctx context.Context, + id int, + story string, +) error { + tag, err := s.pool.Exec( + ctx, + `UPDATE scenarios + SET + scenario = $1, + updated_at = NOW() + WHERE id = $2`, + story, + id, + ) + if err != nil { + return err + } + if tag.RowsAffected() == 0 { + return ErrScenarioNotFound + } + return nil +} diff --git a/internal/services/scenarios_service/scenario_mapper.go b/internal/services/scenarios_service/scenario_mapper.go index a34952e..980ee7d 100644 --- a/internal/services/scenarios_service/scenario_mapper.go +++ b/internal/services/scenarios_service/scenario_mapper.go @@ -19,8 +19,8 @@ func mapScenarios(o []*repos.Scenario) ([]*Scenario, error) { } func mapScenario(o *repos.Scenario) (*Scenario, error) { - story := &storytelling.Story{} - if err := json.Unmarshal([]byte(o.Scenario), story); err != nil { + story, err := mapStory(o.Scenario) + if err != nil { return nil, err } return &Scenario{ @@ -37,3 +37,19 @@ func mapScenario(o *repos.Scenario) (*Scenario, error) { IsDeleted: o.IsDeleted, }, nil } + +func mapStory(o string) (*storytelling.Story, error) { + res := &storytelling.Story{} + if err := json.Unmarshal([]byte(o), res); err != nil { + return nil, err + } + return res, nil +} + +func convertStory(o *storytelling.Story) (string, error) { + b, err := json.Marshal(o) + if err != nil { + return "", err + } + return string(b), nil +} diff --git a/internal/services/scenarios_service/service.go b/internal/services/scenarios_service/service.go index ead15ff..cebfcb2 100644 --- a/internal/services/scenarios_service/service.go +++ b/internal/services/scenarios_service/service.go @@ -2,6 +2,8 @@ package scenarios_service import ( "context" + "errors" + "evening_detective_server/internal/modules/storytelling" "evening_detective_server/internal/repos/scenarios_repo" ) @@ -67,3 +69,81 @@ func (s *ScenarioService) DeleteScenarioByID( ) error { return s.scenariosRepo.DeleteScenarioByID(ctx, id) } + +func (s *ScenarioService) AddScenarioPlace( + ctx context.Context, + id int, + place *storytelling.Place, +) error { + story, err := s.getStory(ctx, id) + if err != nil { + return err + } + story.Places = append( + story.Places, + place, + ) + return s.updateStory(ctx, id, story) +} + +func (s *ScenarioService) UpdateScenarioPlace( + ctx context.Context, + id int, + code string, + place *storytelling.Place, +) error { + story, err := s.getStory(ctx, id) + if err != nil { + return err + } + for i := range story.Places { + if story.Places[i].Code == code { + story.Places[i] = place + break + } + } + return s.updateStory(ctx, id, story) +} + +func (s *ScenarioService) DeleteScenarioPlace( + ctx context.Context, + id int, + code string, +) error { + story, err := s.getStory(ctx, id) + if err != nil { + return err + } + for i := range story.Places { + if story.Places[i].Code == code { + story.Places = append(story.Places[:i], story.Places[i+1:]...) + break + } + } + return s.updateStory(ctx, id, story) +} + +func (s *ScenarioService) getStory(ctx context.Context, id int) (*storytelling.Story, error) { + storyString, err := s.scenariosRepo.GetStoryByScenarioID(ctx, id) + if err != nil { + return nil, err + } + return mapStory(storyString) +} + +func (s *ScenarioService) updateStory(ctx context.Context, id int, story *storytelling.Story) error { + mapCodes := map[string]struct{}{} + for _, place := range story.Places { + mapCodes[place.Code] = struct{}{} + } + if len(mapCodes) != len(story.Places) { + return errors.New("Такой код точки уже существует") + } + + storyString, err := convertStory(story) + if err != nil { + return err + } + + return s.scenariosRepo.UpdateStoryByScenarioID(ctx, id, storyString) +} diff --git a/proto/main.pb.go b/proto/main.pb.go index fb34d5e..1698d0c 100644 --- a/proto/main.pb.go +++ b/proto/main.pb.go @@ -2259,7 +2259,8 @@ func (x *DeleteScenarioRsp) GetError() string { type AddScenarioPlaceReq struct { state protoimpl.MessageState `protogen:"open.v1"` - Place *Place `protobuf:"bytes,1,opt,name=place,proto3" json:"place,omitempty"` + Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Place *Place `protobuf:"bytes,2,opt,name=place,proto3" json:"place,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -2294,6 +2295,13 @@ func (*AddScenarioPlaceReq) Descriptor() ([]byte, []int) { return file_main_proto_rawDescGZIP(), []int{44} } +func (x *AddScenarioPlaceReq) GetId() int32 { + if x != nil { + return x.Id + } + return 0 +} + func (x *AddScenarioPlaceReq) GetPlace() *Place { if x != nil { return x.Place @@ -2347,8 +2355,9 @@ func (x *AddScenarioPlaceRsp) GetError() string { type UpdateScenarioPlaceReq struct { state protoimpl.MessageState `protogen:"open.v1"` - Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` - Place *Place `protobuf:"bytes,2,opt,name=place,proto3" json:"place,omitempty"` + Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"` + Place *Place `protobuf:"bytes,3,opt,name=place,proto3" json:"place,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -2383,6 +2392,13 @@ func (*UpdateScenarioPlaceReq) Descriptor() ([]byte, []int) { return file_main_proto_rawDescGZIP(), []int{46} } +func (x *UpdateScenarioPlaceReq) GetId() int32 { + if x != nil { + return x.Id + } + return 0 +} + func (x *UpdateScenarioPlaceReq) GetCode() string { if x != nil { return x.Code @@ -2443,7 +2459,8 @@ func (x *UpdateScenarioPlaceRsp) GetError() string { type DeleteScenarioPlaceReq struct { state protoimpl.MessageState `protogen:"open.v1"` - Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` + Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -2478,6 +2495,13 @@ func (*DeleteScenarioPlaceReq) Descriptor() ([]byte, []int) { return file_main_proto_rawDescGZIP(), []int{48} } +func (x *DeleteScenarioPlaceReq) GetId() int32 { + if x != nil { + return x.Id + } + return 0 +} + func (x *DeleteScenarioPlaceReq) GetCode() string { if x != nil { return x.Code @@ -2667,20 +2691,23 @@ const file_main_proto_rawDesc = "" + "\x11DeleteScenarioReq\x12\x0e\n" + "\x02id\x18\x01 \x01(\x05R\x02id\")\n" + "\x11DeleteScenarioRsp\x12\x14\n" + - "\x05error\x18\x01 \x01(\tR\x05error\"R\n" + - "\x13AddScenarioPlaceReq\x12;\n" + - "\x05place\x18\x01 \x01(\v2%.crabs.evening_detective_server.PlaceR\x05place\"+\n" + + "\x05error\x18\x01 \x01(\tR\x05error\"b\n" + + "\x13AddScenarioPlaceReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x05R\x02id\x12;\n" + + "\x05place\x18\x02 \x01(\v2%.crabs.evening_detective_server.PlaceR\x05place\"+\n" + "\x13AddScenarioPlaceRsp\x12\x14\n" + - "\x05error\x18\x01 \x01(\tR\x05error\"i\n" + - "\x16UpdateScenarioPlaceReq\x12\x12\n" + - "\x04code\x18\x01 \x01(\tR\x04code\x12;\n" + - "\x05place\x18\x02 \x01(\v2%.crabs.evening_detective_server.PlaceR\x05place\".\n" + + "\x05error\x18\x01 \x01(\tR\x05error\"y\n" + + "\x16UpdateScenarioPlaceReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x05R\x02id\x12\x12\n" + + "\x04code\x18\x02 \x01(\tR\x04code\x12;\n" + + "\x05place\x18\x03 \x01(\v2%.crabs.evening_detective_server.PlaceR\x05place\".\n" + "\x16UpdateScenarioPlaceRsp\x12\x14\n" + - "\x05error\x18\x01 \x01(\tR\x05error\",\n" + - "\x16DeleteScenarioPlaceReq\x12\x12\n" + - "\x04code\x18\x01 \x01(\tR\x04code\".\n" + + "\x05error\x18\x01 \x01(\tR\x05error\"<\n" + + "\x16DeleteScenarioPlaceReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x05R\x02id\x12\x12\n" + + "\x04code\x18\x02 \x01(\tR\x04code\".\n" + "\x16DeleteScenarioPlaceRsp\x12\x14\n" + - "\x05error\x18\x01 \x01(\tR\x05error2\x8c%\n" + + "\x05error\x18\x01 \x01(\tR\x05error2\x9b%\n" + "\x16EveningDetectiveServer\x12\xa6\x01\n" + "\x04Ping\x12'.crabs.evening_detective_server.PingReq\x1a'.crabs.evening_detective_server.PingRsp\"L\x92A3\x12)Проверить доступностьb\x06\n" + "\x04\n" + @@ -2733,13 +2760,13 @@ const file_main_proto_rawDesc = "" + "\x0eUpdateScenario\x121.crabs.evening_detective_server.UpdateScenarioReq\x1a1.crabs.evening_detective_server.UpdateScenarioRsp\"`\x92A?\n" + "\x10Сценарии\x12+Редактировать сценарий\x82\xd3\xe4\x93\x02\x18:\x01*\x1a\x13/api/scenarios/{id}\x12\xc9\x01\n" + "\x0eDeleteScenario\x121.crabs.evening_detective_server.DeleteScenarioReq\x1a1.crabs.evening_detective_server.DeleteScenarioRsp\"Q\x92A3\n" + - "\x10Сценарии\x12\x1fУдалить сценарий\x82\xd3\xe4\x93\x02\x15*\x13/api/scenarios/{id}\x12\xea\x01\n" + - "\x10AddScenarioPlace\x123.crabs.evening_detective_server.AddScenarioPlaceReq\x1a3.crabs.evening_detective_server.AddScenarioPlaceRsp\"l\x92AI\n" + - "\x1bТочки сценария\x12*Создать точку сценария\x82\xd3\xe4\x93\x02\x1a:\x01*\"\x15/api/scenarios/places\x12\xfc\x01\n" + - "\x13UpdateScenarioPlace\x126.crabs.evening_detective_server.UpdateScenarioPlaceReq\x1a6.crabs.evening_detective_server.UpdateScenarioPlaceRsp\"u\x92AK\n" + - "\x1bТочки сценария\x12,Обновить точку сценария\x82\xd3\xe4\x93\x02!:\x01*\x1a\x1c/api/scenarios/places/{code}\x12\xf7\x01\n" + - "\x13DeleteScenarioPlace\x126.crabs.evening_detective_server.DeleteScenarioPlaceReq\x1a6.crabs.evening_detective_server.DeleteScenarioPlaceRsp\"p\x92AI\n" + - "\x1bТочки сценария\x12*Удалить точку сценария\x82\xd3\xe4\x93\x02\x1e*\x1c/api/scenarios/places/{code}B\xd7\x01\x92A\xc8\x01\x12U\n" + + "\x10Сценарии\x12\x1fУдалить сценарий\x82\xd3\xe4\x93\x02\x15*\x13/api/scenarios/{id}\x12\xef\x01\n" + + "\x10AddScenarioPlace\x123.crabs.evening_detective_server.AddScenarioPlaceReq\x1a3.crabs.evening_detective_server.AddScenarioPlaceRsp\"q\x92AI\n" + + "\x1bТочки сценария\x12*Создать точку сценария\x82\xd3\xe4\x93\x02\x1f:\x01*\"\x1a/api/scenarios/{id}/places\x12\x81\x02\n" + + "\x13UpdateScenarioPlace\x126.crabs.evening_detective_server.UpdateScenarioPlaceReq\x1a6.crabs.evening_detective_server.UpdateScenarioPlaceRsp\"z\x92AK\n" + + "\x1bТочки сценария\x12,Обновить точку сценария\x82\xd3\xe4\x93\x02&:\x01*\x1a!/api/scenarios/{id}/places/{code}\x12\xfc\x01\n" + + "\x13DeleteScenarioPlace\x126.crabs.evening_detective_server.DeleteScenarioPlaceReq\x1a6.crabs.evening_detective_server.DeleteScenarioPlaceRsp\"u\x92AI\n" + + "\x1bТочки сценария\x12*Удалить точку сценария\x82\xd3\xe4\x93\x02#*!/api/scenarios/{id}/places/{code}B\xd7\x01\x92A\xc8\x01\x12U\n" + "KДокументация сервиса \"Вечерний детектив\"2\x06v0.1.0Z]\n" + "[\n" + "\n" + diff --git a/proto/main.pb.gw.go b/proto/main.pb.gw.go index ac1dc71..6555e80 100644 --- a/proto/main.pb.gw.go +++ b/proto/main.pb.gw.go @@ -632,6 +632,7 @@ func request_EveningDetectiveServer_AddScenarioPlace_0(ctx context.Context, mars var ( protoReq AddScenarioPlaceReq metadata runtime.ServerMetadata + err error ) if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) @@ -639,6 +640,14 @@ func request_EveningDetectiveServer_AddScenarioPlace_0(ctx context.Context, mars if req.Body != nil { _, _ = io.Copy(io.Discard, req.Body) } + val, ok := pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + protoReq.Id, err = runtime.Int32(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } msg, err := client.AddScenarioPlace(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } @@ -647,10 +656,19 @@ func local_request_EveningDetectiveServer_AddScenarioPlace_0(ctx context.Context var ( protoReq AddScenarioPlaceReq metadata runtime.ServerMetadata + err error ) if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } + val, ok := pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + protoReq.Id, err = runtime.Int32(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } msg, err := server.AddScenarioPlace(ctx, &protoReq) return msg, metadata, err } @@ -667,7 +685,15 @@ func request_EveningDetectiveServer_UpdateScenarioPlace_0(ctx context.Context, m if req.Body != nil { _, _ = io.Copy(io.Discard, req.Body) } - val, ok := pathParams["code"] + val, ok := pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + protoReq.Id, err = runtime.Int32(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + val, ok = pathParams["code"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "code") } @@ -688,7 +714,15 @@ func local_request_EveningDetectiveServer_UpdateScenarioPlace_0(ctx context.Cont if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - val, ok := pathParams["code"] + val, ok := pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + protoReq.Id, err = runtime.Int32(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + val, ok = pathParams["code"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "code") } @@ -709,7 +743,15 @@ func request_EveningDetectiveServer_DeleteScenarioPlace_0(ctx context.Context, m if req.Body != nil { _, _ = io.Copy(io.Discard, req.Body) } - val, ok := pathParams["code"] + val, ok := pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + protoReq.Id, err = runtime.Int32(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + val, ok = pathParams["code"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "code") } @@ -727,7 +769,15 @@ func local_request_EveningDetectiveServer_DeleteScenarioPlace_0(ctx context.Cont metadata runtime.ServerMetadata err error ) - val, ok := pathParams["code"] + val, ok := pathParams["id"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + } + protoReq.Id, err = runtime.Int32(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + } + val, ok = pathParams["code"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "code") } @@ -1131,7 +1181,7 @@ func RegisterEveningDetectiveServerHandlerServer(ctx context.Context, mux *runti var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/AddScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/places")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/AddScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/{id}/places")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -1151,7 +1201,7 @@ func RegisterEveningDetectiveServerHandlerServer(ctx context.Context, mux *runti var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/UpdateScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/places/{code}")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/UpdateScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/{id}/places/{code}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -1171,7 +1221,7 @@ func RegisterEveningDetectiveServerHandlerServer(ctx context.Context, mux *runti var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/DeleteScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/places/{code}")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/DeleteScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/{id}/places/{code}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -1552,7 +1602,7 @@ func RegisterEveningDetectiveServerHandlerClient(ctx context.Context, mux *runti ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/AddScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/places")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/AddScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/{id}/places")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -1569,7 +1619,7 @@ func RegisterEveningDetectiveServerHandlerClient(ctx context.Context, mux *runti ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/UpdateScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/places/{code}")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/UpdateScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/{id}/places/{code}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -1586,7 +1636,7 @@ func RegisterEveningDetectiveServerHandlerClient(ctx context.Context, mux *runti ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/DeleteScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/places/{code}")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/DeleteScenarioPlace", runtime.WithHTTPPathPattern("/api/scenarios/{id}/places/{code}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -1622,9 +1672,9 @@ var ( pattern_EveningDetectiveServer_GetScenario_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"api", "scenarios", "id"}, "")) pattern_EveningDetectiveServer_UpdateScenario_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"api", "scenarios", "id"}, "")) pattern_EveningDetectiveServer_DeleteScenario_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"api", "scenarios", "id"}, "")) - pattern_EveningDetectiveServer_AddScenarioPlace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "scenarios", "places"}, "")) - pattern_EveningDetectiveServer_UpdateScenarioPlace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "scenarios", "places", "code"}, "")) - pattern_EveningDetectiveServer_DeleteScenarioPlace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "scenarios", "places", "code"}, "")) + pattern_EveningDetectiveServer_AddScenarioPlace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"api", "scenarios", "id", "places"}, "")) + pattern_EveningDetectiveServer_UpdateScenarioPlace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"api", "scenarios", "id", "places", "code"}, "")) + pattern_EveningDetectiveServer_DeleteScenarioPlace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"api", "scenarios", "id", "places", "code"}, "")) ) var (