diff --git a/.idea/.idea.BookHive/.idea/workspace.xml b/.idea/.idea.BookHive/.idea/workspace.xml
index 1ce5d21..5b763c5 100644
--- a/.idea/.idea.BookHive/.idea/workspace.xml
+++ b/.idea/.idea.BookHive/.idea/workspace.xml
@@ -7,21 +7,12 @@
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -130,7 +121,7 @@
-
+
@@ -188,7 +179,15 @@
1773135809527
-
+
+
+ 1773739675537
+
+
+
+ 1773739675537
+
+
@@ -204,7 +203,8 @@
-
+
+
diff --git a/BookHive/DTO/Book/GetBookDetailsDto.cs b/BookHive/DTO/Book/GetBookDetailsDto.cs
index 80f55ec..f85586d 100644
--- a/BookHive/DTO/Book/GetBookDetailsDto.cs
+++ b/BookHive/DTO/Book/GetBookDetailsDto.cs
@@ -12,8 +12,11 @@ public class GetBookDetailsDto
public int PageCount { get; set; }
public DateOnly PublishedDate { get; set; }
public string? Genre { get; set; }
+ public decimal? AverageRating { get; set; }
+ public int? ReviewCount { get; set; }
public int AuthorId { get; set; }
+ public string? AuthorNationality { get; set; }
public GetAuthorDto? Author { get; set; }
public List? Reviews { get; set; }
diff --git a/BookHive/DTO/Loan/GetLoanDto.cs b/BookHive/DTO/Loan/GetLoanDto.cs
index 3eccf3b..c810064 100644
--- a/BookHive/DTO/Loan/GetLoanDto.cs
+++ b/BookHive/DTO/Loan/GetLoanDto.cs
@@ -8,12 +8,11 @@ public class GetLoanDto
public int Id { get; set; }
public int BookId { get; set; }
+ public string? BookTitle { get; set; }
public int MemberId { get; set; }
+ public string? MemberFullName { get; set; }
public DateOnly LoanDate { get; set; }
public DateOnly DueDate { get; set; }
public DateOnly? ReturnDate { get; set; }
-
- public GetBookDto? Book { get; set; }
- public GetMemberDto? Member { get; set; }
}
\ No newline at end of file
diff --git a/BookHive/DTO/Review/GetReviewDto.cs b/BookHive/DTO/Review/GetReviewDto.cs
index 80cb72f..948d338 100644
--- a/BookHive/DTO/Review/GetReviewDto.cs
+++ b/BookHive/DTO/Review/GetReviewDto.cs
@@ -8,12 +8,12 @@ public class GetReviewDto
public int Id { get; set; }
public int BookId { get; set; }
+ public string? BookTitle { get; set; }
+
public int MemberId { get; set; }
+ public string? MemberFullName { get; set; }
public int Rating { get; set; }
public string? Comment { get; set; }
public DateTime CreatedAt { get; set; }
-
- public GetBookDto? Book { get; set; }
- public GetMemberDto? Member { get; set; }
}
\ No newline at end of file
diff --git a/BookHive/MappingProfiles/DtoToEntityMappings.cs b/BookHive/MappingProfiles/DtoToEntityMappings.cs
index 0908c1c..f58a0d1 100644
--- a/BookHive/MappingProfiles/DtoToEntityMappings.cs
+++ b/BookHive/MappingProfiles/DtoToEntityMappings.cs
@@ -13,18 +13,26 @@ public class DtoToEntityMappings : Profile
public DtoToEntityMappings()
{
CreateMap();
- CreateMap();
+ CreateMap()
+ .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap();
- CreateMap();
+ CreateMap()
+ .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap();
- CreateMap();
+ CreateMap()
+ .ForMember(dest => dest.Id, opt => opt.Ignore())
+ .ForMember(
+ dest => dest.Email,
+ opt => opt.PreCondition(src => !string.IsNullOrEmpty(src.Email)));
CreateMap();
- CreateMap();
+ CreateMap()
+ .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap();
- CreateMap();
+ CreateMap()
+ .ForMember(dest => dest.Id, opt => opt.Ignore());
}
}
\ No newline at end of file
diff --git a/BookHive/MappingProfiles/EntityToDtoMappings.cs b/BookHive/MappingProfiles/EntityToDtoMappings.cs
index 6fe0b79..91c0671 100644
--- a/BookHive/MappingProfiles/EntityToDtoMappings.cs
+++ b/BookHive/MappingProfiles/EntityToDtoMappings.cs
@@ -19,16 +19,40 @@ public class EntityToDtoMappings : Profile
opt.MapFrom(src =>
src.Author!.FirstName + " " + src.Author.LastName)
);
- CreateMap();
+ CreateMap()
+ .ForMember(
+ dest => dest.AverageRating,
+ opt => opt.MapFrom(src => src.Reviews.Any() ? src.Reviews.Average(r => r.Rating) : 0)
+ )
+ .ForMember(
+ dest => dest.ReviewCount,
+ opt => opt.MapFrom(src => src.Reviews.Count)
+ );
CreateMap();
CreateMap();
- CreateMap();
+ CreateMap()
+ .ForMember(
+ dest => dest.BookTitle,
+ opt =>
+ opt.MapFrom(src => src.Book!.Title))
+ .ForMember(
+ dest => dest.MemberFullName,
+ opt =>
+ opt.MapFrom(src => src.Member!.FirstName + ' ' + src.Member!.LastName));
CreateMap();
CreateMap();
- CreateMap();
+ CreateMap()
+ .ForMember(
+ dest => dest.BookTitle,
+ opt =>
+ opt.MapFrom(src => src.Book!.Title))
+ .ForMember(
+ dest => dest.MemberFullName,
+ opt =>
+ opt.MapFrom(src => src.Member!.FirstName + ' ' + src.Member!.LastName));
}
}
\ No newline at end of file
diff --git a/BookHive/Program.cs b/BookHive/Program.cs
index 5c611ea..4ec64a1 100644
--- a/BookHive/Program.cs
+++ b/BookHive/Program.cs
@@ -1,7 +1,5 @@
-using AutoMapper;
using AutoMapper.EquivalencyExpression;
using BookHive;
-using BookHive.MappingProfiles;
using BookHive.Repositories;
using FastEndpoints;
using FastEndpoints.Security;
@@ -38,16 +36,20 @@ builder.Services.AddScoped();
builder.Services.AddHttpContextAccessor();
-MapperConfiguration mappingConfig = new(mc =>
+builder.Services.AddAutoMapper(cfg =>
{
- mc.AddCollectionMappers();
- mc.AddProfile(new DtoToEntityMappings());
- mc.AddProfile(new EntityToDtoMappings());
-}, new LoggerFactory());
+ cfg.AddCollectionMappers();
+}, typeof(Program).Assembly);
+// MapperConfiguration mappingConfig = new(mc =>
+// {
+// mc.AddCollectionMappers();
+// mc.AddProfile(new DtoToEntityMappings());
+// mc.AddProfile(new EntityToDtoMappings());
+// }, new LoggerFactory());
-AutoMapper.IMapper mapper = mappingConfig.CreateMapper();
-builder.Services.AddSingleton(mapper);
+// AutoMapper.IMapper mapper = mappingConfig.CreateMapper();
+// builder.Services.AddSingleton(mapper);
WebApplication app = builder.Build();
app.UseAuthentication()