Skip to content

Commit

Permalink
Merge pull request #162 from TraviTago/fix/#72
Browse files Browse the repository at this point in the history
fix: verify-code API 응답에 회원가입 여부 추가
  • Loading branch information
twoosky authored Oct 17, 2023
2 parents fd1e70b + 4051438 commit 7ecca39
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 22 deletions.
4 changes: 3 additions & 1 deletion api/src/main/java/com/tago/api/infra/fcm/FCMClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ public void send(FCMSendDto dto) {

String token = fcmTokenUtil.get(dto.getPhoneNumber());
Message message = Message.builder()
.putData("payload", dto.getPayload())
.putData("title", dto.getTitle())
.putData("content", dto.getContent())
.setToken(token)
.build();

try {
FirebaseMessaging.getInstance().send(message);
String response = FirebaseMessaging.getInstance().send(message);
log.info("## SUCCESS SEND FCM ## " + response);
} catch (FirebaseMessagingException e) {
throw new FailedSendFCMException(e);
}
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/com/tago/api/infra/fcm/FCMSendDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class FCMSendDto {
private String title;
private String content;
private String phoneNumber;
private String payload;
}
1 change: 1 addition & 0 deletions api/src/main/java/com/tago/api/infra/fcm/FCMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class FCMService {
public void sendByTripMemberEvent(TripMemberEvent event) {
FCMType type = FCMType.from(event.getAction());
fcmClient.send(FCMSendDto.builder()
.payload(String.valueOf(event.getTripId()))
.title(type.getTitle())
.content(type.getContent(event.getName()))
.phoneNumber(event.getPhoneNumber())
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/com/tago/api/infra/fcm/FCMType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.function.Function;
@Getter
public enum FCMType {
CREATE_TRIP_MEMBER("TAGO", (name) -> name + "님! 여행메이트가 한명 추가되었어요! 클릭해서 확인해보세요."),
CREATE_TRIP_MEMBER("TAGO", (name) -> name + "님! 여행인원이 한명 추가되었어요! 클릭해서 확인해보세요."),
DELETE_TRIP_MEMBER("TAGO", (name) -> name + "님! 여행인원이 줄어들었어요. 클릭해서 확인해보세요."),
COMPLETE_TRIP_MEMBER("TAGO", (name) -> name + "님! 여행인원이 모두 모집되었네요! 클릭해서 확인해보세요."),
CREATE_DISPATCH("TAGO", (name) -> name + "님! 여행을 같이 할 기사님이 배정되었어요. 클릭해서 확인해보세요.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.tago.api.infra.sms.domain.dto.SmsRequest;
import com.tago.api.infra.sms.domain.dto.SmsResponse;
import com.tago.api.infra.sms.util.VerificationCodeUtil;
import com.tago.domain.member.handler.MemberQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -13,14 +14,21 @@ public class SmsService {

private final SmsClient smsClient;
private final VerificationCodeUtil verificationCodeUtil;
private final MemberQueryService memberQueryService;

public void send(SmsRequest.Send request) {
smsClient.send(request);
}

public SmsResponse.VerifyCode verifyCode(SmsRequest.VerifyCode request) {
verificationCodeUtil.verify(request.getNumber(), request.getCode());
return new SmsResponse.VerifyCode(true);
return new SmsResponse.VerifyCode(true, isSignUp(request.getNumber()));
}

public Boolean isSignUp(String number) {
String regEx = "(\\d{3})(\\d{3,4})(\\d{4})";
String phoneNumber = number.replaceAll(regEx, "$1-$2-$3");
return memberQueryService.existsByPhoneNumber(phoneNumber);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class SmsResponse {
@AllArgsConstructor
@Schema(name = "AuthSmsVerifyCodeResponse")
public static class VerifyCode {
private boolean isVerify;
private Boolean isVerify;
private Boolean isSignUp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class DispatchEvent implements Event {
private Long tripId;
private String phoneNumber;
private String name;
private Action action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.tago.domain.driver.handler.DispatchCommandService;
import com.tago.domain.driver.handler.DispatchQueryService;
import com.tago.domain.driver.service.factory.dispatch.DispatchService;
import com.tago.domain.member.domain.Member;
import com.tago.domain.trip.domain.Trip;
import com.tago.domain.trip.exception.TripNotFoundException;
import com.tago.domain.tripmember.domain.TripMember;
Expand Down Expand Up @@ -37,22 +38,23 @@ public void dispatch(Trip trip, Driver driver) {
.build();

dispatchCommandService.save(dispatch);
producerEvent(trip);
publishEvent(trip);
}

private void validateDispatchAble(Trip trip) {
dispatchQueryService.findOptionalByTrip(trip)
.ifPresent(dispatch -> {throw new AlreadyExistsDispatchException();});
}

private void producerEvent(Trip trip) {
trip.getTripMembers().forEach(this::publish);
private void publishEvent(Trip trip) {
trip.getTripMembers().forEach(tripMember -> publish(trip, tripMember.getMember()));
}

public void publish(TripMember tripMember) {
public void publish(Trip trip, Member member) {
dispatchEventProducer.produceEvent(DispatchEvent.builder()
.name(tripMember.getMember().getName())
.phoneNumber(tripMember.getMember().getPhoneNumber())
.tripId(trip.getId())
.name(member.getName())
.phoneNumber(member.getPhoneNumber())
.action(DispatchEvent.Action.CREATE)
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public Optional<Member> findOptionalByPhoneNumber(String phoneNumber) {
public boolean existsById(Long memberId) {
return memberRepository.existsById(memberId);
}

public boolean existsByPhoneNumber(String phoneNumber) {
return memberRepository.existsByPhoneNumber(phoneNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

public interface MemberRepository extends JpaRepository<Member, Long>, MemberCustomRepository {
Optional<Member> findByPhoneNumber(String phoneNumber);
Boolean existsByPhoneNumber(String phoneNumber);
}
2 changes: 1 addition & 1 deletion domain/src/main/java/com/tago/domain/trip/domain/Trip.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void deleteTripMember(Member member) {
this.tripMembers.addAll(tripMembers);
}

private boolean isLimitMember() {
public boolean isLimitMember() {
return this.currentCnt >= this.maxCnt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)

public class TripMemberEvent implements Event {
private Long tripId;
private String name;
private String phoneNumber;
private Action action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

import com.tago.domain.member.domain.Member;
import com.tago.domain.trip.domain.Trip;
import com.tago.domain.tripmember.domain.TripMember;
import com.tago.domain.tripmember.event.producer.TripMemberEvent;
import com.tago.domain.tripmember.event.producer.TripMemberEventProducer;
import com.tago.domain.tripmember.exception.AlreadyExistsTripMemberException;
import com.tago.domain.tripmember.handler.TripMemberQueryService;
import com.tago.domain.tripmember.service.factory.TripMemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -28,8 +26,8 @@ public String getState() {
@Override
public void action(Trip trip, Member member) {
validateJoinedAble(trip, member);
trip.getTripMembers().forEach(this::publish);
trip.join(member);
publishEvent(trip, member);
}

private void validateJoinedAble(Trip trip, Member member) {
Expand All @@ -38,14 +36,28 @@ private void validateJoinedAble(Trip trip, Member member) {
}
}

private void publish(TripMember tripMember) {
private void publishEvent(Trip trip, Member member) {
trip.getTripMembers().stream()
.filter(tripMember -> !tripMember.getMember().equals(member))
.forEach(tripMember -> publish(trip, tripMember.getMember(), getEventAction(trip)));
}

private void publish(Trip trip, Member member, TripMemberEvent.Action action) {
tripMemberEventProducer.produceEvent(TripMemberEvent.builder()
.name(tripMember.getMember().getName())
.phoneNumber(tripMember.getMember().getPhoneNumber())
.action(TripMemberEvent.Action.CREATE)
.tripId(trip.getId())
.name(member.getName())
.phoneNumber(member.getPhoneNumber())
.action(action)
.build()
);
}

private TripMemberEvent.Action getEventAction(Trip trip) {
if (trip.isLimitMember()) {
return TripMemberEvent.Action.COMPLETE;
}
return TripMemberEvent.Action.CREATE;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public String getState() {
@Override
public void action(Trip trip, Member member) {
trip.leave(member);
trip.getTripMembers().forEach(this::publish);
trip.getTripMembers().forEach(tripMember -> publish(trip, tripMember.getMember()));
}

private void publish(TripMember tripMember) {
private void publish(Trip trip, Member member) {
tripMemberEventProducer.produceEvent(TripMemberEvent.builder()
.name(tripMember.getMember().getName())
.phoneNumber(tripMember.getMember().getPhoneNumber())
.tripId(trip.getId())
.name(member.getName())
.phoneNumber(member.getPhoneNumber())
.action(TripMemberEvent.Action.DELETE)
.build()
);
Expand Down

0 comments on commit 7ecca39

Please sign in to comment.