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

feat: create delivery endpoint #133

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -7,18 +7,12 @@ public sealed class EntityCreatedResponse
/// Gets the entity identifier.
/// </summary>
public Guid Id { get; }

public int IntId { get; }
public List<int> IntIds { get; }
#endregion

#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="EntityCreatedResponse"/> class.
/// </summary>
/// <param name="id">The entity identifier.</param>
public EntityCreatedResponse(Guid id) => Id = id;

public EntityCreatedResponse(int id) => IntId = id;
public EntityCreatedResponse(List<int> ids) => IntIds = ids;
#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Dhanman.MyHome.Application.Contracts.DeliveryPersons;

public class CreateDeliveryPersonRequest
{
#region Properties
public string Name { get; set; }
public string CompanyName { get; set; }
public string MobileNumber { get; set; }

#endregion

#region Constructors
public CreateDeliveryPersonRequest(string name, string companyName, string mobileNumber)
{
Name = name;
CompanyName = companyName;
MobileNumber = mobileNumber;
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void Update<TEntity>(TEntity entity)
DbSet<TEntity> SetInt<TEntity>()
where TEntity : EntityInt;

Task<TEntity?> GetBydIdIntAsync<TEntity>(int id)
Task<TEntity?> GetByIdIntAsync<TEntity>(int id)
where TEntity : EntityInt;

void InsertInt<TEntity>(TEntity entity)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using B2aTech.CrossCuttingConcern.Core.Result;
using Dhanman.MyHome.Application.Abstractions.Messaging;
using Dhanman.MyHome.Application.Contracts.Common;
namespace Dhanman.MyHome.Application.Features.DeliveryPersons.Commands.CreateDeliveryPerson;

public class CreateDeliveryPersonCommand : ICommand<Result<EntityCreatedResponse>>
{
#region Properties
public string Name { get; set; }
public string CompanyName { get; set; }
public string MobileNumber { get; set; }

#endregion

#region Constructors
public CreateDeliveryPersonCommand( string name, string companyName, string mobileNumber)
{
Name = name;
CompanyName = companyName;
MobileNumber = mobileNumber;
}

#endregion
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using B2aTech.CrossCuttingConcern.Core.Result;
using Dhanman.MyHome.Application.Abstractions.Data;
using Dhanman.MyHome.Application.Abstractions.Messaging;
using Dhanman.MyHome.Application.Contracts.Common;
using Dhanman.MyHome.Application.Features.DeliveryPersons.Events;
using Dhanman.MyHome.Domain.Abstractions;
using Dhanman.MyHome.Domain.Entities.Deliveries;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace Dhanman.MyHome.Application.Features.DeliveryPersons.Commands.CreateDeliveryPerson;

public class CreateDeliveryPersonCommandHandler : ICommandHandler<CreateDeliveryPersonCommand, Result<EntityCreatedResponse>>
{
#region Properties
private readonly IDeliveryPersonRepository _deliveryPersonRepository;
private readonly IMediator _mediator;
#endregion

#region Constructors
public CreateDeliveryPersonCommandHandler(IDeliveryPersonRepository deliveryPersonRepository, IMediator mediator)
{
_deliveryPersonRepository = deliveryPersonRepository;
_mediator = mediator;
}
#endregion

#region Methods
public async Task<Result<EntityCreatedResponse>> Handle(CreateDeliveryPersonCommand request, CancellationToken cancellationToken)
{
var deliveryPersonRequest = new DeliveryPerson(request.Name, request.CompanyName, request.MobileNumber);
_deliveryPersonRepository.Insert(deliveryPersonRequest);

await _mediator.Publish(new DeliveryPersonCreatedEvent(deliveryPersonRequest.Id), cancellationToken);
return Result.Success(new EntityCreatedResponse(deliveryPersonRequest.Id));
}
#endregion
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Dhanman.MyHome.Domain.Abstractions;
using FluentValidation;
namespace Dhanman.MyHome.Application.Features.DeliveryPersons.Commands.CreateDeliveryPerson;

public class CreateDeliveryPersonCommandValidator : AbstractValidator<CreateDeliveryPersonCommand>
{
public CreateDeliveryPersonCommandValidator(IDeliveryPersonRepository deliveryPersonRepository)
{
RuleFor(c => c.Name)
.NotEmpty().WithMessage("The Name is required.");

RuleFor(c => c.CompanyName)
.NotEmpty().WithMessage("The Company Name is required.");

RuleFor(c => c.MobileNumber)
.NotEmpty().WithMessage("The Mobile Number is required.");

RuleFor(c => c.MobileNumber)
.MustAsync(async (mobileNumber, cancellation) => await deliveryPersonRepository.IsUniqueMobileNumber(mobileNumber, cancellation))
.WithMessage("The Mobile Number must be unique.");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Dhanman.MyHome.Application.Abstractions.Messaging;

namespace Dhanman.MyHome.Application.Features.DeliveryPersons.Events;

public sealed class DeliveryPersonCreatedEvent : IEvent
{
#region Properties
public int DeliveryPersonId { get; }

#endregion

#region Constructors
public DeliveryPersonCreatedEvent(int deliveryPersonId) => DeliveryPersonId = deliveryPersonId;

#endregion
}






Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public UpdateRequestApproveStatusCommandHandler(IResidentRequestRepository resid
#region Methods
public async Task<Result<EntityUpdatedResponse>> Handle(UpdateRequestApproveStatusCommand request, CancellationToken cancellationToken)
{
var updateRequestApproveStatus = await _residentRequestRepository.GetBydIdIntAsync(request.Id);
var updateRequestApproveStatus = await _residentRequestRepository.GetByIdIntAsync(request.Id);

if (updateRequestApproveStatus is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public UpdateRequestRejectStatusCommandHandler(IResidentRequestRepository reside
#region Methods
public async Task<Result<EntityUpdatedResponse>> Handle(UpdateRequestRejectStatusCommand request, CancellationToken cancellationToken)
{
var updateRequestRejectStatus = await _residentRequestRepository.GetBydIdIntAsync(request.Id);
var updateRequestRejectStatus = await _residentRequestRepository.GetByIdIntAsync(request.Id);

if (updateRequestRejectStatus is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DeleteUnitCommandHandler(IUnitRepository unitRepository, IMediator mediat
#region Methods
public async Task<Result<EntityDeletedResponse>> Handle(DeleteUnitCommand request, CancellationToken cancellationToken)
{
var updateUnits = await _unitRepository.GetBydIdIntAsync(request.UnitId);
var updateUnits = await _unitRepository.GetByIdIntAsync(request.UnitId);

if (updateUnits == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public UpdateUnitCommandHandler(IUnitRepository unitRepository, IMediator mediat
#region Methods
public async Task<Result<EntityUpdatedResponse>> Handle(UpdateUnitCommand request, CancellationToken cancellationToken)
{
var updateUnits = await _unitRepository.GetBydIdIntAsync(request.UnitId);
var updateUnits = await _unitRepository.GetByIdIntAsync(request.UnitId);

if (updateUnits == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IBookingFacilitesRepository
{
#region Methodes
Task<BookingFacilitie?> GetBydIdIntAsync(int id);
Task<BookingFacilitie?> GetByIdIntAsync(int id);
#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Dhanman.MyHome.Domain.Entities.Deliveries;

namespace Dhanman.MyHome.Domain.Abstractions;

public interface IDeliveryPersonRepository
{
Task<DeliveryPerson?> GetByIdAsync(int id);

void Insert(DeliveryPerson person);

Task<bool> IsUniqueMobileNumber(string mobileNumber, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IOccupancyTypeRepository
{
#region Methods
Task<OccupancyType?> GetBydIdIntAsync(int id);
Task<OccupancyType?> GetByIdIntAsync(int id);
Task<int> GetBydNameAsync(string occupancyType);
void Insert(OccupantType occupancyType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IOccupantTypeRepository
{
#region Methods
Task<OccupantType?> GetBydIdIntAsync(int id);
Task<OccupantType?> GetByIdIntAsync(int id);
Task<int> GetBydNameAsync(string occupantType);
void Insert(OccupantType occupantType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IResidentRepository
{
#region Methods
Task<Resident?> GetBydIdIntAsync(int id);
Task<Resident?> GetByIdIntAsync(int id);

void Insert(Resident resident);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IResidentRequestRepository
{
#region Methods
Task<ResidentRequest?> GetBydIdIntAsync(int id);
Task<ResidentRequest?> GetByIdIntAsync(int id);

void Insert(ResidentRequest residentRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IResidentUnitRepository
{
#region Methods
Task<ResidentUnit?> GetBydIdIntAsync(int id);
Task<ResidentUnit?> GetByIdIntAsync(int id);

void Insert(ResidentUnit residentUnit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IServiceProviderRepository
{
#region Methods
Task<ServiceProvider?> GetBydIdIntAsync(int id);
Task<ServiceProvider?> GetByIdIntAsync(int id);

void Insert(ServiceProvider serviceProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IUnitRepository
{
#region Methods
Task<Unit?> GetBydIdIntAsync(int id);
Task<Unit?> GetByIdIntAsync(int id);

void Insert(Unit unit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IUnitServiceProviderRespository
{
#region Methods
Task<UnitServiceProvider?> GetBydIdIntAsync(int id);
Task<UnitServiceProvider?> GetByIdIntAsync(int id);

void InsertInt(UnitServiceProvider unitServiceProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Dhanman.MyHome.Domain.Abstractions;
public interface IUnitTypeRepository
{
#region Methods
Task<UnitType?> GetBydIdIntAsync(int id);
Task<UnitType?> GetByIdIntAsync(int id);
Task<int> GetBydNameAsync(string unitType);
void Insert(UnitType unitType);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using B2aTech.CrossCuttingConcern.Core.Abstractions;
using B2aTech.CrossCuttingConcern.Core.Primitives;

namespace Dhanman.MyHome.Domain.Entities.Deliveries;

public class DeliveryPerson : EntityInt,ISoftDeletableEntity,IAuditableEntity
{
#region Properties
public string Name { get; set; }
public string CompanyName { get; set; }
public string MobileNumber { get; set; }
public Guid CreatedBy { get; protected set; }
public DateTime CreatedOnUtc { get; }
public Guid? ModifiedBy { get; protected set; }
public DateTime? ModifiedOnUtc { get; }
public DateTime? DeletedOnUtc { get; }
public bool IsDeleted { get; }
#endregion

#region Constructor
public DeliveryPerson(string name, string companyName, string mobileNumber)
{
Name = name;
CompanyName = companyName;
MobileNumber = mobileNumber;
}
#endregion

}
30 changes: 30 additions & 0 deletions src/Core/Dhanman.MyHome.Domain/Entities/Deliveries/Pin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using B2aTech.CrossCuttingConcern.Core.Primitives;

namespace Dhanman.MyHome.Domain.Entities.Deliveries;

public class Pin : EntityInt
{
#region Properties
public string PinCode { get; set; }
public int? ServiceProviderId { get; set; }
public int? VisitorId { get; set; }
public int? DeliveryId { get; set; }
public DateTime EffectiveStartDateTime { get; set; }
public DateTime? EffectiveEndDateTime { get; set; }
#endregion

#region Contructors
public Pin() { }
public Pin(int id, int serviceProviderId, int visitorId, int deliveryId, string pinCode, DateTime effectiveStartDateTime, DateTime effectiveEndDateTime)
{
Id = id;
ServiceProviderId = serviceProviderId;
VisitorId = visitorId;
DeliveryId = deliveryId;
PinCode = pinCode;
EffectiveStartDateTime = effectiveStartDateTime;
EffectiveEndDateTime = effectiveEndDateTime;
}
#endregion

}
7 changes: 7 additions & 0 deletions src/Dhanman.MyHome.Api/Contracts/ApiRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,12 @@ public static class BuildingsTypes
{
public const string GetAllBuildingTypes = apiVersion + "buildingTypes";
}


public static class DeliveryPersons
{
public const string CreateDeliveryPerson = apiVersion + "DeliveryPerson";
}

}

Loading