diff --git a/src/main/java/com/goormdari/domain/routine/presentation/RoutineController.java b/src/main/java/com/goormdari/domain/routine/presentation/RoutineController.java index 4fabb42..2caf951 100644 --- a/src/main/java/com/goormdari/domain/routine/presentation/RoutineController.java +++ b/src/main/java/com/goormdari/domain/routine/presentation/RoutineController.java @@ -40,7 +40,7 @@ public class RoutineController { @Operation(summary = "루틴 완수", description = "사진을 업로드하여 루틴을 완수합니다") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "루틴 완수 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}), + @ApiResponse(responseCode = "200", description = "루틴 완수 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}), @ApiResponse(responseCode = "400", description = "루틴 완수 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), }) @PostMapping("/upload") @@ -58,12 +58,12 @@ public ResponseCustom uploadRoutine( } Long userId = jwtUtil.extractId(jwt); String imgURL = s3Service.uploadImageToS3(completeRoutineRequest.file()); - return ResponseCustom.OK(routineService.completeRoutine(userId, completeRoutineRequest,imgURL)); + return ResponseCustom.OK(routineService.completeRoutine(userId, completeRoutineRequest, imgURL)); } @Operation(summary = "루틴 삭제", description = "이미지 url, routineIndex로 삭제") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "루틴 완수 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ResponseCustom.class))}), + @ApiResponse(responseCode = "200", description = "루틴 완수 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ResponseCustom.class))}), @ApiResponse(responseCode = "400", description = "루틴 완수 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), }) @DeleteMapping("/upload") @@ -82,20 +82,19 @@ public ResponseCustom deleteRoutine( } Long userId = jwtUtil.extractId(jwt); s3Service.deleteImageOnS3(imgURL); - return ResponseCustom.OK(routineService.deleteRoutineByUserIdAndRoutineIndex(userId,routineIndex)); + return ResponseCustom.OK(routineService.deleteRoutineByUserIdAndRoutineIndex(userId, routineIndex)); } @Operation(summary = "유저별 루틴 전체 조회", description = "userId로 해당 유저 루틴 전체 조회") @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "루틴 완수 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ResponseCustom.class))}), + @ApiResponse(responseCode = "200", description = "루틴 완수 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ResponseCustom.class))}), @ApiResponse(responseCode = "400", description = "루틴 완수 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), }) @GetMapping("/{userId}") - public ResponseCustom> getAllRoutineByUserId( + public ResponseCustom> getAllRoutineByUserId( @Parameter(description = "조회 할 userId", required = true) @PathVariable("userId") Long userId ) { return ResponseCustom.OK(routineService.findAllRoutineByUserId(userId)); } - } diff --git a/src/main/java/com/goormdari/domain/user/domain/DefaultProfileUrl.java b/src/main/java/com/goormdari/domain/user/domain/DefaultProfileUrl.java new file mode 100644 index 0000000..0e97876 --- /dev/null +++ b/src/main/java/com/goormdari/domain/user/domain/DefaultProfileUrl.java @@ -0,0 +1,32 @@ +package com.goormdari.domain.user.domain; + +import java.util.Random; + +public enum DefaultProfileUrl { + A("https://goormdari.s3.ap-northeast-2.amazonaws.com/394624e7-8fe3-4c95-8141-3935df511922-KakaoTalk_Photo_2024-09-28-20-30-53%20004.png"), + B("https://goormdari.s3.ap-northeast-2.amazonaws.com/7e0b113d-e904-45e7-9ac0-64f0d177e41a-KakaoTalk_Photo_2024-09-28-20-30-53%20003.png"), + C("https://goormdari.s3.ap-northeast-2.amazonaws.com/e8555819-8da6-43c2-947b-c032e4de931d-KakaoTalk_Photo_2024-09-28-20-30-53%20002.png"), + D("https://goormdari.s3.ap-northeast-2.amazonaws.com/7e7085f0-3fef-4348-b726-422a50b1d1d4-KakaoTalk_Photo_2024-09-28-20-30-52%20001.png"); + + private String profileUrl; + + DefaultProfileUrl(String profileUrl) { + this.profileUrl = profileUrl; + } + + public String getProfileUrl() { + return profileUrl; + } + + public static String getRandomProfileUrl() { + DefaultProfileUrl[] values = DefaultProfileUrl.values(); + + // 랜덤 인덱스 생성 + Random random = new Random(); + int index = random.nextInt(values.length); // 0에서 배열의 길이만큼 랜덤 숫자 생성 + + // 랜덤으로 선택된 문자 출력 + return values[index].getProfileUrl(); + } + +} diff --git a/src/main/java/com/goormdari/domain/user/domain/User.java b/src/main/java/com/goormdari/domain/user/domain/User.java index 423097a..ad351f7 100644 --- a/src/main/java/com/goormdari/domain/user/domain/User.java +++ b/src/main/java/com/goormdari/domain/user/domain/User.java @@ -68,10 +68,11 @@ public void updateCurrentStep(int currentStep) { } @Builder - public User(String nickname, String username, String password, String role) { + public User(String nickname, String username, String password, String role, String profileUrl) { this.nickname = nickname; this.username = username; this.password = password; this.role = role; + this.profileUrl = profileUrl; } } diff --git a/src/main/java/com/goormdari/domain/user/domain/service/UserService.java b/src/main/java/com/goormdari/domain/user/domain/service/UserService.java index 709944e..35621e8 100644 --- a/src/main/java/com/goormdari/domain/user/domain/service/UserService.java +++ b/src/main/java/com/goormdari/domain/user/domain/service/UserService.java @@ -1,12 +1,15 @@ package com.goormdari.domain.user.domain.service; import com.amazonaws.services.kms.model.NotFoundException; +import com.goormdari.domain.team.domain.Team; import com.goormdari.domain.team.domain.repository.TeamRepository; +import com.goormdari.domain.user.domain.DefaultProfileUrl; +import com.goormdari.domain.user.domain.dto.response.findByTeamIdResponse; import com.goormdari.domain.user.domain.dto.response.findCurrentStepResponse; import com.goormdari.domain.user.domain.User; -import com.goormdari.domain.user.domain.dto.request.AddUserRequest; -import com.goormdari.domain.user.domain.dto.response.JwtResponse; -import com.goormdari.domain.user.domain.dto.request.LoginRequest; +import com.goormdari.domain.user.domain.dto.AddUserRequest; +import com.goormdari.domain.user.domain.dto.JwtResponse; +import com.goormdari.domain.user.domain.dto.LoginRequest; import com.goormdari.domain.user.domain.repository.UserRepository; import com.goormdari.global.config.security.jwt.JWTUtil; import jakarta.transaction.Transactional; @@ -20,6 +23,10 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + @Slf4j @Service @RequiredArgsConstructor @@ -45,12 +52,15 @@ public Long save(AddUserRequest dto) { throw new IllegalArgumentException("Username is already exists."); } + + // 사용자 저장 return userRepository.save(User.builder() .nickname(dto.getNickname()) .username(dto.getUsername()) .password(passwordEncoder.encode(dto.getPassword())) .role("ROLE_USER") + .profileUrl(DefaultProfileUrl.getRandomProfileUrl()) .build()).getId(); }