aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Services/DevHive.Services/Interfaces/IFriendsService.cs4
-rw-r--r--src/Services/DevHive.Services/Services/FriendsService.cs12
-rw-r--r--src/Web/DevHive.Web/Controllers/FriendsController.cs8
3 files changed, 12 insertions, 12 deletions
diff --git a/src/Services/DevHive.Services/Interfaces/IFriendsService.cs b/src/Services/DevHive.Services/Interfaces/IFriendsService.cs
index e337793..52f23f3 100644
--- a/src/Services/DevHive.Services/Interfaces/IFriendsService.cs
+++ b/src/Services/DevHive.Services/Interfaces/IFriendsService.cs
@@ -5,7 +5,7 @@ namespace DevHive.Services.Interfaces
{
public interface IFriendsService
{
- Task<bool> AddFriend(Guid userId, Guid friendId);
- Task<bool> RemoveFriend(Guid userId, Guid friendId);
+ Task<bool> AddFriend(Guid userId, string friendUsername);
+ Task<bool> RemoveFriend(Guid userId, string friendUsername);
}
}
diff --git a/src/Services/DevHive.Services/Services/FriendsService.cs b/src/Services/DevHive.Services/Services/FriendsService.cs
index 4e3e355..98f654b 100644
--- a/src/Services/DevHive.Services/Services/FriendsService.cs
+++ b/src/Services/DevHive.Services/Services/FriendsService.cs
@@ -16,29 +16,29 @@ namespace DevHive.Services.Services
this._friendRepository = friendRepository;
}
- public async Task<bool> AddFriend(Guid userId, Guid friendId)
+ public async Task<bool> AddFriend(Guid userId, string friendUsername)
{
User user = await this._friendRepository.GetByIdAsync(userId) ??
throw new ArgumentNullException(string.Format(ErrorMessages.DoesNotExist, nameof(user)));
- User friend = await this._friendRepository.GetByIdAsync(friendId) ??
+ User friend = await this._friendRepository.GetByUsernameAsync(friendUsername) ??
throw new ArgumentNullException(string.Format(ErrorMessages.DoesNotExist, nameof(friend)));
bool addedToUser = user.Friends.Add(friend) && await this._friendRepository.EditAsync(userId, user);
- bool addedToFriend = friend.Friends.Add(user) && await this._friendRepository.EditAsync(friendId, friend);
+ bool addedToFriend = friend.Friends.Add(user) && await this._friendRepository.EditAsync(friend.Id, friend);
return addedToUser && addedToFriend;
}
- public async Task<bool> RemoveFriend(Guid userId, Guid friendId)
+ public async Task<bool> RemoveFriend(Guid userId, string friendUsername)
{
User user = await this._friendRepository.GetByIdAsync(userId) ??
throw new ArgumentNullException(string.Format(ErrorMessages.DoesNotExist, nameof(user)));
- User friend = await this._friendRepository.GetByIdAsync(friendId) ??
+ User friend = await this._friendRepository.GetByUsernameAsync(friendUsername) ??
throw new ArgumentNullException(string.Format(ErrorMessages.DoesNotExist, nameof(friend)));
bool addedToUser = user.Friends.Remove(friend) && await this._friendRepository.EditAsync(userId, user);
- bool addedToFriend = friend.Friends.Remove(user) && await this._friendRepository.EditAsync(friendId, friend);
+ bool addedToFriend = friend.Friends.Remove(user) && await this._friendRepository.EditAsync(friend.Id, friend);
return addedToUser && addedToFriend;
}
}
diff --git a/src/Web/DevHive.Web/Controllers/FriendsController.cs b/src/Web/DevHive.Web/Controllers/FriendsController.cs
index 9f3ec13..318ae64 100644
--- a/src/Web/DevHive.Web/Controllers/FriendsController.cs
+++ b/src/Web/DevHive.Web/Controllers/FriendsController.cs
@@ -29,24 +29,24 @@ namespace DevHive.Web.Controllers
[HttpPost]
[Authorize(Roles = "User,Admin")]
- public async Task<IActionResult> AddFriend(Guid userId, Guid friendId, [FromHeader] string authorization)
+ public async Task<IActionResult> AddFriend(Guid userId, string friendUsername, [FromHeader] string authorization)
{
if (!this._jwtService.ValidateToken(userId, authorization))
return new UnauthorizedResult();
- return (await this._friendsService.AddFriend(userId, friendId)) ?
+ return (await this._friendsService.AddFriend(userId, friendUsername)) ?
new OkResult() :
new BadRequestResult();
}
[HttpDelete]
[Authorize(Roles = "User,Admin")]
- public async Task<IActionResult> RemoveFriend(Guid userId, Guid friendId, [FromHeader] string authorization)
+ public async Task<IActionResult> RemoveFriend(Guid userId, string friendUsername, [FromHeader] string authorization)
{
if (!this._jwtService.ValidateToken(userId, authorization))
return new UnauthorizedResult();
- return (await this._friendsService.RemoveFriend(userId, friendId)) ?
+ return (await this._friendsService.RemoveFriend(userId, friendUsername)) ?
new OkResult() :
new BadRequestResult();
}