Skip to content

Commit

Permalink
refatorando endpoints e ajustando testes
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoKroetz committed Jun 27, 2024
1 parent 9466a88 commit 997535f
Show file tree
Hide file tree
Showing 25 changed files with 183 additions and 270 deletions.
6 changes: 3 additions & 3 deletions Hotel.Domain/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ public async Task<IActionResult> UpdateAddressAsync([FromBody] Address address)

//Editar gênero do administrador.
//Administradores autenticados podem acessar.
[HttpPatch("gender/{gender:int}")]
public async Task<IActionResult> UpdateGenderAsync([FromRoute] int gender)
[HttpPatch("gender")]
public async Task<IActionResult> UpdateGenderAsync([FromBody] UpdateGender updateGender)
{
var adminId = _userService.GetUserIdentifier(User);
return Ok(await _handler.HandleUpdateGenderAsync(adminId, (EGender)gender));
return Ok(await _handler.HandleUpdateGenderAsync(adminId, (EGender)updateGender.Gender));
}

//Editar data de nascimento do administrador.
Expand Down
6 changes: 3 additions & 3 deletions Hotel.Domain/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public async Task<IActionResult> UpdateAddressAsync([FromBody] Address address)
}

// Endpoint para editar o gênero do cliente (usando ID do token)
[HttpPatch("gender/{gender:int}")]
public async Task<IActionResult> UpdateGenderAsync([FromRoute] int gender)
[HttpPatch("gender")]
public async Task<IActionResult> UpdateGenderAsync([FromBody] UpdateGender updateGender)
{
var customerId = _userService.GetUserIdentifier(User);
return Ok(await _handler.HandleUpdateGenderAsync(customerId, (EGender)gender));
return Ok(await _handler.HandleUpdateGenderAsync(customerId, (EGender)updateGender.Gender));
}

// Endpoint para editar a data de nascimento do cliente (usando ID do token)
Expand Down
6 changes: 3 additions & 3 deletions Hotel.Domain/Controllers/EmployeeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ public async Task<IActionResult> UpdateAddressAsync([FromBody] Address address)
return Ok(await _handler.HandleUpdateAddressAsync(userId, address));
}

[HttpPatch("gender/{gender:int}")]
public async Task<IActionResult> UpdateGenderAsync([FromRoute] int gender)
[HttpPatch("gender")]
public async Task<IActionResult> UpdateGenderAsync([FromBody] UpdateGender updateGender)
{
var userId = _userService.GetUserIdentifier(User);
return Ok(await _handler.HandleUpdateGenderAsync(userId, (EGender)gender));
return Ok(await _handler.HandleUpdateGenderAsync(userId, (EGender)updateGender.Gender));
}

[HttpPatch("date-of-birth")]
Expand Down
8 changes: 4 additions & 4 deletions Hotel.Domain/Controllers/FeedbackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public async Task<IActionResult> DeleteAsync([FromRoute] Guid id)
}

// Endpoint para atualizar a avaliação (rate) de um feedback
[HttpPatch("{Id:guid}/rate/{rate:int}")]
public async Task<IActionResult> UpdateRateAsync([FromRoute] Guid id, [FromRoute] int rate)
[HttpPatch("rate/{Id:guid}")]
public async Task<IActionResult> UpdateRateAsync([FromRoute] Guid id, [FromBody] UpdateRate update)
{
var customerId = _userService.GetUserIdentifier(User);
return Ok(await _handler.HandleUpdateRateAsync(id, rate, customerId));
return Ok(await _handler.HandleUpdateRateAsync(id, update.Rate, customerId));
}

// Endpoint para atualizar o comentário de um feedback
[HttpPatch("{Id:guid}/comment")]
[HttpPatch("comment/{Id:guid}")]
public async Task<IActionResult> UpdateCommentAsync([FromRoute] Guid id, [FromBody] UpdateComment updateComment)
{
var customerId = _userService.GetUserIdentifier(User);
Expand Down
6 changes: 3 additions & 3 deletions Hotel.Domain/Controllers/ReportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task<IActionResult> CancelAsync([FromRoute] Guid id)
}

