-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
.../java/javalab/umc7th_mission/domain/membermission/controller/MemberMissionController.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,44 @@ | ||
package javalab.umc7th_mission.domain.membermission.controller; | ||
|
||
import javalab.umc7th_mission.config.annotation.CheckPage; | ||
import javalab.umc7th_mission.config.apipayload.ApiResponse; | ||
import javalab.umc7th_mission.domain.membermission.dto.MemberMissionResponseDTO; | ||
import javalab.umc7th_mission.domain.membermission.service.MemberMissionService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/missions") | ||
public class MemberMissionController { | ||
|
||
private final MemberMissionService memberMissionService; | ||
private static final Integer PAGE_SIZE = 10; | ||
|
||
@GetMapping("/member/{memberId}/ongoing") | ||
public ApiResponse<Page<MemberMissionResponseDTO>> getOngoingMissionsByMember( | ||
@PathVariable Long memberId, | ||
@RequestParam @CheckPage Integer page | ||
) { | ||
Pageable pageable = PageRequest.of(page, PAGE_SIZE); | ||
return ApiResponse.onSuccess( | ||
memberMissionService.getOngoingMissionsByMember(memberId, pageable)); | ||
} | ||
|
||
@PatchMapping("/member/{memberId}/complete/{missionId}") | ||
public ResponseEntity<String> completeMission( | ||
@PathVariable Long memberId, | ||
@PathVariable Long missionId | ||
) { | ||
memberMissionService.completeMission(memberId, missionId); | ||
return ResponseEntity.ok("Mission marked as complete"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/javalab/umc7th_mission/domain/membermission/dto/MemberMissionResponseDTO.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,11 @@ | ||
package javalab.umc7th_mission.domain.membermission.dto; | ||
|
||
public record MemberMissionResponseDTO( | ||
Long missionId, | ||
String missionSpec, | ||
Integer reward, | ||
String status, | ||
String storeName | ||
) { | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
.../java/javalab/umc7th_mission/domain/membermission/repository/MemberMissionRepository.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,14 @@ | ||
package javalab.umc7th_mission.domain.membermission.repository; | ||
|
||
import java.util.Optional; | ||
import javalab.umc7th_mission.domain.membermission.MemberMission; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberMissionRepository extends JpaRepository<MemberMission, Long> { | ||
|
||
Page<MemberMission> findByMemberIdAndStatus(Long memberId, String status, Pageable pageable); | ||
|
||
Optional<MemberMission> findByMemberIdAndMissionId(Long memberId, Long missionId); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/javalab/umc7th_mission/domain/membermission/service/MemberMissionService.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,46 @@ | ||
package javalab.umc7th_mission.domain.membermission.service; | ||
|
||
import javalab.umc7th_mission.config.apipayload.code.status.ErrorStatus; | ||
import javalab.umc7th_mission.config.apipayload.exception.GeneralException; | ||
import javalab.umc7th_mission.domain.membermission.MemberMission; | ||
import javalab.umc7th_mission.domain.membermission.dto.MemberMissionResponseDTO; | ||
import javalab.umc7th_mission.domain.membermission.repository.MemberMissionRepository; | ||
import javalab.umc7th_mission.domain.mission.MissionStatus; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MemberMissionService { | ||
|
||
private final MemberMissionRepository memberMissionRepository; | ||
|
||
public Page<MemberMissionResponseDTO> getOngoingMissionsByMember(Long memberId, | ||
Pageable pageable) { | ||
String status = MissionStatus.CHALLENGING.name(); | ||
|
||
return memberMissionRepository.findByMemberIdAndStatus(memberId, status, pageable) | ||
.map(memberMission -> new MemberMissionResponseDTO( | ||
memberMission.getMission().getId(), | ||
memberMission.getMission().getMissionSpec(), | ||
memberMission.getMission().getReward(), | ||
memberMission.getStatus().name(), | ||
memberMission.getMission().getStore().getName() | ||
)); | ||
} | ||
|
||
@Transactional | ||
public void completeMission(Long memberId, Long missionId) { | ||
MemberMission memberMission = memberMissionRepository.findByMemberIdAndMissionId(memberId, | ||
missionId) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus._BAD_REQUEST)); | ||
if (!memberMission.getStatus().equals(MissionStatus.CHALLENGING)) { | ||
throw new GeneralException(ErrorStatus._BAD_REQUEST); | ||
} | ||
memberMission.complete(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/javalab/umc7th_mission/domain/mission/controller/MissionController.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,34 @@ | ||
package javalab.umc7th_mission.domain.mission.controller; | ||
|
||
import javalab.umc7th_mission.config.annotation.CheckPage; | ||
import javalab.umc7th_mission.config.apipayload.ApiResponse; | ||
import javalab.umc7th_mission.domain.mission.dto.MissionResponseDto; | ||
import javalab.umc7th_mission.domain.mission.service.MissionService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/missions") | ||
public class MissionController { | ||
|
||
private static final Integer PAGE_SIZE = 10; | ||
private final MissionService service; | ||
|
||
@GetMapping("/store/{storeId}") | ||
public ApiResponse<Page<MissionResponseDto>> getMissionsByStore( | ||
@PathVariable Long storeId, | ||
@RequestParam @CheckPage Integer page | ||
) { | ||
Pageable pageable = PageRequest.of(page, PAGE_SIZE); | ||
Page<MissionResponseDto> missions = service.getMissionsByStore(storeId, pageable); | ||
return ApiResponse.onSuccess(missions); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/javalab/umc7th_mission/domain/mission/dto/MissionResponseDto.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,11 @@ | ||
package javalab.umc7th_mission.domain.mission.dto; | ||
|
||
public record MissionResponseDto( | ||
Long missionId, | ||
Integer reward, | ||
String missionSpec, | ||
String storeName | ||
) { | ||
|
||
} | ||
|
12 changes: 12 additions & 0 deletions
12
src/main/java/javalab/umc7th_mission/domain/mission/repository/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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package javalab.umc7th_mission.domain.mission.repository; | ||
|
||
import javalab.umc7th_mission.domain.mission.Mission; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MissionRepository extends JpaRepository<Mission, Long> { | ||
|
||
Page<Mission> findByStoreId(Long storeId, Pageable pageable); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/javalab/umc7th_mission/domain/mission/service/MissionService.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,27 @@ | ||
package javalab.umc7th_mission.domain.mission.service; | ||
|
||
import javalab.umc7th_mission.domain.mission.dto.MissionResponseDto; | ||
import javalab.umc7th_mission.domain.mission.repository.MissionRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MissionService { | ||
|
||
private final MissionRepository repository; | ||
|
||
public Page<MissionResponseDto> getMissionsByStore(Long storeId, Pageable pageable) { | ||
return repository.findByStoreId(storeId, pageable) | ||
.map(mission -> new MissionResponseDto( | ||
mission.getId(), | ||
mission.getReward(), | ||
mission.getMissionSpec(), | ||
mission.getStore().getName() | ||
)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/javalab/umc7th_mission/domain/review/controller/ReviewController.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 javalab.umc7th_mission.domain.review.controller; | ||
|
||
import javalab.umc7th_mission.config.apipayload.ApiResponse; | ||
import javalab.umc7th_mission.domain.review.dto.ReviewResponse.ReviewsDTO; | ||
import javalab.umc7th_mission.domain.review.service.ReviewService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ReviewController { | ||
|
||
private final ReviewService reviewService; | ||
|
||
private static final Integer PAGE_SIZE = 10; | ||
|
||
@GetMapping("/member") | ||
public ApiResponse<ReviewsDTO> getReviewsByMember( | ||
Long memberId, // 로그인 되어있다고 가정 | ||
@RequestParam(defaultValue = "0") int page | ||
) { | ||
memberId = 0L; // 추후 argumentResolver 이용 | ||
Pageable pageable = PageRequest.of(page, PAGE_SIZE); | ||
ReviewsDTO result = reviewService.getReviewsByMember(memberId, pageable); | ||
return ApiResponse.onSuccess(result); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/javalab/umc7th_mission/domain/review/dto/ReviewRequest.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,5 @@ | ||
package javalab.umc7th_mission.domain.review.dto; | ||
|
||
public class ReviewRequest { | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/javalab/umc7th_mission/domain/review/dto/ReviewResponse.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,25 @@ | ||
package javalab.umc7th_mission.domain.review.dto; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public final class ReviewResponse { | ||
|
||
private ReviewResponse() { | ||
} | ||
|
||
public record ReviewsDTO( | ||
List<ReviewDTO> reviews | ||
) { | ||
|
||
} | ||
|
||
public record ReviewDTO( | ||
String nickname, | ||
Double score, | ||
String body, | ||
LocalDate createdAt | ||
) { | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/javalab/umc7th_mission/domain/review/repository/ReviewRepository.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,12 @@ | ||
package javalab.umc7th_mission.domain.review.repository; | ||
|
||
import javalab.umc7th_mission.domain.review.Review; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReviewRepository extends JpaRepository<Review, Long> { | ||
|
||
Page<Review> findByMemberId(Long memberId, Pageable pageable); | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/javalab/umc7th_mission/domain/review/service/ReviewService.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,38 @@ | ||
package javalab.umc7th_mission.domain.review.service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javalab.umc7th_mission.domain.review.Review; | ||
import javalab.umc7th_mission.domain.review.dto.ReviewResponse; | ||
import javalab.umc7th_mission.domain.review.dto.ReviewResponse.ReviewDTO; | ||
import javalab.umc7th_mission.domain.review.repository.ReviewRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReviewService { | ||
|
||
private final ReviewRepository reviewRepository; | ||
|
||
public ReviewResponse.ReviewsDTO getReviewsByMember(Long memberId, Pageable pageable) { | ||
Page<Review> reviews = reviewRepository.findByMemberId(memberId, pageable); | ||
|
||
List<ReviewDTO> reviewDTOs = new ArrayList<>(); | ||
for (Review review : reviews) { | ||
ReviewDTO reviewDTO = new ReviewDTO( | ||
review.getMember().getName(), | ||
review.getScore(), | ||
review.getBody(), | ||
review.getCreatedAt().toLocalDate() | ||
); | ||
reviewDTOs.add(reviewDTO); | ||
} | ||
|
||
return new ReviewResponse.ReviewsDTO(reviewDTOs); | ||
|
||
} | ||
} | ||
|