Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change project structure #2

Merged
merged 37 commits into from
Oct 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5834046
feat: edit or delete unnecessary files and projects
HlibPavlyk Sep 1, 2024
1945731
feat: update domain entities
HlibPavlyk Sep 2, 2024
0e45a68
feat: update entity type configuration
HlibPavlyk Sep 2, 2024
b018300
feat: add backend presentation layer
HlibPavlyk Sep 2, 2024
1dcc94a
feat: fix repositories
HlibPavlyk Sep 2, 2024
592ae5b
feat: improve repositories
HlibPavlyk Sep 3, 2024
45bab86
feat: fix auth service
HlibPavlyk Sep 3, 2024
c82d41f
feat: recreate base backend logic
HlibPavlyk Sep 6, 2024
0581232
feat: add patch endpoints
HlibPavlyk Sep 6, 2024
ce63ddf
feat: update repositories and entity configs
HlibPavlyk Sep 7, 2024
7c6510c
feat: complete album endpoints
HlibPavlyk Sep 7, 2024
b4c8786
feat: add unit tests for created services
HlibPavlyk Sep 7, 2024
9f9cc2f
feat: add client part based on angular
HlibPavlyk Sep 12, 2024
47a80c5
feat: add album component
HlibPavlyk Sep 15, 2024
12b26f3
feat: add album view component
HlibPavlyk Sep 15, 2024
eee7df4
feat: add top bar component
HlibPavlyk Sep 15, 2024
9eaca59
feat: add section bar
HlibPavlyk Sep 15, 2024
83783eb
feat: add basic logit to top bar
HlibPavlyk Sep 15, 2024
7b46f3a
feat: add routing
HlibPavlyk Sep 15, 2024
7b1c664
feat: add sorting to albums
HlibPavlyk Sep 23, 2024
3ebec3e
feat: update get paged albums func
HlibPavlyk Sep 24, 2024
78ab2f2
feat: implement album page get on front
HlibPavlyk Sep 24, 2024
280c95a
feat: add register/login components
HlibPavlyk Sep 25, 2024
7e2a19a
feat: add auth guard and interceptor
HlibPavlyk Sep 25, 2024
06f8871
feat: complete login component
HlibPavlyk Sep 25, 2024
d933979
feat: complete register component
HlibPavlyk Sep 25, 2024
eeb33c4
feat: add album-form component
HlibPavlyk Sep 25, 2024
1a71e25
chore: update auth logic
HlibPavlyk Sep 30, 2024
18b1cdb
chore: update form component
HlibPavlyk Sep 30, 2024
b8b86e3
feat: add user service and controller
HlibPavlyk Oct 3, 2024
2adc8c3
feat: add some album service methods
HlibPavlyk Oct 3, 2024
ba1094d
feat: update album view component
HlibPavlyk Oct 3, 2024
6e88355
feat: add profile component
HlibPavlyk Oct 3, 2024
ad0ede9
chore: make some fixes
HlibPavlyk Oct 3, 2024
67b4953
feat: add stats component
HlibPavlyk Oct 3, 2024
3c52f68
feat: add author row to album cards
HlibPavlyk Oct 4, 2024
7825fbf
feat: update link to user profile
HlibPavlyk Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add patch endpoints
- add services and controllers
- edit automapper for that purpose
- make small fixes in other endpoints and services
HlibPavlyk committed Sep 6, 2024
commit 05812322791ee1105d78b7aa241201a47deb63c3
17 changes: 16 additions & 1 deletion src/CoinyProject.Api/Controllers/AlbumController.cs
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public async Task<IActionResult> AddAlbum([FromBody] AlbumPostDto album)
try
{
var id = await _albumService.AddAlbumAsync(album);
return Created($"/api/albums/{id}", id);
return CreatedAtAction(nameof(GetAlbumById), new { id }, await _albumService.GetAlbumById(id));
}
catch (ArgumentNullException e)
{
@@ -50,4 +50,19 @@ public async Task<IActionResult> GetAlbumById([FromRoute] Guid id)
return NotFound(e.Message);
}
}

[HttpPatch("{id:guid}")]
[Authorize]
public async Task<IActionResult> UpdateAlbum([FromRoute] Guid id, [FromBody] AlbumPatchDto album)
{
try
{
await _albumService.UpdateAlbumAsync(id, album);
return Ok(await _albumService.GetAlbumById(id));
}
catch (NotFoundException e)
{
return NotFound(e.Message);
}
}
}
43 changes: 37 additions & 6 deletions src/CoinyProject.Api/Controllers/AlbumElementController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CoinyProject.Application.Abstractions.Services;
using CoinyProject.Application.Dto.Album;
using CoinyProject.Application.Dto.AlbumElement;
using CoinyProject.Domain.Exceptions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -16,25 +17,26 @@ public AlbumElementController(IAlbumElementService albumElementService)
{
_albumElementService = albumElementService;
}