// Endpoint para atualizar prioridade
[HttpPatch("{id:guid}/priority/{priority:int}")]
public async Task<IActionResult> CancelAsync([FromRoute] Guid id, [FromRoute] int priority)
=> Ok(await _handler.HandleUpdatePriorityAsync((EPriority)priority, id));
[HttpPatch("priority/{id:guid}")]
public async Task<IActionResult> CancelAsync([FromRoute] Guid id, [FromBody] UpdatePriority priority)
=> Ok(await _handler.HandleUpdatePriorityAsync((EPriority)priority.Priority, id));
}
16 changes: 8 additions & 8 deletions Hotel.Domain/Controllers/ReservationControllers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ public async Task<IActionResult> DeleteAsync([FromRoute] Guid id)
//Atualizar check out.
//Somente administradores ou funcionários com permissão podem atualizar check out de reservas que não são suas.
//Administradores e funcionários tem acesso por padrão.
[HttpPatch("{Id:guid}/check-out")]
[HttpPatch("expected-check-out/{Id:guid}")]
[AuthorizePermissions([EPermissions.UpdateReservationCheckout, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission], [ERoles.Customer])]
public async Task<IActionResult> UpdateCheckoutAsync([FromRoute] Guid id, [FromBody] UpdateCheckOut updateCheckOut)
=> Ok(await _handler.HandleUpdateExpectedCheckOutAsync(id, updateCheckOut.CheckOut));
public async Task<IActionResult> UpdateCheckoutAsync([FromRoute] Guid id, [FromBody] UpdateExpectedCheckOut update)
=> Ok(await _handler.HandleUpdateExpectedCheckOutAsync(id, update.ExpectedCheckOut));

//Atualizar check in.
//Somente administradores ou funcionários com permissão podem atualizar check in de reservas que não são suas.
//Administradores e funcionários tem acesso por padrão.
[HttpPatch("{Id:guid}/check-in")]
[HttpPatch("expected-check-in/{Id:guid}")]
[AuthorizePermissions([EPermissions.UpdateReservationCheckIn, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission], [ERoles.Customer])]
public async Task<IActionResult> UpdateCheckInAsync([FromRoute] Guid id, [FromBody] UpdateCheckIn updateCheckIn)
=> Ok(await _handler.HandleUpdateExpectedCheckInAsync(id, updateCheckIn.CheckIn));
public async Task<IActionResult> UpdateCheckInAsync([FromRoute] Guid id, [FromBody] UpdateExpectedCheckIn update)
=> Ok(await _handler.HandleUpdateExpectedCheckInAsync(id, update.ExpectedCheckIn));

