Commit 17b4ddd7 authored by Jakub Formánek's avatar Jakub Formánek
Browse files

Merge branch '27-remaining-fixes' into 'milestone-2'

fix: remaining fixes

See merge request !36
parents 035bf97b ccce25ab
Loading
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -16,8 +16,4 @@
      <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.11" />
    </ItemGroup>

    <ItemGroup>
      <Folder Include="Images\" />
    </ItemGroup>

</Project>
+16 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ public class BookService : IBookService
    public async Task<ResponseBookDto> AddBookAsync(AddBookDto addBookDto, IFormFile image)
    {
        var book = _mapper.Map<Book>(addBookDto);

        if (image != null)
        {
            var imagePath = Path.Combine("images", image.FileName);
@@ -67,7 +68,8 @@ public class BookService : IBookService
    public async Task<ResponseBookDto> UpdateBookAsync(
        int id,
        UpdateBookDto updateBookDto,
        IFormFile image
        IFormFile image,
        int? userId
    )
    {
        var book = await _unitOfWork.BookRepository.GetByIdAsync(id);
@@ -77,7 +79,18 @@ public class BookService : IBookService
            throw new NotFoundException("Book", id);
        }
        _mapper.Map(updateBookDto, book);

        if (userId != null)
        {
            if (await _unitOfWork.UserRepository.GetByIdAsync(userId.Value) != null)
            {
                book.LastEditorId = userId;
                book.EditCount += 1;
            }
            else
            {
                throw new NotFoundException("User", userId.Value);
            }
        }
        if (image != null)
        {
            var imagePath = Path.Combine("images", image.FileName);
@@ -109,8 +122,7 @@ public class BookService : IBookService

    private async Task<IEnumerable<ResponseBookDto>> GetBooksAsync(BookFilterDto filter)
    {
        var books = await _unitOfWork.BookRepository.GetAllAsync();
        var query = books.AsQueryable();
        var query = _unitOfWork.BookRepository.GetQueryable();

        if (!string.IsNullOrEmpty(filter.Name))
        {
+6 −1
Original line number Diff line number Diff line
@@ -11,7 +11,12 @@ public interface IBookService
    Task<IEnumerable<ResponseBookDto>> GetAllBooksAsync();
    Task<ResponseBookDto> GetBookByIdAsync(int id);
    Task<ResponseBookDto> AddBookAsync(AddBookDto addBookDto, IFormFile image);
    Task<ResponseBookDto> UpdateBookAsync(int id, UpdateBookDto updateBookDto, IFormFile image);
    Task<ResponseBookDto> UpdateBookAsync(
        int id,
        UpdateBookDto updateBookDto,
        IFormFile image,
        int? userId
    );
    Task DeleteBookAsync(int id);
    Task<IEnumerable<ResponseBookDto>> GetFilteredBooksAsync(BookFilterDto filter);
}
+2 −0
Original line number Diff line number Diff line
@@ -9,4 +9,6 @@ public interface IRepository<T>
    void Update(T entity);
    Task<T?> GetByIdAsync(int id);
    Task<IEnumerable<T>> GetAllAsync();

    IQueryable<T> GetQueryable();
}
+5 −0
Original line number Diff line number Diff line
@@ -42,4 +42,9 @@ public class Repository<T> : IRepository<T>
    {
        return await _entities.ToListAsync();
    }

    public IQueryable<T> GetQueryable()
    {
        return _entities;
    }
}
Loading