-
Notifications
You must be signed in to change notification settings - Fork 12
[9,10주차/밤하늘] 워크북 제출합니다. #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bamhaneul/main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
| package umc.repository.mission; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import umc.domain.Mission; | ||
| import umc.domain.Restaurant; | ||
| import umc.domain.User; | ||
|
|
||
| public interface MissionRepository extends JpaRepository<Mission, Long> { | ||
|
|
||
| Page<Mission> findAllByRestaurant(Restaurant restaurant, Pageable pageable); | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,19 @@ | ||
| package umc.repository.review; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Slice; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import umc.domain.Restaurant; | ||
| import umc.domain.Review; | ||
| import umc.domain.User; | ||
|
|
||
| public interface ReviewRepository extends JpaRepository<Review, Long> { | ||
|
|
||
| Page<Review> findAllByRestaurant(Restaurant restaurant, Pageable pageable); | ||
|
|
||
| Page<Review> findAllByUser(User user, Pageable pageable); | ||
| Slice<Review> findReviewsByUser(User user, Pageable pageable); | ||
| //Page<Review> findAllByRestaurant(Restaurant restaurant, Pageable pageable); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,36 @@ | ||
| package umc.repository.user; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
| import umc.domain.Mission; | ||
| import umc.domain.User; | ||
| import umc.domain.mapping.UserMission; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface UserMissionRepository extends JpaRepository<UserMission, Long> { | ||
|
|
||
| Boolean existsUserMissionByUserAndMission(User user, Mission mission); | ||
|
|
||
| @Query( | ||
| value = "SELECT um " + | ||
| "FROM UserMission um " + | ||
| "JOIN FETCH um.mission m " + | ||
| "WHERE um.user.id = :userId " + | ||
| " AND um.isCompleted = false", | ||
| countQuery = "SELECT COUNT(um) " + | ||
| "FROM UserMission um " + | ||
| "WHERE um.user.id = :userId " + | ||
| " AND um.isCompleted = false" | ||
| ) | ||
| Page<UserMission> findOngoingByUserId( | ||
| @Param("userId") Long userId, | ||
| Pageable pageable | ||
| ); | ||
|
|
||
| Optional<UserMission> findByUserAndMission(User user, Mission mission); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,12 @@ | |
| import umc.converter.MissionConverter; | ||
| import umc.domain.Mission; | ||
| import umc.domain.Restaurant; | ||
| import umc.domain.User; | ||
| import umc.domain.mapping.UserMission; | ||
| import umc.repository.mission.MissionRepository; | ||
| import umc.repository.restaurant.RestaurantRepository; | ||
| import umc.repository.user.UserMissionRepository; | ||
| import umc.repository.user.UserRepository; | ||
| import umc.web.dto.mission.MissionRequestDTO; | ||
|
|
||
| @Service | ||
|
|
@@ -19,6 +23,8 @@ public class MissionCommandServiceImpl implements MissionCommandService { | |
|
|
||
| private final MissionRepository missionRepository; | ||
| private final RestaurantRepository restaurantRepository; | ||
| private final UserMissionRepository userMissionRepository; | ||
| private final UserRepository userRepository; | ||
|
|
||
| @Override | ||
| public void createMission(MissionRequestDTO.createMissionDTO request, Long restaurantId) { | ||
|
|
@@ -33,4 +39,28 @@ public void createMission(MissionRequestDTO.createMissionDTO request, Long resta | |
| missionRepository.save(mission); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void changeMissionStatus(Long userId, Long missionId) { | ||
|
|
||
| Mission mission = missionRepository.findById(missionId).orElseThrow( | ||
| () -> new GeneralException(ErrorStatus.MISSION_NOT_FOUND) | ||
| ); | ||
|
|
||
| User user = userRepository.findById(userId).orElseThrow( | ||
| () -> new GeneralException(ErrorStatus.USER_NOT_FOUND) | ||
| ); | ||
|
|
||
| UserMission userMission = userMissionRepository.findByUserAndMission(user, mission).orElseThrow( | ||
| () -> new GeneralException(ErrorStatus.USERMISSION_NOT_FOUND) | ||
|
Comment on lines
+46
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엔티티 대신 storeId, memberId로 조회하는 게 더 효율적일 것 같아요 !
|
||
| ); | ||
|
|
||
| if(userMission.getIsCompleted()){ | ||
| userMission.changeIsCompleted(false); | ||
| }else{ | ||
| userMission.changeIsCompleted(true); | ||
| } | ||
|
|
||
| userMissionRepository.save(userMission); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package umc.service.mission; | ||
|
|
||
| import org.springframework.data.domain.Page; | ||
| import umc.domain.Mission; | ||
| import umc.domain.mapping.UserMission; | ||
|
|
||
| public interface MissionQueryService { | ||
|
|
||
| Page<Mission> getMissionListByRestaurantId(Long restaurantId, Integer page); | ||
|
|
||
| Page<UserMission> getMissionListByUserId(Long userId, Integer page); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package umc.service.mission; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import umc.apiPayload.code.status.ErrorStatus; | ||
| import umc.apiPayload.exception.GeneralException; | ||
| import umc.domain.Mission; | ||
| import umc.domain.Restaurant; | ||
| import umc.domain.User; | ||
| import umc.domain.mapping.UserMission; | ||
| import umc.repository.mission.MissionRepository; | ||
| import umc.repository.restaurant.RestaurantRepository; | ||
| import umc.repository.user.UserMissionRepository; | ||
| import umc.repository.user.UserRepository; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class MissionQueryServiceImpl implements MissionQueryService { | ||
|
|
||
| private final MissionRepository missionRepository; | ||
| private final RestaurantRepository restaurantRepository; | ||
| private final UserRepository userRepository; | ||
| private final UserMissionRepository userMissionRepository; | ||
|
|
||
| @Override | ||
| public Page<Mission> getMissionListByRestaurantId(Long restaurantId, Integer page) { | ||
|
|
||
| Restaurant restaurant = restaurantRepository.findById(restaurantId).orElseThrow( | ||
| () -> new GeneralException(ErrorStatus.RESTAURANT_NOT_FOUND) | ||
| ); | ||
|
|
||
| Page<Mission> missionPage = missionRepository.findAllByRestaurant(restaurant, PageRequest.of(page, 10)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 페이징 기본 크기가 10이긴 한데, 프론트에서 혹시 다른 값을 요청할 수도 있으니 size 값도 받는 게 좋을 것 같아요 ! |
||
| return missionPage; | ||
| } | ||
|
|
||
| @Override | ||
| public Page<UserMission> getMissionListByUserId(Long userId, Integer page) { | ||
|
|
||
| User user = userRepository.findById(userId).orElseThrow( | ||
| () -> new GeneralException(ErrorStatus.USER_NOT_FOUND) | ||
| ); | ||
|
|
||
| Page<UserMission> userMissionPage = userMissionRepository.findOngoingByUserId(userId, PageRequest.of(page, 10)); | ||
|
|
||
| return userMissionPage; | ||
| } | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package umc.service.review; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Slice; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import umc.domain.Review; | ||
|
|
||
| public interface ReviewQueryService { | ||
| Page<Review> getReviewList(Long storeId, Integer page); | ||
|
|
||
| Page<Review> getReviewListByUserId(Long userId, Integer page); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 리스트로 안 받고, Page로 받으면 밑에서 따로 Page 관련 값들 세팅 안 해도 돼서 더 효율적일 것 같아요 !
Page<MissionResponseDTO.MissionDTO> userMissionDTOPage = userMissionList.map(MissionConverter::toMissionDTO);