diff --git a/src/apigateway/clients/comment.py b/src/apigateway/clients/comment.py index 7ec125b..e5e37b0 100644 --- a/src/apigateway/clients/comment.py +++ b/src/apigateway/clients/comment.py @@ -14,9 +14,9 @@ async def edit_comment(self, comment_id: int, text: str) -> comment_pb2.EditComm request = comment_pb2.EditCommentRequest(comment_id=comment_id, text=text) return await self.call(self._stub.EditComment, request) - async def delete_comment(self, comment_id: int) -> comment_pb2.DeleteCommentResponse: - request = comment_pb2.DeleteCommentRequest(comment_id=comment_id) - return await self.call(self._stub.DeleteComment, request) + async def set_status_comment(self, comment_id: int, status: str) -> comment_pb2.SetStatusResponse: + request = comment_pb2.SetStatusRequest(comment_id=comment_id, status=status) + return await self.call(self._stub.SetStatus, request) async def get_comments(self, mod_id: int) -> comment_pb2.GetCommentsResponse: request = comment_pb2.GetCommentsRequest(mod_id=mod_id) diff --git a/src/apigateway/resolvers/mutation/comment.py b/src/apigateway/resolvers/mutation/comment.py index cabbf52..de88caf 100644 --- a/src/apigateway/resolvers/mutation/comment.py +++ b/src/apigateway/resolvers/mutation/comment.py @@ -1,3 +1,4 @@ +from enum import StrEnum from typing import Any from ariadne import ObjectType @@ -11,6 +12,13 @@ comment_mutation = ObjectType("CommentMutation") +class CommentStatus(StrEnum): + COMMENT_STATUS_UNSPECIFIED = "COMMENT_STATUS_UNSPECIFIED" + COMMENT_STATUS_DELETED = "COMMENT_STATUS_DELETED" + COMMENT_STATUS_HIDDEN = "COMMENT_STATUS_HIDDEN" + COMMENT_STATUS_ON_MODERATION = "COMMENT_STATUS_ON_MODERATION" + + class CreateCommentInput(BaseModel): mod_id: int author_id: int @@ -52,18 +60,19 @@ async def resolve_edit_comment(parent: object, info: GraphQLResolveInfo, input: return resp.success # type: ignore -class DeleteCommentInput(BaseModel): +class CommentSetStatusInput(BaseModel): comment_id: int + status: CommentStatus @field_validator("comment_id", mode="before") def _comment_id(cls, v: Any) -> int: return validate_and_convert_id(v, "comment_id") -@comment_mutation.field("deleteComment") +@comment_mutation.field("setStatus") @handle_grpc_errors -async def resolve_delete_comment(parent: object, info: GraphQLResolveInfo, input: DeleteCommentInput) -> bool: - data = DeleteCommentInput.model_validate(input) +async def resolve_set_status_comment(parent: object, info: GraphQLResolveInfo, input: CommentSetStatusInput) -> bool: + data = CommentSetStatusInput.model_validate(input) client = info.context["clients"]["comment_service"] - resp = await client.delete_comment(data.comment_id) + resp = await client.set_status_comment(data.comment_id, data.status.value) return resp.success # type: ignore diff --git a/src/apigateway/resolvers/mutation/mod.py b/src/apigateway/resolvers/mutation/mod.py index 2a2e1cc..1c1f570 100644 --- a/src/apigateway/resolvers/mutation/mod.py +++ b/src/apigateway/resolvers/mutation/mod.py @@ -45,7 +45,7 @@ async def resolve_create_mod(parent: object, info: GraphQLResolveInfo, input: Cr return CreateModResult(mod_id=resp.mod_id, s3_key=resp.s3_key, upload_url=resp.upload_url).model_dump() -class SetStatusInput(BaseModel): +class ModSetStatusInput(BaseModel): mod_id: int status: ModStatus @@ -56,8 +56,8 @@ def validate_mod_id(cls, v: Any) -> int: @mod_mutation.field("setStatus") @handle_grpc_errors -async def resolve_set_status_mod(parent: object, info: GraphQLResolveInfo, input: SetStatusInput) -> bool: - data = SetStatusInput.model_validate(input) +async def resolve_set_status_mod(parent: object, info: GraphQLResolveInfo, input: ModSetStatusInput) -> bool: + data = ModSetStatusInput.model_validate(input) client = info.context["clients"]["mod_service"] resp = await client.set_status_mod(data.mod_id, data.status.value) return resp.success # type: ignore diff --git a/src/apigateway/schema/mutation/comment.graphql b/src/apigateway/schema/mutation/comment.graphql index 614bc4e..7b96e0d 100644 --- a/src/apigateway/schema/mutation/comment.graphql +++ b/src/apigateway/schema/mutation/comment.graphql @@ -1,7 +1,7 @@ type CommentMutation { createComment(input: CreateCommentInput!): ID! editComment(input: EditCommentInput!): Boolean! - deleteComment(input: DeleteCommentInput!): Boolean! + setStatus(input: CommentSetStatusInput!): Boolean! } input CreateCommentInput { @@ -15,6 +15,7 @@ input EditCommentInput { text: String! } -input DeleteCommentInput { +input CommentSetStatusInput { comment_id: ID! + status: CommentStatus! } diff --git a/src/apigateway/schema/mutation/mod.graphql b/src/apigateway/schema/mutation/mod.graphql index 7268f2a..2c10412 100644 --- a/src/apigateway/schema/mutation/mod.graphql +++ b/src/apigateway/schema/mutation/mod.graphql @@ -6,7 +6,7 @@ type CreateModResult { type ModMutation { createMod(input: CreateModInput!): CreateModResult! - setStatus(input: SetStatusInput!): Boolean! + setStatus(input: ModSetStatusInput!): Boolean! } input CreateModInput { @@ -16,7 +16,7 @@ input CreateModInput { description: String! } -input SetStatusInput { +input ModSetStatusInput { mod_id: ID! status: ModStatus! } \ No newline at end of file diff --git a/src/apigateway/schema/query/comment.graphql b/src/apigateway/schema/query/comment.graphql index 5f92ba7..9701091 100644 --- a/src/apigateway/schema/query/comment.graphql +++ b/src/apigateway/schema/query/comment.graphql @@ -2,6 +2,13 @@ type CommentQuery { getComments(input: GetCommentsInput!): [Comment] } +enum CommentStatus { + COMMENT_STATUS_UNSPECIFIED + COMMENT_STATUS_DELETED + COMMENT_STATUS_HIDDEN + COMMENT_STATUS_ON_MODERATION +} + type Comment { id: ID! author_id: ID! diff --git a/src/apigateway/stubs/comment/comment_pb2.py b/src/apigateway/stubs/comment/comment_pb2.py index 7a0be3d..69ca316 100644 --- a/src/apigateway/stubs/comment/comment_pb2.py +++ b/src/apigateway/stubs/comment/comment_pb2.py @@ -25,13 +25,15 @@ from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rcomment.proto\x12\x07\x63omment\x1a\x1fgoogle/protobuf/timestamp.proto\"\x95\x01\n\x07\x43omment\x12\n\n\x02id\x18\x01 \x01(\x03\x12\x11\n\tauthor_id\x18\x02 \x01(\x03\x12\x0c\n\x04text\x18\x03 \x01(\t\x12.\n\ncreated_at\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12-\n\tedited_at\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"G\n\x14\x43reateCommentRequest\x12\x0e\n\x06mod_id\x18\x01 \x01(\x03\x12\x11\n\tauthor_id\x18\x02 \x01(\x03\x12\x0c\n\x04text\x18\x03 \x01(\t\"+\n\x15\x43reateCommentResponse\x12\x12\n\ncomment_id\x18\x01 \x01(\x03\"$\n\x12GetCommentsRequest\x12\x0e\n\x06mod_id\x18\x01 \x01(\x03\"I\n\x13GetCommentsResponse\x12\x0e\n\x06mod_id\x18\x01 \x01(\x03\x12\"\n\x08\x63omments\x18\x02 \x03(\x0b\x32\x10.comment.Comment\"*\n\x14\x44\x65leteCommentRequest\x12\x12\n\ncomment_id\x18\x01 \x01(\x03\"(\n\x15\x44\x65leteCommentResponse\x12\x0f\n\x07success\x18\x01 \x01(\x08\"6\n\x12\x45\x64itCommentRequest\x12\x12\n\ncomment_id\x18\x01 \x01(\x03\x12\x0c\n\x04text\x18\x02 \x01(\t\"&\n\x13\x45\x64itCommentResponse\x12\x0f\n\x07success\x18\x01 \x01(\x08\x32\xc4\x02\n\x0e\x43ommentService\x12N\n\rCreateComment\x12\x1d.comment.CreateCommentRequest\x1a\x1e.comment.CreateCommentResponse\x12H\n\x0bGetComments\x12\x1b.comment.GetCommentsRequest\x1a\x1c.comment.GetCommentsResponse\x12N\n\rDeleteComment\x12\x1d.comment.DeleteCommentRequest\x1a\x1e.comment.DeleteCommentResponse\x12H\n\x0b\x45\x64itComment\x12\x1b.comment.EditCommentRequest\x1a\x1c.comment.EditCommentResponseb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rcomment.proto\x12\x07\x63omment\x1a\x1fgoogle/protobuf/timestamp.proto\"\x95\x01\n\x07\x43omment\x12\n\n\x02id\x18\x01 \x01(\x03\x12\x11\n\tauthor_id\x18\x02 \x01(\x03\x12\x0c\n\x04text\x18\x03 \x01(\t\x12.\n\ncreated_at\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12-\n\tedited_at\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"G\n\x14\x43reateCommentRequest\x12\x0e\n\x06mod_id\x18\x01 \x01(\x03\x12\x11\n\tauthor_id\x18\x02 \x01(\x03\x12\x0c\n\x04text\x18\x03 \x01(\t\"+\n\x15\x43reateCommentResponse\x12\x12\n\ncomment_id\x18\x01 \x01(\x03\"$\n\x12GetCommentsRequest\x12\x0e\n\x06mod_id\x18\x01 \x01(\x03\"I\n\x13GetCommentsResponse\x12\x0e\n\x06mod_id\x18\x01 \x01(\x03\x12\"\n\x08\x63omments\x18\x02 \x03(\x0b\x32\x10.comment.Comment\"N\n\x10SetStatusRequest\x12\x12\n\ncomment_id\x18\x01 \x01(\x03\x12&\n\x06status\x18\x02 \x01(\x0e\x32\x16.comment.CommentStatus\"$\n\x11SetStatusResponse\x12\x0f\n\x07success\x18\x01 \x01(\x08\"6\n\x12\x45\x64itCommentRequest\x12\x12\n\ncomment_id\x18\x01 \x01(\x03\x12\x0c\n\x04text\x18\x02 \x01(\t\"&\n\x13\x45\x64itCommentResponse\x12\x0f\n\x07success\x18\x01 \x01(\x08*\x88\x01\n\rCommentStatus\x12\x1e\n\x1a\x43OMMENT_STATUS_UNSPECIFIED\x10\x00\x12\x1a\n\x16\x43OMMENT_STATUS_DELETED\x10\x01\x12\x19\n\x15\x43OMMENT_STATUS_HIDDEN\x10\x02\x12 \n\x1c\x43OMMENT_STATUS_ON_MODERATION\x10\x03\x32\xb8\x02\n\x0e\x43ommentService\x12N\n\rCreateComment\x12\x1d.comment.CreateCommentRequest\x1a\x1e.comment.CreateCommentResponse\x12H\n\x0bGetComments\x12\x1b.comment.GetCommentsRequest\x1a\x1c.comment.GetCommentsResponse\x12\x42\n\tSetStatus\x12\x19.comment.SetStatusRequest\x1a\x1a.comment.SetStatusResponse\x12H\n\x0b\x45\x64itComment\x12\x1b.comment.EditCommentRequest\x1a\x1c.comment.EditCommentResponseb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'comment_pb2', _globals) if not _descriptor._USE_C_DESCRIPTORS: DESCRIPTOR._loaded_options = None + _globals['_COMMENTSTATUS']._serialized_start=657 + _globals['_COMMENTSTATUS']._serialized_end=793 _globals['_COMMENT']._serialized_start=60 _globals['_COMMENT']._serialized_end=209 _globals['_CREATECOMMENTREQUEST']._serialized_start=211 @@ -42,14 +44,14 @@ _globals['_GETCOMMENTSREQUEST']._serialized_end=365 _globals['_GETCOMMENTSRESPONSE']._serialized_start=367 _globals['_GETCOMMENTSRESPONSE']._serialized_end=440 - _globals['_DELETECOMMENTREQUEST']._serialized_start=442 - _globals['_DELETECOMMENTREQUEST']._serialized_end=484 - _globals['_DELETECOMMENTRESPONSE']._serialized_start=486 - _globals['_DELETECOMMENTRESPONSE']._serialized_end=526 - _globals['_EDITCOMMENTREQUEST']._serialized_start=528 - _globals['_EDITCOMMENTREQUEST']._serialized_end=582 - _globals['_EDITCOMMENTRESPONSE']._serialized_start=584 - _globals['_EDITCOMMENTRESPONSE']._serialized_end=622 - _globals['_COMMENTSERVICE']._serialized_start=625 - _globals['_COMMENTSERVICE']._serialized_end=949 + _globals['_SETSTATUSREQUEST']._serialized_start=442 + _globals['_SETSTATUSREQUEST']._serialized_end=520 + _globals['_SETSTATUSRESPONSE']._serialized_start=522 + _globals['_SETSTATUSRESPONSE']._serialized_end=558 + _globals['_EDITCOMMENTREQUEST']._serialized_start=560 + _globals['_EDITCOMMENTREQUEST']._serialized_end=614 + _globals['_EDITCOMMENTRESPONSE']._serialized_start=616 + _globals['_EDITCOMMENTRESPONSE']._serialized_end=654 + _globals['_COMMENTSERVICE']._serialized_start=796 + _globals['_COMMENTSERVICE']._serialized_end=1108 # @@protoc_insertion_point(module_scope) diff --git a/src/apigateway/stubs/comment/comment_pb2.pyi b/src/apigateway/stubs/comment/comment_pb2.pyi index 7b44b4f..930e8d1 100644 --- a/src/apigateway/stubs/comment/comment_pb2.pyi +++ b/src/apigateway/stubs/comment/comment_pb2.pyi @@ -2,6 +2,7 @@ import datetime from google.protobuf import timestamp_pb2 as _timestamp_pb2 from google.protobuf.internal import containers as _containers +from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from collections.abc import Iterable as _Iterable, Mapping as _Mapping @@ -9,6 +10,17 @@ from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union DESCRIPTOR: _descriptor.FileDescriptor +class CommentStatus(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): + __slots__ = () + COMMENT_STATUS_UNSPECIFIED: _ClassVar[CommentStatus] + COMMENT_STATUS_DELETED: _ClassVar[CommentStatus] + COMMENT_STATUS_HIDDEN: _ClassVar[CommentStatus] + COMMENT_STATUS_ON_MODERATION: _ClassVar[CommentStatus] +COMMENT_STATUS_UNSPECIFIED: CommentStatus +COMMENT_STATUS_DELETED: CommentStatus +COMMENT_STATUS_HIDDEN: CommentStatus +COMMENT_STATUS_ON_MODERATION: CommentStatus + class Comment(_message.Message): __slots__ = ("id", "author_id", "text", "created_at", "edited_at") ID_FIELD_NUMBER: _ClassVar[int] @@ -53,13 +65,15 @@ class GetCommentsResponse(_message.Message): comments: _containers.RepeatedCompositeFieldContainer[Comment] def __init__(self, mod_id: _Optional[int] = ..., comments: _Optional[_Iterable[_Union[Comment, _Mapping]]] = ...) -> None: ... -class DeleteCommentRequest(_message.Message): - __slots__ = ("comment_id",) +class SetStatusRequest(_message.Message): + __slots__ = ("comment_id", "status") COMMENT_ID_FIELD_NUMBER: _ClassVar[int] + STATUS_FIELD_NUMBER: _ClassVar[int] comment_id: int - def __init__(self, comment_id: _Optional[int] = ...) -> None: ... + status: CommentStatus + def __init__(self, comment_id: _Optional[int] = ..., status: _Optional[_Union[CommentStatus, str]] = ...) -> None: ... -class DeleteCommentResponse(_message.Message): +class SetStatusResponse(_message.Message): __slots__ = ("success",) SUCCESS_FIELD_NUMBER: _ClassVar[int] success: bool diff --git a/src/apigateway/stubs/comment/comment_pb2_grpc.py b/src/apigateway/stubs/comment/comment_pb2_grpc.py index cba8422..1e74b2a 100644 --- a/src/apigateway/stubs/comment/comment_pb2_grpc.py +++ b/src/apigateway/stubs/comment/comment_pb2_grpc.py @@ -26,7 +26,8 @@ class CommentServiceStub(object): - """Missing associated documentation comment in .proto file.""" + """Сервис для работы с комментариями: создание, получение, изменение статуса, редактирование + """ def __init__(self, channel): """Constructor. @@ -44,10 +45,10 @@ def __init__(self, channel): request_serializer=comment__pb2.GetCommentsRequest.SerializeToString, response_deserializer=comment__pb2.GetCommentsResponse.FromString, _registered_method=True) - self.DeleteComment = channel.unary_unary( - '/comment.CommentService/DeleteComment', - request_serializer=comment__pb2.DeleteCommentRequest.SerializeToString, - response_deserializer=comment__pb2.DeleteCommentResponse.FromString, + self.SetStatus = channel.unary_unary( + '/comment.CommentService/SetStatus', + request_serializer=comment__pb2.SetStatusRequest.SerializeToString, + response_deserializer=comment__pb2.SetStatusResponse.FromString, _registered_method=True) self.EditComment = channel.unary_unary( '/comment.CommentService/EditComment', @@ -57,28 +58,33 @@ def __init__(self, channel): class CommentServiceServicer(object): - """Missing associated documentation comment in .proto file.""" + """Сервис для работы с комментариями: создание, получение, изменение статуса, редактирование + """ def CreateComment(self, request, context): - """Missing associated documentation comment in .proto file.""" + """Создание комментария + """ context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') def GetComments(self, request, context): - """Missing associated documentation comment in .proto file.""" + """Получение комментариев + """ context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') - def DeleteComment(self, request, context): - """Missing associated documentation comment in .proto file.""" + def SetStatus(self, request, context): + """Изменение статуса комментария + """ context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') def EditComment(self, request, context): - """Missing associated documentation comment in .proto file.""" + """Редактирование комментария + """ context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') @@ -96,10 +102,10 @@ def add_CommentServiceServicer_to_server(servicer, server): request_deserializer=comment__pb2.GetCommentsRequest.FromString, response_serializer=comment__pb2.GetCommentsResponse.SerializeToString, ), - 'DeleteComment': grpc.unary_unary_rpc_method_handler( - servicer.DeleteComment, - request_deserializer=comment__pb2.DeleteCommentRequest.FromString, - response_serializer=comment__pb2.DeleteCommentResponse.SerializeToString, + 'SetStatus': grpc.unary_unary_rpc_method_handler( + servicer.SetStatus, + request_deserializer=comment__pb2.SetStatusRequest.FromString, + response_serializer=comment__pb2.SetStatusResponse.SerializeToString, ), 'EditComment': grpc.unary_unary_rpc_method_handler( servicer.EditComment, @@ -115,7 +121,8 @@ def add_CommentServiceServicer_to_server(servicer, server): # This class is part of an EXPERIMENTAL API. class CommentService(object): - """Missing associated documentation comment in .proto file.""" + """Сервис для работы с комментариями: создание, получение, изменение статуса, редактирование + """ @staticmethod def CreateComment(request, @@ -172,7 +179,7 @@ def GetComments(request, _registered_method=True) @staticmethod - def DeleteComment(request, + def SetStatus(request, target, options=(), channel_credentials=None, @@ -185,9 +192,9 @@ def DeleteComment(request, return grpc.experimental.unary_unary( request, target, - '/comment.CommentService/DeleteComment', - comment__pb2.DeleteCommentRequest.SerializeToString, - comment__pb2.DeleteCommentResponse.FromString, + '/comment.CommentService/SetStatus', + comment__pb2.SetStatusRequest.SerializeToString, + comment__pb2.SetStatusResponse.FromString, options, channel_credentials, insecure,