-
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.
[8주차/공공] 워크북 제출합니다.
- Loading branch information
Showing
53 changed files
with
803 additions
and
266 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
2 changes: 1 addition & 1 deletion
2
src/main/java/javalab/umc7th_mission/apiPayload/exception/ExceptionAdvice.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
2 changes: 1 addition & 1 deletion
2
src/main/java/javalab/umc7th_mission/apiPayload/exception/GeneralException.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
10 changes: 10 additions & 0 deletions
10
src/main/java/javalab/umc7th_mission/apiPayload/exception/handler/FoodCategoryHandler.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 javalab.umc7th_mission.apiPayload.exception.handler; | ||
|
||
import umc.spring.apiPayload.code.BaseErrorCode; | ||
import umc.spring.apiPayload.exception.GeneralException; | ||
|
||
public class FoodCategoryHandler extends GeneralException { | ||
public FoodCategoryHandler(BaseErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/javalab/umc7th_mission/apiPayload/exception/handler/TempHandler.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
50 changes: 50 additions & 0 deletions
50
src/main/java/javalab/umc7th_mission/controller/MemberRestController.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,50 @@ | ||
package javalab.umc7th_mission.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import umc.spring.apiPayload.ApiResponse; | ||
import umc.spring.apiPayload.exception.GeneralException; | ||
import umc.spring.converter.MemberConverter; | ||
import umc.spring.domain.Member; | ||
import umc.spring.dto.MemberRequestDTO; | ||
import umc.spring.dto.MemberResponseDTO; | ||
import umc.spring.service.MemberService.MemberCommandService; | ||
import umc.spring.service.MissionService.MissionService; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/members") | ||
public class MemberRestController { | ||
|
||
private final MemberCommandService memberCommandService; | ||
private final MissionService missionService; | ||
|
||
@PostMapping("/") | ||
public ApiResponse<MemberResponseDTO.JoinResultDTO> join(@RequestBody @Valid MemberRequestDTO.JoinDto request){ | ||
Member member = memberCommandService.joinMember(request); | ||
return ApiResponse.onSuccess(MemberConverter.toJoinResultDTO(member)); | ||
} | ||
|
||
// 미션 도전 시작 API | ||
@PostMapping("/{memberId}/missions/{missionId}/start") | ||
public ResponseEntity<ApiResponse<String>> startMission( | ||
@PathVariable Long memberId, @PathVariable Long missionId) { | ||
|
||
try { | ||
missionService.startMission(memberId, missionId); // MissionService에서 도전 시작 처리 | ||
// 미션 도전 성공 시 응답 | ||
return ResponseEntity.ok(ApiResponse.onSuccess("미션 도전이 시작되었습니다.")); | ||
} catch (GeneralException e) { | ||
// 이미 도전 중인 미션인 경우 | ||
ApiResponse<String> errorResponse = ApiResponse.onFailure("BAD_REQUEST", "이미 도전 중인 미션입니다.", null); | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorResponse); | ||
} catch (Exception e) { | ||
// 기타 서버 오류 발생 시 | ||
ApiResponse<String> errorResponse = ApiResponse.onFailure("INTERNAL_SERVER_ERROR", "서버 오류: " + e.getMessage(), null); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/javalab/umc7th_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.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import umc.spring.dto.MissionRequestDTO; | ||
import umc.spring.dto.MissionResponseDTO; | ||
import umc.spring.service.MissionService.MissionService; | ||
|
||
import jakarta.validation.Valid; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/mission") | ||
public class MissionController { | ||
|
||
private final MissionService missionService; | ||
|
||
@PostMapping | ||
public ResponseEntity<?> addMission(@RequestBody @Valid MissionRequestDTO request) { | ||
try { | ||
// 성공적으로 미션을 추가한 경우 | ||
MissionResponseDTO response = missionService.addMission(request); | ||
return ResponseEntity.ok(response); | ||
} catch (IllegalArgumentException e) { | ||
// 클라이언트 요청 오류 | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); | ||
} catch (Exception e) { | ||
// 서버 내부 오류 | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("서버 에러: " + e.getMessage()); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/javalab/umc7th_mission/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,23 @@ | ||
package javalab.umc7th_mission.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import umc.spring.dto.ReviewRequestDTO; | ||
import umc.spring.dto.ReviewResponseDTO; | ||
import umc.spring.service.ReviewService.ReviewService; | ||
|
||
@RestController | ||
@RequestMapping("/review") | ||
@RequiredArgsConstructor | ||
public class ReviewController { | ||
|
||
private final ReviewService reviewService; | ||
|
||
// 리뷰 추가 API | ||
@PostMapping | ||
public ResponseEntity<ReviewResponseDTO> addReview(@RequestBody ReviewRequestDTO request) { | ||
ReviewResponseDTO response = reviewService.addReview(request); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/javalab/umc7th_mission/controller/StoreController.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,28 @@ | ||
package javalab.umc7th_mission.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
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; | ||
import umc.spring.apiPayload.ApiResponse; | ||
import umc.spring.converter.StoreConverter; | ||
import umc.spring.domain.Store; | ||
import umc.spring.dto.StoreRequestDTO; | ||
import umc.spring.dto.StoreResponseDTO; | ||
import umc.spring.service.StoreService.StoreService; | ||
|
||
@RestController | ||
@RequestMapping("/stores") | ||
@RequiredArgsConstructor | ||
public class StoreController { | ||
|
||
private final StoreService storeService; | ||
|
||
@PostMapping("/") | ||
public ApiResponse<StoreResponseDTO> addStore(@RequestBody @Valid StoreRequestDTO request) { | ||
Store store = storeService.addStore(request); | ||
return ApiResponse.onSuccess(StoreConverter.toStoreResponseDTO(store)); // 응답 DTO로 변환하여 반환 | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/javalab/umc7th_mission/controller/TempController.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
44 changes: 44 additions & 0 deletions
44
src/main/java/javalab/umc7th_mission/converter/MemberConverter.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 umc.spring.converter; | ||
|
||
import umc.spring.domain.Member; | ||
import umc.spring.domain.enums.Gender; | ||
import umc.spring.dto.MemberRequestDTO; | ||
import umc.spring.dto.MemberResponseDTO; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
|
||
public class MemberConverter { | ||
|
||
public static MemberResponseDTO.JoinResultDTO toJoinResultDTO(Member member){ | ||
return MemberResponseDTO.JoinResultDTO.builder() | ||
.memberId(member.getId()) | ||
.createdAt(LocalDateTime.now()) | ||
.build(); | ||
} | ||
|
||
public static Member toMember(MemberRequestDTO.JoinDto request){ | ||
|
||
Gender gender = null; | ||
|
||
switch (request.getGender()){ | ||
case 1: | ||
gender = Gender.MALE; | ||
break; | ||
case 2: | ||
gender = Gender.FEMALE; | ||
break; | ||
case 3: | ||
gender = Gender.NONE; | ||
break; | ||
} | ||
|
||
return Member.builder() | ||
.address(request.getAddress()) | ||
.specAddress(request.getSpecAddress()) | ||
.gender(gender) | ||
.name(request.getName()) | ||
.memberPreferList(new ArrayList<>()) | ||
.build(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/javalab/umc7th_mission/converter/MemberPreferConverter.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,21 @@ | ||
package umc.spring.converter; | ||
|
||
import umc.spring.domain.foodCategory; | ||
import umc.spring.domain.mapping.MemberPrefer; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class MemberPreferConverter { | ||
|
||
public static List<MemberPrefer> toMemberPreferList(List<foodCategory> foodCategoryList){ | ||
|
||
return foodCategoryList.stream() | ||
.map(foodCategory -> | ||
MemberPrefer.builder() | ||
.foodCategory(foodCategory) | ||
.build() | ||
).collect(Collectors.toList()); | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
src/main/java/javalab/umc7th_mission/converter/MissionConverter.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,16 @@ | ||
package umc.spring.converter; | ||
|
||
import umc.spring.domain.Mission; | ||
import umc.spring.dto.MissionResponseDTO; | ||
|
||
public class MissionConverter { | ||
public static MissionResponseDTO toMissionResponseDTO(Mission mission) { | ||
return MissionResponseDTO.builder() | ||
.id(mission.getId()) | ||
.missionSpec(mission.getMissionSpec()) | ||
.reward(mission.getReward()) | ||
.deadline(mission.getDeadline()) | ||
.storeName(mission.getStore().getName()) | ||
.build(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/javalab/umc7th_mission/converter/StoreConverter.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,26 @@ | ||
package umc.spring.converter; | ||
|
||
import umc.spring.domain.Region; | ||
import umc.spring.domain.Store; | ||
import umc.spring.dto.StoreRequestDTO; | ||
import umc.spring.dto.StoreResponseDTO; | ||
|
||
public class StoreConverter { | ||
public static Store toStore(StoreRequestDTO request, Region region) { | ||
return Store.builder() | ||
.name(request.getName()) | ||
.address(request.getAddress()) | ||
.region(region) | ||
.score(request.getScore()) // score 값 추가 | ||
.build(); | ||
} | ||
|
||
public static StoreResponseDTO toStoreResponseDTO(Store store) { | ||
return StoreResponseDTO.builder() | ||
.id(store.getId()) | ||
.name(store.getName()) | ||
.address(store.getAddress()) | ||
.regionName(store.getRegion().getName()) // 지역 이름도 포함 | ||
.build(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/javalab/umc7th_mission/dto/MemberRequestDTO.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,32 @@ | ||
package umc.spring.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Getter; | ||
import umc.spring.validation.annotation.ExistCategories; | ||
|
||
import java.util.List; | ||
|
||
public class MemberRequestDTO { | ||
|
||
@Getter | ||
public static class JoinDto{ | ||
@NotBlank | ||
String name; | ||
@NotNull | ||
Integer gender; | ||
@NotNull | ||
Integer birthYear; | ||
@NotNull | ||
Integer birthMonth; | ||
@NotNull | ||
Integer birthDay; | ||
@Size(min = 5, max = 12) | ||
String address; | ||
@Size(min = 5, max = 12) | ||
String specAddress; | ||
@ExistCategories | ||
List<Long> preferCategory; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/javalab/umc7th_mission/dto/MemberResponseDTO.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,20 @@ | ||
package umc.spring.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class MemberResponseDTO { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class JoinResultDTO{ | ||
Long memberId; | ||
LocalDateTime createdAt; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/javalab/umc7th_mission/dto/MissionRequestDTO.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,15 @@ | ||
package umc.spring.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Setter | ||
public class MissionRequestDTO { | ||
private String missionSpec; | ||
private int reward; | ||
private LocalDate deadline; | ||
private Long storeId; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/javalab/umc7th_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,18 @@ | ||
package umc.spring.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@Builder | ||
public class MissionResponseDTO { | ||
private Long id; | ||
private String missionSpec; | ||
private int reward; | ||
private LocalDate deadline; | ||
private String storeName; | ||
} |
Oops, something went wrong.