Skip to content
Merged
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
@@ -1,9 +1,12 @@
package hyu.erica.capstone.repository;

import hyu.erica.capstone.domain.TripPlan;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface TripPlanRepository extends JpaRepository<TripPlan, Long> {

List<TripPlan> findAllByUser_Id(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hyu.erica.capstone.web.dto.user.request.SignInRequestDTO;
import hyu.erica.capstone.web.dto.user.request.SignUpRequestDTO;
import hyu.erica.capstone.web.dto.user.request.UpdateInfoRequestDTO;
import hyu.erica.capstone.web.dto.user.response.MyTripPlanResponse;

public interface UserCommandService {

Expand All @@ -14,5 +15,7 @@ public interface UserCommandService {

void updateInfo(Long userId, UpdateInfoRequestDTO request);

MyTripPlanResponse getMyTripPlans(Long userId);

void reissueToken(String refreshToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@

import hyu.erica.capstone.api.code.status.ErrorStatus;
import hyu.erica.capstone.api.exception.GeneralException;
import hyu.erica.capstone.domain.TripPlan;
import hyu.erica.capstone.domain.User;
import hyu.erica.capstone.repository.TripPlanRepository;
import hyu.erica.capstone.repository.UserRepository;
import hyu.erica.capstone.security.JwtTokenProvider;
import hyu.erica.capstone.service.user.UserCommandService;
import hyu.erica.capstone.web.dto.user.request.SignInRequestDTO;
import hyu.erica.capstone.web.dto.user.request.SignUpRequestDTO;
import hyu.erica.capstone.web.dto.user.request.UpdateInfoRequestDTO;
import hyu.erica.capstone.web.dto.user.response.MyTripPlanResponse;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@Transactional
@RequiredArgsConstructor
public class UserCommandServiceImpl implements UserCommandService {

private final UserRepository userRepository;
private final TripPlanRepository tripPlanRepository;
private final JwtTokenProvider jwtTokenProvider;


Expand Down Expand Up @@ -71,6 +78,16 @@ public void updateInfo(Long userId, UpdateInfoRequestDTO request) {
user.updateInfo(request.nickname(), request.phoneNumber(), request.profileImage());
}

@Override
public MyTripPlanResponse getMyTripPlans(Long userId) {
log.info(userId.toString());
if (!userRepository.existsById(userId)){
throw new GeneralException(ErrorStatus._USER_NOT_FOUND);
}
List<TripPlan> allByUserId = tripPlanRepository.findAllByUser_Id(userId);
return MyTripPlanResponse.of(allByUserId);
}

@Override
public void reissueToken(String refreshToken) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,14 @@ public ApiResponse<?> editProfile(
return ApiResponse.onSuccess(SuccessStatus._OK);
}

// 마이페이지 - 내 여행 계획 조회
@Operation(summary = "[회원 관련] 내 여행 계획 조회", description = """
### 내 여행 계획을 조회합니다.
""")
@GetMapping("/trip-plans")
public ApiResponse<?> myTripPlans() {
return ApiResponse.onSuccess(SuccessStatus._OK, userCommandService.getMyTripPlans(SecurityUtils.getCurrentUserId()));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public record AttractionListResponseDTO(List<AttractionResponseDTO> attractions,

public static AttractionListResponseDTO of(List<Attraction> attractions) {
List<AttractionResponseDTO> responseDTOS = attractions.stream()
.map(attraction -> new AttractionResponseDTO(attraction.getContentId(), attraction.getContentName(), attraction.getImageUrl()))
.map(attraction -> new AttractionResponseDTO(attraction.getContentId(), attraction.getContentName(), attraction.getImageUrl(),
attraction.getAddress()))
.toList();
return new AttractionListResponseDTO(responseDTOS, attractions.size());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hyu.erica.capstone.web.dto.tripPlan.response.attraction;

public record AttractionResponseDTO(Long attractionId, String name, String imageUrl) {
public record AttractionResponseDTO(Long attractionId, String name, String imageUrl, String address) {

public static AttractionResponseDTO of(Long attractionId, String name, String imageUrl) {
return new AttractionResponseDTO(attractionId, name, imageUrl);
public static AttractionResponseDTO of(Long attractionId, String name, String imageUrl, String address) {
return new AttractionResponseDTO(attractionId, name, imageUrl, address);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import hyu.erica.capstone.domain.Restaurant;

public record RestaurantResponseDTO(Long restaurantId, String name, String imageUrl) {
public record RestaurantResponseDTO(Long restaurantId, String name, String imageUrl, String address) {

public static RestaurantResponseDTO of(Restaurant restaurant) {
return new RestaurantResponseDTO(restaurant.getId(), restaurant.getRestaurantName(), "추후 작업 예정");
return new RestaurantResponseDTO(restaurant.getId(), restaurant.getRestaurantName(), "추후 작업 예정", restaurant.getRoadAddress());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package hyu.erica.capstone.web.dto.user.response;

import hyu.erica.capstone.domain.TripPlan;
import hyu.erica.capstone.domain.enums.TripPlanStatus;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public record MyTripPlanResponse (List<TripDetail> tripPlans, int totalElements) {

public static MyTripPlanResponse of(List<TripPlan> tripPlans) {
List<TripDetail> tripPlanDetails = tripPlans.stream()
.map(tripPlan -> TripDetail.of(
tripPlan.getId(),
tripPlan.getTitle(),
tripPlan.getTripPlanStatus(),
tripPlan.getStartDate(),
tripPlan.getEndDate(),
tripPlan.getProfileImage(),
tripPlan.getDescription(),
"부산"))
.toList();
return new MyTripPlanResponse(tripPlanDetails, tripPlans.size());
}

private record TripDetail(Long tripPlanId, String tripPlanName, TripPlanStatus tripPlanStatus, LocalDate startDate, LocalDate endDate, Integer dayDiff, String imageUrl, String memo, String city) {
public static TripDetail of(
Long tripPlanId, String tripPlanName, TripPlanStatus tripPlanStatus, LocalDate startDate, LocalDate endDate,
String imageUrl, String memo, String city) {

// dayDiff 오늘부터 여행 종료일 까지의 일수
int dayDiff = (int) (LocalDate.now().toEpochDay() - endDate.toEpochDay());

Comment on lines +32 to +33
Copy link

Copilot AI Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The computation for dayDiff subtracts the trip's endDate from the current date, which may result in negative values if the trip has not ended yet. Consider revising the calculation to 'endDate.toEpochDay() - LocalDate.now().toEpochDay()' to represent the remaining days until the trip ends.

Suggested change
int dayDiff = (int) (LocalDate.now().toEpochDay() - endDate.toEpochDay());
int dayDiff = (int) (endDate.toEpochDay() - LocalDate.now().toEpochDay());

Copilot uses AI. Check for mistakes.
return new TripDetail(tripPlanId, tripPlanName, tripPlanStatus, startDate, endDate, dayDiff ,imageUrl, memo, city);
}
}
}