Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public async Task<OperationResult<GetBookDto>> Handle(AddBookCommand request, Ca
Title = request.NewBook.Title,
Genre = request.NewBook.Genre,
Description = request.NewBook.Description,
AuthorId = request.NewBook.AuthorId
AuthorId = request.NewBook.AuthorId,
PublisherId = request.NewBook.PublisherId,
ImageUrl = request.NewBook.ImageUrl
};

var createdBook = await _repository.AddAsync(bookToCreate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public AddBookCommandValidator()
RuleFor(x => x.NewBook.Genre)
.Length(2, 50).WithMessage("Genre must be between 2 and 20 characters.");

RuleFor(x => x.NewBook.PublisherId)
.NotNull().WithMessage("PublisherId is required, cannot be null.");

RuleFor(x => x.NewBook.ImageUrl)
.MaximumLength(250).WithMessage("ImageUrl must be shorter than 250 characters.");

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public async Task<OperationResult<GetBookDto>> Handle(UpdateBookCommand request,
{
Book bookToUpdate = new()
{
BookId = request.NewBook.Id,
BookId = request.NewBook.BookId,
Title = request.NewBook.Title,
Genre = request.NewBook.Genre,
Description = request.NewBook.Description,
AuthorId = request.NewBook.AuthorId,
PublisherId = request.NewBook.PublisherId,
ImageUrl = request.NewBook.ImageUrl
};

var updatedBook = await _repository.UpdateAsync(bookToUpdate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class UpdateBookCommandValidator : AbstractValidator<UpdateBookCommand>
{
public UpdateBookCommandValidator()
{
RuleFor(x => x.NewBook.Id)
RuleFor(x => x.NewBook.BookId)
.NotNull().WithMessage("BookId is required, cannot be null.");

RuleFor(x => x.NewBook.Description)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public async Task<OperationResult<GetBookCopyDto>> Handle(AddBookCopyCommand req
{
CopyId = Guid.NewGuid(),
BookId = request.Dto.BookId,
Status = request.Dto.Status
Status = request.Dto.Status,
FileSize = request.Dto.FileSize,
FileFormat = request.Dto.FileFormat,
FilePath = request.Dto.FilePath
};

var createdBookCopy = await _repository.AddAsync(bookCopyToCreate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public AddBookCopyCommandValidator()
RuleFor(x => x.Dto.BookId)
.NotEmpty()
.WithMessage("BookId is required.");

RuleFor(x => x.Dto.FilePath)
.MaximumLength(250).WithMessage("FilePath must be shorter than 250 characters.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public async Task<OperationResult<GetBookCopyDto>> Handle(UpdateBookCopyCommand
CopyId = request.Dto.CopyId,
BookId = request.Dto.BookId,
Status = request.Dto.Status,
FileFormat = request.Dto.FileFormat,
FileSize = request.Dto.FileSize,
FilePath = request.Dto.FilePath,
};

var updatedBookCopy = await _repository.UpdateAsync(bookToUpdate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public class AddGenreCommandValidator : AbstractValidator<AddGenreCommand>
{
public AddGenreCommandValidator()
{
RuleFor(x => x.Dto.Description)
.NotEmpty().MaximumLength(50).WithMessage("Description is required");

RuleFor(x => x.Dto.Name)
.NotEmpty().MaximumLength(50).WithMessage("Name is required");

RuleFor(x => x.Dto.Description)
.NotEmpty().MaximumLength(250).WithMessage("Description is required");
}
}
}
5 changes: 4 additions & 1 deletion Application/Dtos/BookCopyDtos/AddBookCopyDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace Application.Dtos.BookCopyDtos
public class AddBookCopyDto
{
public Guid BookId { get; set; }
public string? Status { get; set; }
public string Status { get; set; }
public string FileFormat { get; set; }
public long FileSize { get; set; }
public string FilePath { get; set; }
}
}
3 changes: 3 additions & 0 deletions Application/Dtos/BookCopyDtos/GetBookCopyDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ public class GetBookCopyDto
public Guid CopyId { get; set; }
public Guid BookId { get; set; }
public string? Status { get; set; }
public string? FileFormat { get; set; }
public long? FileSize { get; set; }
public string? FilePath { get; set; }
}
}
3 changes: 3 additions & 0 deletions Application/Dtos/BookCopyDtos/UpdateBookCopyDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ public class UpdateBookCopyDto
public Guid CopyId { get; set; }
public Guid BookId { get; set; }
public string? Status { get; set; }
public string? FileFormat { get; set; }
public long? FileSize { get; set; }
public string? FilePath { get; set; }
}
}
2 changes: 2 additions & 0 deletions Application/Dtos/BookDtos/AddBookDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public class AddBookDto()
public string Genre { get; set; }
public string Description { get; set; }
public Guid AuthorId { get; set; }
public int? PublisherId { get; set; }
public string ImageUrl { get; set; }
}
}
2 changes: 1 addition & 1 deletion Application/Dtos/BookDtos/BookDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class BookDto(Guid id, string title, Guid authorId, string description)
{
public Guid Id { get; set; } = id;
public Guid BookId { get; set; } = id;
public string Title { get; set; } = title;
public string Description { get; set; } = description;
public Guid AuthorId { get; set; } = authorId;
Expand Down
2 changes: 2 additions & 0 deletions Application/Dtos/BookDtos/GetBookDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class GetBookDto()
public string Genre { get; set; }
public string Description { get; set; }
public int Copies { get; set; }
public string ImageUrl { get; set; }
public Guid AuthorId { get; set; }
public string PublisherId { get; set; }
}
}
4 changes: 3 additions & 1 deletion Application/Dtos/BookDtos/UpdateBookDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ namespace Application.Dtos.BookDtos
{
public class UpdateBookDto()
{
public Guid Id { get; set; }
public Guid BookId { get; set; }
public string Title { get; set; }
public string Genre { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
public Guid AuthorId { get; set; }
public int PublisherId { get; set; }
}
}
5 changes: 0 additions & 5 deletions Application/Mappings/BookMappingProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ public BookMappingProfiles()
{
CreateMap<Book, GetBookDto>();
CreateMap<Book, AddBookDto>();
CreateMap<AddBookDto, Book>();
CreateMap<BookDto, Book>();
CreateMap<GetBookDto, Book>();
CreateMap<Book, GetBookDto>();
CreateMap<Book, UpdateBookDto>();


// For Testing:
CreateMap<AddBookDto, Book>()
.ForMember(dest => dest.AuthorId, opt => opt.MapFrom(src => src.AuthorId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<OperationResult<List<GetBookDto>>> Handle(GetAllBooksQuery req

mappedBooksFromDatabase = _mapper.Map<List<GetBookDto>>(allBooksFromDatabase);

_memoryCache.Set(cacheKey, mappedBooksFromDatabase, TimeSpan.FromMinutes(5));
// _memoryCache.Set(cacheKey, mappedBooksFromDatabase, TimeSpan.FromMinutes(0));
}

return OperationResult<List<GetBookDto>>.Success(mappedBooksFromDatabase);
Expand Down
3 changes: 1 addition & 2 deletions Domain/Entities/Core/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Book() : IEntity<Guid>
[Required(ErrorMessage = "Title is required")]
[StringLength(100, ErrorMessage = "Title cant be longer than 150 characters")]
public string Title { get; set; }

public string ImageUrl { get; set; }
public DateTime? PublicationDate { get; set; }
public Guid? AuthorId { get; set; }
public string? Genre { get; set; }
Expand All @@ -28,7 +28,6 @@ public class Book() : IEntity<Guid>
public Publisher Publisher { get; set; }
public ICollection<BookCopy> Copies { get; set; }
public ICollection<Review> Reviews { get; set; }
public ICollection<Reservation> Reservations { get; set; }


// Explicit implementation of IEntity<Guid>
Expand Down
4 changes: 4 additions & 0 deletions Domain/Entities/Locations/BookCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class BookCopy : IEntity<Guid>
public Guid BookId { get; set; }
public int BranchId { get; set; }
public string? Status { get; set; }
public string FileFormat { get; set; }
public long? FileSize { get; set; }
public string FilePath { get; set; }


// Navigation properties
public Book Book { get; set; }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
public partial class NewMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down Expand Up @@ -207,6 +207,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
{
BookId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Title = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
ImageUrl = table.Column<string>(type: "nvarchar(max)", nullable: false),
PublicationDate = table.Column<DateTime>(type: "datetime2", nullable: true),
AuthorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
Genre = table.Column<string>(type: "nvarchar(max)", nullable: true),
Expand Down Expand Up @@ -241,7 +242,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
CopyId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
BookId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
BranchId = table.Column<int>(type: "int", nullable: false),
Status = table.Column<string>(type: "nvarchar(max)", nullable: true)
Status = table.Column<string>(type: "nvarchar(max)", nullable: true),
FileFormat = table.Column<string>(type: "nvarchar(max)", nullable: false),
FileSize = table.Column<long>(type: "bigint", nullable: true),
FilePath = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
Expand Down Expand Up @@ -322,8 +326,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
Status = table.Column<string>(type: "nvarchar(max)", nullable: false),
ReservationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
CopyId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
BookId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false)
},
constraints: table =>
{
Expand All @@ -340,11 +343,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
principalTable: "BookCopies",
principalColumn: "CopyId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Reservations_Books_BookId",
column: x => x.BookId,
principalTable: "Books",
principalColumn: "BookId");
});

migrationBuilder.CreateIndex(
Expand Down Expand Up @@ -416,11 +414,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
table: "Borrowings",
column: "UserId");

migrationBuilder.CreateIndex(
name: "IX_Reservations_BookId",
table: "Reservations",
column: "BookId");

migrationBuilder.CreateIndex(
name: "IX_Reservations_CopyId",
table: "Reservations",
Expand Down
Loading
Loading