//Adicionar um serviço a uma reserva, ou seja, o cliente
//requisitou o serviço e o serviço é adicionado através desse endpoint.
Expand All @@ -135,14 +135,14 @@ public async Task<IActionResult> ReservationCheckInAsync([FromRoute] Guid Id, [F
return Ok(await _handler.HandleReservationCheckInAsync(Id, cardOptions.TokenId));
}

[HttpPatch("finish/{Id:guid}")]
[HttpPost("finish/{Id:guid}")]
public async Task<IActionResult> FinishReservationAsync([FromRoute] Guid Id)
{
var customerId = _userService.GetUserIdentifier(User);
return Ok(await _handler.HandleFinishReservationAsync(Id, customerId));
}

[HttpPatch("cancel/{Id:guid}")]
[HttpPost("cancel/{Id:guid}")]
public async Task<IActionResult> CancelReservationAsync([FromRoute] Guid Id)
{
var customerId = _userService.GetUserIdentifier(User);
Expand Down
28 changes: 14 additions & 14 deletions Hotel.Domain/Controllers/RoomController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,33 @@ public async Task<IActionResult> RemoveServiceAsync([FromRoute] Guid id, [FromRo
=> Ok(await _handler.HandleRemoveServiceAsync(id, serviceId));

// Endpoint para atualizar o número de um quarto (com permissão)
[HttpPatch("{id:guid}/number/{number:int}")]
[HttpPatch("number/{id:guid}")]
[AuthorizePermissions([EPermissions.UpdateRoomNumber, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission])]
public async Task<IActionResult> UpdateNumberAsync([FromRoute] Guid id, [FromRoute] int number)
=> Ok(await _handler.HandleUpdateNumberAsync(id, number));
public async Task<IActionResult> UpdateNumberAsync([FromRoute] Guid id, [FromBody] UpdateRoomNumber update)
=> Ok(await _handler.HandleUpdateNumberAsync(id, update.Number));

// Endpoint para atualizar o nome de um quarto (com permissão)
[HttpPatch("{id:guid}")]
[HttpPatch("name/{id:guid}")]
[AuthorizePermissions([EPermissions.UpdateRoomName, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission])]
public async Task<IActionResult> UpdateNameAsync([FromRoute] Guid id, [FromQuery] string name)
=> Ok(await _handler.HandleUpdateNameAsync(id, name));
public async Task<IActionResult> UpdateNameAsync([FromRoute] Guid id, [FromBody] UpdateRoomName update)
=> Ok(await _handler.HandleUpdateNameAsync(id, update.Name));

// Endpoint para atualizar a capacidade de um quarto (com permissão)
[HttpPatch("{id:guid}/capacity/{capacity:int}")]
[HttpPatch("capacity/{id:guid}")]
[AuthorizePermissions([EPermissions.UpdateRoomCapacity, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission])]
public async Task<IActionResult> UpdateCapacityAsync([FromRoute] Guid id, [FromRoute] int capacity)
=> Ok(await _handler.HandleUpdateCapacityAsync(id, capacity));
public async Task<IActionResult> UpdateCapacityAsync([FromRoute] Guid id, [FromBody] UpdateRoomCapacity update)
=> Ok(await _handler.HandleUpdateCapacityAsync(id, update.Capacity));

// Endpoint para atualizar a categoria de um quarto (com permissão)
[HttpPatch("{id:guid}/category/{categoryId:guid}")]
[HttpPatch("category/{id:guid}")]
[AuthorizePermissions([EPermissions.UpdateRoomCategory, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission])]
public async Task<IActionResult> UpdateCategoryAsync([FromRoute] Guid id, [FromRoute] Guid categoryId)
=> Ok(await _handler.HandleUpdateCategoryAsync(id, categoryId));
public async Task<IActionResult> UpdateCategoryAsync([FromRoute] Guid id, [FromBody] UpdateRoomCategory update)
=> Ok(await _handler.HandleUpdateCategoryAsync(id, update.CategoryId));

// Endpoint para atualizar o preço de um quarto (com permissão)
[HttpPatch("{id:guid}/price")]
[HttpPatch("price/{id:guid}")]
[AuthorizePermissions([EPermissions.UpdateRoomPrice, EPermissions.DefaultAdminPermission, EPermissions.DefaultEmployeePermission])]
public async Task<IActionResult> UpdatePriceAsync([FromRoute] Guid id, [FromBody] UpdatePriceDTO update)
public async Task<IActionResult> UpdatePriceAsync([FromRoute] Guid id, [FromBody] UpdateRoomPrice update)
=> Ok(await _handler.HandleUpdatePriceAsync(id, update.Price));

// Endpoint para ativar um quarto
Expand Down
3 changes: 2 additions & 1 deletion Hotel.Domain/DTOs/Base/User/UpdateFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public record UpdateDateOfBirth(DateTime? DateOfBirth) : IDataTransferObject;

public record UpdatePassword(string Password) : IDataTransferObject;
public record UpdatePassword(string Password) : IDataTransferObject;
public record UpdateGender(int Gender);
9 changes: 0 additions & 9 deletions Hotel.Domain/DTOs/FeedbackDTOs/UpdateComment.cs

This file was deleted.

14 changes: 0 additions & 14 deletions Hotel.Domain/DTOs/FeedbackDTOs/UpdateFeedback.cs

This file was deleted.

7 changes: 7 additions & 0 deletions Hotel.Domain/DTOs/FeedbackDTOs/UpdateFields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Hotel.Domain.DTOs.FeedbackDTOs;

public record UpdateFeedback(string Comment, int Rate);

public record UpdateComment(string Comment);

public record UpdateRate(int Rate);
3 changes: 3 additions & 0 deletions Hotel.Domain/DTOs/ReportDTOs/NewPriority.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Hotel.Domain.DTOs.ReportDTOs;

public record UpdatePriority(int Priority);
9 changes: 0 additions & 9 deletions Hotel.Domain/DTOs/ReservationDTOs/UpdateCheckIn.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Hotel.Domain/DTOs/ReservationDTOs/UpdateCheckOut.cs

This file was deleted.

4 changes: 4 additions & 0 deletions Hotel.Domain/DTOs/ReservationDTOs/UpdateFields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Hotel.Domain.DTOs.ReservationDTOs;

public record UpdateExpectedCheckIn(DateTime ExpectedCheckIn);
public record UpdateExpectedCheckOut(DateTime ExpectedCheckOut);
11 changes: 11 additions & 0 deletions Hotel.Domain/DTOs/RoomDTOs/UpdateFields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Hotel.Domain.DTOs.RoomDTOs;

public record UpdateRoomPrice(decimal Price);

public record UpdateRoomNumber(int Number);

public record UpdateRoomName(string Name);

public record UpdateRoomDescription(string Description);
public record UpdateRoomCapacity(int Capacity);
public record UpdateRoomCategory(Guid CategoryId);
11 changes: 0 additions & 11 deletions Hotel.Domain/DTOs/RoomDTOs/UpdatePriceDTO.cs

This file was deleted.

Loading

0 comments on commit 997535f

Please sign in to comment.