diff --git a/src/main/java/com/swp/PodBookingSystem/controller/AccountController.java b/src/main/java/com/swp/PodBookingSystem/controller/AccountController.java index 7581d6db..053dd071 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/AccountController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/AccountController.java @@ -1,9 +1,6 @@ package com.swp.PodBookingSystem.controller; -import com.swp.PodBookingSystem.dto.request.Account.AccountCreationRequest; -import com.swp.PodBookingSystem.dto.request.Account.AccountPaginationDTO; -import com.swp.PodBookingSystem.dto.request.Account.AccountResponseClient; -import com.swp.PodBookingSystem.dto.request.Account.AccountUpdateAdminRequest; +import com.swp.PodBookingSystem.dto.request.Account.*; import com.swp.PodBookingSystem.dto.request.CalendarRequest; import com.swp.PodBookingSystem.dto.respone.Account.AccountOrderResponse; import com.swp.PodBookingSystem.dto.respone.ApiResponse; @@ -108,17 +105,17 @@ ApiResponse getMe(@RequestHeader("Authorization") String .build(); } -// @GetMapping("/send-email") -// public String sendEmail() throws MessagingException, IOException { -// sendEmailService.sendCalenderInvite( -// CalendarRequest.builder() -// .subject("Đăt lịch ở POD Booking") -// .description("Hãy đặt lịch ở calendar để không bỏ lỡ lịch") -// .summary("Đăt lịch ở POD Booking") -// .to("phuongnguyen2772004.work@gmail.com") -// .eventDateTime(LocalDateTime.now()).build()); -// return "Send email successfully"; -// } + @PostMapping("/send-email") + public String sendEmail(@RequestBody SendMailRequest request) throws MessagingException, IOException { + sendEmailService.sendCalenderInvite( + CalendarRequest.builder() + .subject("Đăt lịch ở POD Booking") + .description("Hãy đặt lịch ở calendar để không bị bỏ lỡ") + .summary("Đăt lịch ở POD Booking") + .to(request.getEmail()) + .eventDateTime(LocalDateTime.parse("2024-10-27T17:00:00")).build()); + return "Send email successfully"; + } @GetMapping("/staff") public ResponseEntity> getAllStaffAccounts() { diff --git a/src/main/java/com/swp/PodBookingSystem/controller/SocketController.java b/src/main/java/com/swp/PodBookingSystem/controller/SocketController.java index 3e670f39..dbb0849e 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/SocketController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/SocketController.java @@ -1,6 +1,5 @@ package com.swp.PodBookingSystem.controller; -import com.swp.PodBookingSystem.dto.request.ChatMessage; import com.swp.PodBookingSystem.dto.socketPayload.UpdateOrder; import lombok.extern.slf4j.Slf4j; import org.springframework.messaging.handler.annotation.MessageMapping; @@ -8,8 +7,6 @@ import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.web.bind.annotation.RestController; -import java.util.Date; - @Slf4j @RestController public class SocketController { diff --git a/src/main/java/com/swp/PodBookingSystem/dto/request/ChatMessage.java b/src/main/java/com/swp/PodBookingSystem/dto/request/Account/SendMailRequest.java similarity index 50% rename from src/main/java/com/swp/PodBookingSystem/dto/request/ChatMessage.java rename to src/main/java/com/swp/PodBookingSystem/dto/request/Account/SendMailRequest.java index a3206d4f..da80989a 100644 --- a/src/main/java/com/swp/PodBookingSystem/dto/request/ChatMessage.java +++ b/src/main/java/com/swp/PodBookingSystem/dto/request/Account/SendMailRequest.java @@ -1,17 +1,13 @@ -package com.swp.PodBookingSystem.dto.request; +package com.swp.PodBookingSystem.dto.request.Account; import lombok.*; import lombok.experimental.FieldDefaults; -import java.util.Date; - @Data @NoArgsConstructor @AllArgsConstructor @Builder @FieldDefaults(level = AccessLevel.PRIVATE) -public class ChatMessage { - String nickname; - String content; - Date timestamp; +public class SendMailRequest { + String email; } diff --git a/src/main/java/com/swp/PodBookingSystem/service/SendEmailService.java b/src/main/java/com/swp/PodBookingSystem/service/SendEmailService.java index 23f11816..abee8e57 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/SendEmailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/SendEmailService.java @@ -12,10 +12,7 @@ import jakarta.mail.BodyPart; import jakarta.mail.Message; import jakarta.mail.MessagingException; -import jakarta.mail.internet.InternetAddress; -import jakarta.mail.internet.MimeBodyPart; -import jakarta.mail.internet.MimeMessage; -import jakarta.mail.internet.MimeMultipart; +import jakarta.mail.internet.*; import jakarta.mail.util.ByteArrayDataSource; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; @@ -87,7 +84,7 @@ private BodyPart createCalenderMimeBody(CalendarRequest calenderDto) throws IOEx return calenderBody; } - private String createCal(CalendarRequest calenderDto) { + private String createCal(CalendarRequest calenderDto) throws AddressException { ICalendar ical = new ICalendar(); ical.addProperty(new Method(Method.REQUEST)); @@ -95,6 +92,7 @@ private String createCal(CalendarRequest calenderDto) { event.setSummary(calenderDto.getSummary()); event.setDescription(calenderDto.getDescription()); event.setDateStart(getStartDate(calenderDto.getEventDateTime())); + event.setOrganizer(String.valueOf(new InternetAddress(fromEmailId))); event.setDuration(new Duration.Builder() .hours(2) .build()); @@ -112,7 +110,7 @@ public void sendMailReminder() throws MessagingException { LocalDate toDay = LocalDate.now(); List orders = orderDetailService.getNextDayBookings(toDay); - for (OrderDetail orderDetail : orders){ + for (OrderDetail orderDetail : orders) { String email = orderDetail.getCustomer().getEmail(); String subject = "Room Booking Reminder"; String text = "Dear " + orderDetail.getCustomer().getName() + ",\n\n"