Skip to content

Commit

Permalink
Merge pull request #33 from Leen-odeh3/Refactor
Browse files Browse the repository at this point in the history
Refactor code "Update Calculate Discounted Price after booking for rooms"
  • Loading branch information
Leen-odeh3 authored Aug 24, 2024
2 parents ef9f72c + 35d9d3d commit 0a83975
Show file tree
Hide file tree
Showing 84 changed files with 23,918 additions and 1,084 deletions.
7 changes: 0 additions & 7 deletions HotelBookingPlatform.API/Controllers/AmenityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ public AmenityController(IAmenityService amenityService, IResponseHandler respon
Tags = new[] { "Amenities" })]
public async Task<IActionResult> GetAllAmenities()
{
try
{
var amenities = await _amenityService.GetAllAmenity();
return _responseHandler.Success(amenities, "Amenities retrieved successfully.");
}
catch (KeyNotFoundException ex)
{
return _responseHandler.NotFound(ex.Message);
}
}
}

16 changes: 9 additions & 7 deletions HotelBookingPlatform.API/Controllers/CityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
public class CityController : ControllerBase
{
private readonly ICityService _cityService;
private readonly ICityHotelService _cityHotelService;
private readonly IImageService _imageService;
private readonly IResponseHandler _responseHandler;
private readonly ILog _log;

public CityController(ICityService cityService, IImageService imageService, IResponseHandler responseHandler, ILog log)
public CityController(ICityService cityService, IImageService imageService, IResponseHandler responseHandler, ILog log,ICityHotelService cityHotelService)
{
_cityService = cityService;
_imageService = imageService;
_responseHandler = responseHandler;
_log = log;
_cityHotelService = cityHotelService;
}

[HttpPost]
Expand Down Expand Up @@ -47,7 +49,7 @@ public async Task<IActionResult> GetCities(
public async Task<IActionResult> GetCity(int id, [FromQuery] bool includeHotels = false)
{
var city = await _cityService.GetCity(id, includeHotels);
return _responseHandler.Success(city);
return _responseHandler.Success(city, "Retrieve city successfully.");
}

[HttpPut("{id}")]
Expand All @@ -71,26 +73,26 @@ public async Task<IActionResult> DeleteCity(int id)
[ResponseCache(CacheProfileName = "DefaultCache")]
public async Task<IActionResult> GetHotelsForCity(int cityId)
{
var hotels = await _cityService.GetHotelsForCityAsync(cityId);
var hotels = await _cityHotelService.GetHotelsForCityAsync(cityId);
_log.Log($"Retrieving hotels for city ID: {cityId}", "info");
return _responseHandler.Success(hotels);
return _responseHandler.Success(hotels, "Get Hotels For City Done");
}

[HttpPost("{cityId}/hotels")]
[Authorize(Roles = "Admin")]
[SwaggerOperation(Summary = "Add a hotel to a specific city.")]
public async Task<IActionResult> AddHotelToCity(int cityId, [FromBody] HotelCreateRequest hotelRequest)
{
await _cityService.AddHotelToCityAsync(cityId, hotelRequest);
return _responseHandler.Success(message: "Hotel added to city successfully.");
await _cityHotelService.AddHotelToCityAsync(cityId, hotelRequest);
return _responseHandler.Success(message: "Hotel added to city successfully.");
}

[HttpDelete("{cityId}/hotel/{hotelId}")]
[Authorize(Roles = "Admin")]
[SwaggerOperation(Summary = "Remove a hotel from a specific city.")]
public async Task<IActionResult> DeleteHotelFromCity(int cityId, int hotelId)
{
await _cityService.DeleteHotelFromCityAsync(cityId, hotelId);
await _cityHotelService.DeleteHotelFromCityAsync(cityId, hotelId);
_log.Log($"Hotel ID: {hotelId} removed from city ID: {cityId} successfully", "info");
return _responseHandler.Success(message: "Hotel removed from city successfully.");
}
Expand Down
25 changes: 6 additions & 19 deletions HotelBookingPlatform.API/Controllers/DiscountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,6 @@ public async Task<IActionResult> UpdateDiscount(int id, [FromBody] UpdateDiscoun
return _responseHandler.Success(discount, "Discount updated successfully.");
}

[HttpGet]
[SwaggerOperation(
Summary = "Get all discounts",
Description = "Retrieves a list of all available discounts."
)]
[SwaggerResponse(200, "Discounts retrieved successfully.", typeof(IEnumerable<DiscountDto>))]
[SwaggerResponse(404, "No discounts found.")]
[SwaggerResponse(500, "An unexpected error occurred.")]
public async Task<IActionResult> GetAllDiscounts()
{
var discounts = await _discountService.GetAllDiscountsAsync();
return _responseHandler.Success(discounts, "Discounts retrieved successfully.");
}

[HttpGet("{id}")]
[SwaggerOperation(
Summary = "Get a discount by ID",
Expand Down Expand Up @@ -105,18 +91,19 @@ public async Task<IActionResult> GetActiveDiscounts()

[HttpGet("top-discounts")]
[SwaggerOperation(
Summary = "Get rooms with highest active discounts",
Description = "Retrieves a list of rooms with the highest active discounts."
)]
Summary = "Get rooms with highest active discounts",
Description = "Retrieves a list of rooms with the highest active discounts."
)]
[SwaggerResponse(200, "Rooms with highest active discounts retrieved successfully.", typeof(IEnumerable<DiscountDto>))]
[SwaggerResponse(404, "No active discounts found.")]
[SwaggerResponse(500, "An unexpected error occurred.")]
public async Task<IActionResult> GetRoomsWithHighestDiscountsAsync(int topN = 5)
public async Task<IActionResult> GetRoomsWithHighestDiscountsAsync([FromQuery] int topN = 5)
{
var roomsWithDiscounts = await _discountService.GetRoomsWithHighestDiscountsAsync(topN);
var roomsWithDiscounts = await _discountService.GetTopDiscountsAsync(topN);
if (!roomsWithDiscounts.Any())
return _responseHandler.NotFound("No active discounts found.");

return _responseHandler.Success(roomsWithDiscounts, "Rooms with highest active discounts retrieved successfully.");
}

}
11 changes: 6 additions & 5 deletions HotelBookingPlatform.API/Controllers/HomePageController.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
namespace HotelBookingPlatform.API.Controllers;
using HotelBookingPlatform.Application.Core.Abstracts.HotelManagementService;
namespace HotelBookingPlatform.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class HomePageController : ControllerBase
{
private readonly ICityService _cityService;
private readonly IHotelService _hotelService;
private readonly IHotelSearchService _HotelSearchService;
private readonly IRoomService _roomService;
public HomePageController(ICityService cityService, IHotelService hotelService, IRoomService roomService)
public HomePageController(ICityService cityService, IHotelSearchService hotelService, IRoomService roomService)
{
_cityService = cityService;
_hotelService = hotelService;
_HotelSearchService = hotelService;
_roomService = roomService;
}
/// <summary>
Expand Down Expand Up @@ -41,7 +42,7 @@ public async Task<ActionResult<IEnumerable<CityResponseDto>>> GetTrendingDestina
)]
public async Task<ActionResult<SearchResultsDto>> Search([FromQuery] SearchRequestDto request)
{
var searchResults = await _hotelService.SearchHotelsAsync(request);
var searchResults = await _HotelSearchService.SearchHotelsAsync(request);

if (searchResults.Hotels is null || !searchResults.Hotels.Any())
{
Expand Down
96 changes: 58 additions & 38 deletions HotelBookingPlatform.API/Controllers/HotelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@
[ApiController]
public class HotelController : ControllerBase
{
private readonly IHotelService _hotelService;
private readonly IImageService _imageService;
private readonly IResponseHandler _responseHandler;
private readonly ILog _logger;
public HotelController(IHotelService hotelService, IImageService imageService, IResponseHandler responseHandler, ILog logger)
private readonly IHotelManagementService _hotelManagementService;
private readonly IHotelSearchService _hotelSearchService;
private readonly IHotelAmenityService _hotelAmenityService;
private readonly IHotelReviewService _hotelReviewService;
private readonly IImageService _imageService;
private readonly IResponseHandler _responseHandler;
private readonly IHotelRoomService _hotelRoomService;
private readonly ILog _logger;
private readonly IRoomClassService _roomClassService;
public HotelController(
IHotelManagementService hotelManagementService,
IHotelSearchService hotelSearchService,
IHotelAmenityService hotelAmenityService,
IHotelReviewService hotelReviewService,
IImageService imageService,
IResponseHandler responseHandler,
ILog logger,IHotelRoomService hotelRoomService,IRoomClassService roomClassService)
{
_hotelService = hotelService;
_imageService = imageService;
_responseHandler = responseHandler;
_logger = logger;
}

// GET: api/Hotel
[HttpGet]
[ResponseCache(CacheProfileName = "DefaultCache")]
[SwaggerOperation(Summary = "Get a list of hotels", Description = "Retrieves a list of hotels based on optional filters and pagination.")]
public async Task<IActionResult> GetHotels(
[FromQuery] string hotelName,
[FromQuery] string description,
[FromQuery] int pageSize = 10,
[FromQuery] int pageNumber = 1)
{
_logger.Log("Fetching hotels list", "info");
var hotels = await _hotelService.GetHotels(hotelName, description, pageSize, pageNumber);
return _responseHandler.Success(hotels);
_hotelManagementService = hotelManagementService ?? throw new ArgumentNullException(nameof(hotelManagementService));
_hotelSearchService = hotelSearchService ?? throw new ArgumentNullException(nameof(hotelSearchService));
_hotelAmenityService = hotelAmenityService ?? throw new ArgumentNullException(nameof(hotelAmenityService));
_hotelReviewService = hotelReviewService ?? throw new ArgumentNullException(nameof(hotelReviewService));
_imageService = imageService ?? throw new ArgumentNullException(nameof(imageService));
_responseHandler = responseHandler ?? throw new ArgumentNullException(nameof(responseHandler));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_hotelRoomService = hotelRoomService ?? throw new ArgumentNullException(nameof(hotelRoomService));
_roomClassService = roomClassService ?? throw new ArgumentNullException(nameof(roomClassService));
}

// GET: api/Hotel/5
Expand All @@ -36,8 +38,8 @@ public async Task<IActionResult> GetHotels(
[SwaggerOperation(Summary = "Get a hotel by ID", Description = "Retrieves the details of a specific hotel by its ID.")]
public async Task<IActionResult> GetHotel(int id)
{
var hotel = await _hotelService.GetHotel(id);
return _responseHandler.Success(hotel);
var hotel = await _hotelManagementService.GetHotel(id);
return _responseHandler.Success(hotel, "Hotel Retrieved successfully.");
}

// PUT: api/Hotel/5
Expand All @@ -46,8 +48,8 @@ public async Task<IActionResult> GetHotel(int id)
[SwaggerOperation(Summary = "Update an existing hotel", Description = "Updates the details of an existing hotel specified by its ID.")]
public async Task<IActionResult> UpdateHotel(int id, [FromBody] HotelResponseDto request)
{
var updatedHotel = await _hotelService.UpdateHotelAsync(id, request);
return _responseHandler.Success(updatedHotel);
var updatedHotel = await _hotelManagementService.UpdateHotelAsync(id, request);
return _responseHandler.Success(updatedHotel, "Update successfully.");
}

// DELETE: api/Hotel/5
Expand All @@ -56,7 +58,7 @@ public async Task<IActionResult> UpdateHotel(int id, [FromBody] HotelResponseDto
[SwaggerOperation(Summary = "Delete a hotel", Description = "Deletes a hotel specified by its ID.")]
public async Task<IActionResult> DeleteHotel(int id)
{
var result = await _hotelService.DeleteHotel(id);
var result = _hotelManagementService.DeleteHotel(id);
return _responseHandler.Success("Hotel deleted successfully.");
}

Expand All @@ -70,7 +72,7 @@ public async Task<IActionResult> SearchHotel(
[FromQuery] int pageSize = 10,
[FromQuery] int pageNumber = 1)
{
var hotels = await _hotelService.SearchHotel(name, desc, pageSize, pageNumber);
var hotels = await _hotelSearchService.GetHotels(name, desc, pageSize, pageNumber);
return _responseHandler.Success(hotels);
}

Expand All @@ -79,16 +81,16 @@ public async Task<IActionResult> SearchHotel(
public async Task<IActionResult> GetRoomsByHotelIdAsync(int hotelId)
{
_logger.Log($"Fetching rooms for hotel with ID {hotelId}", "info");
var rooms = await _hotelService.GetRoomsByHotelIdAsync(hotelId);
return _responseHandler.Success(rooms);
var rooms = _hotelRoomService.GetRoomsByHotelIdAsync(hotelId);
return _responseHandler.Success(rooms, "Rooms retrieved successfully.");
}

[HttpPost("{hotelId}/amenities")]
[Authorize(Roles = "Admin")]
[SwaggerOperation(Summary = "Add an amenity to a specific hotel.")]
public async Task<IActionResult> AddAmenityToHotel(int hotelId, [FromBody] AmenityCreateRequest request)
{
var amenityDto = await _hotelService.AddAmenityToHotelAsync(hotelId, request);
var amenityDto = await _hotelAmenityService.AddAmenityToHotelAsync(hotelId, request);
return _responseHandler.Created(amenityDto, "Amenity added successfully.");
}

Expand All @@ -97,8 +99,8 @@ public async Task<IActionResult> AddAmenityToHotel(int hotelId, [FromBody] Ameni
public async Task<IActionResult> GetAmenitiesByHotelId(int hotelId)
{
_logger.Log($"Fetching amenities for hotel with ID {hotelId}", "info");
var amenities = await _hotelService.GetAmenitiesByHotelIdAsync(hotelId);
return _responseHandler.Success(amenities);
var amenities = await _hotelAmenityService.GetAmenitiesByHotelIdAsync(hotelId);
return _responseHandler.Success(amenities, "Amenity Retrieved successfully.");
}

[HttpDelete("{hotelId}/amenities/{amenityId}")]
Expand All @@ -107,16 +109,16 @@ public async Task<IActionResult> GetAmenitiesByHotelId(int hotelId)
public async Task<IActionResult> DeleteAmenityFromHotel(int hotelId, int amenityId)
{
_logger.Log($"Removing amenity with ID {amenityId} from hotel with ID {hotelId}", "info");
await _hotelService.DeleteAmenityFromHotelAsync(hotelId, amenityId);
await _hotelAmenityService.DeleteAmenityFromHotelAsync(hotelId, amenityId);
return _responseHandler.Success("Amenity deleted successfully.");
}

[HttpGet("{id}/rating")]
[SwaggerOperation(Summary = "Get the review rating of a specific hotel.")]
public async Task<IActionResult> GetHotelReviewRating(int id)
{
var ratingDto = await _hotelService.GetHotelReviewRatingAsync(id);
return _responseHandler.Success(ratingDto);
var ratingDto = await _hotelReviewService.GetHotelReviewRatingAsync(id);
return _responseHandler.Success(ratingDto, "retrieve successfully");
}


Expand Down Expand Up @@ -170,5 +172,23 @@ public async Task<IActionResult> GetImagesForCity(int hotelId)

return _responseHandler.Success(response,"Images retrieved successfully for the hotel.");
}


[HttpPost("{hotelId}/roomclasses")]
[Authorize(Roles = "Admin")]
[SwaggerOperation(Summary = "Add a RoomClass to a specific hotel.")]
public async Task<IActionResult> AddRoomClassToHotel(int hotelId, [FromBody] RoomClassRequestDto request)
{
var roomClassDto = await _roomClassService.CreateRoomClass(request);
return _responseHandler.Created(roomClassDto, "RoomClass added successfully.");
}

[HttpGet("{hotelId}/roomclasses")]
[SwaggerOperation(Summary = "Retrieve all RoomClasses for a specific hotel.")]
public async Task<IActionResult> GetRoomClassesByHotelId(int hotelId)
{
var roomClassesDto = await _roomClassService.GetRoomClassesByHotelId(hotelId);
return _responseHandler.Success(roomClassesDto, "Room classes retrieved successfully.");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class InvoiceController : ControllerBase
private readonly IInvoiceRecordService _invoiceService;
private readonly IResponseHandler _responseHandler;
private readonly ILog _logger;

public InvoiceController(IInvoiceRecordService invoiceService, IResponseHandler responseHandler, ILog logger)
{
_invoiceService = invoiceService;
Expand Down
8 changes: 3 additions & 5 deletions HotelBookingPlatform.API/Controllers/OwnerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ public async Task<IActionResult> CreateOwner([FromBody] OwnerCreateDto request)
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> UpdateOwner(int id, [FromBody] OwnerCreateDto request)
{
var existingOwner = await _ownerService.UpdateOwnerAsync(id, request);
if (existingOwner is null)
_logger.Log($"Owner with ID: {id} not found", "warning");

return _responseHandler.Success(existingOwner, "Owner updated successfully.");
var updatedOwner = await _ownerService.UpdateOwnerAsync(id, request);
_logger.Log($"Owner with ID: {id} updated successfully", "info");
return _responseHandler.Success(updatedOwner, "Owner updated successfully.");
}

// DELETE: api/Owner/5
Expand Down
Loading

0 comments on commit 0a83975

Please sign in to comment.