Compare commits
2 Commits
8af2dddb45
...
fcab12f175
Author | SHA1 | Date | |
---|---|---|---|
|
fcab12f175 | ||
|
f5b04fa745 |
@@ -65,7 +65,8 @@ public class RelationshipController(AppDatabase db, RelationshipService rels) :
|
||||
|
||||
[HttpPost("{userId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<Relationship>> CreateRelationship(Guid userId, [FromBody] RelationshipRequest request)
|
||||
public async Task<ActionResult<Relationship>> CreateRelationship(Guid userId,
|
||||
[FromBody] RelationshipRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||
|
||||
@@ -87,7 +88,8 @@ public class RelationshipController(AppDatabase db, RelationshipService rels) :
|
||||
|
||||
[HttpPatch("{userId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<Relationship>> UpdateRelationship(Guid userId, [FromBody] RelationshipRequest request)
|
||||
public async Task<ActionResult<Relationship>> UpdateRelationship(Guid userId,
|
||||
[FromBody] RelationshipRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||
|
||||
@@ -106,6 +108,18 @@ public class RelationshipController(AppDatabase db, RelationshipService rels) :
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{userId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<Relationship>> GetRelationship(Guid userId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||
|
||||
var relationship = await rels.GetRelationship(currentUser.Id, userId);
|
||||
if (relationship is null) return NotFound();
|
||||
|
||||
return relationship;
|
||||
}
|
||||
|
||||
[HttpPost("{userId:guid}/friends")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<Relationship>> SendFriendRequest(Guid userId)
|
||||
|
@@ -130,6 +130,23 @@ public class ChatRoomController(
|
||||
return Ok(dmRoom);
|
||||
}
|
||||
|
||||
[HttpGet("direct/{userId:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<ChatRoom>> GetDirectChatRoom(Guid userId)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var room = await db.ChatRooms
|
||||
.Include(c => c.Members)
|
||||
.Where(c => c.Type == ChatRoomType.DirectMessage && c.Members.Count == 2)
|
||||
.Where(c => c.Members.Any(m => m.AccountId == currentUser.Id))
|
||||
.Where(c => c.Members.Any(m => m.AccountId == userId))
|
||||
.FirstOrDefaultAsync();
|
||||
if (room is null) return NotFound();
|
||||
|
||||
return Ok(room);
|
||||
}
|
||||
|
||||
public class ChatRoomRequest
|
||||
{
|
||||
|
Reference in New Issue
Block a user