Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using FlightBooking.Service.Data.DTO;
using FlightBooking.Service.Services;
using FlightBooking.Service.Services.Interfaces;
using Microsoft.AspNetCore.Mvc;
using System.Net.Mime;
namespace FlightBooking.Service.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BookingsController : ControllerBase
{
private readonly IBookingService _bookingService;
private readonly IBookingOrderService _bookingOrderService;
public BookingsController(IBookingService bookingService, IBookingOrderService bookingOrderService)
{
_bookingService = bookingService;
_bookingOrderService = bookingOrderService;
}
[HttpGet("bookingNumber/{bookingNumber}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookingDTO))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ProblemDetails))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
public async Task<IActionResult> GetBookingsByBookingNumber([FromRoute] string bookingNumber)
{
ServiceResponse<BookingDTO?> result = await _bookingService.GetBookingByBookingNumberAsync(bookingNumber);
return result.FormatResponse();
}
[HttpGet("email/{email}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<BookingDTO>))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
public IActionResult GetBookingsByEmail([FromRoute] string email)
{
ServiceResponse<IEnumerable<BookingDTO>?> result = _bookingService.GetBookingsByEmail(email);
return result.FormatResponse();
}
[HttpGet("orderNumber/{orderNumber}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<BookingDTO>))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
public IActionResult GetBookingsByOrderNumber([FromRoute] string orderNumber)
{
ServiceResponse<IEnumerable<BookingDTO>?> result = _bookingService.GetBookingsByOrderNumber(orderNumber);
return result.FormatResponse();
}
[HttpGet("id/{bookingId}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookingDTO))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ProblemDetails))]
public async Task<IActionResult> GetBookingById([FromRoute] int bookingId)
{
ServiceResponse<BookingDTO?> result = await _bookingService.GetBookingByBookingId(bookingId);
return result.FormatResponse();
}
[HttpPost]
[Consumes(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookingResponseDTO))]
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity, Type = typeof(ProblemDetails))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
[ProducesResponseType(StatusCodes.Status500InternalServerError, Type = typeof(ProblemDetails))]
public async Task<IActionResult> PostBooking([FromBody] BookingOrderDTO bookingOrderDTO)
{
ServiceResponse<BookingResponseDTO?> result = await _bookingOrderService.CreateBookingOrderAsync(bookingOrderDTO);
return result.FormatResponse();
}
[HttpGet("payment/{orderNumber}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(BookingResponseDTO))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ProblemDetails))]
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity, Type = typeof(ProblemDetails))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
public async Task<IActionResult> GetBookingPayment([FromRoute] string orderNumber)
{
ServiceResponse<BookingResponseDTO?> result = await _bookingOrderService.GetCheckoutUrlAsync(orderNumber);
return result.FormatResponse();
}
}
}