Skip to content

Commit

Permalink
[MODIFY] /user/main시에 로그인되지 않은 유저는 401이 아닌 정상 응답을 보내도록 변경 (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
kseysh authored Jan 10, 2025
2 parents cdb46af + 8b8e981 commit 6a0f388
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class WebSecurityConfig {
"/api/v2/auth/**",
"/api/v2/config/**",
"/api/v2/firebase/**",
"/api/v2/notification/**"
"/api/v2/notification/**",
"/api/v2/user/main"
};

private final JwtExceptionFilter jwtExceptionFilter;
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/sopt/app/facade/UserFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import lombok.val;
import org.sopt.app.application.playground.PlaygroundAuthService;
import org.sopt.app.application.notification.NotificationService;
import org.sopt.app.application.operation.OperationInfo;
import org.sopt.app.application.app_service.AppServiceService;
import org.sopt.app.domain.entity.User;
import org.sopt.app.presentation.user.UserResponse.AppService;
import org.sopt.app.presentation.user.UserResponse.MainView;
import org.sopt.app.presentation.user.UserResponse.*;
import org.sopt.app.presentation.user.UserResponseMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -25,11 +23,15 @@ public class UserFacade {

@Transactional(readOnly = true)
public MainView getMainViewInfo(User user) {
val mainViewUser = playgroundAuthService.getPlaygroundUserForMainView(user.getPlaygroundToken(),
user.getPlaygroundId());
val dummyOperation = OperationInfo.MainView.builder().announcement("공지다!").attendanceScore(2D).build();
if(user == null) {
return MainView.unauthenticatedMainView();
}

val mainViewUser = playgroundAuthService.getPlaygroundUserForMainView(
user.getPlaygroundToken(), user.getPlaygroundId()
);
val mainViewNotification = notificationService.getNotificationConfirmStatus(user.getId());
return userResponseMapper.ofMainView(mainViewUser, dummyOperation, mainViewNotification);
return userResponseMapper.ofMainView(mainViewUser, Operation.defaultOperation(), mainViewNotification);
}

@Transactional(readOnly = true)
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/sopt/app/presentation/user/UserResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public static class MainView {
@Schema(description = "알림 전체 읽음 여부", example = "false")
private Boolean isAllConfirm;

public static MainView unauthenticatedMainView() {
return MainView.builder()
.user(Playground.unauthenticatedUser())
.operation(Operation.defaultOperation())
.isAllConfirm(false)
.build();
}
}

@Getter
Expand All @@ -36,6 +43,15 @@ public static class Playground {
@Schema(description = "유저 활동 기수 정보", example = "[32,30,29]")
private List<Long> generationList;

public static Playground unauthenticatedUser() {
return Playground.builder()
.status("UNAUTHENTICATED")
.name("")
.profileImage("")
.generationList(List.of())
.build();
}

}

@Getter
Expand All @@ -48,6 +64,12 @@ public static class Operation {
@Schema(description = "솝트 공지", example = "공지다!")
private String announcement;

public static Operation defaultOperation() {
return Operation.builder()
.attendanceScore(0D)
.announcement("")
.build();
}
}

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

import org.mapstruct.*;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo;
import org.sopt.app.application.operation.OperationInfo;
import org.sopt.app.presentation.user.UserResponse.*;

@Mapper(
Expand All @@ -12,7 +11,7 @@
)
public interface UserResponseMapper {

UserResponse.MainView ofMainView(PlaygroundProfileInfo.MainView user, OperationInfo.MainView operation,
UserResponse.MainView ofMainView(PlaygroundProfileInfo.MainView user, UserResponse.Operation operation,
Boolean isAllConfirm);

UserResponse.ProfileMessage of(ProfileMessage profileMessage);
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/sopt/app/facade/UserFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.MainView;
import org.sopt.app.application.playground.PlaygroundAuthService;
import org.sopt.app.application.notification.NotificationService;
import org.sopt.app.application.operation.OperationInfo;
import org.sopt.app.common.fixtures.UserFixture;
import org.sopt.app.presentation.user.UserResponse;
import org.sopt.app.presentation.user.UserResponse.Operation;
Expand Down Expand Up @@ -49,8 +48,8 @@ void getMainViewInfo() {
//when
when(playgroundAuthService.getPlaygroundUserForMainView(anyString(), anyLong())).thenReturn(playgroundAuthInfo);
when(notificationService.getNotificationConfirmStatus(anyLong())).thenReturn(isNotificationConfirm);
when(userResponseMapper.ofMainView(any(MainView.class), any(OperationInfo.MainView.class),
anyBoolean())).thenReturn(mainViewResponse);
when(userResponseMapper.ofMainView(any(MainView.class), any(UserResponse.Operation.class), anyBoolean()))
.thenReturn(mainViewResponse);

UserResponse.MainView expected = UserResponse.MainView.builder()
.user(mainViewResponse.getUser())
Expand Down

0 comments on commit 6a0f388

Please sign in to comment.