-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from sentemon/postservice-add-graphql-api
Added GraphQL Api and Configured MassTransit between microservices
- Loading branch information
Showing
56 changed files
with
892 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
backend/src/PostService/PostService.Api/GraphQL/Mutations/CommentMutation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Security.Claims; | ||
using PostService.Application.Commands.AddComment; | ||
using PostService.Application.Commands.DeleteComment; | ||
using PostService.Application.DTOs; | ||
|
||
namespace PostService.Api.GraphQL.Mutations; | ||
|
||
public class CommentMutation | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
|
||
public CommentMutation(IHttpContextAccessor httpContextAccessor) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
} | ||
|
||
public async Task<CommentDto> CreateComment(CreateCommentDto input, [Service] AddCommentCommandHandler addCommentCommandHandler) | ||
{ | ||
var userId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; | ||
var command = new AddCommentCommand(input, userId); | ||
|
||
var result = await addCommentCommandHandler.HandleAsync(command); | ||
|
||
if (!result.IsSuccess) | ||
{ | ||
throw new GraphQLException(new Error(result.Error.Message)); | ||
} | ||
|
||
return result.Response; | ||
} | ||
|
||
public async Task<string> DeleteComment(Guid id, Guid postId, [Service] DeleteCommentCommandHandler deleteCommentCommandHandler) | ||
{ | ||
var userId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; | ||
var command = new DeleteCommentCommand(id, postId, userId); | ||
|
||
var result = await deleteCommentCommandHandler.HandleAsync(command); | ||
|
||
if (!result.IsSuccess) | ||
{ | ||
throw new GraphQLException(new Error(result.Error.Message)); | ||
} | ||
|
||
return result.Response; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
backend/src/PostService/PostService.Api/GraphQL/Mutations/LikeMutation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Security.Claims; | ||
using PostService.Application.Commands.AddLike; | ||
using PostService.Application.Commands.DeleteLike; | ||
using PostService.Application.DTOs; | ||
|
||
namespace PostService.Api.GraphQL.Mutations; | ||
|
||
public class LikeMutation | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
|
||
public LikeMutation(IHttpContextAccessor httpContextAccessor) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
} | ||
|
||
public async Task<LikeDto> AddLike(Guid postId, [Service] AddLikeCommandHandler addLikeCommandHandler) | ||
{ | ||
var userId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; | ||
var command = new AddLikeCommand(postId, userId); | ||
|
||
var result = await addLikeCommandHandler.HandleAsync(command); | ||
|
||
if (!result.IsSuccess) | ||
{ | ||
throw new GraphQLException(new Error(result.Error.Message)); | ||
} | ||
|
||
return result.Response; | ||
} | ||
|
||
public async Task<string> DeleteLike(Guid id, Guid postId, [Service] DeleteLikeCommandHandler deleteLikeCommandHandler) | ||
{ | ||
var userId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; | ||
var command = new DeleteLikeCommand(id, postId, userId); | ||
|
||
var result = await deleteLikeCommandHandler.HandleAsync(command); | ||
|
||
if (!result.IsSuccess) | ||
{ | ||
throw new GraphQLException(new Error(result.Error.Message)); | ||
} | ||
|
||
return result.Response; | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
backend/src/PostService/PostService.Api/GraphQL/Mutations/Mutation.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.