Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ public ApiResponse<MissionResDTO.CreateMission> createMission(
)
);
}

//특정가게의미션을 조회
@GetMapping("/stores/{storeId}")
@Operation(summary = "특정 가게의 미션 목록 조회", description = "특정 가게에 등록된 미션 목록을 페이징하여 조회합니다.")
public ApiResponse<List<MissionResDTO.MissionList>> getStoreMissions(
@PathVariable Long storeId,
@ValidPage @RequestParam Integer page
) {
Pageable pageable = PageRequest.of(page - 1, 10);
Page<com.example.umc9th2.domain.mission.entity.Mission> missionPage = missionService.getStoreMissions(storeId, pageable);
List<MissionResDTO.MissionList> result = MissionConverter.toMissionListDTO(missionPage.getContent());
return ApiResponse.onSuccess(GeneralSuccessCode.OK, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ public static MissionResDTO.CreateMission toCreateMissionDTO(Mission mission) {
mission.getStore().getStoreName()
);
}

// 미션목록반환
public static List<MissionResDTO.MissionList> toMissionListDTO(List<Mission> missionList) {
return missionList.stream()
.map(mission -> new MissionResDTO.MissionList(
mission.getMissionId(),
mission.getTitle(),
mission.getDescription(),
mission.getRewardPoints(),
mission.getIsActive()
))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public record CreateMission(
Integer rewardPoints,
String storeName //store 에서
) {}
//미션 week 9
public record MissionList(
Long missionId,
String title,
String description,
Integer rewardPoints,
Boolean isActive
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@Getter
@Setter
@NoArgsConstructor
@Builder
public class Mission {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface MissionRepository extends JpaRepository<Mission, Long> {
//특정 가게의 미션 목록
Page<Mission> findByStore_StoreId(Long storeId, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ public ApiResponse<ReviewResDTO.CreateReview> createReview(
ReviewResDTO.CreateReview result = reviewCommandService.createReview(request, userId);
return ApiResponse.onSuccess(code, result);
}
//작성한 리뷰 목록조회
@GetMapping("/my-reviews")
@Operation(summary = "내가 작성한 리뷰 목록 조회", description = "특정 사용자가 작성한 리뷰 목록을 페이징하여 조회합니다.")
public ApiResponse<List<ReviewResDTO.MyReviewList>> getMyReviews(
@RequestParam Long userId,
@ValidPage @RequestParam Integer page
) {
Pageable pageable = PageRequest.of(page - 1, 10);
Page<Review> reviewPage = reviewQueryService.getMyReviews(userId, pageable);
List<ReviewResDTO.MyReviewList> result = ReviewConverter.toMyReviewListDTO(reviewPage.getContent());
return ApiResponse.onSuccess(GeneralSuccessCode.OK, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ public static ReviewResDTO.CreateReview toCreateReviewResultDto(Review review) {
LocalDateTime.now()
);
}

//내가 작성한 리뷰 DTO 반환해
public static List<ReviewResDTO.MyReviewList> toMyReviewListDTO(List<Review> reviewList) {
return reviewList.stream()
.map(review -> new ReviewResDTO.MyReviewList(
review.getReviewId(),
review.getStore() != null ? review.getStore().getStoreName() : null,
review.getRating(),
review.getContent(),
review.getCreatedAt()
))
.toList();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ public record CreateReview(
String storeName,
LocalDateTime createdAt
) {}
//내가 작성한 review 목ㄹ곻
public record MyReviewList(
Long reviewId,
String storeName,
Integer rating,
String content,
LocalDateTime createdAt
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.example.umc9th2.domain.user.entity.User;
import com.example.umc9th2.domain.store.entity.Store;
import com.example.umc9th2.global.BaseEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -13,8 +15,9 @@
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Review {
public class Review extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
import org.springframework.data.jpa.repository.*;

public interface ReviewRepository extends JpaRepository<Review, Long>, ReviewQueryDsl {
//내가 작성한 리뷰 목록
Page<Review> findByUser_UserId(Long userId, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ public List<Review> searchReview(String type, String query) {

List<Review> reviewList = reviewRepository.searchReview(builder);
return reviewList;


}
public Page<Review> getMyReviews(Long userId, Pageable pageable) {
return reviewRepository.findByUser_UserId(userId, pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ public ApiResponse<UserMissionResDTO.ChallengeMission> challengeMission(
UserMissionResDTO.ChallengeMission result = userMissionService.challengeMission(missionId);
return ApiResponse.onSuccess(code, result);
}
//진행중인 미션목록죄회
@GetMapping("/in-progress")
@Operation(summary = "내가 진행중인 미션 목록 조회", description = "특정 사용자가 진행중인 미션 목록을 페이징하여 조회합니다.")
public ApiResponse<List<MyMissionDTO>> getInProgressMissions(
@RequestParam Long userId,
@ValidPage @RequestParam Integer page
) {
Pageable pageable = PageRequest.of(page - 1, 10);
Page<MyMissionDTO> missionPage = userMissionService.getInProgressMissions(userId, pageable);
return ApiResponse.onSuccess(GeneralSuccessCode.OK, missionPage.getContent());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public record MyMissionDTO(
String title,
String description,
Integer rewardPoints,
String status,
LocalDateTime clearedAt,
boolean status, // String에서 바꿈
LocalDateTime clearedAt, LocalDateTime clearedAt,
String storeName,
String regionName
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,26 @@ public interface UserMissionRepository extends JpaRepository<UserMission, Long>
order by um.status asc, um.clearedAt desc
""")
List<MyMissionDTO> findMyMissions(@Param("userId") Long userId, Pageable pageable);
@Query("""
select new com.example.umc9th2.domain.user.dto.MyMissionDTO(
m.missionId,
m.title,
m.description,
m.rewardPoints,
um.status,
um.clearedAt,
s.storeName,
rg.regionName
)
from UserMission um
join um.mission m
join m.store s
join s.region rg
where um.user.userId = :userId
and um.status = false
order by um.clearedAt desc
""")
Page<MyMissionDTO> findInProgressMissions(@Param("userId") Long userId, Pageable pageable);


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class UserMissionService {
public List<MyMissionDTO> getMyMissions(Long userId, Pageable pageable) {
return userMissionRepository.findMyMissions(userId, pageable);
}

public Page<MyMissionDTO> getInProgressMissions(Long userId, Pageable pageable) {
return userMissionRepository.findInProgressMissions(userId, pageable);
}

//미션 도전

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.umc9th2.global.annotation;

import com.example.umc9th2.global.apiPayload.code.GeneralErrorCode;
import com.example.umc9th2.global.apiPayload.exception.GeneralException;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

//tnwjdwnd

public class PageValidator implements ConstraintValidator<ValidPage, Integer> {

@Override
public void initialize(ValidPage constraintAnnotation) {
}

@Override
public boolean isValid(Integer page, ConstraintValidatorContext context) {
if (page == null) {
throw new GeneralException(GeneralErrorCode.INVALID_PAGE);
}
if (page <= 0) {
throw new GeneralException(GeneralErrorCode.INVALID_PAGE);
}
return true;
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/example/umc9th2/global/annotation/ValidPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.umc9th2.global.annotation;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.*;

@Documented
@Constraint(validatedBy = PageValidator.class)
@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidPage {
String message() default "페이지 번호는 1 이상이어야 합니다.";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public enum GeneralErrorCode implements BaseErrorCode{
NOT_FOUND(HttpStatus.NOT_FOUND,
"COMMON404_1",
"요청한 리소스를 찾을 수 없습니다."),
//추가함
INVALID_PAGE(HttpStatus.BAD_REQUEST,
"COMMON400_2",
"페이지 번호는 1 이상이어야 합니다."),
//에러 핸들러 추가된 enum
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR,
"COMMON500_1",
Expand Down