Skip to content
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
4 changes: 4 additions & 0 deletions src/main/java/org/sopt/app/application/user/UserInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.sopt.app.application.user;

public record UserInfo (Long userId){
}
10 changes: 10 additions & 0 deletions src/main/java/org/sopt/app/application/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ public List<String> getIcons(IconType iconType) {
.map(Icons::getIconUrl)
.toList();
}

@Transactional
public UserInfo createUser(Long userId) {
User user = User.builder()
.id(userId)
.build();
User savedUser = userRepository.save(user);

return new UserInfo(savedUser.getId());
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/sopt/app/common/response/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum ErrorCode {
INVALID_PLAYGROUND_CODE("유효하지 않은 플레이그라운드 OAuth 코드입니다.", HttpStatus.UNAUTHORIZED),
UNAUTHORIZED("권한이 없습니다", HttpStatus.UNAUTHORIZED),
TOKEN_EXPIRED("토큰이 만료되었습니다.", HttpStatus.UNAUTHORIZED),

INVALID_INTERNAL_API_KEY("유효하지 않은 내부 API key 입니다.", HttpStatus.UNAUTHORIZED),
// AUTH_CLIENT
RESPONSE_ERROR("외부 서버 응답 오류", HttpStatus.INTERNAL_SERVER_ERROR),
COMMUNICATION_ERROR("외부 서버 통신 실패", HttpStatus.INTERNAL_SERVER_ERROR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class WebSecurityConfig {
"/api/v2/firebase/**",
"/api/v2/notification/**",
"/api/v2/user/main",
"/api/v2/user/register",
"/api/v2/home/app-service",
"/api/v2/home/floating-button",
"/api/v2/home/review-form"
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/sopt/app/facade/UserFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.sopt.app.application.notification.NotificationService;
import org.sopt.app.application.app_service.AppServiceService;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo;
import org.sopt.app.application.user.UserInfo;
import org.sopt.app.application.user.UserService;
import org.sopt.app.domain.entity.User;
import org.sopt.app.presentation.user.UserResponse.*;
import org.sopt.app.presentation.user.UserResponseMapper;
Expand All @@ -25,6 +27,7 @@ public class UserFacade {
private final AppServiceService appServiceService;
private final UserResponseMapper userResponseMapper;
private final PlatformService platformService;
private final UserService userService;

@Transactional(readOnly = true)
public MainView getMainViewInfo(Long userId) {
Expand All @@ -50,4 +53,9 @@ public List<AppService> getAppServiceInfo() {
.map(AppService::of)
.toList();
}

@Transactional
public UserInfo createUser(Long requestUserId){
Comment on lines +57 to +58
Copy link
Member

@huncozyboy huncozyboy Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저번에 재헌님이랑 대화해보면서 나오기도 했었던 읽기/쓰기와 관련해서 코멘트 남깁니다

제가 코멘트 남긴 부분의 createUser 메서드 처럼 (이번에 추가된 메서드가 아닌 기존 메서드도 동일)
Facade 패턴에서 UserFacade 내부에서 트랜잭션을 잡아주고 있는 구조로 이해했어요

application/user/UserService에서도 @transactional 으로 설정되어 있는 구조로 이해했는데,
" 실제 쓰기 트랜잭션만 서비스에 두고 파사드/컨트롤러는 읽기에 집중 " 시키는거는 어떨까라는 생각이 들었습니다

저도 파사드 패턴에 대해서는 자세하게 알지 못하지만, Facade 자체에서도 트랜잭션을 잡아주게 되면서 생기는 사이드 이펙트는 없을까 ? 라는 생각에서 시작된 궁금증이였어요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 생각했을 땐 파사드 패턴이 현재는 도메인별 서비스를 가져와서 사용하는 구조이다보니 트랜잭션을 설정할 수 밖에 없는 것 같아요. 지훈님이 말씀하신 실제 쓰기 트랜잭션만 서비스에 둔다는게 @transactional 을 서비스에만 걸어준다는 방식으로 이해했는데 이게 맞을까요??
이런 식으로 @transactional 룰을 정하면 어떤 이점이 있다고 생각하셨을까요?

제 개인적인 생각으론 필요에 따라서 @transactional 을 설정하는게 바람직한 것 같아요. 사실 지금 구조는 단순 save 메서드만 호출하는 구조이기 때문에 @transactional을 호출하지 않아도 SimplaJpaRepo에서 자동으로 트랜잭션을 걸어주지만, "추후 기능적 확장을 고려했을 때 해당 메서드에 @transactional을 걸어주는게 좋겠다"라는 생각이었습니다. 만약 다른 정보를 가져와서 함께 유저에게 저장해준다던가, 다른 정보도 함께 수정된다던가 할 때는 결국 작업의 원자성을 보장하기 위해서 @transactional을 파사드단에서도 걸어주는게 필요하다는 입장입니다.

혹시 지훈님이 걱정하시는 사이드 이펙트는 어떤 게 있을까요??

return userService.createUser(requestUserId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.val;

import org.sopt.app.application.platform.PlatformService;
import org.sopt.app.application.playground.PlaygroundAuthService;
import org.sopt.app.application.playground.dto.PlaygroundPostInfo.PlaygroundPost;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo;
import org.sopt.app.domain.entity.User;
import org.sopt.app.common.exception.UnauthorizedException;
import org.sopt.app.common.response.ErrorCode;
import org.sopt.app.facade.UserFacade;
import org.sopt.app.presentation.user.UserResponse.AppService;
import org.sopt.app.presentation.user.UserRequest.CreateUserRequest;
import org.sopt.app.presentation.user.UserResponse.Create;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down Expand Up @@ -61,4 +64,25 @@ public ResponseEntity<UserResponse.Generation> getGenerationInfo(
userResponseMapper.ofGeneration(
platformService.getUserActiveInfo(userId)));
}

@Operation
@ApiResponses({
@ApiResponse(responseCode = "200", description = "success"),
@ApiResponse(responseCode = "401", description = "token error", content = @Content),
@ApiResponse(responseCode = "500", description = "server error", content = @Content)
})
@PostMapping("/register")
public ResponseEntity<Create> createDefaultUserProfile(
@RequestBody CreateUserRequest request,
@RequestHeader("apiKey") String apiKey,
@Value("${internal.auth.api-key}") String internalApiKey
){
if(!internalApiKey.equals(apiKey)){
throw new UnauthorizedException(ErrorCode.INVALID_INTERNAL_API_KEY);
}

return ResponseEntity.ok(
userResponseMapper.ofCreate(
userFacade.createUser(request.getUserId())));
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/sopt/app/presentation/user/UserRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ public static class EditProfileMessageRequest {
@NotNull(message = "profileMessage may not be null")
private String profileMessage;
}

@Getter
@AllArgsConstructor(access = AccessLevel.PUBLIC)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class CreateUserRequest{
@Schema(description = "생성된 UserId", example = "101")
@NotNull(message = "userId may not be null")
private Long userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.util.stream.Collectors;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.sopt.app.application.app_service.dto.AppServiceInfo;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo;
import org.sopt.app.application.playground.dto.PlaygroundProfileInfo.PlaygroundProfile;
import org.sopt.app.domain.enums.PlaygroundPart;

Expand Down Expand Up @@ -186,4 +186,11 @@ public static SoptLog of(int soptLevel, Long pokeCount, Long soptampRank, Long d
.build();
}
}

@Getter
@AllArgsConstructor
public static class Create {
@Schema(description = "생성된 유저 ID", example = "101")
private Long userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

@Mapper(
Expand All @@ -17,4 +18,6 @@ UserResponse.MainView ofMainView(PlaygroundProfileInfo.MainView user, UserRespon
UserResponse.ProfileMessage of(ProfileMessage profileMessage);

UserResponse.Generation ofGeneration(PlaygroundProfileInfo.UserActiveInfo userActiveInfo);

Create ofCreate(UserInfo userInfo);
}