From d28e062a6d62d9ab0bd6951d99b5121500b7296a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:29:41 +0900 Subject: [PATCH 01/11] =?UTF-8?q?feat=20:=20=EA=B0=9C=EC=9D=B8=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EC=A1=B0=ED=9A=8C=EC=9A=A9=20=EC=BF=BC=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/repository/NotificationMemberRepository.java | 4 +++- .../notification/repository/NotificationOwnerRepository.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java index e9c5b5a7..0a2452eb 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java @@ -1,8 +1,10 @@ package com.prgrms.catchtable.notification.repository; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.notification.domain.NotificationMember; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationMemberRepository extends JpaRepository { - + Optional findByMember(Member member); } diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java index bca2921d..113323a4 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java @@ -1,8 +1,10 @@ package com.prgrms.catchtable.notification.repository; import com.prgrms.catchtable.notification.domain.NotificationOwner; +import com.prgrms.catchtable.owner.domain.Owner; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationOwnerRepository extends JpaRepository { - + Optional findByOwner(Owner owner); } From 6dc7edefe6f90b6f548c1dbd0d8b134319707b45 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:30:09 +0900 Subject: [PATCH 02/11] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20enum=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/NotificationContent.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/common/NotificationContent.java diff --git a/src/main/java/com/prgrms/catchtable/common/NotificationContent.java b/src/main/java/com/prgrms/catchtable/common/NotificationContent.java new file mode 100644 index 00000000..0a37bcf7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/common/NotificationContent.java @@ -0,0 +1,23 @@ +package com.prgrms.catchtable.common; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public enum NotificationContent { + RESERVATION_COMPLETED("예약이 완료되었습니다"), + RESERVATION_ONE_HOUR_LEFT("예약 시간 1시간 전입니다."), + RESERVATION_TIME_TO_ENTER("예약시간이 되었습니다"), + WAITING_REGISTER_COMPLETED("웨이팅 등록이 완료되었습니다"), + WAITING_RANK_THIRD("웨이팅 순서가 3번째가 되었습니다"), + WAITING_TIME_TO_ENTER("웨이팅이 끝났습니다. 입장 부탁드립니다."), + WAITING_CANCELLED_AUTOMATICALLY("웨이팅이 자동으로 취소되었습니다."); + + private final String message; + + + + + +} From fa47bf878bb019e304fe49a39e159b43583bce59 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:30:22 +0900 Subject: [PATCH 03/11] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20=EC=A0=84?= =?UTF-8?q?=EC=86=A1=20=EC=9A=94=EC=B2=AD=20dto=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/dto/request/SendMessageRequest.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java diff --git a/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java new file mode 100644 index 00000000..7c2034f7 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/dto/request/SendMessageRequest.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.notification.dto.request; + +import com.prgrms.catchtable.common.NotificationContent; + +public record SendMessageRequest(NotificationContent content) { + +} From eba16e1c189133109cab8ca8c5372c04100a4b7a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:30:44 +0900 Subject: [PATCH 04/11] =?UTF-8?q?feat=20:=20owner=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1=EC=9E=90=EC=97=90=20own?= =?UTF-8?q?er=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/notification/domain/NotificationOwner.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java index 4f4c3935..4a3885e5 100644 --- a/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java +++ b/src/main/java/com/prgrms/catchtable/notification/domain/NotificationOwner.java @@ -36,7 +36,8 @@ public class NotificationOwner extends BaseEntity { private Owner owner; @Builder - public NotificationOwner(String message) { + public NotificationOwner(Owner owner, String message) { + this.owner = owner; this.message = message; } } From b65ca72e09d05d43e3b081432ad6dbf6705c4389 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:31:12 +0900 Subject: [PATCH 05/11] =?UTF-8?q?feat=20:=20Owner=EC=97=90=20Email=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80(slack=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=B3=B4=EB=82=BC=20=EB=95=8C=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EC=B6=9C=EC=9D=84=20=EC=9C=84=ED=95=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/prgrms/catchtable/owner/domain/Owner.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index a4e17aab..78c73348 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -35,6 +35,9 @@ public class Owner extends BaseEntity { @Column(name = "owner_name") private String name; + @Column(name = "email") + private String email; + @Column(name = "phone_number") private String phoneNumber; @@ -50,8 +53,9 @@ public class Owner extends BaseEntity { private Shop shop; @Builder - public Owner(String name, String phoneNumber, Gender gender, LocalDate dateBirth) { + public Owner(String name, String email, String phoneNumber, Gender gender, LocalDate dateBirth) { this.name = name; + this.email = email; this.phoneNumber = phoneNumber; this.gender = gender; this.dateBirth = dateBirth; From 852b78ac41cad26812e2433e2f698bd98086b0ca Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:31:26 +0900 Subject: [PATCH 06/11] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/NotificationService.java | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java diff --git a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java new file mode 100644 index 00000000..b6f364c4 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java @@ -0,0 +1,141 @@ +package com.prgrms.catchtable.notification.service; + +import static com.prgrms.catchtable.common.exception.ErrorCode.*; +import static org.springframework.http.HttpMethod.*; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.notification.domain.NotificationMember; +import com.prgrms.catchtable.notification.domain.NotificationOwner; +import com.prgrms.catchtable.notification.dto.request.SendMessageRequest; +import com.prgrms.catchtable.notification.repository.NotificationMemberRepository; +import com.prgrms.catchtable.notification.repository.NotificationOwnerRepository; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import lombok.RequiredArgsConstructor; + +import lombok.extern.slf4j.Slf4j; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +@RequiredArgsConstructor +@Slf4j +public class NotificationService { + + @Value("${slack.token}") + private String slackToken; + + private final NotificationMemberRepository notificationMemberRepository; + private final NotificationOwnerRepository notificationOwnerRepository; + private final MemberRepository memberRepository; // 추후 삭제 예정 + private final OwnerRepository ownerRepository; // 추후 삭제 예정 + private JSONObject jsonObject; + + public void sendMessageToMemberAndSave(SendMessageRequest request) { + String url = "https://slack.com/api/chat.postMessage"; // slack 메세지를 보내도록 요청하는 Slack API + // member 예제 데이터 + Member member = Member.builder() + .email("dlswns661035@gmail.com") // 이 부분 이메일 바꿔서 하면 해당 이메일의 슬랙 개인으로 dm 보냄 + .build(); + + String email = member.getEmail(); + String message = request.content().getMessage(); + String slackId = getSlackIdByEmail(email); // 이메일을 통해 사용자의 슬랙 고유 ID 추출 + + requestToSendMessage(slackId, message); // 알림 요청 보내는 함수 호출 + + + NotificationMember notification = NotificationMember.builder() + .member(member) + .message(message) + .build(); + memberRepository.save(member); // 추후 삭제 예정 + notificationMemberRepository.save(notification); // 해당 사용자의 알림 생성 후 저장 + + } + + public void sendMessageToOwnerAndSave(SendMessageRequest request) { + String url = "https://slack.com/api/chat.postMessage"; // slack 메세지를 보내도록 요청하는 Slack API + //Owner 예제 데이터 + Owner owner = Owner.builder() + .email("dlswns661035@gmail.com") // 이 부분 이메일 바꿔서 하면 해당 이메일의 슬랙 개인으로 dm 보냄 + .build(); + + String email = owner.getEmail(); + String message = request.content().getMessage(); + String slackId = getSlackIdByEmail(email); + + requestToSendMessage(slackId, message); + + NotificationOwner notification = NotificationOwner.builder() + .owner(owner) + .message(message) + .build(); + ownerRepository.save(owner); //추후 삭제 예정 + notificationOwnerRepository.save(notification); + } + + private void requestToSendMessage(String slackId, String message){ + String url = "https://slack.com/api/chat.postMessage"; + + // 헤더에 캐치테이블 클론 슬랙 토큰 삽입 + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + slackToken); + headers.add("Content-type", "application/json; charset=utf-8"); + + + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("channel", slackId); // 채널 필드에 사용자의 슬랙 고유 ID + jsonObject.put("text", message); // 메세지 필드에 메세지 + String body = jsonObject.toString(); + + HttpEntity requestEntity = new HttpEntity<>(body, headers); + RestTemplate restTemplate = new RestTemplate(); + + ResponseEntity response = restTemplate.exchange( + url, + POST, + requestEntity, + String.class + );// post로 위에서 만든 Json body 전송 요청 + + jsonObject = new JSONObject(response.getBody()); + String result = jsonObject.get("ok").toString(); + + if(result.equals("false")){ // 알림 요청 보낸 후 응답의 ok필드 값이 false면 슬랙아이디가 잘못되었다는 것 + throw new BadRequestCustomException(SLACK_ID_IS_WRONG); + } + + // ok 필드값이 true면 알림 전송 완료 된것임 + } + + public String getSlackIdByEmail(String email) { + String url = "https://slack.com/api/users.lookupByEmail?email=".concat(email); + + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + slackToken); + headers.add("Content-type", "application/x-www-form-urlencoded"); + + RestTemplate restTemplate = new RestTemplate(); + HttpEntity requestEntity = new HttpEntity<>(headers); + ResponseEntity responseEntity = restTemplate.exchange( + url, + GET, + requestEntity, + String.class + ); + jsonObject = new JSONObject(responseEntity.getBody()); + JSONObject profile = jsonObject.getJSONObject("user"); + + return profile.get("id").toString(); + } +} From fc7b0de73637311334c41589eccdb20b9c8deb36 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:31:44 +0900 Subject: [PATCH 07/11] =?UTF-8?q?feat=20:=20=EC=8A=AC=EB=9E=99=20Id=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EA=B4=80=EB=A0=A8=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index 686a2544..d3252d30 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -28,7 +28,9 @@ public enum ErrorCode { CAN_NOT_ENTRY("웨이팅을 입장 처리할 수 없습니다"), WAITING_DOES_NOT_EXIST("웨이팅이 존재하지 않습니다"), SHOP_NOT_RUNNING("가게가 영업시간이 아닙니다."), - INTERNAL_SERVER_ERROR("내부 서버 오류입니다."); + INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), + + SLACK_ID_IS_WRONG("요청한 슬랙 Id를 찾을 수 없거나 잘못 되었습니다"); private final String message; } \ No newline at end of file From 3654d5fcfd3c5c9f2eb52dc8ca047cf6e2f5ecd7 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:32:15 +0900 Subject: [PATCH 08/11] =?UTF-8?q?feat=20:=20api=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=9A=A9=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NotificationController.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java diff --git a/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java new file mode 100644 index 00000000..cf1ae996 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java @@ -0,0 +1,19 @@ +package com.prgrms.catchtable.notification.controller; + +import com.prgrms.catchtable.notification.dto.request.SendMessageRequest; +import com.prgrms.catchtable.notification.service.NotificationService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class NotificationController { + private final NotificationService notificationService; + + @GetMapping("/test") + public void test(@RequestBody SendMessageRequest request){ + notificationService.sendMessageToMemberAndSave(request); + } +} From 57b44338474c71001f291a48b433622ab626f1f5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:32:34 +0900 Subject: [PATCH 09/11] =?UTF-8?q?chore=20:=20Json=20=EB=B3=80=ED=99=98=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 758ad7da..4860a110 100644 --- a/build.gradle +++ b/build.gradle @@ -60,6 +60,9 @@ dependencies { runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + implementation group: 'org.json', name: 'json', version: '20231013' + + } tasks.named('test') { From 0d7173c26824417bbd147140b91bfdbe4c9695a8 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 17:52:32 +0900 Subject: [PATCH 10/11] =?UTF-8?q?docs=20:=20test=20yaml=20=EC=8A=AC?= =?UTF-8?q?=EB=9E=99=20=ED=86=A0=ED=81=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/resources/application.yaml b/src/test/resources/application.yaml index 1beefa13..fdaaf576 100644 --- a/src/test/resources/application.yaml +++ b/src/test/resources/application.yaml @@ -44,4 +44,6 @@ jwt: logging.level: org.hibernate.SQL: debug org.hibernate.orm.jdbc.bind: trace +slack: + token: xoxb-6433151143155-6426645660710-QosE3VDLJM62hLgSISYqLTUu From 92e4f0e2a66ad7ea053cb4a52764d3fae46e5dc0 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sun, 7 Jan 2024 18:53:59 +0900 Subject: [PATCH 11/11] =?UTF-8?q?style=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/common/NotificationContent.java | 3 --- .../controller/NotificationController.java | 3 ++- .../repository/NotificationMemberRepository.java | 1 + .../repository/NotificationOwnerRepository.java | 1 + .../notification/service/NotificationService.java | 14 +++++--------- .../com/prgrms/catchtable/owner/domain/Owner.java | 3 ++- .../service/OwnerReservationService.java | 2 +- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/common/NotificationContent.java b/src/main/java/com/prgrms/catchtable/common/NotificationContent.java index 0a37bcf7..06af80c9 100644 --- a/src/main/java/com/prgrms/catchtable/common/NotificationContent.java +++ b/src/main/java/com/prgrms/catchtable/common/NotificationContent.java @@ -17,7 +17,4 @@ public enum NotificationContent { private final String message; - - - } diff --git a/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java index cf1ae996..07007c94 100644 --- a/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java +++ b/src/main/java/com/prgrms/catchtable/notification/controller/NotificationController.java @@ -10,10 +10,11 @@ @RestController @RequiredArgsConstructor public class NotificationController { + private final NotificationService notificationService; @GetMapping("/test") - public void test(@RequestBody SendMessageRequest request){ + public void test(@RequestBody SendMessageRequest request) { notificationService.sendMessageToMemberAndSave(request); } } diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java index 0a2452eb..44598e0e 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationMemberRepository.java @@ -6,5 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationMemberRepository extends JpaRepository { + Optional findByMember(Member member); } diff --git a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java index 113323a4..eb840345 100644 --- a/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java +++ b/src/main/java/com/prgrms/catchtable/notification/repository/NotificationOwnerRepository.java @@ -6,5 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface NotificationOwnerRepository extends JpaRepository { + Optional findByOwner(Owner owner); } diff --git a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java index b6f364c4..eb862c67 100644 --- a/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java +++ b/src/main/java/com/prgrms/catchtable/notification/service/NotificationService.java @@ -1,7 +1,8 @@ package com.prgrms.catchtable.notification.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.*; -import static org.springframework.http.HttpMethod.*; +import static com.prgrms.catchtable.common.exception.ErrorCode.SLACK_ID_IS_WRONG; +import static org.springframework.http.HttpMethod.GET; +import static org.springframework.http.HttpMethod.POST; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.member.domain.Member; @@ -14,7 +15,6 @@ import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.repository.OwnerRepository; import lombok.RequiredArgsConstructor; - import lombok.extern.slf4j.Slf4j; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Value; @@ -51,7 +51,6 @@ public void sendMessageToMemberAndSave(SendMessageRequest request) { requestToSendMessage(slackId, message); // 알림 요청 보내는 함수 호출 - NotificationMember notification = NotificationMember.builder() .member(member) .message(message) @@ -82,7 +81,7 @@ public void sendMessageToOwnerAndSave(SendMessageRequest request) { notificationOwnerRepository.save(notification); } - private void requestToSendMessage(String slackId, String message){ + private void requestToSendMessage(String slackId, String message) { String url = "https://slack.com/api/chat.postMessage"; // 헤더에 캐치테이블 클론 슬랙 토큰 삽입 @@ -90,8 +89,6 @@ private void requestToSendMessage(String slackId, String message){ headers.add("Authorization", "Bearer " + slackToken); headers.add("Content-type", "application/json; charset=utf-8"); - - JSONObject jsonObject = new JSONObject(); jsonObject.put("channel", slackId); // 채널 필드에 사용자의 슬랙 고유 ID jsonObject.put("text", message); // 메세지 필드에 메세지 @@ -110,7 +107,7 @@ private void requestToSendMessage(String slackId, String message){ jsonObject = new JSONObject(response.getBody()); String result = jsonObject.get("ok").toString(); - if(result.equals("false")){ // 알림 요청 보낸 후 응답의 ok필드 값이 false면 슬랙아이디가 잘못되었다는 것 + if (result.equals("false")) { // 알림 요청 보낸 후 응답의 ok필드 값이 false면 슬랙아이디가 잘못되었다는 것 throw new BadRequestCustomException(SLACK_ID_IS_WRONG); } @@ -120,7 +117,6 @@ private void requestToSendMessage(String slackId, String message){ public String getSlackIdByEmail(String email) { String url = "https://slack.com/api/users.lookupByEmail?email=".concat(email); - HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + slackToken); headers.add("Content-type", "application/x-www-form-urlencoded"); diff --git a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java index 78c73348..7079b780 100644 --- a/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java +++ b/src/main/java/com/prgrms/catchtable/owner/domain/Owner.java @@ -53,7 +53,8 @@ public class Owner extends BaseEntity { private Shop shop; @Builder - public Owner(String name, String email, String phoneNumber, Gender gender, LocalDate dateBirth) { + public Owner(String name, String email, String phoneNumber, Gender gender, + LocalDate dateBirth) { this.name = name; this.email = email; this.phoneNumber = phoneNumber; diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java index 6972ccf3..085d99e4 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/OwnerReservationService.java @@ -40,7 +40,7 @@ public void modifyReservationStatus( ) { ReservationStatus modifyStatus = request.status(); // 요청으로 들어온 변경하려는 예약상태 추출 - if(modifyStatus == COMPLETED){ // 취소, 노쇼 처리가 아닌 경우 예외 + if (modifyStatus == COMPLETED) { // 취소, 노쇼 처리가 아닌 경우 예외 throw new BadRequestCustomException(ALREADY_COMPLETED_RESERVATION); }