-
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.
Merge pull request #24 from Timetris-Trendithon/past
✨Feat: 이번달 지난 기록 조회 기능 추가
- Loading branch information
Showing
7 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
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
Empty file.
31 changes: 31 additions & 0 deletions
31
src/main/java/com/trendithon/timetris/domain/past/controller/PastController.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.trendithon.timetris.domain.past.controller; | ||
|
||
import com.trendithon.timetris.domain.past.dto.PastViewDTO; | ||
import com.trendithon.timetris.domain.past.service.PastService; | ||
import com.trendithon.timetris.global.auth.jwt.TokenProvider; | ||
import com.trendithon.timetris.global.exception.ApiResponse; | ||
import com.trendithon.timetris.global.exception.enums.SuccessStatus; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/past") | ||
public class PastController { | ||
|
||
private final PastService pastService; | ||
private final TokenProvider tokenProvider; | ||
|
||
@GetMapping("") | ||
public ApiResponse<List<PastViewDTO>> readPastsController(HttpServletRequest request){ | ||
long userId = tokenProvider.getUserId(request); | ||
List<PastViewDTO> pastViewDTOList = pastService.readPastsAll(userId); | ||
return ApiResponse.success(SuccessStatus.OK, pastViewDTOList); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/trendithon/timetris/domain/past/dto/PastViewDTO.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,40 @@ | ||
package com.trendithon.timetris.domain.past.dto; | ||
|
||
import com.trendithon.timetris.domain.mainpage.domain.Date; | ||
import com.trendithon.timetris.domain.mainpage.domain.Do; | ||
import com.trendithon.timetris.domain.mainpage.domain.Plan; | ||
import com.trendithon.timetris.domain.mainpage.domain.See; | ||
import com.trendithon.timetris.domain.mainpage.dto.DoViewDTO; | ||
import com.trendithon.timetris.domain.mainpage.dto.MainPageDTO; | ||
import com.trendithon.timetris.domain.mainpage.dto.PlanViewDTO; | ||
import com.trendithon.timetris.domain.mainpage.dto.SeeViewDTO; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor @NoArgsConstructor | ||
public class PastViewDTO { | ||
|
||
LocalDate localDate; | ||
List<PlanViewDTO> planViewDTOList; | ||
List<DoViewDTO> doViewDTOList; | ||
List<SeeViewDTO> seeViewDTO; | ||
|
||
public static PastViewDTO from(Date date, List<Plan> planList, List<Do> doList, List<See> seeList){ | ||
LocalDate localDate1 = date.getDate(); | ||
List<PlanViewDTO> planViewDTOS = planList.stream() | ||
.map(PlanViewDTO::of) | ||
.toList(); | ||
List<DoViewDTO> doViewDTOS = doList.stream() | ||
.map(DoViewDTO::of) | ||
.toList(); | ||
List<SeeViewDTO> seeViewDTO1 = seeList.stream() | ||
.map(SeeViewDTO::of) | ||
.toList(); | ||
return new PastViewDTO(localDate1, planViewDTOS, doViewDTOS, seeViewDTO1); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/trendithon/timetris/domain/past/service/PastService.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.trendithon.timetris.domain.past.service; | ||
|
||
import com.trendithon.timetris.domain.past.dto.PastViewDTO; | ||
import org.springframework.stereotype.Service; | ||
import java.util.List; | ||
|
||
@Service | ||
public interface PastService { | ||
List<PastViewDTO> readPastsAll(long userId); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/trendithon/timetris/domain/past/service/PathServiceImpl.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,51 @@ | ||
package com.trendithon.timetris.domain.past.service; | ||
|
||
import com.trendithon.timetris.domain.mainpage.domain.*; | ||
import com.trendithon.timetris.domain.mainpage.dto.MainPageDTO; | ||
import com.trendithon.timetris.domain.mainpage.repository.*; | ||
import com.trendithon.timetris.domain.member.domain.User; | ||
import com.trendithon.timetris.domain.member.repository.UserRepository; | ||
import com.trendithon.timetris.domain.past.dto.PastViewDTO; | ||
import com.trendithon.timetris.global.exception.CustomException; | ||
import com.trendithon.timetris.global.exception.enums.ErrorStatus; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.time.Month; | ||
import java.time.Year; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class PathServiceImpl implements PastService{ | ||
|
||
private final DateRepository dateRepository; | ||
private final UserRepository userRepository; | ||
private final UserDateRepository userDateRepository; | ||
private final PlanRepository planRepository; | ||
private final DoRepository doRepository; | ||
private final SeeRepository seeRepository; | ||
|
||
@Override | ||
public List<PastViewDTO> readPastsAll(long userId) { | ||
LocalDate localDate = LocalDate.now(); | ||
int year = localDate.getYear(); | ||
int month = localDate.getMonth().getValue(); | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR)); | ||
List<Date> dateList = dateRepository.findAllByYearAndMonth(year, month); | ||
List<PastViewDTO> result = new ArrayList<>(); | ||
dateList.forEach(date -> { | ||
UserDate userDate = userDateRepository.findByUser_IdAndDate_Id(userId, date.getId()); | ||
List<Plan> planList = planRepository.findAllByUserDate(userDate); | ||
List<Do> doList = doRepository.findAllByUserDate(userDate); | ||
List<See> see = seeRepository.findByUserDate(userDate); | ||
result.add(PastViewDTO.from(date, planList, doList, see)); | ||
}); | ||
return result; | ||
} | ||
} |