-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc69afd
commit a3d75be
Showing
36 changed files
with
1,515 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace ChitChat.Application.Models.Dtos.User | ||
{ | ||
public class ProfileDto | ||
{ | ||
public Guid Id { get; set; } | ||
public string DisplayName { get; set; } | ||
public string AvatarUrl { get; set; } | ||
public string Email { get; set; } | ||
public string PhoneNumber { get; set; } | ||
public string? Bio { get; set; } | ||
public DateTime DateOfBirth { get; set; } | ||
public string? Gender { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/ChitChat.Application/Models/Dtos/User/ProfileRequestDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace ChitChat.Application.Models.Dtos.User | ||
{ | ||
public class ProfileRequestDto | ||
{ | ||
public string DisplayName { get; set; } | ||
public string AvatarUrl { get; set; } | ||
public string PhoneNumber { get; set; } | ||
public string? Bio { get; set; } | ||
public DateTime DateOfBirth { get; set; } | ||
public string? Gender { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/ChitChat.Application/Services/Interface/IProfileService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using ChitChat.Application.Models.Dtos.User; | ||
|
||
namespace ChitChat.Application.Services.Interface | ||
{ | ||
public interface IProfileService | ||
{ | ||
Task<List<ProfileDto>> GetAllProfilesAsync(string searchText, int pageIndex, int pageSize); | ||
Task<ProfileDto> GetProfileByIdAsync(Guid userId); | ||
Task<ProfileDto> CreatProfileAsync(ProfileRequestDto request); | ||
Task<ProfileDto> UpdateProfileAsync(Guid userId, ProfileDto request); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using AutoMapper; | ||
|
||
using ChitChat.Application.Exceptions; | ||
using ChitChat.Application.Helpers; | ||
using ChitChat.Application.Localization; | ||
using ChitChat.Application.Models.Dtos.User; | ||
using ChitChat.Application.Services.Interface; | ||
using ChitChat.DataAccess.Repositories.Interface; | ||
using ChitChat.DataAccess.Repositories.Interrface; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ChitChat.Application.Services | ||
{ | ||
public class ProfileService : IProfileService | ||
{ | ||
private readonly IMapper _mapper; | ||
private readonly IBaseRepository<Domain.Entities.UserEntities.Profile> _profileRepository; | ||
private readonly IClaimService _claimService; | ||
private readonly IUserRepository _userRepository; | ||
public ProfileService(IMapper mapper | ||
, IBaseRepository<Domain.Entities.UserEntities.Profile> profileRepository | ||
, IClaimService claimService | ||
, IUserRepository userRepository) | ||
{ | ||
this._mapper = mapper; | ||
this._profileRepository = profileRepository; | ||
this._claimService = claimService; | ||
this._userRepository = userRepository; | ||
} | ||
public async Task<List<ProfileDto>> GetAllProfilesAsync(string searchText, int pageIndex, int pageSize) | ||
{ | ||
var paginationResponse = await _profileRepository.GetAllAsync( | ||
p => p.IsDeleted == false && p.SearchData.Contains(searchText), p => p.OrderByDescending(p => p.Id) | ||
, pageIndex, pageSize, p => p.Include(p => p.UserApplication)); | ||
return _mapper.Map<List<ProfileDto>>(paginationResponse.Items); | ||
} | ||
public async Task<ProfileDto> GetProfileByIdAsync(Guid userId) | ||
{ | ||
var userProfile = await _profileRepository.GetFirstOrDefaultAsync(p => p.Id == userId, p => p.Include(c => c.UserApplication)); | ||
if (userProfile == null) | ||
{ | ||
throw new NotFoundException(ValidationTexts.NotFound.Format("User", userId)); | ||
} | ||
var response = _mapper.Map<ProfileDto>(userProfile); | ||
return response; | ||
} | ||
public async Task<ProfileDto> CreatProfileAsync(ProfileRequestDto request) | ||
{ | ||
var userId = _claimService.GetUserId(); | ||
Domain.Entities.UserEntities.Profile userProfile = this._mapper.Map<Domain.Entities.UserEntities.Profile>(request); | ||
userProfile.Id = Guid.Parse(userId); | ||
userProfile.UserApplicationId = userId; | ||
if (await _profileRepository.GetFirstOrDefaultAsync(p => p.Id == userProfile.Id) != null) | ||
throw new ConflictException(ValidationTexts.Conflict.Format(userProfile.GetType(), userId)); | ||
var userApplication = await _userRepository.GetFirstOrDefaultAsync(p => p.Id == userId.ToString()); | ||
userProfile.SearchData = this.GenerateSearchData(request.DisplayName, userApplication.Email ?? "", userId); | ||
await _profileRepository.AddAsync(userProfile); | ||
_mapper.Map(request, userApplication); | ||
await _userRepository.UpdateAsync(userApplication); | ||
var response = _mapper.Map<ProfileDto>(userProfile); | ||
_mapper.Map(userApplication, response); | ||
return response; | ||
} | ||
public async Task<ProfileDto> UpdateProfileAsync(Guid userId, ProfileDto request) | ||
{ | ||
if (userId.ToString() != _claimService.GetUserId()) | ||
{ | ||
throw new ForbiddenException(ValidationTexts.Forbidden.Format(typeof(Domain.Entities.UserEntities.Profile), userId)); | ||
} | ||
var userProfile = await _profileRepository.GetFirstOrDefaultAsync(p => p.Id == userId); | ||
var userApplication = await _userRepository.GetFirstOrDefaultAsync(p => p.Id == userId.ToString()); | ||
if (userProfile == null || userApplication == null) | ||
{ | ||
throw new NotFoundException(ValidationTexts.NotFound.Format(userProfile.GetType(), userId)); | ||
} | ||
_mapper.Map(request, userProfile); | ||
_mapper.Map(request, userApplication); | ||
userProfile.SearchData = this.GenerateSearchData(request.DisplayName, userApplication.Email ?? "", userId.ToString()); | ||
await _profileRepository.UpdateAsync(userProfile); | ||
await _userRepository.UpdateAsync(userApplication); | ||
return request; | ||
} | ||
private string GenerateSearchData(string displayName, string email, string userId) | ||
{ | ||
return displayName + email + userId; | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/ChitChat.Application/Validators/User/ProfileRequestValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using ChitChat.Application.Models.Dtos.User; | ||
using ChitChat.Domain.Enums; | ||
|
||
using FluentValidation; | ||
|
||
namespace ChitChat.Application.Validators.User | ||
{ | ||
public class ProfileRequestValidator : AbstractValidator<ProfileRequestDto> | ||
{ | ||
public ProfileRequestValidator() | ||
{ | ||
RuleFor(profile => profile.Gender) | ||
.NotNull() | ||
.NotEmpty() | ||
.Must(gender => Enum.TryParse(typeof(Gender), gender, true, out _)) | ||
.WithMessage("Invalid gender value. Allowed values are: Male, Female, Other."); | ||
RuleFor(profile => profile.Bio) | ||
.NotNull() | ||
.NotEmpty(); | ||
RuleFor(profile => profile.DateOfBirth) | ||
.NotEmpty() | ||
.NotNull(); | ||
} | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/ChitChat.Application/Validators/User/RegisterationRequestValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/ChitChat.DataAccess/Configurations/ProfileConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using ChitChat.Domain.Entities.UserEntities; | ||
|
||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace ChitChat.DataAccess.Configurations | ||
{ | ||
public class ProfileConfiguration : IEntityTypeConfiguration<Profile> | ||
{ | ||
public ProfileConfiguration() { } | ||
|
||
public void Configure(EntityTypeBuilder<Profile> builder) | ||
{ | ||
builder | ||
.HasOne(p => p.UserApplication) | ||
.WithOne() | ||
.HasForeignKey<Profile>(p => p.UserApplicationId); | ||
} | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/ChitChat.DataAccess/Configurations/UserFollowerRequestConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/ChitChat.DataAccess/Configurations/UserInteractionConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.