Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/apigateway/clients/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 14 additions & 5 deletions src/apigateway/resolvers/mutation/comment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import StrEnum
from typing import Any

from ariadne import ObjectType
Expand All @@ -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
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/apigateway/resolvers/mutation/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
5 changes: 3 additions & 2 deletions src/apigateway/schema/mutation/comment.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type CommentMutation {
createComment(input: CreateCommentInput!): ID!
editComment(input: EditCommentInput!): Boolean!
deleteComment(input: DeleteCommentInput!): Boolean!
setStatus(input: CommentSetStatusInput!): Boolean!
}

input CreateCommentInput {
Expand All @@ -15,6 +15,7 @@ input EditCommentInput {
text: String!
}

input DeleteCommentInput {
input CommentSetStatusInput {
comment_id: ID!
status: CommentStatus!
}
4 changes: 2 additions & 2 deletions src/apigateway/schema/mutation/mod.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type CreateModResult {

type ModMutation {
createMod(input: CreateModInput!): CreateModResult!
setStatus(input: SetStatusInput!): Boolean!
setStatus(input: ModSetStatusInput!): Boolean!
}

input CreateModInput {
Expand All @@ -16,7 +16,7 @@ input CreateModInput {
description: String!
}

input SetStatusInput {
input ModSetStatusInput {
mod_id: ID!
status: ModStatus!
}
7 changes: 7 additions & 0 deletions src/apigateway/schema/query/comment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
24 changes: 13 additions & 11 deletions src/apigateway/stubs/comment/comment_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions src/apigateway/stubs/comment/comment_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ 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
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]
Expand Down Expand Up @@ -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
Expand Down
47 changes: 27 additions & 20 deletions src/apigateway/stubs/comment/comment_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@


class CommentServiceStub(object):
"""Missing associated documentation comment in .proto file."""
"""Сервис для работы с комментариями: создание, получение, изменение статуса, редактирование
"""

def __init__(self, channel):
"""Constructor.
Expand All @@ -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',
Expand All @@ -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!')
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -172,7 +179,7 @@ def GetComments(request,
_registered_method=True)

@staticmethod
def DeleteComment(request,
def SetStatus(request,
target,
options=(),
channel_credentials=None,
Expand All @@ -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,
Expand Down
Loading