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

Case project #23

Merged
merged 4 commits into from
Apr 29, 2024
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
@@ -1,15 +1,15 @@
using LibraryTrackingApp.Application.DataTransferObjects;
using LibraryTrackingApp.Application.Features.Books.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;
using LibraryTrackingApp.Domain.Entities.Library;

namespace LibraryTrackingApp.Application.Features.Books.Behaviors.Mapping;
namespace LibraryTrackingApp.Application.Features.BookInventories.Behaviors.Mapping;

public class BookMappingProfile : Profile
{
public BookMappingProfile()
{
CreateMap<Book, BookDTO>().ReverseMap();
CreateMap<Book, CreateBookCommandRequest>().ReverseMap();
CreateMap<BookCatalog, BookDTO>().ReverseMap();
CreateMap<BookCatalog, CreateBookCommandRequest>().ReverseMap();
CreateMap<BookDTO, CreateBookCommandRequest>().ReverseMap();

// lazım olan yerde burda map'leme yapılabilir.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Application.Features.Books.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;

namespace LibraryTrackingApp.Application.Features.Books.Behaviors.Validator;
namespace LibraryTrackingApp.Application.Features.BookInventories.Behaviors.Validator;
public class CreateBookCommandRequestValidator : AbstractValidator<CreateBookCommandRequest>
{
public CreateBookCommandRequestValidator()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;

namespace LibraryTrackingApp.Application.Features.BookInventories.Behaviors.Validator;


public class DeleteBookCommandRequestValidator : AbstractValidator<DeleteBookCommandRequest>
{
public DeleteBookCommandRequestValidator()
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using LibraryTrackingApp.Application.Features.BookInventories.Queries.Requests;

namespace LibraryTrackingApp.Application.Features.BookInventories.Behaviors.Validator;

public class GetAllBooksQueryRequestValidator : AbstractValidator<GetAllBooksQueryRequest>
{
public GetAllBooksQueryRequestValidator()
{

}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Application.Features.Books.Queries.Requests;
using LibraryTrackingApp.Application.Features.BookInventories.Queries.Requests;

namespace LibraryTrackingApp.Application.Features.Books.Behaviors.Validator;
namespace LibraryTrackingApp.Application.Features.BookInventories.Behaviors.Validator;

public class GetBookQueryRequestValidator : AbstractValidator<GetBookQueryRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;

namespace LibraryTrackingApp.Application.Features.BookInventories.Behaviors.Validator;


public class UpdateBookCommandRequestValidator : AbstractValidator<UpdateBookCommandRequest>
{
public UpdateBookCommandRequestValidator()
{

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using LibraryTrackingApp.Application.Features.Books.Commands.Requests;
using LibraryTrackingApp.Application.Features.Books.Commands.Responses;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;

namespace LibraryTrackingApp.Application.Features.Books.Commands.Handlers;
namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Handlers;

// book crud işlemleri tekrdan düzenelecektir.
public class CreateBookCommandHandler : IRequestHandler<CreateBookCommandRequest, CreateBookCommandResponse>
Expand All @@ -25,7 +25,7 @@ public async Task<CreateBookCommandResponse> Handle(CreateBookCommandRequest req

try
{
var existingBook = await _unitOfWork.GetReadRepository<Domain.Entities.Library.Book>()
var existingBook = await _unitOfWork.GetReadRepository<Domain.Entities.Library.BookCatalog>()
.ExistsAsync(b => b.ISBN == request.ISBN);

if (existingBook)
Expand All @@ -40,11 +40,11 @@ public async Task<CreateBookCommandResponse> Handle(CreateBookCommandRequest req



var newBook = _mapper.Map<Domain.Entities.Library.Book>(request);
var newBook = _mapper.Map<Domain.Entities.Library.BookCatalog>(request);
newBook.Id = Guid.NewGuid();

var writeRepository = _unitOfWork.GetWriteRepository<Domain.Entities.Library.Book>();

var writeRepository = _unitOfWork.GetWriteRepository<Domain.Entities.Library.BookCatalog>();
bool isAdded = await writeRepository.AddAsync(newBook);

if (isAdded)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using LibraryTrackingApp.Application.Features.Books.Commands.Requests;
using LibraryTrackingApp.Application.Features.Books.Commands.Responses;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;

namespace LibraryTrackingApp.Application.Features.Books.Commands.Handlers;
namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Handlers;


public class DeleteBookCommandHandler : IRequestHandler<DeleteBookCommandRequest, DeleteBookCommandResponse>
Expand All @@ -18,7 +18,7 @@ public async Task<DeleteBookCommandResponse> Handle(DeleteBookCommandRequest req
try
{

var readRepository = _unitOfWork.GetReadRepository<Domain.Entities.Library.Book>();
var readRepository = _unitOfWork.GetReadRepository<Domain.Entities.Library.BookCatalog>();

Guid bookId;
bool isGuid = Guid.TryParse(request.IdOrISBN, out bookId);
Expand All @@ -39,7 +39,7 @@ public async Task<DeleteBookCommandResponse> Handle(DeleteBookCommandRequest req
}
else
{
var writeRepository = _unitOfWork.GetWriteRepository<Domain.Entities.Library.Book>();
var writeRepository = _unitOfWork.GetWriteRepository<Domain.Entities.Library.BookCatalog>();
bool isDeleted = await writeRepository.DeleteAsync(existingBookStock);
if (isDeleted)
{
Expand Down Expand Up @@ -67,7 +67,7 @@ public async Task<DeleteBookCommandResponse> Handle(DeleteBookCommandRequest req
}
catch (Exception ex)
{
return new ()
return new()
{
StatusCode = 500,
Success = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using LibraryTrackingApp.Application.Features.Books.Commands.Requests;
using LibraryTrackingApp.Application.Features.Books.Commands.Responses;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;

namespace LibraryTrackingApp.Application.Features.Books.Commands.Handlers;
namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Handlers;

public class UpdateBookCommandHandler : IRequestHandler<UpdateBookCommandRequest, UpdateBookCommandResponse>
{
Expand All @@ -17,7 +17,7 @@ public async Task<UpdateBookCommandResponse> Handle(UpdateBookCommandRequest req
{
try
{
var readRepository = _unitOfWork.GetReadRepository<Domain.Entities.Library.Book>();
var readRepository = _unitOfWork.GetReadRepository<Domain.Entities.Library.BookCatalog>();

var existingBook = await readRepository.GetSingleAsync(s => s.Id == request.Id);

Expand All @@ -33,7 +33,7 @@ public async Task<UpdateBookCommandResponse> Handle(UpdateBookCommandRequest req

else
{
var writeRepository = _unitOfWork.GetWriteRepository<Domain.Entities.Library.Book>();
var writeRepository = _unitOfWork.GetWriteRepository<Domain.Entities.Library.BookCatalog>();

existingBook.Title = request.Title;
existingBook.ISBN = request.ISBN;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json.Serialization;
using LibraryTrackingApp.Application.Features.Books.Commands.Responses;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;

namespace LibraryTrackingApp.Application.Features.Books.Commands.Requests;
namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;

public class CreateBookCommandRequest : IRequest<CreateBookCommandResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;

namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;

public class DeleteBookCommandRequest : IRequest<DeleteBookCommandResponse>
{
public string IdOrISBN { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibraryTrackingApp.Application.Features.Books.Commands.Responses;
using LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;
using System.Text.Json.Serialization;

namespace LibraryTrackingApp.Application.Features.Books.Commands.Requests;
namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Requests;

public class UpdateBookCommandRequest : IRequest<UpdateBookCommandResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Application.Shared.Wrappers.Results;

namespace LibraryTrackingApp.Application.Features.Books.Commands.Responses;
namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;

public class CreateBookCommandResponse : CommandResult
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Application.Shared.Wrappers.Results;

namespace LibraryTrackingApp.Application.Features.Books.Commands.Responses;
namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;

public class DeleteBookCommandResponse : CommandResult
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Application.Shared.Wrappers.Results;

namespace LibraryTrackingApp.Application.Features.Books.Commands.Responses;
namespace LibraryTrackingApp.Application.Features.BookInventories.Commands.Responses;

public class UpdateBookCommandResponse : CommandResult
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Domain.Events;

namespace LibraryTrackingApp.Application.Features.Books.Events;
namespace LibraryTrackingApp.Application.Features.BookInventories.Events;

public class BookCommandEvent : BaseEvent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace LibraryTrackingApp.Application.Features.Books.Events;
namespace LibraryTrackingApp.Application.Features.BookInventories.Events;

public class BookCommandEventHandler : INotificationHandler<BookCommandEvent>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibraryTrackingApp.Application.Features.Books.Queries.Requests;
using LibraryTrackingApp.Application.Features.Books.Queries.Responses;
using LibraryTrackingApp.Application.Features.BookInventories.Queries.Requests;
using LibraryTrackingApp.Application.Features.BookInventories.Queries.Responses;

namespace LibraryTrackingApp.Application.Features.Books.Queries.Handlers;
namespace LibraryTrackingApp.Application.Features.BookInventories.Queries.Handlers;

public class GetAllBooksQueryHandler : IRequestHandler<GetAllBooksQueryRequest, GetAllBooksQueryResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using LibraryTrackingApp.Application.Features.Books.Queries.Requests;
using LibraryTrackingApp.Application.Features.Books.Queries.Responses;
using LibraryTrackingApp.Application.Features.BookInventories.Queries.Requests;
using LibraryTrackingApp.Application.Features.BookInventories.Queries.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;
using System.Net;

namespace LibraryTrackingApp.Application.Features.Books.Queries.Handlers;
namespace LibraryTrackingApp.Application.Features.BookInventories.Queries.Handlers;

public class GetBookQueryHandler : IRequestHandler<GetBookQueryRequest, GetBookQueryResponse>
{
Expand All @@ -22,7 +22,7 @@ public async Task<GetBookQueryResponse> Handle(GetBookQueryRequest request, Canc
try
{
var readRepository = _unitOfWork
.GetReadRepository<Domain.Entities.Library.Book>();
.GetReadRepository<Domain.Entities.Library.BookCatalog>();


var existingAuthor = await
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using LibraryTrackingApp.Application.Features.BookInventories.Queries.Responses;

namespace LibraryTrackingApp.Application.Features.BookInventories.Queries.Requests;

public class GetAllBooksQueryRequest : IRequest<GetAllBooksQueryResponse>
{
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using LibraryTrackingApp.Application.Features.BookInventories.Queries.Responses;

namespace LibraryTrackingApp.Application.Features.BookInventories.Queries.Requests;

public class GetBookQueryRequest : IRequest<GetBookQueryResponse>
{
public Guid BookId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Application.Shared.Wrappers.Results;

namespace LibraryTrackingApp.Application.Features.Books.Queries.Responses;
namespace LibraryTrackingApp.Application.Features.BookInventories.Queries.Responses;

public class GetAllBooksQueryResponse : PaginatedQueryResult<BookDTO>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibraryTrackingApp.Application.DataTransferObjects;
using LibraryTrackingApp.Application.Shared.Wrappers.Results;

namespace LibraryTrackingApp.Application.Features.Books.Queries.Responses;
namespace LibraryTrackingApp.Application.Features.BookInventories.Queries.Responses;

public class GetBookQueryResponse : QueryResult<BookDTO>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CancellationToken cancellationToken
try
{
var existingBook = await _unitOfWork
.GetReadRepository<Domain.Entities.Library.Book>()
.GetReadRepository<Domain.Entities.Library.BookCatalog>()
.ExistsAsync(b => b.Id == request.BookId);


Expand All @@ -44,9 +44,9 @@ CancellationToken cancellationToken


var readRepository =
_unitOfWork.GetReadRepository<Domain.Entities.Library.BookStock>();
_unitOfWork.GetReadRepository<Domain.Entities.Library.BookStockOLD>();
var writeRepository =
_unitOfWork.GetWriteRepository<Domain.Entities.Library.BookStock>();
_unitOfWork.GetWriteRepository<Domain.Entities.Library.BookStockOLD>();

var existingBookStock = await readRepository.GetSingleAsync(
s => s.BookId == request.BookId
Expand Down Expand Up @@ -103,7 +103,7 @@ CancellationToken cancellationToken
}
else
{
var newBookStock = new Domain.Entities.Library.BookStock()
var newBookStock = new Domain.Entities.Library.BookStockOLD()
{
Id = request.BookId,
Quantity = request.Quantity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
using LibraryTrackingApp.Application.Features.BookStocks.Queries.Requests;
using LibraryTrackingApp.Application.Features.BookStocks.Queries.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;

namespace LibraryTrackingApp.Application.Features.BookStocks.Queries.Handlers;

public class GetAllBookStocksQueryHandler : IRequestHandler<GetAllBookStockQueryRequest, GetAllBookStockQueryResponse>
{
public Task<GetAllBookStockQueryResponse> Handle(GetAllBookStockQueryRequest request, CancellationToken cancellationToken)
private readonly IUnitOfWork<Guid> _unitOfWork;
private readonly IMediator _mediator;
private readonly IMapper _mapper;

public GetAllBookStocksQueryHandler(
IUnitOfWork<Guid> unitOfWork,
IMapper mapper,
IMediator mediator
)
{
_unitOfWork = unitOfWork;
_mediator = mediator;
_mapper = mapper;
}
public async Task<GetAllBookStockQueryResponse> Handle(GetAllBookStockQueryRequest request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
try
{
return new() { };
}
catch (Exception ex)
{
return new()
{
StatusCode = 500,
Success = false,
StateMessages = new[] { $"Bir hata oluştu: {ex.Message}" }

};
}
}
}
Loading
Loading