Commit c42016bf authored by adnansetiawan's avatar adnansetiawan
Browse files

Merge remote-tracking branch 'origin/development' into feature/unit-testing-for-api

* origin/development:
  retur total when stop parking
  return total on stop parking transaction
parents 77d1d93c de2f0f2b
......@@ -62,21 +62,24 @@ namespace EasyParking.API.Controllers
/// </summary>
/// <param name="stopParkingRequest"></param>
/// <returns></returns>
/// <response code="200">Returns boolean succes or not</response>
/// <response code="200">Returns parking detail</response>
[HttpPost("transaction/stop")]
[ProducesResponseType(typeof(bool), 200)]
[ProducesResponseType(typeof(ParkingTransactionDto), 200)]
public IActionResult Stop(StopParkingRequest stopParkingRequest)
{
ParkingTransactionDto parkingTransactionDto = null;
try
{
_parkingService.StopParking(stopParkingRequest.LicensePlate,
stopParkingRequest.InputedById);
var parking = _parkingService.StopParking(stopParkingRequest.LicensePlate,
stopParkingRequest.InputedById);
parkingTransactionDto = parking.MapToDto();
}
catch (Exception ex)
{
return new BadRequestObjectResult(ex.Message);
}
return new OkObjectResult(true);
return new OkObjectResult(parkingTransactionDto);
}
/// <summary>
......
......@@ -10,6 +10,7 @@ namespace EasyParking.API.Dtos
public DateTime? StopTime { get; set; }
public TimeSpan Duration { get; set; }
public bool HasStopped { get; set; }
public decimal Total { get; set; }
public UserDto InputedBy { get; set; }
}
}
......@@ -16,7 +16,8 @@ namespace EasyParking.API.Mapper
LicensePlate = parkingTransaction.LicensePlate,
Slot = parkingTransaction.Slot.MapToDto(),
StartTime = parkingTransaction.StartTime,
StopTime = parkingTransaction.StopTime
StopTime = parkingTransaction.StopTime,
Total = parkingTransaction.Total
};
}
}
......
......@@ -36,7 +36,7 @@ namespace EasyParking.Core.Parking
{
return _parkingRepository.GetActiveParkingByPlate(licensePlate);
}
public void StopParking(string licensePlate, Guid inputedBy)
public ParkingTransaction StopParking(string licensePlate, Guid inputedBy)
{
var user = _userRepository.GetByUserId(inputedBy);
if (user == null)
......@@ -47,7 +47,7 @@ namespace EasyParking.Core.Parking
_parkingRepository.SetStopTime(activeParking.Id);
_slotRepository.SetAvailable(activeParking.Slot.Id, true);
return _parkingRepository.GetById(activeParking.Id);
}
}
}
......@@ -24,6 +24,15 @@ namespace EasyParking.Core
return StopTime.HasValue;
}
}
public decimal Total
{
get
{
if (Slot.Zona.Rate == null)
return 0;
return (Slot.Zona.Rate.Price * Duration.Hours) + Slot.Zona.Rate.Price;
}
}
public User InputedBy { get; set; }
}
......
......@@ -90,8 +90,10 @@ namespace EasyParking.Infrastructure.Mapper
InputedBy = parkingTransaction.InputedBy.MapToEntity(),
Slot = parkingTransaction.Slot.MapToEntity(),
StartTime = parkingTransaction.StartTime,
StopTime = parkingTransaction.StopTime
StopTime = parkingTransaction.StopTime,
};
}
}
public static class CustomerMapper
......
......@@ -35,6 +35,7 @@ namespace EasyParking.Infrastructure.Repositories
.Include(x => x.Slot)
.Include(x => x.Slot.Zona)
.Include(x => x.Slot.Zona.Location)
.Include(x => x.Slot.Zona.Rate)
.Include(x => x.InputedBy)
.Include(x => x.InputedBy.UserRole)
.FirstOrDefault(x => x.LicensePlate.ToLower()
......@@ -45,10 +46,11 @@ namespace EasyParking.Infrastructure.Repositories
public Core.ParkingTransaction GetById(Guid parkingTransactionId)
{
var response = _dbContext.ParkingTransactions
.Include(x => x.Slot.Zona).Include(x => x.Slot.Zona.Location)
.Include(x => x.Slot.Zona).Include(x => x.Slot.Zona.Location).Include(x => x.Slot.Zona.Rate)
.Include(x => x.InputedBy)
.Include(x => x.InputedBy.UserRole)
.FirstOrDefault(x => x.Id == parkingTransactionId);
return response?.MapToEntity() ?? null;
}
......@@ -57,6 +59,7 @@ namespace EasyParking.Infrastructure.Repositories
return _dbContext.ParkingTransactions
.Include(x => x.Slot.Zona)
.Include(x => x.Slot.Zona.Location)
.Include(x => x.Slot.Zona.Rate)
.Include(x => x.InputedBy)
.Include(x => x.InputedBy.UserRole)
.Select(x => x.MapToEntity()).ToList();
......@@ -65,9 +68,6 @@ namespace EasyParking.Infrastructure.Repositories
public void SetStopTime(Guid parkingTransactionId)
{
var activeParkingByPlate = _dbContext.ParkingTransactions
.Include(x => x.Slot.Zona).Include(x => x.Slot.Zona.Location)
.Include(x => x.InputedBy)
.Include(x => x.InputedBy.UserRole)
.FirstOrDefault(x => x.Id == parkingTransactionId);
if (activeParkingByPlate != null)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment