diff --git a/Services/ProfileService.cs b/Services/ProfileService.cs index a75cde9cbf41e55f8bad8ed54445ef180d2d3877..c60f5f91c0f6fdca714bbb27977572f1f9d9fb6a 100644 --- a/Services/ProfileService.cs +++ b/Services/ProfileService.cs @@ -12,9 +12,9 @@ namespace Group17profile.Services; public interface IProfileService { Task<ProfileDTO> CreateOrUpdateProfile(ProfileDTO profile, int userId); - Task<UserProfileDTO> GetProfileForUser(int userId); - Task<string> UploadBannerPicture(int userId, IFormFile bannerPicture); - Task<string> EditBannerPicture(int userId, IFormFile? bannerPicture = null); + Task<UserProfileDTO> GetProfileForUser(ProfileDTO profile, int userId); + Task<string> UploadBannerPicture(ProfileDTO profile, int userId, IFormFile bannerPicture); + Task<string> EditBannerPicture(ProfileDTO profile, int userId, IFormFile? bannerPicture = null); } public class ProfileService : IProfileService @@ -29,14 +29,13 @@ public class ProfileService : IProfileService _mapper = mapper; _profileRepository = profileRepository; _userRepository = userRepository; - } public async Task<ProfileDTO> CreateOrUpdateProfile(ProfileDTO profile, int userId) { var user = _userRepository.GetByIdThrowIfNull(userId); var age = DateTimeOffset.Now.Year - profile.DoB.GetValueOrDefault().Year; - + if (age is <= 16 or >= 100) { throw new ProfileException("Please enter valid age"); @@ -53,7 +52,7 @@ public class ProfileService : IProfileService record.FavouriteShows = builder.ToString(); } - + if (user.ProfileId == null) { var newProfile = await _profileRepository.CreateAndSaveAsync(record); @@ -69,20 +68,34 @@ public class ProfileService : IProfileService var user = _userRepository.GetByIdThrowIfNull(userId); if (user.ProfileId == null) 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() .FirstOrDefault(p => p.Id == user.ProfileId)); 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(); } - - 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(); } - } \ No newline at end of file