Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…king-system-server into PBS-65-Dashboard
  • Loading branch information
Hoang-Nguyen-Huy committed Oct 31, 2024
2 parents fa5c8e4 + 5b0b49e commit cc175a6
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
@EnableMethodSecurity
public class SecurityConfig {
private final String[] PUBLIC_ENDPOINTS = {"/accounts", "/accounts/me",
"/auth/login", "/auth/introspect", "/auth/refresh-token", "/auth/logout", "/auth/login/google"
"/auth/login", "/auth/introspect", "/auth/refresh-token",
"/auth/logout", "/auth/login/google",
"/rooms/slots-by-rooms-and-date","/rooms/available-by-type-and-date"
};

private final String[] ADMIN_ENDPOINTS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import com.swp.PodBookingSystem.dto.respone.Account.AccountOrderResponse;
import com.swp.PodBookingSystem.dto.respone.ApiResponse;
import com.swp.PodBookingSystem.dto.respone.AccountResponse;
import com.swp.PodBookingSystem.dto.respone.Order.OrderManagementResponse;
import com.swp.PodBookingSystem.dto.respone.PaginationResponse;
import com.swp.PodBookingSystem.entity.Account;
import com.swp.PodBookingSystem.enums.AccountRole;
import com.swp.PodBookingSystem.exception.AppException;
import com.swp.PodBookingSystem.exception.ErrorCode;
import com.swp.PodBookingSystem.mapper.AccountMapper;
import com.swp.PodBookingSystem.service.AccountService;
import com.swp.PodBookingSystem.service.OrderService;
import com.swp.PodBookingSystem.service.SendEmailService;
import jakarta.mail.MessagingException;
import jakarta.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -45,6 +47,7 @@ public class AccountController {
AccountMapper accountMapper;
SendEmailService sendEmailService;
JwtDecoder jwtDecoder;
OrderService orderService;

@PostMapping
ApiResponse<AccountResponse> createAccount(@RequestBody @Valid AccountCreationRequest request) {
Expand Down Expand Up @@ -124,6 +127,16 @@ ApiResponse sendEmail(@RequestBody SendMailRequest request) throws MessagingExce
.build();
}

@PostMapping("/send-email-order")
ApiResponse sendEmailOrder(@RequestBody SendMailOrderRequest request) throws MessagingException, IOException {
OrderManagementResponse order = orderService.getInfoOrder(request.getOrderId());
sendEmailService.sendMailTemplate(request.getEmail(), order, "Hóa đơn tại FlexiPod");
return ApiResponse.builder()
.message("Gửi lời mời đặt lịch thành công")
.code(200)
.build();
}

@GetMapping("/staff")
public ResponseEntity<List<AccountOrderResponse>> getAllStaffAccounts() {
return ResponseEntity.status(HttpStatus.OK).body(accountService.getAllStaffAccounts());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.swp.PodBookingSystem.controller;

import com.swp.PodBookingSystem.dto.request.Room.RoomAvailabilityDTO;
import com.swp.PodBookingSystem.dto.request.Slot.SlotCreationRequest;
import com.swp.PodBookingSystem.dto.request.Slot.SlotDTO;
import com.swp.PodBookingSystem.dto.respone.ApiResponse;
import com.swp.PodBookingSystem.dto.request.Room.RoomCreationRequest;
import com.swp.PodBookingSystem.dto.request.Room.RoomPaginationDTO;
import com.swp.PodBookingSystem.dto.respone.Calendar.DateResponse;
import com.swp.PodBookingSystem.dto.respone.PaginationResponse;
import com.swp.PodBookingSystem.dto.respone.Room.BookedRoomDto;
import com.swp.PodBookingSystem.dto.respone.Room.RoomResponse;
Expand Down Expand Up @@ -87,13 +86,13 @@ PaginationResponse<List<Room>> getFilteredRoom(@RequestParam(required = false) S
@GetMapping("/available-rooms")
ApiResponse<List<Room>> getAvailableRoomsByRoomTypeId(@RequestParam Integer typeId,
@RequestParam(required = false) List<String> slots) {
List<SlotCreationRequest> slotList = new ArrayList<>();
List<SlotDTO> slotList = new ArrayList<>();
if(slots!=null) {
for(String slot: slots) {
String[] parts = slot.split("_");
LocalDateTime startTime = LocalDateTime.parse(parts[0]);
LocalDateTime endTime = LocalDateTime.parse(parts[1]);
slotList.add(new SlotCreationRequest(startTime,endTime));
slotList.add(new SlotDTO(startTime,endTime));
}
}
return ApiResponse.<List<Room>>builder()
Expand All @@ -102,24 +101,13 @@ ApiResponse<List<Room>> getAvailableRoomsByRoomTypeId(@RequestParam Integer typ
.build();
}

@GetMapping("/calendar")
ApiResponse<List<DateResponse>> getCalendar(@RequestParam List<Integer> roomIds,
@RequestParam(required = false) Integer servicePackageId,
@RequestParam LocalDate selectedDate,
@RequestParam List<String> slots
) {
return ApiResponse.<List<DateResponse>>builder()
.data(roomService.getCalendar(roomIds,servicePackageId,selectedDate,slots))
.message("Get calendar successfully")
.build();
}

@GetMapping("/unavailable")
ApiResponse<List<RoomAvailabilityDTO>> getUnavailableRooms(@RequestParam LocalDateTime startTime,
ApiResponse<List<RoomAvailabilityDTO>> getUnavailableRooms(@RequestParam List<Integer> roomIds,
@RequestParam LocalDateTime startTime,
@RequestParam LocalDateTime endTime
) {
return ApiResponse.<List<RoomAvailabilityDTO>>builder()
.data(roomService.getUnavailableRooms(startTime,endTime))
.data(roomService.getUnavailableRooms(roomIds,startTime,endTime))
.message("Get unavailable rooms successfully")
.build();
}
Expand Down Expand Up @@ -164,4 +152,22 @@ ApiResponse<Integer> countCurrentlyServedRooms() {
.data(roomService.countCurrentlyServedRooms())
.build();
}
@GetMapping("/available-by-type-and-date")
ApiResponse<List<Room>> getRoomsByTypeAndDate(@RequestParam Integer typeId, @RequestParam String date) {
LocalDate selectedDate = LocalDate.parse(date);
return ApiResponse.<List<Room>>builder()
.data(roomService.getRoomsByTypeAndDate(typeId, selectedDate))
.message("Get rooms by typeId and date successfully")
.build();
}

@GetMapping("/slots-by-rooms-and-date")
ApiResponse<List<SlotDTO>> getSlotsByRoomsAndDate(@RequestParam(required = false) List<Integer> roomIds, @RequestParam(required = false) String date) {
return ApiResponse.<List<SlotDTO>>builder()
.data(roomService.getSlotsByRoomsAndDate(roomIds, date))
.message("Get slots by rooms and date successfully")
.build();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.swp.PodBookingSystem.dto.request.Account;

import lombok.*;
import lombok.experimental.FieldDefaults;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@FieldDefaults(level = AccessLevel.PRIVATE)
public class SendMailOrderRequest {
String email;
String orderId;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.swp.PodBookingSystem.dto.request.Room;

import com.swp.PodBookingSystem.dto.request.Slot.SlotDTO;
import lombok.*;
import lombok.experimental.FieldDefaults;

import java.time.LocalDateTime;
import java.util.List;

@Data
@NoArgsConstructor
Expand All @@ -13,6 +14,5 @@
public class RoomAvailabilityDTO {
Integer roomId;
String name;
LocalDateTime startTime;
LocalDateTime endTime;
List<SlotDTO> slots;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.swp.PodBookingSystem.dto.respone.Calendar;
package com.swp.PodBookingSystem.dto.request.Slot;

import lombok.*;
import lombok.experimental.FieldDefaults;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -13,5 +12,4 @@
public class SlotDTO {
LocalDateTime startTime;
LocalDateTime endTime;
boolean available;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.swp.PodBookingSystem.dto.respone.Calendar;

import com.swp.PodBookingSystem.dto.request.Slot.SlotCreationRequest;
import lombok.*;
import lombok.experimental.FieldDefaults;

Expand All @@ -14,5 +13,5 @@
public class RoomDTO {
int roomId;
String roomName;
List<SlotDTO> slots;
List<SlotCustomDTO> slots;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.swp.PodBookingSystem.dto.request.Slot;
package com.swp.PodBookingSystem.dto.respone.Calendar;

import lombok.*;
import lombok.experimental.FieldDefaults;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@FieldDefaults(level = AccessLevel.PRIVATE)
public class SlotCreationRequest {
public class SlotCustomDTO {
LocalDateTime startTime;
LocalDateTime endTime;
boolean available;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.swp.PodBookingSystem.repository;

import com.swp.PodBookingSystem.dto.request.Slot.SlotDTO;
import com.swp.PodBookingSystem.dto.respone.Room.BookedRoomDto;
import com.swp.PodBookingSystem.entity.OrderDetail;
import com.swp.PodBookingSystem.entity.Room;
Expand Down Expand Up @@ -62,4 +63,35 @@ List<OrderDetail> findRoomAvailabilityWithinDateRange(
"WHERE :currentTime BETWEEN od.startTime AND od.endTime " +
"AND od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully")
int countCurrentlyServedRooms(@Param("currentTime") LocalDateTime currentTime);

@Query("SELECT r FROM Room r " +
"JOIN OrderDetail od ON r.id = od.room.id " +
"WHERE r.roomType.id = :typeId " +
"AND r.status = com.swp.PodBookingSystem.enums.RoomStatus.Available " +
"AND od.startTime >= :startTime " +
"AND od.endTime <= :endTime " +
"AND (od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully " +
"OR od.status = com.swp.PodBookingSystem.enums.OrderStatus.Pending) "
)
List<Room> getRoomsByTypeAndDate(@Param("typeId") Integer typeId,
@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime);

@Query("SELECT DISTINCT NEW com.swp.PodBookingSystem.dto.request.Slot.SlotDTO(od.startTime,od.endTime) " +
"FROM OrderDetail od " +
"WHERE od.room.id = :roomId " +
"AND od.room.status = com.swp.PodBookingSystem.enums.RoomStatus.Available " +
"AND od.startTime >= :startTime " +
"AND od.endTime <= :endTime " +
"AND (od.status = com.swp.PodBookingSystem.enums.OrderStatus.Successfully " +
"OR od.status = com.swp.PodBookingSystem.enums.OrderStatus.Pending) "
)
List<SlotDTO> getSlotsByRoomAndDate(@Param("roomId")Integer roomId,
@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime);

@Query("SELECT r FROM Room r " +
"JOIN r.roomType rt " +
"WHERE rt.id = :typeId")
List<Room> findAllByTypeId(@Param("typeId") Integer typeId);
}
Loading

0 comments on commit cc175a6

Please sign in to comment.