Skip to content

Commit

Permalink
Update: Removal of BookStock Entity. Code Refactoring.
Browse files Browse the repository at this point in the history
-  Change: BookStock entity has been removed from the project.
-  Description: The BookStock entity has been successfully removed from the project as planned. All relevant references and associations have been updated accordingly. This change has been completed successfully.
  • Loading branch information
ilyasbozdemir committed May 1, 2024
1 parent eaf8ff6 commit d451838
Show file tree
Hide file tree
Showing 119 changed files with 681 additions and 15,405 deletions.

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

0 comments on commit d451838

Please sign in to comment.