[HttpPost]
[Authorize]
public async Task<IActionResult> AddAlbumElement([FromForm] AlbumElementPostDto element)
{
try
{
var id = await _albumElementService.AddAlbumElement(element);
return Ok(id);
return CreatedAtAction(nameof(GetAlbumElementById), new { id },
await _albumElementService.GetAlbumElementByIdAsync(id));
}
catch (ArgumentNullException e)
{
return BadRequest(e.Message);
}
}
[HttpGet("{albumId:guid}")]
public async Task<IActionResult> GetPagedAlbumElementsByAlbumIdAsync([FromRoute]Guid albumId,
[FromQuery]int page = 1, int size = 10)

[HttpGet("by-album/{albumId:guid}")]
public async Task<IActionResult> GetPagedAlbumElementsByAlbumIdAsync([FromRoute] Guid albumId,
[FromQuery] int page = 1, int size = 10)
{
try
{
@@ -50,4 +52,33 @@ public async Task<IActionResult> GetPagedAlbumElementsByAlbumIdAsync([FromRoute]
return NotFound(e.Message);
}
}

[HttpGet("{id:guid}")]
public async Task<IActionResult> GetAlbumElementById([FromRoute] Guid id)
{
try
{
var element = await _albumElementService.GetAlbumElementByIdAsync(id);
return Ok(element);
}
catch (NotFoundException e)
{
return NotFound(e.Message);
}
}

[HttpPatch("{id:guid}")]
[Authorize]
public async Task<IActionResult> UpdateAlbumElement([FromRoute] Guid id, [FromForm] AlbumElementPatchDto element)
{
try
{
await _albumElementService.UpdateAlbumElementAsync(id, element);
return Ok(await _albumElementService.GetAlbumElementByIdAsync(id));
}
catch (NotFoundException e)
{
return NotFound(e.Message);
}
}
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ public interface IGenericRepository<TEntity> where TEntity : class
Task<TEntity?> GetByIdAsync(Guid id);
Task<IEnumerable<TEntity>?> GetAllAsync();
Task AddAsync(TEntity entity);
void Update(TEntity entity);
void Remove(TEntity entity);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CoinyProject.Application.Dto.Album;
using CoinyProject.Application.DTO.Album;
using CoinyProject.Application.Dto.AlbumElement;
using CoinyProject.Application.Dto.Other;

namespace CoinyProject.Application.Abstractions.Services;
@@ -8,5 +9,7 @@ public interface IAlbumElementService
{
Task<Guid> AddAlbumElement(AlbumElementPostDto element);
Task<PagedResponse<AlbumElementGetDto> > GetPagedAlbumElementsByAlbumIdAsync(Guid id, int page, int size);
Task<AlbumElementGetDto> GetAlbumElementByIdAsync(Guid id);
Task<Guid> UpdateAlbumElementAsync(Guid id, AlbumElementPatchDto element);

}
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@ namespace CoinyProject.Application.Abstractions.Services
public interface IAlbumService
{
Task<Guid> AddAlbumAsync(AlbumPostDto album);
Task<AlbumWithElementsGetDto> GetAlbumById(Guid id);
Task<AlbumGetDto> GetAlbumById(Guid id);
Task<Guid> UpdateAlbumAsync(Guid id, AlbumPatchDto album);
/*Task AddAlbumElement(AlbumElementPostDto? albumElement);
Task<IEnumerable<AlbumGetDto>> GetAllAlbumsDTO(string? userId);
Task<IEnumerable<AlbumGetForViewDTO>> GetAllAlbumsForView(string? userId);
12 changes: 9 additions & 3 deletions src/CoinyProject.Application/AutoMapper/AutoMapperProfile.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
using CoinyProject.Application.AutoMapper.Resolvers;
using CoinyProject.Application.Dto.Album;
using CoinyProject.Application.DTO.Album;
using CoinyProject.Application.Dto.AlbumElement;
using CoinyProject.Application.Dto.Other;
using CoinyProject.Domain.Entities;

@@ -15,11 +16,16 @@ public AutoMapperProfile()

CreateMap<AlbumPostDto, Album>();
CreateMap<AlbumElementPostDto, AlbumElement>()
.ForMember(dest => dest.ImageUrl, opt => opt.Ignore());
.ForMember(dest => dest.ImageUrl, src => src.Ignore());

CreateMap<Album, AlbumWithElementsGetDto>();
CreateMap<Album, AlbumGetDto>();
CreateMap<AlbumElement, AlbumElementGetDto>()
.ForMember(dest => dest.ImageUrl, src => src.MapFrom<ImageUrlResolver>());
.ForMember(dest => dest.ImageUrl, src => src.MapFrom<GetImageUrlResolver>());

CreateMap<AlbumPatchDto, Album>()
.ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null));
CreateMap<AlbumElementPatchDto, AlbumElement>()
.ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null));



Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using AutoMapper;
using CoinyProject.Application.Abstractions.DataServices;
using CoinyProject.Application.DTO.Album;
using CoinyProject.Application.Dto.AlbumElement;
using CoinyProject.Domain.Entities;

namespace CoinyProject.Application.AutoMapper.Resolvers;

public class ImageUrlResolver : IValueResolver<AlbumElement, AlbumElementGetDto, string>
public class GetImageUrlResolver : IValueResolver<AlbumElement, AlbumElementGetDto, string>
{
private readonly IFileService _fileService;

public ImageUrlResolver(IFileService fileService)
public GetImageUrlResolver(IFileService fileService)
{
_fileService = fileService;
}
17 changes: 0 additions & 17 deletions src/CoinyProject.Application/Dto/Album/AlbumEditDTO.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/CoinyProject.Application/Dto/Album/AlbumElementEditDTO.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/CoinyProject.Application/Dto/Album/AlbumGetForViewDTO.cs

This file was deleted.

3 changes: 3 additions & 0 deletions src/CoinyProject.Application/Dto/Album/AlbumPatchDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace CoinyProject.Application.Dto.Album;

public record AlbumPatchDto(string? Name, string? Description);
13 changes: 0 additions & 13 deletions src/CoinyProject.Application/Dto/Album/AlbumWithElementsGetDto.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

namespace CoinyProject.Application.DTO.Album
namespace CoinyProject.Application.Dto.AlbumElement
{
public class AlbumElementGetDto
{
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Microsoft.AspNetCore.Http;

namespace CoinyProject.Application.Dto.AlbumElement;

public record AlbumElementPatchDto(string? Name, string? Description, IFormFile? Photo);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

using Microsoft.AspNetCore.Http;

namespace CoinyProject.Application.Dto.Album
namespace CoinyProject.Application.Dto.AlbumElement
{
public record AlbumElementPostDto(string Name, string? Description, Guid AlbumId, IFormFile Photo);
}
26 changes: 24 additions & 2 deletions src/CoinyProject.Application/Services/AlbumElementService.cs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
using CoinyProject.Application.Abstractions.Services;
using CoinyProject.Application.Dto.Album;
using CoinyProject.Application.DTO.Album;
using CoinyProject.Application.Dto.AlbumElement;
using CoinyProject.Application.Dto.Other;
using CoinyProject.Domain.Entities;
using CoinyProject.Domain.Exceptions;
@@ -44,10 +45,31 @@ public async Task<PagedResponse<AlbumElementGetDto>> GetPagedAlbumElementsByAlbu

var elements = await _unitOfWork.AlbumElements.GetPagedAlbumElementsByAlbumIdAsync(id, page, size);
if (elements.TotalPages == 0)
{
throw new NotFoundException("No elements found for this album");
}

return _mapper.Map<PagedResponse<AlbumElementGetDto>>(elements);
}

public async Task<AlbumElementGetDto> GetAlbumElementByIdAsync(Guid id)
{
var element = await _unitOfWork.AlbumElements.GetByIdAsync(id);
if (element == null)
throw new NotFoundException("Element not found");

return _mapper.Map<AlbumElementGetDto>(element);
}

public async Task<Guid> UpdateAlbumElementAsync(Guid id, AlbumElementPatchDto element)
{
var oldElement = await _unitOfWork.AlbumElements.GetByIdAsync(id);
if (oldElement == null)
throw new NotFoundException("Element not found");

_mapper.Map(element, oldElement);
if (element.Photo != null)
oldElement.ImageUrl = await _fileService.SaveImageAsync(element.Photo);

await _unitOfWork.SaveChangesAsync();
return id;
}
}
24 changes: 16 additions & 8 deletions src/CoinyProject.Application/Services/AlbumService.cs
Original file line number Diff line number Diff line change
@@ -7,9 +7,7 @@
using CoinyProject.Domain.Entities;
using CoinyProject.Domain.Exceptions;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;


namespace CoinyProject.Application.Services
@@ -18,17 +16,14 @@ public class AlbumService : IAlbumService
{
private readonly IMapper _mapper;
private readonly IUnitOfWork _unitOfWork;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IHttpContextAccessor _httpContextAccessor;

// private readonly string imageFolder = "albums/elements/";

public AlbumService(IMapper mapper, IUnitOfWork unitOfWork, IHostingEnvironment hostingEnvironment,
IHttpContextAccessor httpContextAccessor)
public AlbumService(IMapper mapper, IUnitOfWork unitOfWork, IHttpContextAccessor httpContextAccessor)
{
_mapper = mapper;
_unitOfWork = unitOfWork;
_hostingEnvironment = hostingEnvironment;
_httpContextAccessor = httpContextAccessor;
}

@@ -86,14 +81,27 @@ public async Task<Guid> AddAlbumAsync(AlbumPostDto album)
return entity.Id;
}

public async Task<AlbumWithElementsGetDto> GetAlbumById(Guid id)
public async Task<AlbumGetDto> GetAlbumById(Guid id)
{
var album = await _unitOfWork.Albums.GetByIdAsync(id);

if (album == null)
throw new NotFoundException("Album not found.");

return _mapper.Map<AlbumWithElementsGetDto>(album);
return _mapper.Map<AlbumGetDto>(album);
}

public async Task<Guid> UpdateAlbumAsync(Guid id, AlbumPatchDto album)
{
var oldAlbum = await _unitOfWork.Albums.GetByIdAsync(id);
if (oldAlbum == null)
throw new NotFoundException("Album not found.");

_mapper.Map(album, oldAlbum);
await _unitOfWork.SaveChangesAsync();

return id;

}


Loading