aboutsummaryrefslogtreecommitdiff
path: root/src/Services
diff options
context:
space:
mode:
Diffstat (limited to 'src/Services')
-rw-r--r--src/Services/DevHive.Services.Models/User/UserServiceModel.cs2
-rw-r--r--src/Services/DevHive.Services/Services/ProfilePictureService.cs5
-rw-r--r--src/Services/DevHive.Services/Services/RatingService.cs10
3 files changed, 10 insertions, 7 deletions
diff --git a/src/Services/DevHive.Services.Models/User/UserServiceModel.cs b/src/Services/DevHive.Services.Models/User/UserServiceModel.cs
index 04b618b..ad4e553 100644
--- a/src/Services/DevHive.Services.Models/User/UserServiceModel.cs
+++ b/src/Services/DevHive.Services.Models/User/UserServiceModel.cs
@@ -8,7 +8,7 @@ namespace DevHive.Services.Models.User
{
public class UserServiceModel : BaseUserServiceModel
{
- public string ProfilePictureURL { get; set; }
+ public string ProfilePictureURL { get; set; } = new("/assets/icons/tabler-icon-user.svg");
public HashSet<RoleServiceModel> Roles { get; set; } = new();
diff --git a/src/Services/DevHive.Services/Services/ProfilePictureService.cs b/src/Services/DevHive.Services/Services/ProfilePictureService.cs
index 8a9bb29..7093818 100644
--- a/src/Services/DevHive.Services/Services/ProfilePictureService.cs
+++ b/src/Services/DevHive.Services/Services/ProfilePictureService.cs
@@ -41,7 +41,7 @@ namespace DevHive.Services.Services
await ValidateUserExistsAsync(profilePictureServiceModel.UserId);
User user = await this._userRepository.GetByIdAsync(profilePictureServiceModel.UserId);
- if (!string.IsNullOrEmpty(user.ProfilePicture.PictureURL))
+ if (user.ProfilePicture.Id != Guid.Empty)
{
List<string> file = new() { user.ProfilePicture.PictureURL };
bool removed = await this._cloudinaryService.RemoveFilesFromCloud(file);
@@ -81,8 +81,9 @@ namespace DevHive.Services.Services
throw new ArgumentException("Unable to upload picture!");
User user = await this._userRepository.GetByIdAsync(profilePictureServiceModel.UserId);
- user.ProfilePicture = await this._profilePictureRepository.GetByURLAsync(picUrl);
+ user.ProfilePicture = profilePic;
bool userProfilePicAlter = await this._userRepository.EditAsync(user.Id, user);
+
if (!userProfilePicAlter)
throw new ArgumentException("Unable to alter user's profile picture");
diff --git a/src/Services/DevHive.Services/Services/RatingService.cs b/src/Services/DevHive.Services/Services/RatingService.cs
index 1f77a6e..9d8f4b0 100644
--- a/src/Services/DevHive.Services/Services/RatingService.cs
+++ b/src/Services/DevHive.Services/Services/RatingService.cs
@@ -57,8 +57,9 @@ namespace DevHive.Services.Services
#region Read
public async Task<ReadRatingServiceModel> GetRatingById(Guid ratingId)
{
- Rating rating = await this._ratingRepository.GetByIdAsync(ratingId) ??
- throw new ArgumentException("The rating does not exist");
+ Rating rating = await this._ratingRepository.GetByIdAsync(ratingId);
+ if (rating is null)
+ return null;
ReadRatingServiceModel readRatingServiceModel = this._mapper.Map<ReadRatingServiceModel>(rating);
readRatingServiceModel.UserId = rating.User.Id;
@@ -68,8 +69,9 @@ namespace DevHive.Services.Services
public async Task<ReadRatingServiceModel> GetRatingByPostAndUser(Guid userId, Guid postId)
{
- Rating rating = await this._ratingRepository.GetRatingByUserAndPostId(userId, postId) ??
- throw new ArgumentException("The rating does not exist");
+ Rating rating = await this._ratingRepository.GetRatingByUserAndPostId(userId, postId);
+ if (rating is null)
+ return null;
ReadRatingServiceModel readRatingServiceModel = this._mapper.Map<ReadRatingServiceModel>(rating);
readRatingServiceModel.UserId = rating.User.Id;