-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement week 9 API. Fixes #5
- Loading branch information
jjun522
committed
Nov 29, 2024
1 parent
7dcdf1c
commit 5b997cf
Showing
37 changed files
with
664 additions
and
55 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/java/umc/spring/Vaildator/annotation/CheckPage.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 umc.spring.Vaildator.annotation; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
import umc.spring.Vaildator.vaildator.CheckPageValidator; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Constraint(validatedBy = CheckPageValidator.class) | ||
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CheckPage { | ||
String message() default "페이지 번호는 1 이상의 값이어야 합니다."; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/umc/spring/Vaildator/vaildator/CheckPageValidator.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,32 @@ | ||
package umc.spring.Vaildator.vaildator; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import umc.spring.Vaildator.annotation.CheckPage; | ||
import umc.spring.apiPayload.code.status.ErrorStatus; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CheckPageValidator implements ConstraintValidator<CheckPage, Integer> { | ||
|
||
|
||
@Override | ||
public void initialize(CheckPage constraintAnnotation) { | ||
ConstraintValidator.super.initialize(constraintAnnotation); | ||
} | ||
|
||
@Override | ||
public boolean isValid(Integer value, ConstraintValidatorContext context) { | ||
boolean isValid = value != null && value > 0; | ||
|
||
if (!isValid) { | ||
context.disableDefaultConstraintViolation(); | ||
context.buildConstraintViolationWithTemplate(ErrorStatus.PAGE_Error.toString()) | ||
.addConstraintViolation(); | ||
} | ||
|
||
return isValid; | ||
} | ||
} |
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
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
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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/umc/spring/apiPayload/exception/handler/PageHandler.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 umc.spring.apiPayload.exception.handler; | ||
|
||
import umc.spring.apiPayload.code.BaseErrorCode; | ||
import umc.spring.apiPayload.exception.GeneralException; | ||
|
||
public class PageHandler extends GeneralException { | ||
public PageHandler(BaseErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
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
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,28 @@ | ||
package umc.spring.converter; | ||
|
||
import org.springframework.data.domain.Page; | ||
import umc.spring.domain.Review; | ||
import umc.spring.web.controller.dto.MyReviewDTO.MyReviewResponseDTO; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
public class MyReviewConverter { | ||
|
||
public static MyReviewResponseDTO.PagedReviewDTO toPagedReviewDTO(Page<Review> reviewPage) { | ||
return MyReviewResponseDTO.PagedReviewDTO.builder() | ||
.reviews( | ||
reviewPage.getContent().stream() | ||
.map(review -> MyReviewResponseDTO.ReviewDTO.builder() | ||
.reviewId(review.getId()) | ||
.comment(review.getComment()) | ||
.rating(review.getRating()) | ||
.storeId(review.getStore().getId()) | ||
.createdAt(review.getCreatedAt()) | ||
.build() | ||
).collect(Collectors.toList()) | ||
) | ||
.currentPage(reviewPage.getNumber() + 1) // 0 기반을 1 기반으로 변환 | ||
.totalPages(reviewPage.getTotalPages()) | ||
.build(); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/main/java/umc/spring/converter/UserMissionConverter.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,39 @@ | ||
package umc.spring.converter; | ||
|
||
import umc.spring.domain.UserMission; | ||
import umc.spring.domain.emums.MissionStatus; | ||
import umc.spring.web.controller.dto.MissionDTO.UserMissionResponseDTO; | ||
import umc.spring.web.controller.dto.UserMissionDTO.UserMissionDTO; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class UserMissionConverter { | ||
|
||
public static UserMissionResponseDTO.MissionDTO toUserMissionDTO(UserMission userMission) { | ||
return UserMissionResponseDTO.MissionDTO.builder() | ||
.missionId(userMission.getMission().getId()) | ||
.title(userMission.getMission().getTitle()) | ||
.description(userMission.getMission().getDescription()) | ||
.point(userMission.getMission().getPoint()) | ||
.storeName(userMission.getMission().getStore().getName()) | ||
.build(); | ||
} | ||
|
||
public static UserMissionDTO.MissionUpdateResponseDTO toMissionUpdateDTO(UserMission userMission) { | ||
return UserMissionDTO.MissionUpdateResponseDTO.builder() | ||
.userMissionId(userMission.getId()) | ||
.missionStatus(userMission.getMissionStatus().name()) | ||
.completedDate(userMission.getCompletedDate()) | ||
.build(); | ||
} | ||
// 빌더를 활용하여 상태 변경 | ||
public static UserMission updateMissionStatus(UserMission userMission, MissionStatus missionStatus, LocalDateTime completedDate) { | ||
return UserMission.builder() | ||
.id(userMission.getId()) // 기존 ID 유지 | ||
.user(userMission.getUser()) // 기존 User 유지 | ||
.mission(userMission.getMission()) // 기존 Mission 유지 | ||
.missionStatus(missionStatus) // 변경할 Status | ||
.completedDate(completedDate) // 변경할 Completed Date | ||
.build(); | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
src/main/java/umc/spring/repository/MissionRepository/MissionRepository.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,10 +1,13 @@ | ||
package umc.spring.repository.MissionRepository; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import umc.spring.domain.Store; | ||
import umc.spring.domain.mapping.Mission; | ||
|
||
@Repository | ||
public interface MissionRepository extends JpaRepository<Mission, Long> { | ||
|
||
Page<Mission> findByStore(Store store, Pageable pageable); | ||
} |
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
5 changes: 0 additions & 5 deletions
5
src/main/java/umc/spring/repository/ReviewRepository/ReviewRepositorylmpl.java
This file was deleted.
Oops, something went wrong.
7 changes: 6 additions & 1 deletion
7
...ssionRepository/UerMissionRepository.java → ...sionRepository/UserMissionRepository.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,11 +1,16 @@ | ||
package umc.spring.repository.UserMissionRepository; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import umc.spring.domain.User; | ||
import umc.spring.domain.UserMission; | ||
import umc.spring.domain.emums.MissionStatus; | ||
|
||
@Repository | ||
public interface UerMissionRepository extends JpaRepository<UserMission ,Long> { | ||
public interface UserMissionRepository extends JpaRepository<UserMission ,Long> { | ||
boolean existsByMissionIdAndMissionStatus(Long missionId, MissionStatus missionStatus); | ||
Page<UserMission> findByUserAndMissionStatus(User user, MissionStatus missionStatus, Pageable pageable); | ||
|
||
} |
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
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
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
Oops, something went wrong.