Skip to content

Commit

Permalink
Merge pull request #21 from ilyasbozdemir/case-project
Browse files Browse the repository at this point in the history
Add report loss, damage, and renew book commands
  • Loading branch information
ilyasbozdemir authored Apr 29, 2024
2 parents 57536e3 + 15e5793 commit 70ab638
Show file tree
Hide file tree
Showing 33 changed files with 1,410 additions and 476 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibraryTrackingApp.Application.Features.BorrowLend.Queries.Requests;

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


public class GetAllBorrowsQueryRequestValidator : AbstractValidator<GetAllBorrowsQueryRequest>
{
internal class GetAllBorrowsQueryRequestValidator
public GetAllBorrowsQueryRequestValidator()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using LibraryTrackingApp.Application.Features.BorrowLend.Queries.Requests;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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


public class GetBorrowByIdQueryRequestValidator : AbstractValidator<GetBorrowByIdQueryRequest>
{
internal class GetBorrowByIdQueryRequestValidator
{
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Requests;


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


public class RenewBorrowCommandRequestValidator : AbstractValidator<RenewBorrowCommandRequest>
{
public RenewBorrowCommandRequestValidator()
{
RuleFor(x => x.BorrowId).NotEmpty().WithMessage("BorrowId boş olamaz.");
RuleFor(x => x.RenewalDurationInDays).NotEmpty().GreaterThan(0).WithMessage("Yenileme süresi boş olamaz ve 0'dan büyük olmalıdır.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Requests;


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

public class ReportDamageBookCommandRequestValidator : AbstractValidator<ReportDamageBookCommandRequest>
{
public ReportDamageBookCommandRequestValidator()
{
RuleFor(x => x.BorrowId).NotEmpty().WithMessage("BorrowId boş olamaz.");
RuleFor(x => x.DamageDescription).NotEmpty().WithMessage("Hasar açıklaması boş olamaz.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CancellationToken cancellationToken

if (!existingBook || !existingMember || !existingStaff)
{
return new ()
return new()
{
StatusCode = (int)HttpStatusCode.BadRequest,
Success = false,
Expand Down Expand Up @@ -118,7 +118,7 @@ CancellationToken cancellationToken

if (givenBookResult)
{
return new ()
return new()
{
StatusCode = (int)HttpStatusCode.OK,
Success = true,
Expand All @@ -127,7 +127,7 @@ CancellationToken cancellationToken
}
else
{
return new ()
return new()
{
StatusCode = (int)HttpStatusCode.BadRequest,
Success = true,
Expand All @@ -137,7 +137,7 @@ CancellationToken cancellationToken
}
else
{
return new ()
return new()
{
StatusCode = stockDecreaseResponse.StatusCode,
Success = stockDecreaseResponse.Success,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Requests;
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;

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

public class RenewBorrowCommandHandler
: IRequestHandler<RenewBorrowCommandRequest, RenewBorrowCommandResponse>
{
private readonly IUnitOfWork<Guid> _unitOfWork;
private readonly IMediator _mediator;
private readonly IMapper _mapper;

public RenewBorrowCommandHandler(
IUnitOfWork<Guid> unitOfWork,
IMapper mapper,
IMediator mediator
)
{
_unitOfWork = unitOfWork;
_mediator = mediator;
_mapper = mapper;
}

//yazılcak daha burası

public async Task<RenewBorrowCommandResponse> Handle(
RenewBorrowCommandRequest request,
CancellationToken cancellationToken
)
{
try
{
return new() { };
}
catch (Exception ex)
{
return new()
{
StatusCode = 500,
Success = false,
StateMessages = new[] { $"Bir hata oluştu: {ex.Message}" }
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Requests;
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;

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

public class ReportDamageBookCommandHandler
: IRequestHandler<ReportDamageBookCommandRequest, ReportDamageBookCommandResponse>
{
private readonly IUnitOfWork<Guid> _unitOfWork;
private readonly IMediator _mediator;
private readonly IMapper _mapper;

public ReportDamageBookCommandHandler(
IUnitOfWork<Guid> unitOfWork,
IMapper mapper,
IMediator mediator
)
{
_unitOfWork = unitOfWork;
_mediator = mediator;
_mapper = mapper;
}

public async Task<ReportDamageBookCommandResponse> Handle(
ReportDamageBookCommandRequest request,
CancellationToken cancellationToken
)
{
var response = new ReportDamageBookCommandResponse
{
StatusCode = 200,
Success = true,
StateMessages = new string[] { "Hasar raporu başarıyla oluşturuldu." }
};

return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Requests;
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;
using LibraryTrackingApp.Application.Interfaces.UnitOfWork;

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

public class ReportLossBookCommandHandler
: IRequestHandler<ReportLossBookCommandRequest, ReportLossBookCommandResponse>
{
private readonly IUnitOfWork<Guid> _unitOfWork;
private readonly IMediator _mediator;
private readonly IMapper _mapper;

public ReportLossBookCommandHandler(
IUnitOfWork<Guid> unitOfWork,
IMapper mapper,
IMediator mediator
)
{
_unitOfWork = unitOfWork;
_mediator = mediator;
_mapper = mapper;
}

public async Task<ReportLossBookCommandResponse> Handle(
ReportLossBookCommandRequest request,
CancellationToken cancellationToken
)
{
try
{
return new() { };
}
catch (Exception ex)
{
return new()
{
StatusCode = 500,
Success = false,
StateMessages = new[] { $"Bir hata oluştu: {ex.Message}" }
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ CancellationToken cancellationToken
{
borrowedBook.LateDurationInDays = (int?)
(borrowedBook.ReturnDate - borrowedBook.DueDate)?.TotalDays;
borrowedBook.BorrowStatus = BorrowStatus.DelayedReturn;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;

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

public class RenewBorrowCommandRequest : IRequest<RenewBorrowCommandResponse>
{
public Guid BorrowId { get; set; }
public int RenewalDurationInDays { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;

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

public class ReportDamageBookCommandRequest : IRequest<ReportDamageBookCommandResponse>
{
public Guid BorrowId { get; set; }
public string DamageDescription { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;

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

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


namespace LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;

public class RenewBorrowCommandResponse : CommandResult { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using LibraryTrackingApp.Application.Shared.Wrappers.Results;

namespace LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;
public class ReportDamageBookCommandResponse : CommandResult { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using LibraryTrackingApp.Application.Shared.Wrappers.Results;

namespace LibraryTrackingApp.Application.Features.BorrowLend.Commands.Responses;
public class ReportLossBookCommandResponse : CommandResult { }
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace LibraryTrackingApp.Application.Features.BorrowLend.Queries.Requests
{
internal class GetAllBorrowsQueryRequest
public class GetAllBorrowsQueryRequest
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace LibraryTrackingApp.Application.Features.BorrowLend.Queries.Requests
{
internal class GetBorrowByIdQueryRequest
public class GetBorrowByIdQueryRequest
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ public class Book : BaseEntity<Guid>, IAuditable<Guid>
public Guid AuthorId { get; set; }
public Guid LibraryBranchId { get; set; }
public Guid BookStockId { get; set; }
public Guid BorrowId { get; set; }

public string BookNumber { get; set; }
public string Title { get; set; }
public string ISBN { get; set; }
public string Description { get; set; }
Expand All @@ -36,4 +34,6 @@ public class Book : BaseEntity<Guid>, IAuditable<Guid>
public ICollection<Author> Authors { get; set; }
public ICollection<BookStock> BookStocks { get; set; }
public ICollection<BorrowLend> Borrows { get; set; }
public ICollection<BookEntry> BookEntries { get; set; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace LibraryTrackingApp.Domain.Entities.Library;


//bookstock tablosu kalkıcaktır. stokları teker teker aynı kitapta da verilen numaralar ile ayırarak burda da bunu girerek
// yapılcaktır stok adedi bu şekilde olucaktır.
public class BookEntry : BaseEntity<Guid>, IAuditable<Guid>
{
public Guid Id { get; set; }
public Guid BookId { get; set; }
public string BookNumber { get; set; }
public BookStatus BookStatus { get; set; }
public BookFormat BookFormat { get; set; }
public BookLanguage BookLanguage { get; set; }
public bool IsAvailable { get; set; }

public DateTime EntryDate { get; set; }
public DateTime LastModified { get; set; }

public Book Book { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ public class BorrowLend : BaseEntity<Guid>, IAuditable<Guid>
public Guid MemberId { get; set; }
public Guid LenderId { get; set; }
public DateTime BorrowDate { get; set; }
public DateTime DueDate { get; set; }
public DateTime DueDate { get; set; }
public DateTime? ReturnDate { get; set; }
public BorrowStatus BorrowStatus { get; set; }

public bool HasFee { get; set; }
public decimal FeeAmount { get; set; }
public TimeSpan TimeElapsedSinceBorrowDate => DateTime.Now - BorrowDate;


public DateTime? ReturnDate { get; set; }

public bool? IsLate { get; set; }
public int? LateDurationInDays { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ public enum BookStatus
/// Kitap pasif durumda.
/// </summary>
Inactive = 1 << 1, // 2

/// <summary>
/// Kitap hasarlı durumda.
/// </summary>
Damaged = 1 << 2, // 4

/// <summary>
/// Kitap kayıp durumda.
/// </summary>
Lost = 1 << 3, // 8
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ public enum BorrowLendType
{
Taken,
Given,
Renewed,
Damaged,
Lost,
FetchedSingle,
FetchedAll,
}
Loading

0 comments on commit 70ab638

Please sign in to comment.