Skip to content

Commit

Permalink
feat: revert buying status
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Jul 13, 2024
1 parent 3081ce7 commit dd63aee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions App/Modules/Bookings/API/V1/BookingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ IAuthHelper helper
[Authorize, HttpGet]
public async Task<ActionResult<IEnumerable<BookingPrincipalRes>>> Search([FromQuery] SearchBookingQuery query)
{

var x = await this
.GuardOrAnyAsync(query.UserId, AuthRoles.Field, AuthRoles.Admin)
.ThenAwait(_ => bookingSearchQueryValidator.ValidateAsyncResult(query, "Invalid SearchBookingQuery"))
Expand All @@ -59,6 +58,15 @@ public async Task<ActionResult<IEnumerable<BookingPrincipalRes>>> ListRefunds()
return this.ReturnResult(x);
}

[Authorize(Policy = AuthPolicies.AdminOrTin)]
[HttpPost("revert/{id:guid}")]
public async Task<ActionResult<BookingPrincipalRes>> Revert(Guid id)
{
var x = await service.RevertBuying(id)
.Then(x => x?.ToRes(), Errors.MapAll);
return this.ReturnNullableResult(x, new EntityNotFound("Booking not found", typeof(Booking), id.ToString()));
}

[Authorize(Policy = AuthPolicies.AdminOrTin)]
[HttpGet("reserve/{Direction}/{Date}/{Time}")]
public async Task<ActionResult<BookingPrincipalRes>> Reserve([FromRoute] ReserveBookingQuery query)
Expand Down Expand Up @@ -170,7 +178,8 @@ public async Task<ActionResult<BookingPrincipalRes>> Terminate(Guid id, string?
{
var p = await this
.GuardOrAllAsync(userId, AuthRoles.Field, AuthRoles.Admin)
.ThenAwait(cr => service.Terminate(userId, id, DateTime.UtcNow.Add(TimeSpan.FromMinutes(terminatorOptions.Value.MinBuffer))))
.ThenAwait(cr =>
service.Terminate(userId, id, DateTime.UtcNow.Add(TimeSpan.FromMinutes(terminatorOptions.Value.MinBuffer))))
.Then(b => b?.ToRes(), Errors.MapNone);

return this.ReturnNullableResult(p,
Expand Down
2 changes: 2 additions & 0 deletions Domain/Booking/IService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface IBookingService

Task<Result<BookingPrincipal?>> Buying(Guid id);

Task<Result<BookingPrincipal?>> RevertBuying(Guid id);

Task<Result<BookingPrincipal?>> Complete(Guid id, string bookingNo, string ticketNo, Stream ticketFile);

Task<Result<BookingPrincipal?>> Cancel(string? userId, Guid id);
Expand Down
6 changes: 6 additions & 0 deletions Domain/Booking/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public Task<Result<BookingPrincipal>> Create(string userId, decimal cost, Bookin
.DoAwait(DoType.Ignore, _ => cdcRepository.Add("reserve"));
}

public Task<Result<BookingPrincipal?>> RevertBuying(Guid id)
{
return repo.Update(null, id, new BookingStatus() { Status = BookStatus.Pending, CompletedAt = null }, null, null)
.DoAwait(DoType.Ignore, _ => cdcRepository.Add("create"));
}

// This marks the ticket in the bought status, need to move $$
public Task<Result<BookingPrincipal?>> Complete(Guid id, string bookingNo, string ticketNo, Stream file)
{
Expand Down

0 comments on commit dd63aee

Please sign in to comment.