Skip to content

Commit

Permalink
Merge pull request #65 from SWM-Flash/feature/FLASH-264-consent-marke…
Browse files Browse the repository at this point in the history
…ting-api-change

마케팅 동의 여부값 설정 API
  • Loading branch information
ChoiWonYu authored Sep 13, 2024
2 parents 884691b + 6850ba6 commit d4b68c1
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import com.first.flash.account.auth.application.dto.LoginRequestDto;
import com.first.flash.account.auth.application.dto.LoginResponseDto;
import com.first.flash.account.auth.domain.TokenManager;
import com.first.flash.account.auth.exception.exceptions.MarketingConsentRequiredException;
import com.first.flash.account.auth.infrastructure.dto.SocialInfo;
import com.first.flash.account.member.domain.Member;
import com.first.flash.account.member.domain.MemberRepository;
import com.first.flash.account.member.domain.Role;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand All @@ -35,25 +33,21 @@ public LoginResponseDto login(final LoginRequestDto request) {
log.info("로그인 요청: {}", request);
SocialInfo socialInfo = socialService.getSocialInfo(request.provider(), request.token());
Optional<Member> foundMember = memberRepository.findBySocialId(socialInfo.socialId());
Member member = saveOrGetMember(foundMember, socialInfo, request.hasAgreedToMarketing());
Member member = saveOrGetMember(foundMember, socialInfo);
String accessToken = tokenManager.createAccessToken(member.getId());
return new LoginResponseDto(accessToken, member.isCompleteRegistration());
}

private Member saveOrGetMember(final Optional<Member> foundMember,
final SocialInfo socialInfo, final Boolean hasAgreedToMarketing) {
final SocialInfo socialInfo) {
if (foundMember.isPresent()) {
return foundMember.get();
}
if (Objects.isNull(hasAgreedToMarketing)) {
throw new MarketingConsentRequiredException();
}
Member member = Member.builder()
.id(UUID.randomUUID())
.email(socialInfo.email())
.socialId(socialInfo.socialId())
.role(DEFAULT_ROLE)
.hasAgreedToMarketing(hasAgreedToMarketing)
.build();
memberRepository.save(member);
return member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jakarta.validation.constraints.NotNull;

public record LoginRequestDto(@NotEmpty(message = "토큰은 필수입니다.") String token,
@NotNull(message = "플랫폼은 필수입니다.") @ValidEnum(enumClass = Provider.class) Provider provider,
Boolean hasAgreedToMarketing) {
@NotNull(message = "플랫폼은 필수입니다.") @ValidEnum(enumClass = Provider.class) Provider provider) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.first.flash.account.auth.exception.exceptions.InvalidAppleKeyException;
import com.first.flash.account.auth.exception.exceptions.InvalidTokenException;
import com.first.flash.account.auth.exception.exceptions.MarketingConsentRequiredException;
import com.first.flash.account.auth.exception.exceptions.SocialRequestFailedException;
import com.first.flash.account.auth.exception.exceptions.TokenExpiredException;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -37,12 +36,6 @@ public ResponseEntity<String> handleTokenExpiredException(
return getResponseWithStatus(HttpStatus.BAD_REQUEST, exception);
}

@ExceptionHandler
public ResponseEntity<String> handleMarketingConsentRequiredException(
final MarketingConsentRequiredException exception) {
return getResponseWithStatus(HttpStatus.BAD_REQUEST, exception);
}

private ResponseEntity<String> getResponseWithStatus(final HttpStatus httpStatus,
final RuntimeException exception) {
return ResponseEntity.status(httpStatus)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.first.flash.account.member.application.dto.ConfirmNickNameRequest;
import com.first.flash.account.member.application.dto.ConfirmNickNameResponse;
import com.first.flash.account.member.application.dto.ManageConsentRequest;
import com.first.flash.account.member.application.dto.ManageConsentResponse;
import com.first.flash.account.member.application.dto.MemberCompleteRegistrationRequest;
import com.first.flash.account.member.application.dto.MemberCompleteRegistrationResponse;
import com.first.flash.account.member.application.dto.MemberInfoResponse;
Expand Down Expand Up @@ -70,6 +72,14 @@ public MemberInfoResponse deleteMember() {
return MemberInfoResponse.toDto(member);
}

@Transactional
public ManageConsentResponse manageMarketingConsent(final ManageConsentRequest request) {
Boolean hasAgreedToMarketing = request.hasAgreedToMarketing();
Member member = findMemberByAuthInfo();
member.manageMarketingConsent(hasAgreedToMarketing);
return ManageConsentResponse.toDto(member);
}

private Member findMemberByAuthInfo() {
UUID id = AuthUtil.getId();
return findById(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.first.flash.account.member.application.dto;

import jakarta.validation.constraints.NotNull;

public record ManageConsentRequest(@NotNull(message = "마케팅 수신 동의 여부는 필수입니다.") Boolean hasAgreedToMarketing) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.first.flash.account.member.application.dto;

import com.first.flash.account.member.domain.Member;

public record ManageConsentResponse(boolean hasAgreedToMarketing) {

public static ManageConsentResponse toDto(final Member member) {
return new ManageConsentResponse(member.getHasAgreedToMarketing());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ public boolean hasSameNickName(final String nickName) {
public boolean isCompleteRegistration() {
return Objects.nonNull(nickName);
}

public void manageMarketingConsent(final Boolean hasAgreedToMarketing) {
this.hasAgreedToMarketing = hasAgreedToMarketing;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.first.flash.account.member.application.ReportService;
import com.first.flash.account.member.application.dto.ConfirmNickNameRequest;
import com.first.flash.account.member.application.dto.ConfirmNickNameResponse;
import com.first.flash.account.member.application.dto.ManageConsentRequest;
import com.first.flash.account.member.application.dto.ManageConsentResponse;
import com.first.flash.account.member.application.dto.MemberBlockResponse;
import com.first.flash.account.member.application.dto.MemberCompleteRegistrationRequest;
import com.first.flash.account.member.application.dto.MemberCompleteRegistrationResponse;
Expand Down Expand Up @@ -128,4 +130,19 @@ public ResponseEntity<MemberReportResponse> reportMember(
@RequestBody @Valid final MemberReportRequest request) {
return ResponseEntity.ok(reportService.reportMember(reportedContentId, request));
}

@Operation(summary = "마케팅 수신 동의 여부 설정", description = "마케팅 수신 동의 여부 설정")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "동의 여부 설정 완료",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ManageConsentResponse.class))),
@ApiResponse(responseCode = "400", description = "유효하지 않은 요청 형식",
content = @Content(mediaType = "application/json", examples = {
@ExampleObject(name = "요청값 누락", value = "{\"hasAgreedToMarketing\": \"동의 여부는 필수입니다.\"}"),
}))
})
@PostMapping("/marketing-consent")
public ResponseEntity<ManageConsentResponse> manageMarketingConsent(
@RequestBody @Valid final ManageConsentRequest request) {
return ResponseEntity.ok(memberService.manageMarketingConsent(request));
}
}

0 comments on commit d4b68c1

Please sign in to comment.