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

Update: Removal of BookStock Entity. Code Refactoring. #26

Merged
merged 1 commit into from
May 1, 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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibraryTrackingApp.Application.Features.BookStocks.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookStocks.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;
using System.Net;


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

Expand All @@ -24,101 +24,110 @@ CancellationToken cancellationToken
{
try
{
var existingBook = await _unitOfWork
.GetReadRepository<Domain.Entities.Library.WorkCatalog>()
.ExistsAsync(b => b.Id == request.BookId);
// var existingBook = await _unitOfWork
// .GetReadRepository<Domain.Entities.Library.WorkCatalog>()
// .ExistsAsync(b => b.Id == request.BookId);



if (!existingBook)
{
return new()
{
StatusCode = 404,
Success = false,
StateMessages = new string[] { "Verilen ID'ye ait kitap bulunamadı." }
};
}
else
{

// if (!existingBook)
// {
// return new()
// {
// StatusCode = 404,
// Success = false,
// StateMessages = new string[] { "Verilen ID'ye ait kitap bulunamadı." }
// };
// }
// else



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

// var existingBookStock = await readRepository.GetSingleAsync(
// s => s.BookId == request.BookId
// );
// if (existingBookStock != null)
// {
// if (request.Quantity <= 0)
// {
// return new StockOperationCommandResponse
// {
// StatusCode = (int)HttpStatusCode.BadRequest,
// Success = false,
// StateMessages = new string[]
// {
// "Stok miktarı sıfırdan büyük olmalıdır."
// }
// };
// }

// switch (request.OperationType)
// {
// case StockOperationType.Increase:
// existingBookStock.Quantity += request.Quantity;
// break;
// case StockOperationType.Decrease:
// if (existingBookStock.Quantity < request.Quantity)
// {
// return new()
// {
// StatusCode = 400,
// Success = false,
// StateMessages = new string[]
// {
// "Stok miktarı talep edilen miktardan az."
// }
// };
// }
// existingBookStock.Quantity -= request.Quantity;
// break;
// default:
// return new()
// {
// StatusCode = 400,
// Success = false,
// StateMessages = new string[]
// {
// "Bilinmeyen işlem türü. Lütfen geçerli bir işlem türü belirtin."
// }
// };
// break;
// }

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

var existingBookStock = await readRepository.GetSingleAsync(
s => s.BookId == request.BookId
);
if (existingBookStock != null)
{
if (request.Quantity <= 0)
{
return new StockOperationCommandResponse
{
StatusCode = (int)HttpStatusCode.BadRequest,
Success = false,
StateMessages = new string[]
{
"Stok miktarı sıfırdan büyük olmalıdır."
}
};
}

switch (request.OperationType)
{
case StockOperationType.Increase:
existingBookStock.Quantity += request.Quantity;
break;
case StockOperationType.Decrease:
if (existingBookStock.Quantity < request.Quantity)
{
return new()
{
StatusCode = 400,
Success = false,
StateMessages = new string[]
{
"Stok miktarı talep edilen miktardan az."
}
};
}
existingBookStock.Quantity -= request.Quantity;
break;
default:
return new()
{
StatusCode = 400,
Success = false,
StateMessages = new string[]
{
"Bilinmeyen işlem türü. Lütfen geçerli bir işlem türü belirtin."
}
};
break;
}

await writeRepository.UpdateAsync(existingBookStock);
}
else
{
var newBookStock = new Domain.Entities.Library.BookStockOLD()
{
Id = request.BookId,
Quantity = request.Quantity,
};
await writeRepository.AddAsync(newBookStock);
}

return new()
{
StatusCode = 200,
Success = true,
StateMessages = new string[] { "Kitap Stok kaydı başarıyla güncellendi." }
};
}
// await writeRepository.UpdateAsync(existingBookStock);
// }
// else
// {
// var newBookStock = new Domain.Entities.Library.BookStockOLD()
// {
// Id = request.BookId,
// Quantity = request.Quantity,
// };
// await writeRepository.AddAsync(newBookStock);
// }

// return new()
// {
// StatusCode = 200,
// Success = true,
// StateMessages = new string[] { "Kitap Stok kaydı başarıyla güncellendi." }
// };



return new()
{
StatusCode = 200,
Success = false,
StateMessages = new string[] { $"" }
};
}

catch (Exception ex)
{
return new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CancellationToken cancellationToken
var stockDecreaseResponse = await _mediator.Send(
new StockOperationCommandRequest
{
BookId = borrowedBook.BookId,
BookId = borrowedBook.WorkCatalogId,
OperationType = StockOperationType.Increase,
Quantity = 1,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace LibraryTrackingApp.Application.Features.BookGenres.Behaviors.Mapping;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Behaviors.Mapping;

public class BookGenreMappingProfile : Profile
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Requests;


namespace LibraryTrackingApp.Application.Features.BookGenres.Behaviors.Validator;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Behaviors.Validator;

public class CreateBookGenreCommandRequestValidator : AbstractValidator<CreateBookGenreCommandRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Requests;


namespace LibraryTrackingApp.Application.Features.BookGenres.Behaviors.Validator;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Behaviors.Validator;

public class DeleteBookGenreCommandRequestValidator : AbstractValidator<DeleteBookGenreCommandRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Requests;


namespace LibraryTrackingApp.Application.Features.BookGenres.Behaviors.Validator;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Behaviors.Validator;

public class UpdateBookGenreCommandRequestValidator : AbstractValidator<UpdateBookGenreCommandRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Responses;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;
using LibraryTrackingApp.Domain.Entities;

namespace LibraryTrackingApp.Application.Features.BookGenres.Commands.Handlers;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Commands.Handlers;


public class CreateBookGenreCommandHandler : IRequestHandler<CreateBookGenreCommandRequest, CreateBookGenreCommandResponse>
Expand Down Expand Up @@ -40,7 +40,7 @@ public async Task<CreateBookGenreCommandResponse> Handle(CreateBookGenreCommandR
var newBookGenre = new Domain.Entities.Library.WorkGenre()
{
Name = request.Name,
IsActive= request.IsActive,
IsActive = request.IsActive,
IsDeleted = false,
CreatedById = Guid.NewGuid(),//staff id olucak ilerde
LastModifiedById = Guid.NewGuid(),//staff id olucak ilerde
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Responses;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;

namespace LibraryTrackingApp.Application.Features.BookGenres.Commands.Handlers;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Commands.Handlers;


public class DeleteBookGenreCommandHandler : IRequestHandler<DeleteBookGenreCommandRequest, DeleteBookGenreCommandResponse>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Responses;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Requests;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;
using LibraryTrackingApp.Domain.Entities;

namespace LibraryTrackingApp.Application.Features.BookGenres.Commands.Handlers;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Commands.Handlers;


public class UpdateBookGenreCommandHandler : IRequestHandler<UpdateBookGenreCommandRequest, UpdateBookGenreCommandResponse>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Responses;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Responses;

namespace LibraryTrackingApp.Application.Features.BookGenres.Commands.Requests;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Commands.Requests;

public class CreateBookGenreCommandRequest : IRequest<CreateBookGenreCommandResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LibraryTrackingApp.Application.Features.BookGenres.Commands.Responses;
using LibraryTrackingApp.Application.Features.WorkGenres.Commands.Responses;

namespace LibraryTrackingApp.Application.Features.BookGenres.Commands.Requests;
namespace LibraryTrackingApp.Application.Features.WorkGenres.Commands.Requests;

public class DeleteBookGenreCommandRequest : IRequest<DeleteBookGenreCommandResponse>
{
Expand Down
Loading
Loading