-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from TEAM-ALOM/10-feat-랭킹-기능-구현
rank
- Loading branch information
Showing
16 changed files
with
405 additions
and
5 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/java/com/alom/dorundorunbe/domain/ranking/controller/RankingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.alom.dorundorunbe.domain.ranking.controller; | ||
|
||
import com.alom.dorundorunbe.domain.ranking.domain.Ranking; | ||
import com.alom.dorundorunbe.domain.ranking.dto.*; | ||
import com.alom.dorundorunbe.domain.ranking.service.RankingService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/ranking") | ||
@RequiredArgsConstructor | ||
public class RankingController { | ||
private final RankingService rankingService; | ||
|
||
@PostMapping("/join") | ||
public ResponseEntity<JoiningRankingResponseDto> joinRanking(@RequestBody JoiningRankingRequestDto requestDto){ | ||
Long rankId = rankingService.joinRanking(requestDto.userId()); | ||
Ranking joinRank = rankingService.findOne(rankId); | ||
JoiningRankingResponseDto responseDto = JoiningRankingResponseDto.of(joinRank.getUser().getId(), joinRank.getCreatedAt()); | ||
return ResponseEntity.ok(responseDto); | ||
} | ||
|
||
|
||
@PutMapping | ||
public ResponseEntity<UpdateRankingResponseDto>updateRanking(@RequestBody UpdateRankingRequestDto requestDto){ | ||
Long rankId = rankingService.updateRanking( | ||
requestDto.userId(), | ||
requestDto.tier(), | ||
requestDto.distance(), | ||
requestDto.time(), | ||
requestDto.cadence(), | ||
requestDto.grade() | ||
); | ||
Ranking updateRank = rankingService.findOne(rankId); | ||
|
||
|
||
UpdateRankingResponseDto responseDto = UpdateRankingResponseDto.of(updateRank); | ||
return ResponseEntity.ok(responseDto); | ||
|
||
} | ||
|
||
|
||
@GetMapping | ||
public ResponseEntity<List<RankingDto>> fetchRankings() { | ||
List<Ranking> rankings = rankingService.fetchAllRankings(); | ||
// if (rankings.isEmpty()) { | ||
// throw new RankingNotFoundException("랭킹 데이터가 없습니다."); | ||
// } | ||
//빈 리스트로 반환이 되었을 때 이를 오류처리할것인가에 대한 처리 | ||
List<RankingDto> list = rankings.stream() | ||
.map(RankingDto::of) | ||
.toList(); | ||
return ResponseEntity.ok(list); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...undorunbe/domain/ranking/domain/Rank.java → ...undorunbe/domain/ranking/domain/Tier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package com.alom.dorundorunbe.domain.ranking.domain; | ||
|
||
public enum Rank { | ||
public enum Tier { | ||
STARTER("스타터"), | ||
BEGINNER("비기너"), | ||
AMATEUR("아마추어"), | ||
PRO("프로"); | ||
|
||
private final String rank; | ||
|
||
Rank(String rank) { | ||
Tier(String rank) { | ||
this.rank = rank; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/alom/dorundorunbe/domain/ranking/dto/JoiningRankingRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.alom.dorundorunbe.domain.ranking.dto; | ||
|
||
public record JoiningRankingRequestDto( | ||
Long userId | ||
) { | ||
public static JoiningRankingRequestDto of(Long userId){ | ||
return new JoiningRankingRequestDto(userId); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/alom/dorundorunbe/domain/ranking/dto/JoiningRankingResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.alom.dorundorunbe.domain.ranking.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record JoiningRankingResponseDto( | ||
Long userId, | ||
LocalDateTime createdAt | ||
) { | ||
|
||
public static JoiningRankingResponseDto of(Long userId, LocalDateTime createdAt){ | ||
return new JoiningRankingResponseDto(userId,createdAt); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/alom/dorundorunbe/domain/ranking/dto/RankingDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.alom.dorundorunbe.domain.ranking.dto; | ||
|
||
import com.alom.dorundorunbe.domain.ranking.domain.Tier; | ||
import com.alom.dorundorunbe.domain.ranking.domain.Ranking; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record RankingDto( | ||
Long userId, | ||
Tier tier, | ||
long distance, | ||
long time, | ||
int cadence, | ||
|
||
int grade, | ||
LocalDateTime createdAt, | ||
LocalDateTime modifiedAt | ||
) { | ||
public static RankingDto of(Ranking ranking) { | ||
return new RankingDto( | ||
ranking.getUser().getId(), | ||
ranking.getTier(), | ||
ranking.getDistance(), | ||
ranking.getTime(), | ||
ranking.getCadence(), | ||
ranking.getGrade(), | ||
ranking.getCreatedAt(), | ||
ranking.getModifiedAt() | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/alom/dorundorunbe/domain/ranking/dto/UpdateRankingRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.alom.dorundorunbe.domain.ranking.dto; | ||
|
||
import com.alom.dorundorunbe.domain.ranking.domain.Tier; | ||
|
||
public record UpdateRankingRequestDto( | ||
Long userId, | ||
Tier tier, | ||
long distance, | ||
long time, | ||
int cadence, | ||
int grade | ||
|
||
) { | ||
public static UpdateRankingRequestDto of(Long userId, Tier tier, long distance, long time, int cadence, int grade) { | ||
return new UpdateRankingRequestDto(userId, tier, distance, time, cadence, grade); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/alom/dorundorunbe/domain/ranking/dto/UpdateRankingResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.alom.dorundorunbe.domain.ranking.dto; | ||
|
||
import com.alom.dorundorunbe.domain.ranking.domain.Tier; | ||
import com.alom.dorundorunbe.domain.ranking.domain.Ranking; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record UpdateRankingResponseDto( | ||
Long userId, | ||
Tier tier, | ||
long distance, | ||
long time, | ||
int cadence, | ||
|
||
int grade, | ||
LocalDateTime createdAt, | ||
LocalDateTime modifiedAt | ||
) { | ||
public static UpdateRankingResponseDto of(Ranking ranking) { | ||
return new UpdateRankingResponseDto( | ||
ranking.getUser().getId(), | ||
ranking.getTier(), | ||
ranking.getDistance(), | ||
ranking.getTime(), | ||
ranking.getCadence(), | ||
ranking.getGrade(), | ||
ranking.getCreatedAt(), | ||
ranking.getModifiedAt() | ||
); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/alom/dorundorunbe/domain/ranking/exception/RankingNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.alom.dorundorunbe.domain.ranking.exception; | ||
|
||
public class RankingNotFoundException extends RuntimeException{ | ||
public RankingNotFoundException() { | ||
super(); | ||
} | ||
|
||
public RankingNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
public RankingNotFoundException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public RankingNotFoundException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
protected RankingNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ava/com/alom/dorundorunbe/domain/ranking/exception/UserAlreadyJoinedRankingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.alom.dorundorunbe.domain.ranking.exception; | ||
|
||
public class UserAlreadyJoinedRankingException extends RuntimeException{ | ||
public UserAlreadyJoinedRankingException() { | ||
super(); | ||
} | ||
|
||
public UserAlreadyJoinedRankingException(String message) { | ||
super(message); | ||
} | ||
|
||
public UserAlreadyJoinedRankingException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public UserAlreadyJoinedRankingException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
protected UserAlreadyJoinedRankingException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/alom/dorundorunbe/domain/ranking/exception/UserNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.alom.dorundorunbe.domain.ranking.exception; | ||
|
||
public class UserNotFoundException extends RuntimeException{ | ||
public UserNotFoundException() { | ||
super(); | ||
} | ||
|
||
public UserNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
public UserNotFoundException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public UserNotFoundException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
protected UserNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...in/java/com/alom/dorundorunbe/domain/ranking/exception/advice/ExRankingHandlerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.alom.dorundorunbe.domain.ranking.exception.advice; | ||
|
||
import com.alom.dorundorunbe.domain.ranking.exception.RankingNotFoundException; | ||
import com.alom.dorundorunbe.domain.ranking.exception.UserAlreadyJoinedRankingException; | ||
import com.alom.dorundorunbe.domain.ranking.exception.UserNotFoundException; | ||
import com.alom.dorundorunbe.domain.ranking.exception.common.ErrorResult; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class ExRankingHandlerAdvice { | ||
@ExceptionHandler(UserNotFoundException.class) | ||
public ResponseEntity<ErrorResult> handleUserNotFoundException(UserNotFoundException e) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ErrorResult.of("404", e.getMessage())); | ||
} | ||
|
||
@ExceptionHandler(UserAlreadyJoinedRankingException.class) | ||
public ResponseEntity<ErrorResult> handleUserAlreadyJoinedRankingException(UserAlreadyJoinedRankingException e) { | ||
return ResponseEntity.status(HttpStatus.CONFLICT).body(ErrorResult.of("409", e.getMessage())); | ||
} | ||
|
||
@ExceptionHandler(RankingNotFoundException.class) | ||
public ResponseEntity<ErrorResult> handleRankingNotFoundException(RankingNotFoundException e) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ErrorResult.of("404", e.getMessage())); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/alom/dorundorunbe/domain/ranking/exception/common/ErrorMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.alom.dorundorunbe.domain.ranking.exception.common; | ||
|
||
public class ErrorMessages { | ||
public static final String USER_NOT_FOUND = "사용자를 찾을 수 없습니다."; | ||
public static final String USER_ALREADY_JOINED = "이미 참여 중입니다."; | ||
public static final String RANKING_NOT_FOUND = "랭킹을 찾을 수 없습니다."; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/alom/dorundorunbe/domain/ranking/exception/common/ErrorResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.alom.dorundorunbe.domain.ranking.exception.common; | ||
|
||
public record ErrorResult( | ||
String code, | ||
String message) { | ||
public static ErrorResult of(String code, String message) { | ||
return new ErrorResult(code, message); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/alom/dorundorunbe/domain/ranking/repository/RankingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.alom.dorundorunbe.domain.ranking.repository; | ||
|
||
import com.alom.dorundorunbe.domain.ranking.domain.Ranking; | ||
import com.alom.dorundorunbe.domain.user.domain.User; | ||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface RankingRepository extends JpaRepository<Ranking, Long> { | ||
Optional<Ranking> findByUser(User user); | ||
boolean existsByUser(User user); | ||
|
||
@Override | ||
@EntityGraph(attributePaths = {"user"}) | ||
List<Ranking>findAll(); | ||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.