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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.renzzle.backend.domain.auth.api.request.SignupRequest;
import com.renzzle.backend.domain.auth.api.response.LoginResponse;
import com.renzzle.backend.domain.user.dao.UserRepository;
import com.renzzle.backend.domain.puzzle.training.service.TrainingService;
import com.renzzle.backend.domain.user.domain.UserEntity;
import com.renzzle.backend.global.exception.CustomException;
import com.renzzle.backend.global.exception.ErrorCode;
Expand All @@ -23,6 +24,7 @@ public class AccountService {
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
private final AuthService authService;
private final TrainingService trainingService;

@Transactional(readOnly = true)
public boolean isDuplicatedEmail(String email) {
Expand All @@ -46,7 +48,8 @@ public LoginResponse signUp(SignupRequest request) {
}

UserEntity user = createNewUser(request.email(), request.password(), request.nickname(), request.deviceId());

// 회원가입 시 packId = 1 자동 지급
trainingService.grantPackToUser(user, 1L);
return authService.createAuthTokens(user.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,28 @@ public GetTrainingPuzzleAnswerResponse purchaseTrainingPuzzleAnswer(UserEntity u
.price(ItemPrice.HINT.getPrice())
.build();
}

// 회원가입 시 무료로 특정 Pack을 지급 (잔액 차감 없음)
@Transactional
public void grantPackToUser(UserEntity user, Long packId) {
if (user == null || packId == null) {
throw new CustomException(ErrorCode.VALIDATION_ERROR);
}

Pack pack = packRepository.findById(packId)
.orElseThrow(() -> new CustomException(ErrorCode.NO_SUCH_TRAINING_PACK));

// 이미 보유한 경우 무시
if (userPackRepository.findByUserIdAndPackId(user.getId(), packId).isPresent()) {
return;
}

UserPack userPack = UserPack.builder()
.user(user)
.pack(pack)
.solvedCount(0)
.build();

userPackRepository.save(userPack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.renzzle.backend.domain.auth.api.request.SignupRequest;
import com.renzzle.backend.domain.auth.api.response.LoginResponse;
import com.renzzle.backend.domain.user.dao.UserRepository;
import com.renzzle.backend.domain.puzzle.training.service.TrainingService;
import com.renzzle.backend.domain.user.domain.UserEntity;
import com.renzzle.backend.global.exception.CustomException;
import com.renzzle.backend.global.exception.ErrorCode;
Expand Down Expand Up @@ -34,6 +35,8 @@ public class AccountServiceTest {
private UserRepository userRepository;
@Mock
private AuthService authService;
@Mock
private TrainingService trainingService;

@InjectMocks
private AccountService accountService;
Expand Down Expand Up @@ -62,6 +65,7 @@ public void signUp_ShouldCreateUserAndReturnTokens_WhenValid() {
when(userRepository.existsByDeviceId(deviceId)).thenReturn(false);
when(userRepository.save(any(UserEntity.class))).thenAnswer(i -> UserEntity.builder().id(1L).build());
when(authService.createAuthTokens(anyLong())).thenReturn(mock(LoginResponse.class));
doNothing().when(trainingService).grantPackToUser(any(UserEntity.class), eq(1L));

// when
LoginResponse response = accountService.signUp(validSignupRequest);
Expand Down