-
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.
Add partial implementation of private message handling
- Loading branch information
Showing
11 changed files
with
428 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using AutoMapper; | ||
using CloudinaryDotNet; | ||
using CloudinaryDotNet.Actions; | ||
using Friendster.Controllers.Resources; | ||
using Friendster.Data; | ||
using Friendster.Helpers; | ||
using Friendster.Models; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
|
||
namespace Friendster.Controllers | ||
{ | ||
[ServiceFilter(typeof(LogActivity))] | ||
[Authorize] | ||
[Route("api/users/{userId}/[controller]")] | ||
[ApiController] | ||
public class MessagesController : ControllerBase | ||
{ | ||
private IFriendRepository _repo; | ||
private IMapper _mapper; | ||
|
||
public MessagesController(IFriendRepository repo, IMapper mapper) | ||
{ | ||
_repo = repo; | ||
_mapper = mapper; | ||
} | ||
|
||
[HttpGet("{messageId}", Name = "GetMessage")] | ||
public async Task<IActionResult> GetMessage(int userId, int messageId) | ||
{ | ||
int id = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); | ||
|
||
if (id != userId) | ||
{ | ||
return Unauthorized(); | ||
} | ||
|
||
var message = await _repo.GetMessage(messageId); | ||
var messageResource = _mapper.Map<Message, SendMessageResource>(message); | ||
return Ok(messageResource); | ||
} | ||
|
||
//[HttpPost] | ||
//public async Task<ActionResult> SendMessage(int userId, int recipientId, [FromForm]SendMessageResource sendMessageResource) | ||
//{ | ||
// int id = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); | ||
|
||
// if (id != userId) | ||
// { | ||
// return Unauthorized(); | ||
// } | ||
|
||
|
||
//} | ||
|
||
//[HttpDelete("{messageId}")] | ||
//public async Task<IActionResult> DeleteMessage(int userId, int messageId) | ||
//{ | ||
// int id = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); | ||
|
||
// if (id != userId) | ||
// { | ||
// return Unauthorized(); | ||
// } | ||
|
||
|
||
//} | ||
} | ||
} |
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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Friendster.Controllers.Resources | ||
{ | ||
public class SendMessageResource | ||
{ | ||
public string Content { get; set; } | ||
public DateTime MessageSent { get; set; } | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.