diff --git a/Identity.Presentation/appsettings.Local.Development.json b/Identity.Presentation/appsettings.Local.Development.json new file mode 100644 index 0000000..0db3279 --- /dev/null +++ b/Identity.Presentation/appsettings.Local.Development.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/Ocelot.Presentaition/appsettings.Local.Development.json b/Ocelot.Presentaition/appsettings.Local.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Ocelot.Presentaition/appsettings.Local.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Profile.Application/Profile.Application.csproj b/Profile.Application/Profile.Application.csproj index b58ec12..b6c02ff 100644 --- a/Profile.Application/Profile.Application.csproj +++ b/Profile.Application/Profile.Application.csproj @@ -11,4 +11,8 @@ + + + + diff --git a/Profile.Application/Services/IUserProfileService.cs b/Profile.Application/Services/IUserProfileService.cs index 50b94f4..04334cb 100644 --- a/Profile.Application/Services/IUserProfileService.cs +++ b/Profile.Application/Services/IUserProfileService.cs @@ -8,5 +8,8 @@ public interface IUserProfileService Task GetUserProfileById(string id); + // Định nghĩa trong service interface + Task GetUserProfileByAccountId(string id); + } } diff --git a/Profile.Domain/Repositories/IUserProfileRepository.cs b/Profile.Domain/Repositories/IUserProfileRepository.cs index 9ee8d64..7cc0c01 100644 --- a/Profile.Domain/Repositories/IUserProfileRepository.cs +++ b/Profile.Domain/Repositories/IUserProfileRepository.cs @@ -9,7 +9,14 @@ namespace InfinityNetServer.Services.Profile.Domain.Repositories public interface IUserProfileRepository : ISqlRepository { - + //Định nghĩa hàm repository + // lý do mình ko gọi repository trức tiếp trong controller: + // tách biệt logic vì trong service ngoài gọi truy vấn có thể sẽ làm những việc khác + // ông hình dung: + // tầng DAL <==> repository + // tầng BLL(BUS) <==> service + // tầng GUI <==> controller (ở đây là api thay vì view) + Task GetUserProfileByAccountIdAsync(Guid accountId); } } diff --git a/Profile.Infrastructure/Repositories/UserProfileRepository.cs b/Profile.Infrastructure/Repositories/UserProfileRepository.cs index 573cf2a..98c27bb 100644 --- a/Profile.Infrastructure/Repositories/UserProfileRepository.cs +++ b/Profile.Infrastructure/Repositories/UserProfileRepository.cs @@ -3,6 +3,8 @@ using InfinityNetServer.Services.Profile.Domain.Entities; using InfinityNetServer.Services.Profile.Domain.Repositories; using InfinityNetServer.BuildingBlocks.Infrastructure.PostgreSQL.Repositories; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; namespace InfinityNetServer.Services.Profile.Infrastructure.Repositories { @@ -12,7 +14,9 @@ public class UserProfileRepository : SqlRepository, IUserProf public UserProfileRepository(ProfileDbContext context) : base(context) { } - - + public async Task GetUserProfileByAccountIdAsync(Guid accountId) + { + return await ((ProfileDbContext)_context).UserProfiles.FirstOrDefaultAsync(profile => profile.AccountId == accountId); + } } } diff --git a/Profile.Presentation/Controllers/UserProfileController.cs b/Profile.Presentation/Controllers/UserProfileController.cs index 4c3b347..48ec087 100644 --- a/Profile.Presentation/Controllers/UserProfileController.cs +++ b/Profile.Presentation/Controllers/UserProfileController.cs @@ -11,6 +11,9 @@ using System.Threading.Tasks; using InfinityNetServer.BuildingBlocks.Application.Services; using InfinityNetServer.Services.Profile.Application.Services; +using Microsoft.AspNetCore.Authorization; +using InfinityNetServer.Services.Profile.Domain.Entities; +using AutoMapper; namespace InfinityNetServer.Services.Profile.Presentation.Controllers { @@ -23,9 +26,12 @@ public class UserProfileController : BaseApiController private readonly ILogger _logger; + // khai báo thêm mapper + private readonly IMapper _mapper; + private readonly IConfiguration _configuration; - private readonly IUserProfileService _profileService; + private readonly IUserProfileService _userProfileService; private readonly IMessageBus _messageBus; @@ -33,14 +39,16 @@ public UserProfileController( IAuthenticatedUserService authenticatedUserService, IStringLocalizer localizer, ILogger logger, + IMapper mapper, IConfiguration configuration, IUserProfileService profileService, IMessageBus messageBus) : base(authenticatedUserService) { _localizer = localizer; _logger = logger; + _mapper = mapper; _configuration = configuration; - _profileService = profileService; + _userProfileService = profileService; _messageBus = messageBus; } @@ -50,7 +58,7 @@ public UserProfileController( public IActionResult UpdateProfile([FromBody] UpdateUserProfileRequest request) { // TODO: Call the service to update the user profile - // await _profileService.UpdateProfile(request); + // await _userProfileService.UpdateProfile(request); return Ok(new CommonMessageResponse ( @@ -58,6 +66,18 @@ public IActionResult UpdateProfile([FromBody] UpdateUserProfileRequest request) )); } + [Authorize] + [EndpointDescription("Retrieve user profile")] + [HttpGet("{userId}")] + [ProducesResponseType(typeof(UserProfileResponse), StatusCodes.Status200OK)] + public async Task RetrieveProfile(string userId) + { + _logger.LogInformation("Retrieve user profile"); + + UserProfile currentProfile = await _userProfileService.GetUserProfileById(userId); + + return Ok(_mapper.Map(currentProfile)); + } } } diff --git a/Profile.Presentation/Mappers/ProfileMapper.cs b/Profile.Presentation/Mappers/ProfileMapper.cs index 3b845cf..9264a93 100644 --- a/Profile.Presentation/Mappers/ProfileMapper.cs +++ b/Profile.Presentation/Mappers/ProfileMapper.cs @@ -1,4 +1,5 @@ -using InfinityNetServer.Services.Profile.Domain.Entities; +using InfinityNetServer.BuildingBlocks.Application.DTOs.Responses; +using InfinityNetServer.Services.Profile.Domain.Entities; namespace InfinityNetServer.Services.Profile.Presentation.Mappers; @@ -7,5 +8,15 @@ public class ProfileMapper : AutoMapper.Profile public ProfileMapper() { CreateMap(); + + // tạo mapper + // cú pháp + CreateMap() + .AfterMap((src, dest) => + { + //chỗ này custome nếu trg hợp đích (dest) và nguồn (src) khác tên thuộc tính + dest.CoverId = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRmCy16nhIbV3pI1qLYHMJKwbH2458oiC9EmA&s"; + dest.AvatarId = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRmCy16nhIbV3pI1qLYHMJKwbH2458oiC9EmA&s"; + }); } } diff --git a/Profile.Presentation/Services/UserProfileService.cs b/Profile.Presentation/Services/UserProfileService.cs index dfd99fb..080ca8e 100644 --- a/Profile.Presentation/Services/UserProfileService.cs +++ b/Profile.Presentation/Services/UserProfileService.cs @@ -2,6 +2,7 @@ using InfinityNetServer.Services.Profile.Application.Services; using InfinityNetServer.Services.Profile.Domain.Entities; using InfinityNetServer.Services.Profile.Domain.Repositories; +using MassTransit; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using System; @@ -25,6 +26,14 @@ public UserProfileService(IUserProfileRepository userProfileRepository, ILogger< _localizer = localizer; } + // await async là kiến thức về bất đồng bộ có j ông search youtube xem thêm nha + public async Task GetUserProfileByAccountId(string id) + { + // chỗ này implement cái đã định nghĩa trong interface + // truyền id vào là string nên phải parse ra Guid + return await _userProfileRepository.GetUserProfileByAccountIdAsync(Guid.Parse(id)); + } + public Task GetUserProfileById(string id) { return _userProfileRepository.GetByIdAsync(Guid.Parse(id)); diff --git a/Profile.Presentation/appsettings.Local.Development.json b/Profile.Presentation/appsettings.Local.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Profile.Presentation/appsettings.Local.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +}