-
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.
feat: upload avatar & cover of profiles
- Loading branch information
1 parent
8ed3c8c
commit ac83929
Showing
11 changed files
with
198 additions
and
113 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
Comment.Presentation/Controllers/WeatherForecastController.cs
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
namespace InfinityNetServer.Services.Profile.Application.DTOs.Requests | ||
{ | ||
public sealed record UplodaPhotoRequest | ||
{ | ||
|
||
public string PhotoId { 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
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
67 changes: 0 additions & 67 deletions
67
Profile.Presentation/Controllers/ProfileActionController.cs
This file was deleted.
Oops, something went wrong.
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,136 @@ | ||
using AutoMapper; | ||
using InfinityNetServer.BuildingBlocks.Application.Contracts; | ||
using InfinityNetServer.BuildingBlocks.Application.DTOs.Responses.Profile; | ||
using InfinityNetServer.BuildingBlocks.Application.Exceptions; | ||
using InfinityNetServer.BuildingBlocks.Application.IServices; | ||
using InfinityNetServer.BuildingBlocks.Presentation.Controllers; | ||
using InfinityNetServer.Services.Profile.Application; | ||
using InfinityNetServer.Services.Profile.Application.DTOs.Requests; | ||
using InfinityNetServer.Services.Profile.Application.Exceptions; | ||
using InfinityNetServer.Services.Profile.Application.IServices; | ||
using InfinityNetServer.Services.Profile.Domain.Enums; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Localization; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace InfinityNetServer.Services.Profile.Presentation.Controllers | ||
{ | ||
[Tags("Profile APIs")] | ||
[ApiController] | ||
public class ProfileController( | ||
IAuthenticatedUserService authenticatedUserService, | ||
IStringLocalizer<ProfileSharedResource> localizer, | ||
ILogger<ProfileController> logger, | ||
IMapper mapper, | ||
IMessageBus messageBus, | ||
IProfileService profileService) : BaseApiController(authenticatedUserService) | ||
{ | ||
|
||
|
||
[Authorize] | ||
[EndpointDescription("Retrieve page profile")] | ||
[ProducesResponseType(typeof(UserProfileResponse), StatusCodes.Status200OK)] | ||
[Authorize] | ||
[HttpGet("{id}/actions")] | ||
public IActionResult GetProfileActions(string id) | ||
{ | ||
logger.LogInformation("Retrieve user profile"); | ||
|
||
Guid currentUserId = GetCurrentProfileId != null ? GetCurrentProfileId().Value | ||
: throw new BaseException(BaseError.PROFILE_NOT_FOUND, StatusCodes.Status404NotFound); | ||
|
||
Guid.TryParse(id, out Guid profileId); | ||
|
||
bool isMe = currentUserId == profileId; | ||
|
||
IDictionary<string, bool> actions = new Dictionary<string, bool> | ||
{ | ||
{ ProfileActions.ProfileAvatarUpload.ToString(), isMe }, | ||
{ ProfileActions.ProfileCoverPhotoUpload.ToString(), isMe }, | ||
{ ProfileActions.ProfileAvatarDelete.ToString(), isMe }, | ||
{ ProfileActions.ProfileCoverPhotoDelete.ToString(), isMe }, | ||
{ ProfileActions.ProfileDetailsUpdate.ToString(), isMe }, | ||
{ ProfileActions.ProfileCreate.ToString(), isMe }, | ||
{ ProfileActions.ProfileDelete.ToString(), isMe }, | ||
{ ProfileActions.ProfileStatusLock.ToString(), !isMe }, | ||
{ ProfileActions.ProfileActivityLog.ToString(), isMe }, | ||
{ ProfileActions.ProfilePostCreate.ToString(), isMe }, | ||
{ ProfileActions.ProfilePostSearch.ToString(), isMe }, | ||
{ ProfileActions.ProfileReport.ToString(), !isMe } | ||
}; | ||
|
||
|
||
return Ok(actions); | ||
} | ||
|
||
[Authorize] | ||
[EndpointDescription("Upload profile avatar")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[HttpPost("avatar")] | ||
public async Task<IActionResult> UploadAvatar([FromBody] UplodaPhotoRequest avatar) | ||
{ | ||
|
||
Guid profileId = GetCurrentProfileId() | ||
?? throw new BaseException(BaseError.PROFILE_NOT_FOUND, StatusCodes.Status404NotFound); | ||
|
||
Domain.Entities.Profile profile = await profileService.GetById(profileId.ToString()) | ||
?? throw new BaseException(BaseError.PROFILE_NOT_FOUND, StatusCodes.Status404NotFound); | ||
|
||
try | ||
{ | ||
profile.AvatarId = Guid.Parse(avatar.PhotoId); | ||
profile = await profileService.Update(profile); | ||
await profileService.ConfirmSave(profile.Id.ToString(), profile.AvatarId.ToString(), false, messageBus); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError(ex, "Caused by: {Message}", ex.Message); | ||
throw new ProfileException(ProfileError.UPDATE_PROFILE_FAILED, StatusCodes.Status422UnprocessableEntity); | ||
} | ||
|
||
return Ok(new | ||
{ | ||
Message = localizer["Message.ProfileUpdatedSuccess", profile.Id].ToString(), | ||
Profile = mapper.Map<BaseProfileResponse>(profile) | ||
}); | ||
} | ||
|
||
[Authorize] | ||
[EndpointDescription("Upload profile cover")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[HttpPost("cover")] | ||
public async Task<IActionResult> UploadCover([FromBody] UplodaPhotoRequest request) | ||
{ | ||
|
||
Guid profileId = GetCurrentProfileId() | ||
?? throw new BaseException(BaseError.PROFILE_NOT_FOUND, StatusCodes.Status404NotFound); | ||
|
||
Domain.Entities.Profile profile = await profileService.GetById(profileId.ToString()) | ||
?? throw new BaseException(BaseError.PROFILE_NOT_FOUND, StatusCodes.Status404NotFound); | ||
|
||
try | ||
{ | ||
profile.CoverId = Guid.Parse(request.PhotoId); | ||
profile = await profileService.Update(profile); | ||
await profileService.ConfirmSave(profile.Id.ToString(), profile.CoverId.ToString(), false, messageBus); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError(ex, "Caused by: {Message}", ex.Message); | ||
throw new ProfileException(ProfileError.UPDATE_PROFILE_FAILED, StatusCodes.Status422UnprocessableEntity); | ||
} | ||
|
||
return Ok(new | ||
{ | ||
Message = localizer["Message.ProfileUpdatedSuccess", profile.Id].ToString(), | ||
Profile = mapper.Map<BaseProfileResponse>(profile) | ||
}); | ||
} | ||
|
||
} | ||
} |
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