Skip to content

Commit

Permalink
Merge pull request #46 from DEPthes/feat/user-character-exist
Browse files Browse the repository at this point in the history
캐릭터 존재 여부 확인 기능 구현
  • Loading branch information
EunbeenDev authored Aug 18, 2024
2 parents 33e299c + 4d599b3 commit 6ecf78c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
@Repository
public interface CharacterRepository extends JpaRepository<Character,Long> {
Optional<Character> findByUserId(Long id);

boolean existsByUser(User user);
}
24 changes: 24 additions & 0 deletions src/main/java/com/noplanb/domain/user/application/UserService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.noplanb.domain.user.application;

import com.noplanb.domain.character.domain.Character;
import com.noplanb.domain.character.repository.CharacterRepository;
import com.noplanb.domain.user.domain.User;
import com.noplanb.domain.user.dto.response.MyAccountRes;
import com.noplanb.domain.user.dto.response.UserCharacterExistRes;
import com.noplanb.domain.user.repository.UserRepository;
import com.noplanb.global.config.security.token.UserPrincipal;
import com.noplanb.global.payload.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
Expand All @@ -18,6 +22,7 @@
public class UserService {

final UserRepository userRepository;
private final CharacterRepository characterRepository;

@Transactional
public void saveUser(User user) {
Expand All @@ -36,5 +41,24 @@ public ResponseEntity<?> getMyAccount(UserPrincipal userPrincipal) {
.build();
return ResponseEntity.ok(myAccountRes);
}
public ResponseEntity<?> getUserCharacterExist(UserPrincipal userPrincipal) {
// 사용자 찾기
User user = userRepository.findById(userPrincipal.getId())
.orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다."));

// 캐릭터 존재 여부 확인
boolean isExist = characterRepository.existsByUser(user);

UserCharacterExistRes userCharacterExistRes = UserCharacterExistRes.builder()
.isExist(isExist)
.build();

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(userCharacterExistRes)
.build();

return ResponseEntity.ok(apiResponse);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.amazonaws.Response;
import com.noplanb.domain.user.application.UserService;
import com.noplanb.domain.user.dto.response.MyAccountRes;
import com.noplanb.domain.user.dto.response.UserCharacterExistRes;
import com.noplanb.global.config.security.token.CurrentUser;
import com.noplanb.global.config.security.token.UserPrincipal;
import com.noplanb.global.payload.ErrorResponse;
Expand Down Expand Up @@ -38,4 +39,13 @@ public ResponseEntity<?> getMyAccount(@Parameter @CurrentUser UserPrincipal user
return userService.getMyAccount(userPrincipal);
}

@Operation(summary = "유저 캐릭터 생성 여부 조회 API", description = "유저의 캐릭터 생성 여부를 조회하는 API입니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "캐릭터 생성 여부 조회 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = UserCharacterExistRes.class) ) } ),
@ApiResponse(responseCode = "400", description = "캐릭터 생성 여부 조회 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
})
@GetMapping("/character-exist")
public ResponseEntity<?> getUserCharacterExist(@Parameter @CurrentUser UserPrincipal userPrincipal){
return userService.getUserCharacterExist(userPrincipal);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.noplanb.domain.user.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
public class UserCharacterExistRes {
@Schema(type = "boolean", example = "true", description = "유저의 캐릭터 생성 여부")
private boolean isExist;
}

0 comments on commit 6ecf78c

Please sign in to comment.