Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 결제 요청 독촉 메세지 #111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ordertogether.team14_be.order.details.controller;

import com.ordertogether.team14_be.member.persistence.MemberRepository;
import com.ordertogether.team14_be.member.persistence.entity.Member;
import com.ordertogether.team14_be.member.presentation.LoginMember;
import com.ordertogether.team14_be.order.details.service.SmsService;
Expand All @@ -9,14 +10,22 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/spot/sms/{spotId}")
@RequestMapping("/api/v1")
public class SmsController {

private final SmsService smsService;
private final MemberRepository memberRepository;

@GetMapping
@GetMapping("/spot/sms/{spotId}")
public ResponseEntity<Void> getOrdersInfo(@LoginMember Member member, @PathVariable Long spotId) {
smsService.sendLinkToParticipant(member, spotId);
return ResponseEntity.ok().build();
}

@GetMapping("/orders/sms/{spotId}/{participantId}")
public ResponseEntity<Void> getOrdersInfo(
@LoginMember Member creator, @PathVariable Long spotId, @PathVariable Long participantId) {
smsService.remindToParticipant(participantId, spotId);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ordertogether.team14_be.order.details.service;

import com.ordertogether.team14_be.member.persistence.MemberRepository;
import com.ordertogether.team14_be.member.persistence.entity.Member;
import com.ordertogether.team14_be.order.details.util.SmsUtil;
import com.ordertogether.team14_be.spot.entity.Spot;
Expand All @@ -13,6 +14,7 @@
public class SmsService {
private final SmsUtil smsUtil;
private final SimpleSpotRepository simpleSpotRepository;
private final MemberRepository memberRepository;

public ResponseEntity<?> sendLinkToParticipant(Member member, Long spotId) {
// 수신번호 형태에 맞춰 "-"을 ""로 변환
Expand All @@ -28,4 +30,24 @@ public ResponseEntity<?> sendLinkToParticipant(Member member, Long spotId) {

return ResponseEntity.ok().build();
}

public ResponseEntity<?> remindToParticipant(Long spotId, Long participantId) {
// 수신번호 형태에 맞춰 "-"을 ""로 변환
Member participant =
memberRepository
.findById(participantId)
.orElseThrow(() -> new IllegalArgumentException("사용자 정보를 찾을 수 없습니다."));

String phoneNum = participant.getPhoneNumber().replaceAll("-", "");

Spot spot =
simpleSpotRepository
.findById(spotId)
.orElseThrow(() -> new IllegalArgumentException("스팟 정보가 없습니다."));

String link = spot.getTogetherOrderLink();
smsUtil.remindOrder(phoneNum, link);

return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ private void init() {
NurigoApp.INSTANCE.initialize(apiKey, apiSecretKey, "https://api.coolsms.co.kr");
}

// 단일 메시지 발송 예제
public SingleMessageSentResponse sendOne(String to, String link) {
Message message = new Message();
// 발신번호 및 수신번호는 반드시 01012345678 형태로 입력되어야 합니다.
Expand All @@ -38,4 +37,16 @@ public SingleMessageSentResponse sendOne(String to, String link) {
this.messageService.sendOne(new SingleMessageSendingRequest(message));
return response;
}

public SingleMessageSentResponse remindOrder(String to, String link) {
Message message = new Message();
// 발신번호 및 수신번호는 반드시 01012345678 형태로 입력되어야 합니다.
message.setFrom("01043064404");
message.setTo(to);
message.setText("[여기먹때] 아직 주문이 완료되지 않았습니다. 주문을 완료해주세요. \n" + link);

SingleMessageSentResponse response =
this.messageService.sendOne(new SingleMessageSendingRequest(message));
return response;
}
}