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
Expand Up @@ -34,6 +34,10 @@ public enum ErrorStatus implements BaseErrorCode {
_INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "USER4001", "비밀번호가 일치하지 않습니다."),
_DUPLICATED_EMAIL(HttpStatus.BAD_REQUEST, "USER4002", "이미 가입된 이메일입니다."),

// 여행 취향 관련
_STYLE_NOT_FOUND(HttpStatus.NOT_FOUND, "STYLE4040", "입력하신 여행 스타일을 찾을 수 없습니다."),
_UNAUTHORIZED_USER(HttpStatus.FORBIDDEN, "STYLE4001", "해당 사용자는 권한이 없습니다."),

;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@DynamicInsert
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class TravelPlan {
public class Style {

@Id @GeneratedValue(strategy = IDENTITY)
private Long id;
Expand All @@ -43,4 +43,11 @@ public class TravelPlan {
@ManyToOne
@JoinColumn(name = "user_id")
private User user;

public void updateStyle( LocalDateTime startDate, LocalDateTime endDate, String preferActivity, String requirement) {
this.startDate = startDate;
this.endDate = endDate;
this.preferActivity = preferActivity;
this.requirement = requirement;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package hyu.erica.capstone.repository;

import hyu.erica.capstone.domain.Style;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface StyleRepository extends JpaRepository<Style, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hyu.erica.capstone.service.style;

import hyu.erica.capstone.web.dto.style.request.UserStyleRequestDTO;
import hyu.erica.capstone.web.dto.style.response.UserStyleInitResponseDTO;
import hyu.erica.capstone.web.dto.style.response.UserStyleResponseDTO;

public interface StyleCommandService {

UserStyleInitResponseDTO initStyle(Long userId);

UserStyleResponseDTO updateStyle(Long userId, Long styleId, UserStyleRequestDTO request);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package hyu.erica.capstone.service.style;

import hyu.erica.capstone.api.code.status.ErrorStatus;
import hyu.erica.capstone.api.exception.GeneralException;
import hyu.erica.capstone.domain.Style;
import hyu.erica.capstone.domain.User;
import hyu.erica.capstone.domain.enums.City;
import hyu.erica.capstone.repository.StyleRepository;
import hyu.erica.capstone.repository.UserRepository;
import hyu.erica.capstone.web.dto.style.request.UserStyleRequestDTO;
import hyu.erica.capstone.web.dto.style.response.UserStyleInitResponseDTO;
import hyu.erica.capstone.web.dto.style.response.UserStyleResponseDTO;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class StyleCommandServiceImpl implements StyleCommandService {

private final UserRepository userRepository;
private final StyleRepository styleRepository;

@Override
public UserStyleInitResponseDTO initStyle(Long userId) {
User user = userRepository.findById(userId).orElseThrow( () -> new GeneralException(ErrorStatus._USER_NOT_FOUND));

Style style = Style.builder()
.city(City.BUSAN)
.user(user)
.build();
Style save = styleRepository.save(style);

return UserStyleInitResponseDTO.of(userId, save.getId());
}

@Override
public UserStyleResponseDTO updateStyle(Long userId, Long styleId, UserStyleRequestDTO request) {
Style style = styleRepository.findById(styleId).orElseThrow( () -> new GeneralException(ErrorStatus._STYLE_NOT_FOUND));

if (!Objects.equals(style.getUser().getId(), userId))
throw new GeneralException(ErrorStatus._UNAUTHORIZED_USER);

style.updateStyle(request.startDate(), request.endDate(), request.preferActivity(), request.requirement());

Style save = styleRepository.save(style);

return UserStyleResponseDTO.of(save);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hyu.erica.capstone.service.style;

import hyu.erica.capstone.web.dto.style.response.UserStyleResponseDTO;

public interface StyleQueryService {

UserStyleResponseDTO getStyle(Long styleId, Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package hyu.erica.capstone.service.style;

import hyu.erica.capstone.api.code.status.ErrorStatus;
import hyu.erica.capstone.api.exception.GeneralException;
import hyu.erica.capstone.domain.Style;
import hyu.erica.capstone.domain.User;
import hyu.erica.capstone.repository.StyleRepository;
import hyu.erica.capstone.repository.UserRepository;
import hyu.erica.capstone.web.dto.style.response.UserStyleResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class StyleQueryServiceImpl implements StyleQueryService {

private final StyleRepository styleRepository;
private final UserRepository userRepository;

@Override
public UserStyleResponseDTO getStyle(Long styleId, Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new GeneralException(ErrorStatus._USER_NOT_FOUND));

Style style = styleRepository.findById(styleId)
.orElseThrow(() -> new GeneralException(ErrorStatus._STYLE_NOT_FOUND));

if (!style.getUser().getId().equals(user.getId()))
throw new GeneralException(ErrorStatus._UNAUTHORIZED_USER);

return UserStyleResponseDTO.of(style);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package hyu.erica.capstone.web.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "기본", description = "기본 API")
@RestController
public class DefaultController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Plan", description = "여행 계획 관련 API")
@Tag(name = "[개발 전] 여행 계획", description = "여행 계획 관련 API")
@CrossOrigin
@RestController
@RequestMapping("/api/plans")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package hyu.erica.capstone.web.controller;


import hyu.erica.capstone.api.ApiResponse;
import hyu.erica.capstone.api.code.status.SuccessStatus;
import hyu.erica.capstone.security.utils.SecurityUtils;
import hyu.erica.capstone.service.style.StyleCommandService;
import hyu.erica.capstone.service.style.StyleQueryService;
import hyu.erica.capstone.web.dto.style.request.UserStyleRequestDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "여행 스타일", description = "여행 스타일 관련 API")
@CrossOrigin
@RestController
@RequestMapping("/api/styles")
@RequiredArgsConstructor
public class StyleController {

private final StyleQueryService styleQueryService;
private final StyleCommandService styleCommandService;

@Operation(summary = "[선호 여행 스타일 작성 시작]", description = """
### 선호 여행 스타일 작성을 위한 정보를 가져옵니다. \n
발급 받은 styleId를 통해 수시로 선호 여행 스타일을 임시 저장 할 수 있습니다. \n

### Response Body
- name : 회원 이름
- styleId : 스타일 ID (해당 스타일 ID로 선호 여행 스타일을 조회, 수정할 수 있습니다.)
""")
@GetMapping("/")
public ApiResponse<?> getUserPlanStyle() {
return ApiResponse.of(SuccessStatus._OK, styleCommandService.initStyle(SecurityUtils.getCurrentUserId()));
}

// 선호 여행 스타일 입력
@Operation(summary = "[선호 여행 스타일 입력 및 수정]", description = """
### 선호 여행 스타일을 입력 및 수정합니다. 모든 값은 필수가 아닙니다. \n
styleId를 통해 특정 선호 여행 스타일을 수정할 수 있습니다. \n

### Request Body
- city: 도시
- startDate: 여행 시작 날짜
- endDate: 여행 종료 날짜
- preferActivity: 선호하는 활동
- requirement: 요구사항
""")
@PostMapping("/{styleId}")
public ApiResponse<?> saveUserPlanStyle(@RequestBody UserStyleRequestDTO request,
@PathVariable Long styleId) {
return ApiResponse.onSuccess(SuccessStatus._OK, styleCommandService.updateStyle(SecurityUtils.getCurrentUserId(), styleId, request));
}

// 선호 여행 스타일 조회
@Operation(summary = "[선호 여행 스타일 조회]", description = """
### 선호 여행 스타일을 조회합니다. \n
styleId를 통해 특정 선호 여행 스타일을 조회할 수 있습니다. \n

### Response Body
- city: 도시
- startDate: 여행 시작 날짜
- endDate: 여행 종료 날짜
- preferActivity: 선호하는 활동
- requirement: 요구사항
""")
@GetMapping("/{styleId}")
public ApiResponse<?> getUserPlanStyle(@PathVariable Long styleId) {

return ApiResponse.of(SuccessStatus._OK, styleQueryService.getStyle(styleId, SecurityUtils.getCurrentUserId()));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "[개발 전] 여행", description = "여행 관련 API")
@CrossOrigin
@RestController
@RequestMapping("/api/trip-plans/{tripPlansId}")
public class TripPlanController {

// 여행 기간 입력
@Tag(name = "Trip", description = "여행 관련 API")
@Tag(name = "[개발 전] Trip", description = "여행 관련 API")
@Operation(summary = "여행 기간 입력", description = """
### 여행 기간을 입력합니다.

Expand All @@ -48,7 +49,7 @@ public ApiResponse<?> inputPeriod(
return null;
}

@Tag(name = "Trip", description = "여행 관련 API")
@Tag(name = "[개발 전] Trip", description = "여행 관련 API")
@Operation(summary = "여행 기간 조회", description = """
### 여행 기간을 조회합니다.

Expand All @@ -63,7 +64,7 @@ public ApiResponse<TripPeriodResponseDTO> getPeriod(
}

// 선호 활동 입력
@Tag(name = "Trip", description = "여행 관련 API")
@Tag(name = "[개발 전] Trip", description = "여행 관련 API")
@Operation(summary = "선호 활동 입력", description = """
### 선호 활동을 입력합니다.

Expand All @@ -81,7 +82,7 @@ public ApiResponse<?> inputActivities(
return null;
}

@Tag(name = "Trip", description = "여행 관련 API")
@Tag(name = "[개발 전] Trip", description = "여행 관련 API")
@Operation(summary = "선호 활동 조회", description = """
### 선호 활동을 조회합니다.

Expand All @@ -96,7 +97,7 @@ public ApiResponse<PreferActivitiesResponseDTO> getActivities(
}

// 추가적인 요구 사항 입력
@Tag(name = "Trip", description = "여행 관련 API")
@Tag(name = "[개발 전] Trip", description = "여행 관련 API")
@Operation(summary = "추가적인 요구 사항 입력", description = """
### 추가적인 요구 사항을 입력합니다.

Expand All @@ -114,7 +115,7 @@ public ApiResponse<?> inputAdditional(
return null;
}

@Tag(name = "Trip", description = "여행 관련 API")
@Tag(name = "[개발 전] Trip", description = "여행 관련 API")
@Operation(summary = "추가적인 요구 사항 조회", description = """
### 추가적인 요구 사항을 조회합니다.

Expand All @@ -128,7 +129,7 @@ public ApiResponse<AdditionalInfoResponseDTO> getAdditional(
return null;
}

@Tag(name = "Trip", description = "여행 관련 API")
@Tag(name = "[개발 전] Trip", description = "여행 관련 API")
@Operation(summary = "일정 제공", description = """
### 최종적으로 입력한 정보를 바탕으로 일정을 제공합니다.

Expand All @@ -146,7 +147,7 @@ public ApiResponse<?> finalInput(
/* ------------------------------------------------------------------------------------------------------ */

// 선택지 확인 (여행지)
@Tag(name = "선택지 확인", description = "선택지 확인 API")
@Tag(name = "[개발 전] 선택지 확인", description = "선택지 확인 API")
@Operation(summary = "선택지 (여행지) 확인", description = """
### 선택지 확인 API

Expand All @@ -161,7 +162,7 @@ public ApiResponse<?> checkPlaces(
}

// 선택지 상세 보기 (여행지)
@Tag(name = "선택지 확인", description = "선택지 확인 API")
@Tag(name = "[개발 전] 선택지 확인", description = "선택지 확인 API")
@Operation(summary = "선택지 (여행지) 상세 보기", description = """
### 선택지 상세 보기 API

Expand All @@ -178,7 +179,7 @@ public ApiResponse<?> viewPlaceDetail(
}

// 여행지 키워드 검색
@Tag(name = "선택지 확인", description = "선택지 확인 API")
@Tag(name = "[개발 전] 선택지 확인", description = "선택지 확인 API")
@Operation(summary = "여행지 키워드 검색", description = """
### 여행지 키워드 검색 API

Expand All @@ -197,7 +198,7 @@ public ApiResponse<?> searchPlace(
}

// 여행지 최종 선택
@Tag(name = "선택지 확인", description = "선택지 확인 API")
@Tag(name = "[개발 전] 선택지 확인", description = "선택지 확인 API")
@Operation(summary = "여행지 최종 선택", description = """
### 여행지 최종 선택 API

Expand All @@ -214,7 +215,7 @@ public ApiResponse<?> finalPlace(
}

// 선택지 확인 (음식점)
@Tag(name = "선택지 확인", description = "선택지 확인 API")
@Tag(name = "[개발 전] 선택지 확인", description = "선택지 확인 API")
@Operation(summary = "선택지 (음식점) 확인", description = """
### 선택지 확인 API

Expand All @@ -230,7 +231,7 @@ public ApiResponse<?> checkRestaurants(


// 선택지 상세 보기 (음식점)
@Tag(name = "선택지 확인", description = "선택지 확인 API")
@Tag(name = "[개발 전] 선택지 확인", description = "선택지 확인 API")
@Operation(summary = "선택지 (음식점) 상세 보기", description = """
### 선택지 상세 보기 API

Expand All @@ -248,7 +249,7 @@ public ApiResponse<?> viewRestaurantDetail(


// 음식점 키워드 검색
@Tag(name = "선택지 확인", description = "선택지 확인 API")
@Tag(name = "[개발 전] 선택지 확인", description = "선택지 확인 API")
@Operation(summary = "음식점 키워드 검색", description = """
### 음식점 키워드 검색 API

Expand All @@ -268,7 +269,7 @@ public ApiResponse<?> searchRestaurant(


// 음식점 최종 선택
@Tag(name = "선택지 확인", description = "선택지 확인 API")
@Tag(name = "[개발 전] 선택지 확인", description = "선택지 확인 API")
@Operation(summary = "음식점 최종 선택", description = """
### 음식점 최종 선택 API

Expand Down
Loading