Skip to content

Commit

Permalink
fix: fix method acquired welcome badge logic
Browse files Browse the repository at this point in the history
  • Loading branch information
thguss committed Jul 16, 2024
1 parent ff9cc95 commit a3d5545
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.smeem.application.domain.auth;

import com.smeem.application.domain.badge.Badge;
import com.smeem.application.domain.member.Member;
import com.smeem.application.port.input.AuthUseCase;
import com.smeem.application.port.input.dto.request.auth.SignInRequest;
import com.smeem.application.port.input.dto.request.member.WithdrawRequest;
import com.smeem.application.port.input.dto.response.auth.GenerateTokenResponse;
import com.smeem.application.port.input.dto.response.auth.SignInResponse;
import com.smeem.application.port.output.oauth.OauthPort;
import com.smeem.application.port.output.persistence.BadgePort;
import com.smeem.application.port.output.persistence.MemberPort;
import com.smeem.common.logger.HookLogger;
import com.smeem.common.logger.LoggingMessage;
Expand All @@ -17,8 +15,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -27,24 +23,16 @@ public class AuthService implements AuthUseCase {
private final OauthPort oauthPort;
private final TokenGenerator tokenGenerator;
private final HookLogger hookLogger;
private final BadgePort badgePort;

@Transactional
public SignInResponse signIn(String socialAccessToken, SignInRequest request) {
val social = oauthPort.login(request.socialType(), socialAccessToken);
val signedMember = signIn(social, request);
val acquiredBadges = new ArrayList<Badge>();
if (signedMember.isNew()) {
acquiredBadges.add(badgePort.saveWelcomeBadgeToMember(signedMember.getId()));
}
signedMember.updateTokenInLogin(
tokenGenerator.generateRefreshToken(signedMember.getId()),
request.fcmToken());
memberPort.update(signedMember);
return SignInResponse.of(
tokenGenerator.generateAccessToken(signedMember.getId()),
signedMember,
acquiredBadges);
return SignInResponse.of(tokenGenerator.generateAccessToken(signedMember.getId()), signedMember);
}

private Member signIn(Member.Social social, SignInRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void visit() {
this.visitDays++;
}

public boolean isNew() {
public boolean signUp() {
return this.username == null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class MemberService implements MemberUseCase {
@Transactional
public UpdateMemberResponse updateMember(long memberId, UpdateMemberRequest request) {
val foundMember = memberPort.findById(memberId);
val isSignIn = foundMember.getUsername() == null;
val acquiredBadges = new ArrayList<Badge>();

if (request.username() != null) {
Expand All @@ -50,7 +49,8 @@ public UpdateMemberResponse updateMember(long memberId, UpdateMemberRequest requ
}
memberPort.update(foundMember);

if (isSignIn) {
if (foundMember.signUp()) {
acquiredBadges.add(badgePort.saveWelcomeBadgeToMember(foundMember.getId()));
hookLogger.send(LoggingMessage.signIn(request.username(), memberPort.countAll()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.smeem.application.port.input.dto.response.auth;

import com.smeem.application.domain.badge.Badge;
import com.smeem.application.domain.member.Member;
import com.smeem.application.port.input.dto.response.badge.AcquiredBadgeResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Builder;

import java.util.List;

@Builder(access = AccessLevel.PRIVATE)
public record SignInResponse(
@Schema(description = "스밈 액세스 토큰")
Expand All @@ -18,18 +14,15 @@ public record SignInResponse(
@Schema(description = "서비스에 등록된 회원인가?")
boolean isRegistered,
@Schema(description = "학습계획을 가진 회원인가?")
boolean hasPlan,
@Schema(description = "일기 작성 후 획득한 배지 정보")
List<AcquiredBadgeResponse> badges
boolean hasPlan
) {

public static SignInResponse of(String accessToken, Member member, List<Badge> badges) {
public static SignInResponse of(String accessToken, Member member) {
return SignInResponse.builder()
.accessToken(accessToken)
.refreshToken(member.getRefreshToken())
.isRegistered(member.getUsername() != null)
.hasPlan(member.getGoalId() != null)
.badges(badges.stream().map(AcquiredBadgeResponse::from).toList())
.build();
}
}

0 comments on commit a3d5545

Please sign in to comment.