Skip to content

Commit

Permalink
Merge pull request #30 from DigiLabChallengeHackathon/fix/char
Browse files Browse the repository at this point in the history
fix: char api
  • Loading branch information
andrewkimswe authored Nov 30, 2024
2 parents 1da3032 + c972440 commit 605d62c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/mosabulgyeo/bewavoca/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class User {
* 선택되지 않은 경우 null.
*/
@Column(nullable = true)
private Long selectedCharacterId;
private Long selectedCharacterId = 1L;

@ElementCollection
@CollectionTable(name = "user_cleared_stages", joinColumns = @JoinColumn(name = "user_id"))
Expand Down Expand Up @@ -120,6 +120,7 @@ public User(String deviceId, String nickname) {

this.deviceId = deviceId;
this.nickname = nickname;
this.selectedCharacterId = 1L;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public List<CharacterResponse> getAvailableCharacters(String deviceId) {
* @param request 선택 요청 데이터 (기기 ID, 캐릭터 ID 포함)
* @throws IllegalArgumentException 사용자 또는 캐릭터가 존재하지 않거나 캐릭터 잠금 해제가 되지 않았을 경우
*/
/**
* 캐릭터 선택 기능
* 사용자가 특정 캐릭터를 선택하면 해당 캐릭터를 설정.
*
* @param request 선택 요청 데이터 (기기 ID, 캐릭터 ID 포함)
* @throws IllegalArgumentException 사용자 또는 캐릭터가 존재하지 않을 경우
*/
@Transactional
public void selectCharacter(SelectCharacterRequest request) {
User user = userRepository.findByDeviceId(request.getDeviceId())
Expand All @@ -69,10 +76,6 @@ public void selectCharacter(SelectCharacterRequest request) {
Character character = characterRepository.findById(request.getCharacterId())
.orElseThrow(() -> new IllegalArgumentException("Character not found"));

if (!user.hasClearedRegion(character.getRegion().getId())) {
throw new IllegalArgumentException("Region not cleared for the selected character.");
}

user.setSelectedCharacterId(character.getId());
userRepository.save(user);
}
Expand Down

0 comments on commit 605d62c

Please sign in to comment.