Skip to content
Snippets Groups Projects
Commit ebc0dc2e authored by MikelLiza's avatar MikelLiza Committed by Adiv
Browse files

add

parent 01255df6
No related branches found
No related tags found
No related merge requests found
...@@ -12,9 +12,9 @@ namespace Group17profile.Services; ...@@ -12,9 +12,9 @@ namespace Group17profile.Services;
public interface IProfileService public interface IProfileService
{ {
Task<ProfileDTO> CreateOrUpdateProfile(ProfileDTO profile, int userId); Task<ProfileDTO> CreateOrUpdateProfile(ProfileDTO profile, int userId);
Task<UserProfileDTO> GetProfileForUser(int userId); Task<UserProfileDTO> GetProfileForUser(ProfileDTO profile, int userId);
Task<string> UploadBannerPicture(int userId, IFormFile bannerPicture); Task<string> UploadBannerPicture(ProfileDTO profile, int userId, IFormFile bannerPicture);
Task<string> EditBannerPicture(int userId, IFormFile? bannerPicture = null); Task<string> EditBannerPicture(ProfileDTO profile, int userId, IFormFile? bannerPicture = null);
} }
public class ProfileService : IProfileService public class ProfileService : IProfileService
...@@ -29,14 +29,13 @@ public class ProfileService : IProfileService ...@@ -29,14 +29,13 @@ public class ProfileService : IProfileService
_mapper = mapper; _mapper = mapper;
_profileRepository = profileRepository; _profileRepository = profileRepository;
_userRepository = userRepository; _userRepository = userRepository;
} }
public async Task<ProfileDTO> CreateOrUpdateProfile(ProfileDTO profile, int userId) public async Task<ProfileDTO> CreateOrUpdateProfile(ProfileDTO profile, int userId)
{ {
var user = _userRepository.GetByIdThrowIfNull(userId); var user = _userRepository.GetByIdThrowIfNull(userId);
var age = DateTimeOffset.Now.Year - profile.DoB.GetValueOrDefault().Year; var age = DateTimeOffset.Now.Year - profile.DoB.GetValueOrDefault().Year;
if (age is <= 16 or >= 100) if (age is <= 16 or >= 100)
{ {
throw new ProfileException("Please enter valid age"); throw new ProfileException("Please enter valid age");
...@@ -53,7 +52,7 @@ public class ProfileService : IProfileService ...@@ -53,7 +52,7 @@ public class ProfileService : IProfileService
record.FavouriteShows = builder.ToString(); record.FavouriteShows = builder.ToString();
} }
if (user.ProfileId == null) if (user.ProfileId == null)
{ {
var newProfile = await _profileRepository.CreateAndSaveAsync(record); var newProfile = await _profileRepository.CreateAndSaveAsync(record);
...@@ -69,20 +68,34 @@ public class ProfileService : IProfileService ...@@ -69,20 +68,34 @@ public class ProfileService : IProfileService
var user = _userRepository.GetByIdThrowIfNull(userId); var user = _userRepository.GetByIdThrowIfNull(userId);
if (user.ProfileId == null) if (user.ProfileId == null)
throw new ProfileException("Failed to retrieve profile for user"); throw new ProfileException("Failed to retrieve profile for user");
var record = _mapper.Map<Profile>(profile);
if (!string.IsNullOrWhiteSpace(record.FavouriteShows))
{
var s = record.FavouriteShows.Split(',');
var list = s.ToList();
profile.FavouriteShows = list;
}
var profile = _mapper.Map<ProfileDTO>(_profileRepository.GetAll().AsNoTracking() var profile = _mapper.Map<ProfileDTO>(_profileRepository.GetAll().AsNoTracking()
.FirstOrDefault(p => p.Id == user.ProfileId)); .FirstOrDefault(p => p.Id == user.ProfileId));
return new UserProfileDTO() {User = _mapper.Map<UserDTO>(user), Profile = profile}; return new UserProfileDTO() {User = _mapper.Map<UserDTO>(user), Profile = profile};
} }
public Task<string> UploadBannerPicture(int userId, IFormFile bannerPicture) public Task<string> UploadBannerPicture(ProfileDTO profile, int userId, IFormFile bannerPicture)
{ {
var user = _userRepository.GetByIdThrowIfNull(userId);
if (profile.BannerUrl == null)
{
}
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<string> EditBannerPicture(int userId, IFormFile? bannerPicture = null) public Task<string> EditBannerPicture(ProfileDTO profile, int userId, IFormFile? bannerPicture = null)
{ {
var user = _userRepository.GetByIdThrowIfNull(userId);
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment