aboutsummaryrefslogtreecommitdiff
path: root/src/Services
diff options
context:
space:
mode:
Diffstat (limited to 'src/Services')
-rw-r--r--src/Services/DevHive.Services/Services/ProfilePictureService.cs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Services/DevHive.Services/Services/ProfilePictureService.cs b/src/Services/DevHive.Services/Services/ProfilePictureService.cs
index 0636f5c..8a9bb29 100644
--- a/src/Services/DevHive.Services/Services/ProfilePictureService.cs
+++ b/src/Services/DevHive.Services/Services/ProfilePictureService.cs
@@ -24,7 +24,8 @@ namespace DevHive.Services.Services
public async Task<string> InsertProfilePicture(ProfilePictureServiceModel profilePictureServiceModel)
{
- await ValidateServiceModel(profilePictureServiceModel);
+ ValidateProfPic(profilePictureServiceModel.ProfilePictureFormFile);
+ await ValidateUserExistsAsync(profilePictureServiceModel.UserId);
return await SaveProfilePictureInDatabase(profilePictureServiceModel);
}
@@ -36,7 +37,8 @@ namespace DevHive.Services.Services
public async Task<string> UpdateProfilePicture(ProfilePictureServiceModel profilePictureServiceModel)
{
- await ValidateServiceModel(profilePictureServiceModel);
+ ValidateProfPic(profilePictureServiceModel.ProfilePictureFormFile);
+ await ValidateUserExistsAsync(profilePictureServiceModel.UserId);
User user = await this._userRepository.GetByIdAsync(profilePictureServiceModel.UserId);
if (!string.IsNullOrEmpty(user.ProfilePicture.PictureURL))
@@ -87,12 +89,15 @@ namespace DevHive.Services.Services
return picUrl;
}
- private async Task ValidateServiceModel(ProfilePictureServiceModel profilePictureServiceModel)
+ private static void ValidateProfPic(IFormFile profilePictureFormFile)
{
- if (profilePictureServiceModel.ProfilePictureFormFile.Length == 0)
+ if (profilePictureFormFile.Length == 0)
throw new ArgumentException("Picture cannot be null");
+ }
- if (!await this._userRepository.DoesUserExistAsync(profilePictureServiceModel.UserId))
+ private async Task ValidateUserExistsAsync(Guid userId)
+ {
+ if (!await this._userRepository.DoesUserExistAsync(userId))
throw new ArgumentException("User does not exist!");
}
}