-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Moving the conversation under tag (#111)
* feat: Moving the conversation under tag --------- Co-authored-by: Manikandan Sellasamy <[email protected]>
- Loading branch information
1 parent
b35de94
commit 936663b
Showing
11 changed files
with
174 additions
and
165 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
using datasheetapi.Adapters; | ||
|
||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.Identity.Web.Resource; | ||
|
||
namespace datasheetapi.Controllers; | ||
|
||
[ApiController] | ||
[Route("/conversations")] | ||
[Authorize] | ||
[RequiredScope(RequiredScopesConfigurationKey = "AzureAd:Scopes")] | ||
[RequiresApplicationRoles( | ||
ApplicationRole.Admin, | ||
ApplicationRole.ReadOnlyUser, | ||
ApplicationRole.User | ||
)] | ||
public class MessagesController : ControllerBase | ||
{ | ||
private readonly IConversationService _conversationService; | ||
private readonly ILogger<MessagesController> _logger; | ||
|
||
public MessagesController(ILoggerFactory loggerFactory, | ||
IConversationService conversationService) | ||
{ | ||
_logger = loggerFactory.CreateLogger<MessagesController>(); | ||
_conversationService = conversationService; | ||
} | ||
|
||
[HttpPost("{conversationId}/messages", Name = "AddMessage")] | ||
public async Task<ActionResult<GetMessageDto>> AddMessage( | ||
[FromRoute][NotEmptyGuid] Guid conversationId, [Required] MessageDto messageDto) | ||
{ | ||
_logger.LogDebug("Adding new message in the {conversationId}", conversationId); | ||
var message = messageDto.ToMessageModel(Utils.GetAzureUniqueId(HttpContext.User)); | ||
|
||
var savedMessage = await _conversationService.AddMessage(conversationId, message); | ||
_logger.LogInformation("Added new message in the conversation {conversationId}.", conversationId); | ||
|
||
return savedMessage.ToMessageDto(await _conversationService.GetUserName(savedMessage.UserId)); | ||
} | ||
|
||
[HttpGet("{conversationId}/messages/{messageId}", Name = "GetMessage")] | ||
public async Task<ActionResult<GetMessageDto>> GetMessage( | ||
[NotEmptyGuid] Guid conversationId, [NotEmptyGuid] Guid messageId) | ||
{ | ||
_logger.LogDebug("Fetching message on the conversation {conversationId}.", conversationId); | ||
var message = await _conversationService.GetMessage(messageId); | ||
var username = await _conversationService.GetUserName(message.UserId); | ||
|
||
return message.ToMessageDto(username); | ||
} | ||
|
||
[HttpGet("{conversationId}/messages", Name = "GetMessages")] | ||
public async Task<ActionResult<List<GetMessageDto>>> GetMessages([NotEmptyGuid] Guid conversationId) | ||
{ | ||
_logger.LogDebug("Fetching messages on the conversation {conversationId}.", conversationId); | ||
var messges = await _conversationService.GetMessages(conversationId); | ||
|
||
var userIdNameMap = await _conversationService.GetUserIdUserName( | ||
messges.Select(c => c.UserId).ToList()); | ||
|
||
return messges.ToMessageDtos(userIdNameMap); | ||
} | ||
|
||
[HttpPut("{conversationId}/messages/{messageId}", Name = "UpdateMessage")] | ||
public async Task<ActionResult<GetMessageDto>> UpdateMessage( | ||
[FromRoute][NotEmptyGuid] Guid conversationId, [FromRoute][NotEmptyGuid] Guid messageId, | ||
[Required] MessageDto newMessageDto) | ||
{ | ||
_logger.LogDebug("Updating the message {messageId}.", messageId); | ||
var newMessage = newMessageDto.ToMessageModel(Utils.GetAzureUniqueId(HttpContext.User)); | ||
|
||
var message = await _conversationService.UpdateMessage(messageId, newMessage); | ||
_logger.LogInformation("Updated the message {messageId} on the conversation {conversationId}.", | ||
messageId, conversationId); | ||
|
||
var userName = await _conversationService.GetUserName(message.UserId); | ||
return message.ToMessageDto(userName); | ||
|
||
} | ||
|
||
[HttpDelete("{conversationId}/messages/{messageId}", Name = "DeleteMessage")] | ||
public async Task<ActionResult> DeleteMessage( | ||
[FromRoute][NotEmptyGuid] Guid conversationId, [FromRoute][NotEmptyGuid] Guid messageId) | ||
{ | ||
_logger.LogDebug("Deleting the message {messageId} on conversation {conversationId}.", messageId, conversationId); | ||
await _conversationService.DeleteMessage(messageId, Utils.GetAzureUniqueId(HttpContext.User)); | ||
_logger.LogInformation("Deleted the message {messageId} on conversation {conversationId}.", | ||
messageId, conversationId); | ||
|
||
return NoContent(); | ||
} | ||
} |
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
Oops, something went wrong.