diff --git a/DysonNetwork.Sphere/Account/RelationshipController.cs b/DysonNetwork.Sphere/Account/RelationshipController.cs index 17c9827..5b0a2f4 100644 --- a/DysonNetwork.Sphere/Account/RelationshipController.cs +++ b/DysonNetwork.Sphere/Account/RelationshipController.cs @@ -230,4 +230,24 @@ public class RelationshipController(AppDatabase db, RelationshipService rels) : return BadRequest(err.Message); } } + + [HttpDelete("{userId:guid}/block")] + [Authorize] + public async Task> UnblockUser(Guid userId) + { + if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); + + var relatedUser = await db.Accounts.FindAsync(userId); + if (relatedUser is null) return NotFound("Account was not found."); + + try + { + var relationship = await rels.UnblockAccount(currentUser, relatedUser); + return relationship; + } + catch (InvalidOperationException err) + { + return BadRequest(err.Message); + } + } } \ No newline at end of file diff --git a/DysonNetwork.Sphere/Account/RelationshipService.cs b/DysonNetwork.Sphere/Account/RelationshipService.cs index 1e2b0d9..6dc2905 100644 --- a/DysonNetwork.Sphere/Account/RelationshipService.cs +++ b/DysonNetwork.Sphere/Account/RelationshipService.cs @@ -63,6 +63,19 @@ public class RelationshipService(AppDatabase db, ICacheService cache) return await UpdateRelationship(sender.Id, target.Id, RelationshipStatus.Blocked); return await CreateRelationship(sender, target, RelationshipStatus.Blocked); } + + public async Task UnblockAccount(Account sender, Account target) + { + var relationship = await GetRelationship(sender.Id, target.Id, RelationshipStatus.Blocked); + if (relationship is null) throw new ArgumentException("There is no relationship between you and the user."); + db.Remove(relationship); + await db.SaveChangesAsync(); + + await cache.RemoveAsync($"{UserFriendsCacheKeyPrefix}{sender.Id}"); + await cache.RemoveAsync($"{UserFriendsCacheKeyPrefix}{target.Id}"); + + return relationship; + } public async Task SendFriendRequest(Account sender, Account target) {