From 618332674e3055a794232718dbec2ab79ea3ddd7 Mon Sep 17 00:00:00 2001 From: InSooBeen Date: Fri, 22 Nov 2024 08:54:41 +0900 Subject: [PATCH 1/2] mission: submit week8 mission --- build.gradle | 1 + .../apiPayload/code/status/ErrorStatus.java | 10 ++++ .../study/config/SwaggerConfig.java | 38 ++++++++++++++ .../study/controller/TempController.java | 2 +- .../study/converter/MemberConverter.java | 26 ++++++++++ .../study/converter/MemberFoodConverter.java | 17 +++++++ .../converter/MemberMissionConverter.java | 26 ++++++++++ .../study/converter/MissionConverter.java | 26 ++++++++++ .../study/converter/RestaurantConverter.java | 25 +++++++++ .../study/converter/ReviewConverter.java | 27 ++++++++++ .../study/converter/TempConverter.java | 2 +- .../umc7th_mission/study/domain/Member.java | 9 +++- .../study/domain/Restaurant.java | 6 ++- .../umc7th_mission/study/domain/Review.java | 2 +- .../study/domain/mapping/MemberFood.java | 11 ++++ .../study/domain/mapping/MemberMission.java | 13 ++++- .../umc7th_mission/study/dto/TempRequest.java | 4 -- .../MemberMissionRepository.java | 4 +- .../MemberMissionRepositoryImpl.java | 2 + .../MemberRepository/MemberRepository.java | 2 +- .../MissionRepositoryCustom.java | 3 +- .../MissionRepositoryImpl.java | 5 +- .../RegionRepository/RegionRepository.java | 7 +++ .../RestaurantRepository/FoodRepository.java | 7 +++ .../FoodService/FoodValidationService.java | 7 +++ .../FoodValidationServiceImpl.java | 20 ++++++++ .../MemberMissionCommandService.java | 10 ++++ .../MemberMissionCommandServiceImpl.java | 51 +++++++++++++++++++ .../MemberService/MemberCommandService.java | 8 +++ .../MemberCommandServiceImpl.java | 42 +++++++++++++++ .../MissionService/MissionCommandService.java | 8 +++ .../MissionCommandServiceImpl.java | 29 +++++++++++ .../RegionValidationService.java | 7 +++ .../RegionValidationServiceImpl.java | 21 ++++++++ .../RestaurantCommandService.java | 8 +++ .../RestaurantCommandServiceImpl.java | 26 ++++++++++ ....java => RestaurantValidationService.java} | 2 +- ...a => RestaurantValidationServiceImpl.java} | 2 +- .../ReviewService/ReviewCommandService.java | 8 +++ .../ReviewCommandServiceImpl.java | 35 +++++++++++++ .../annotation/ExistCategories.java | 16 ++++++ .../annotation/ExistRestaurant.java | 17 +++++++ .../validatior/CategoriesExistValidator.java | 36 +++++++++++++ .../validatior/RestaurantExistValidator.java | 37 ++++++++++++++ .../MemberMissionRestController.java | 28 ++++++++++ .../web/controller/MemberRestController.java | 27 ++++++++++ .../web/controller/MissionRestController.java | 27 ++++++++++ .../controller/RestaurantRestController.java | 27 ++++++++++ .../web/controller/ReviewRestController.java | 24 +++++++++ .../{ => web}/dto/AvailableMissionDTO.java | 2 +- .../study/web/dto/TempRequest.java | 4 ++ .../study/{ => web}/dto/TempResponse.java | 2 +- .../web/dto/member/MemberRequestDTO.java | 26 ++++++++++ .../web/dto/member/MemberResponseDTO.java | 19 +++++++ .../MemberMissionRequestDTO.java | 20 ++++++++ .../MemberMissionResponseDTO.java | 19 +++++++ .../web/dto/mission/MissionRequestDTO.java | 31 +++++++++++ .../web/dto/mission/MissionResponseDTO.java | 19 +++++++ .../dto/restaurant/RestaurantRequestDTO.java | 19 +++++++ .../dto/restaurant/RestaurantResponseDTO.java | 19 +++++++ .../web/dto/review/ReviewRequestDTO.java | 29 +++++++++++ .../web/dto/review/ReviewResponseDTO.java | 19 +++++++ src/main/resources/application.yml | 2 +- 63 files changed, 1002 insertions(+), 26 deletions(-) create mode 100644 src/main/java/javalab/umc7th_mission/study/config/SwaggerConfig.java create mode 100644 src/main/java/javalab/umc7th_mission/study/converter/MemberConverter.java create mode 100644 src/main/java/javalab/umc7th_mission/study/converter/MemberFoodConverter.java create mode 100644 src/main/java/javalab/umc7th_mission/study/converter/MemberMissionConverter.java create mode 100644 src/main/java/javalab/umc7th_mission/study/converter/MissionConverter.java create mode 100644 src/main/java/javalab/umc7th_mission/study/converter/RestaurantConverter.java create mode 100644 src/main/java/javalab/umc7th_mission/study/converter/ReviewConverter.java delete mode 100644 src/main/java/javalab/umc7th_mission/study/dto/TempRequest.java create mode 100644 src/main/java/javalab/umc7th_mission/study/repository/RegionRepository/RegionRepository.java create mode 100644 src/main/java/javalab/umc7th_mission/study/repository/RestaurantRepository/FoodRepository.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/FoodService/FoodValidationService.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/FoodService/FoodValidationServiceImpl.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandService.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandServiceImpl.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/MemberService/MemberCommandService.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/MemberService/MemberCommandServiceImpl.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/MissionService/MissionCommandService.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/MissionService/MissionCommandServiceImpl.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/RegionService/RegionValidationService.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/RegionService/RegionValidationServiceImpl.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantCommandService.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantCommandServiceImpl.java rename src/main/java/javalab/umc7th_mission/study/service/RestaurantService/{RestaurantQueryService.java => RestaurantValidationService.java} (85%) rename src/main/java/javalab/umc7th_mission/study/service/RestaurantService/{RestaurantQueryServiceImpl.java => RestaurantValidationServiceImpl.java} (92%) create mode 100644 src/main/java/javalab/umc7th_mission/study/service/ReviewService/ReviewCommandService.java create mode 100644 src/main/java/javalab/umc7th_mission/study/service/ReviewService/ReviewCommandServiceImpl.java create mode 100644 src/main/java/javalab/umc7th_mission/study/validation/annotation/ExistCategories.java create mode 100644 src/main/java/javalab/umc7th_mission/study/validation/annotation/ExistRestaurant.java create mode 100644 src/main/java/javalab/umc7th_mission/study/validation/validatior/CategoriesExistValidator.java create mode 100644 src/main/java/javalab/umc7th_mission/study/validation/validatior/RestaurantExistValidator.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/controller/MemberMissionRestController.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/controller/MemberRestController.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/controller/MissionRestController.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/controller/RestaurantRestController.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/controller/ReviewRestController.java rename src/main/java/javalab/umc7th_mission/study/{ => web}/dto/AvailableMissionDTO.java (86%) create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/TempRequest.java rename src/main/java/javalab/umc7th_mission/study/{ => web}/dto/TempResponse.java (90%) create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/member/MemberRequestDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/member/MemberResponseDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionResponseDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/mission/MissionRequestDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/mission/MissionResponseDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/restaurant/RestaurantRequestDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/restaurant/RestaurantResponseDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/review/ReviewRequestDTO.java create mode 100644 src/main/java/javalab/umc7th_mission/study/web/dto/review/ReviewResponseDTO.java diff --git a/build.gradle b/build.gradle index f0b92ea..f38b8a7 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' implementation 'org.springframework.boot:spring-boot-starter-validation' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' diff --git a/src/main/java/javalab/umc7th_mission/study/apiPayload/code/status/ErrorStatus.java b/src/main/java/javalab/umc7th_mission/study/apiPayload/code/status/ErrorStatus.java index 31e0f5b..055f213 100644 --- a/src/main/java/javalab/umc7th_mission/study/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/javalab/umc7th_mission/study/apiPayload/code/status/ErrorStatus.java @@ -18,6 +18,16 @@ public enum ErrorStatus implements BaseErrorCode { MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST, "MEMBER4001", "사용자가 없습니다."), NICKNAME_NOT_EXIST(HttpStatus.BAD_REQUEST, "MEMBER4002", "닉네임은 필수 입니다."), + MISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "MEMBER_MISSION_4001", "미션이 존재하지 않습니다."), + + MEMBER_MISSION_ALREADY_IN_CHALLENGING(HttpStatus.CONFLICT, "MEMBER_MISSION4002", "이미 진행 중인 미션입니다."), + + FOOD_CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "FOOD_CATEGORY4001", "음식 카테고리가 없습니다."), + + RESTAURANT_NOT_FOUND(HttpStatus.NOT_FOUND, "RESTAURANT4001", "식당이 없습니다."), + + REGION_NOT_FOUND(HttpStatus.NOT_FOUND, "REGION4001", "지역이 없습니다."), + ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, "ARTICLE4001", "게시글이 없습니다."), TEMP_EXCEPTION(HttpStatus.BAD_REQUEST, "TEMP4001", "이거는 테스트"); diff --git a/src/main/java/javalab/umc7th_mission/study/config/SwaggerConfig.java b/src/main/java/javalab/umc7th_mission/study/config/SwaggerConfig.java new file mode 100644 index 0000000..2e6e446 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/config/SwaggerConfig.java @@ -0,0 +1,38 @@ +package javalab.umc7th_mission.study.config; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.servers.Server; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + + @Bean + public OpenAPI UMCstudyAPI() { + Info info = new Info() + .title("UMC Server WorkBook API") + .description("UMC Server WorkBook API 명세서") + .version("1.0.0"); + + String jwtSchemeName = "JWT TOKEN"; + SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName); + + Components components = new Components() + .addSecuritySchemes(jwtSchemeName, new SecurityScheme() + .name(jwtSchemeName) + .type(SecurityScheme.Type.HTTP) + .scheme("bearer") + .bearerFormat("JWT")); + + return new OpenAPI() + .addServersItem(new Server().url("/")) + .info(info) + .addSecurityItem(securityRequirement) + .components(components); + } +} \ No newline at end of file diff --git a/src/main/java/javalab/umc7th_mission/study/controller/TempController.java b/src/main/java/javalab/umc7th_mission/study/controller/TempController.java index 96c7330..5da4e75 100644 --- a/src/main/java/javalab/umc7th_mission/study/controller/TempController.java +++ b/src/main/java/javalab/umc7th_mission/study/controller/TempController.java @@ -2,7 +2,7 @@ import javalab.umc7th_mission.study.apiPayload.ApiResponse; import javalab.umc7th_mission.study.converter.TempConverter; -import javalab.umc7th_mission.study.dto.TempResponse; +import javalab.umc7th_mission.study.web.dto.TempResponse; import javalab.umc7th_mission.study.service.TempService.TempQueryService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; diff --git a/src/main/java/javalab/umc7th_mission/study/converter/MemberConverter.java b/src/main/java/javalab/umc7th_mission/study/converter/MemberConverter.java new file mode 100644 index 0000000..a3dbaa3 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/converter/MemberConverter.java @@ -0,0 +1,26 @@ +package javalab.umc7th_mission.study.converter; + +import javalab.umc7th_mission.study.domain.Member; +import javalab.umc7th_mission.study.web.dto.member.MemberRequestDTO; +import javalab.umc7th_mission.study.web.dto.member.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){ + return Member.builder() + .name(request.getName()) + .birth(request.getBirth()) + .address(request.getAddress()) + .memberFoodList(new ArrayList<>()) + .build(); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/converter/MemberFoodConverter.java b/src/main/java/javalab/umc7th_mission/study/converter/MemberFoodConverter.java new file mode 100644 index 0000000..9dfc6d5 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/converter/MemberFoodConverter.java @@ -0,0 +1,17 @@ +package javalab.umc7th_mission.study.converter; + +import javalab.umc7th_mission.study.domain.Food; +import javalab.umc7th_mission.study.domain.mapping.MemberFood; + +import java.util.List; +import java.util.stream.Collectors; + +public class MemberFoodConverter { + public static List toMemberFoodList(List foodList){ + return foodList.stream() + .map(food -> MemberFood.builder() + .food(food) + .build() + ).collect(Collectors.toList()); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/converter/MemberMissionConverter.java b/src/main/java/javalab/umc7th_mission/study/converter/MemberMissionConverter.java new file mode 100644 index 0000000..a1c6e5f --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/converter/MemberMissionConverter.java @@ -0,0 +1,26 @@ +package javalab.umc7th_mission.study.converter; + +import javalab.umc7th_mission.study.domain.Member; +import javalab.umc7th_mission.study.domain.Mission; +import javalab.umc7th_mission.study.domain.mapping.MemberMission; +import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionRequestDTO; +import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionResponseDTO; + +import java.time.LocalDate; + +public class MemberMissionConverter { + public static MemberMissionResponseDTO.AddMemberMissionResultDTO toAddMemberMissionResultDTO(MemberMission memberMission){ + return MemberMissionResponseDTO.AddMemberMissionResultDTO.builder() + .memberMissionId(memberMission.getId()) + .createdAt(LocalDate.now()) + .build(); + } + + public static MemberMission toMemberMission(Member member, Mission mission){ + return MemberMission.builder() + .member(member) + .mission(mission) + .startDate(LocalDate.now()) + .build(); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/converter/MissionConverter.java b/src/main/java/javalab/umc7th_mission/study/converter/MissionConverter.java new file mode 100644 index 0000000..31c97da --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/converter/MissionConverter.java @@ -0,0 +1,26 @@ +package javalab.umc7th_mission.study.converter; + +import javalab.umc7th_mission.study.domain.Mission; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.web.dto.mission.MissionRequestDTO; +import javalab.umc7th_mission.study.web.dto.mission.MissionResponseDTO; + +import java.time.LocalDate; + +public class MissionConverter { + public static MissionResponseDTO.AddMissionResultDTO toAddMissionResultDTO(Mission mission){ + return new MissionResponseDTO.AddMissionResultDTO().builder() + .missionId(mission.getId()) + .createdAt(LocalDate.now()) + .build(); + } + public static Mission toMission(MissionRequestDTO.AddMissionDto request, Restaurant restaurant){ + return Mission.builder() + .name(request.getName()) + .content(request.getContent()) + .point(request.getPoint()) + .deadline(request.getDeadline()) + .restaurant(restaurant) + .build(); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/converter/RestaurantConverter.java b/src/main/java/javalab/umc7th_mission/study/converter/RestaurantConverter.java new file mode 100644 index 0000000..e8e8a08 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/converter/RestaurantConverter.java @@ -0,0 +1,25 @@ +package javalab.umc7th_mission.study.converter; + +import javalab.umc7th_mission.study.domain.Region; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.web.dto.restaurant.RestaurantRequestDTO; +import javalab.umc7th_mission.study.web.dto.restaurant.RestaurantResponseDTO; + +import java.time.LocalDate; + +public class RestaurantConverter { + public static RestaurantResponseDTO.AddRestaurantResultDTO toAddRestaurantResultDTO(Restaurant restaurant) { + return RestaurantResponseDTO.AddRestaurantResultDTO.builder() + .restaurantId(restaurant.getId()) + .createdAt(LocalDate.now()) + .build(); + } + public static Restaurant toRestaurant(RestaurantRequestDTO.AddRestaurantDto request, Region region){ + return Restaurant.builder() + .name(request.getName()) + .address(request.getAddress()) + .type(request.getType()) + .region(region) + .build(); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/converter/ReviewConverter.java b/src/main/java/javalab/umc7th_mission/study/converter/ReviewConverter.java new file mode 100644 index 0000000..8ca32c6 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/converter/ReviewConverter.java @@ -0,0 +1,27 @@ +package javalab.umc7th_mission.study.converter; + +import javalab.umc7th_mission.study.domain.Member; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.domain.Review; +import javalab.umc7th_mission.study.web.dto.review.ReviewRequestDTO; +import javalab.umc7th_mission.study.web.dto.review.ReviewResponseDTO; + +import java.time.LocalDateTime; + +public class ReviewConverter { + public static ReviewResponseDTO.AddReviewResultDTO toAddReviewResultDTO(Review review) { + return ReviewResponseDTO.AddReviewResultDTO.builder() + .reviewId(review.getId()) + .createdAt(LocalDateTime.now()) + .build(); + } + + public static Review toReview(ReviewRequestDTO.AddReviewDto request, Member member, Restaurant restaurant) { + return Review.builder() + .score(request.getScore()) + .content(request.getContent()) + .member(member) + .restaurant(restaurant) + .build(); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/converter/TempConverter.java b/src/main/java/javalab/umc7th_mission/study/converter/TempConverter.java index 8a0932c..0f66336 100644 --- a/src/main/java/javalab/umc7th_mission/study/converter/TempConverter.java +++ b/src/main/java/javalab/umc7th_mission/study/converter/TempConverter.java @@ -1,6 +1,6 @@ package javalab.umc7th_mission.study.converter; -import javalab.umc7th_mission.study.dto.TempResponse; +import javalab.umc7th_mission.study.web.dto.TempResponse; public class TempConverter { public static TempResponse.TempTestDTO toTempDTO(){ diff --git a/src/main/java/javalab/umc7th_mission/study/domain/Member.java b/src/main/java/javalab/umc7th_mission/study/domain/Member.java index 12030b6..dd6a3d5 100644 --- a/src/main/java/javalab/umc7th_mission/study/domain/Member.java +++ b/src/main/java/javalab/umc7th_mission/study/domain/Member.java @@ -10,6 +10,9 @@ import javalab.umc7th_mission.study.domain.mapping.MemberMission; import javalab.umc7th_mission.study.domain.mapping.MemberQuestion; import javalab.umc7th_mission.study.domain.mapping.MemberTerm; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; import java.time.LocalDate; import java.util.ArrayList; @@ -18,6 +21,8 @@ @Entity @Getter +@DynamicUpdate +@DynamicInsert @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @@ -42,7 +47,7 @@ public class Member extends BaseEntity { @Column(nullable = true, length = 15) private String phoneNumber; - @Column(nullable = false) + @ColumnDefault("0") private Integer point; @Enumerated(EnumType.STRING) @@ -50,7 +55,7 @@ public class Member extends BaseEntity { private Role role; @Enumerated(EnumType.STRING) - @Column(columnDefinition = "VARCHAR(10)") + @Column(columnDefinition = "VARCHAR(10) DEFAULT 'ACTIVE'") private MemberStatus status; @Column(nullable = true) diff --git a/src/main/java/javalab/umc7th_mission/study/domain/Restaurant.java b/src/main/java/javalab/umc7th_mission/study/domain/Restaurant.java index 7d2169e..8f2e729 100644 --- a/src/main/java/javalab/umc7th_mission/study/domain/Restaurant.java +++ b/src/main/java/javalab/umc7th_mission/study/domain/Restaurant.java @@ -6,6 +6,8 @@ import javalab.umc7th_mission.study.domain.Review; import javalab.umc7th_mission.study.domain.enums.RestaurantStatus; import javalab.umc7th_mission.study.domain.common.BaseEntity; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; import java.time.LocalDate; import java.util.ArrayList; @@ -13,6 +15,8 @@ @Entity @Getter +@DynamicUpdate +@DynamicInsert @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @@ -31,7 +35,7 @@ public class Restaurant extends BaseEntity { private String address; @Enumerated(EnumType.STRING) - @Column(nullable = false, length = 10) + @Column(columnDefinition = "VARCHAR(10) DEFAULT 'ACTIVE'") private RestaurantStatus status; private LocalDate inactiveDate; diff --git a/src/main/java/javalab/umc7th_mission/study/domain/Review.java b/src/main/java/javalab/umc7th_mission/study/domain/Review.java index 2496792..c4651cf 100644 --- a/src/main/java/javalab/umc7th_mission/study/domain/Review.java +++ b/src/main/java/javalab/umc7th_mission/study/domain/Review.java @@ -20,7 +20,7 @@ public class Review extends BaseEntity { @Column(nullable = false) private Integer score; - @Column(columnDefinition = "TEXT") + @Column(nullable =false, columnDefinition = "TEXT") private String content; @ManyToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/javalab/umc7th_mission/study/domain/mapping/MemberFood.java b/src/main/java/javalab/umc7th_mission/study/domain/mapping/MemberFood.java index e34eb73..7c59f9f 100644 --- a/src/main/java/javalab/umc7th_mission/study/domain/mapping/MemberFood.java +++ b/src/main/java/javalab/umc7th_mission/study/domain/mapping/MemberFood.java @@ -23,4 +23,15 @@ public class MemberFood extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "food_id") private Food food; + + public void setMember(Member member){ + if(this.member != null) + member.getMemberFoodList().remove(this); + this.member = member; + member.getMemberFoodList().add(this); + } + + public void setFood(Food food){ + this.food = food; + } } diff --git a/src/main/java/javalab/umc7th_mission/study/domain/mapping/MemberMission.java b/src/main/java/javalab/umc7th_mission/study/domain/mapping/MemberMission.java index 294a047..424570c 100644 --- a/src/main/java/javalab/umc7th_mission/study/domain/mapping/MemberMission.java +++ b/src/main/java/javalab/umc7th_mission/study/domain/mapping/MemberMission.java @@ -6,9 +6,15 @@ import javalab.umc7th_mission.study.domain.Mission; import javalab.umc7th_mission.study.domain.common.BaseEntity; import javalab.umc7th_mission.study.domain.enums.MissionStatus; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import java.time.LocalDate; @Entity @Getter +@DynamicUpdate +@DynamicInsert @Builder @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @@ -18,11 +24,14 @@ public class MemberMission extends BaseEntity { private Long id; @Enumerated(EnumType.STRING) - @Column(nullable = false, length = 20) + @Column(columnDefinition = "VARCHAR(20) DEFAULT 'CHALLENGING'") private MissionStatus status; @Column(nullable = false) - private Integer bossNumber; + private LocalDate startDate; + + @Column(nullable = true) + private LocalDate endDate; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") diff --git a/src/main/java/javalab/umc7th_mission/study/dto/TempRequest.java b/src/main/java/javalab/umc7th_mission/study/dto/TempRequest.java deleted file mode 100644 index 44002e9..0000000 --- a/src/main/java/javalab/umc7th_mission/study/dto/TempRequest.java +++ /dev/null @@ -1,4 +0,0 @@ -package javalab.umc7th_mission.study.dto; - -public class TempRequest { -} diff --git a/src/main/java/javalab/umc7th_mission/study/repository/MemberMissionRepository/MemberMissionRepository.java b/src/main/java/javalab/umc7th_mission/study/repository/MemberMissionRepository/MemberMissionRepository.java index 2b383c9..9f54797 100644 --- a/src/main/java/javalab/umc7th_mission/study/repository/MemberMissionRepository/MemberMissionRepository.java +++ b/src/main/java/javalab/umc7th_mission/study/repository/MemberMissionRepository/MemberMissionRepository.java @@ -3,6 +3,6 @@ import javalab.umc7th_mission.study.domain.mapping.MemberMission; import org.springframework.data.jpa.repository.JpaRepository; -public interface MemberMissionRepository extends JpaRepository, MemberMissionRepositoryCustom{ - +public interface MemberMissionRepository extends JpaRepository, MemberMissionRepositoryCustom{ + MemberMission findMemberMissionByMemberIdAndMissionId(Long memberId, Long missionId); } diff --git a/src/main/java/javalab/umc7th_mission/study/repository/MemberMissionRepository/MemberMissionRepositoryImpl.java b/src/main/java/javalab/umc7th_mission/study/repository/MemberMissionRepository/MemberMissionRepositoryImpl.java index 9471ae2..ae0e331 100644 --- a/src/main/java/javalab/umc7th_mission/study/repository/MemberMissionRepository/MemberMissionRepositoryImpl.java +++ b/src/main/java/javalab/umc7th_mission/study/repository/MemberMissionRepository/MemberMissionRepositoryImpl.java @@ -1,5 +1,6 @@ package javalab.umc7th_mission.study.repository.MemberMissionRepository; +import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import ext.javalab.umc7th_mission.study.domain.QMission; import ext.javalab.umc7th_mission.study.domain.QRegion; @@ -53,4 +54,5 @@ public Long countCompletedMemberMissionsByMemberIdAndRegion(Long memberId, Strin ) .fetchOne(); } + } diff --git a/src/main/java/javalab/umc7th_mission/study/repository/MemberRepository/MemberRepository.java b/src/main/java/javalab/umc7th_mission/study/repository/MemberRepository/MemberRepository.java index 1166be6..3e5c7ed 100644 --- a/src/main/java/javalab/umc7th_mission/study/repository/MemberRepository/MemberRepository.java +++ b/src/main/java/javalab/umc7th_mission/study/repository/MemberRepository/MemberRepository.java @@ -3,6 +3,6 @@ import javalab.umc7th_mission.study.domain.Member; import org.springframework.data.jpa.repository.JpaRepository; -public interface MemberRepository extends JpaRepository, MemberRepositoryCustom { +public interface MemberRepository extends JpaRepository, MemberRepositoryCustom { } diff --git a/src/main/java/javalab/umc7th_mission/study/repository/MissionRepository/MissionRepositoryCustom.java b/src/main/java/javalab/umc7th_mission/study/repository/MissionRepository/MissionRepositoryCustom.java index f0091b5..35e801c 100644 --- a/src/main/java/javalab/umc7th_mission/study/repository/MissionRepository/MissionRepositoryCustom.java +++ b/src/main/java/javalab/umc7th_mission/study/repository/MissionRepository/MissionRepositoryCustom.java @@ -1,7 +1,6 @@ package javalab.umc7th_mission.study.repository.MissionRepository; -import javalab.umc7th_mission.study.domain.Mission; -import javalab.umc7th_mission.study.dto.AvailableMissionDTO; +import javalab.umc7th_mission.study.web.dto.AvailableMissionDTO; import org.springframework.data.domain.Pageable; import java.util.List; diff --git a/src/main/java/javalab/umc7th_mission/study/repository/MissionRepository/MissionRepositoryImpl.java b/src/main/java/javalab/umc7th_mission/study/repository/MissionRepository/MissionRepositoryImpl.java index 760898e..0ccb0bb 100644 --- a/src/main/java/javalab/umc7th_mission/study/repository/MissionRepository/MissionRepositoryImpl.java +++ b/src/main/java/javalab/umc7th_mission/study/repository/MissionRepository/MissionRepositoryImpl.java @@ -3,13 +3,10 @@ import com.querydsl.core.types.Projections; import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; -import ext.javalab.umc7th_mission.study.domain.QMember; import ext.javalab.umc7th_mission.study.domain.QMission; -import ext.javalab.umc7th_mission.study.domain.QRegion; import ext.javalab.umc7th_mission.study.domain.QRestaurant; import ext.javalab.umc7th_mission.study.domain.mapping.QMemberMission; -import javalab.umc7th_mission.study.domain.Mission; -import javalab.umc7th_mission.study.dto.AvailableMissionDTO; +import javalab.umc7th_mission.study.web.dto.AvailableMissionDTO; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; diff --git a/src/main/java/javalab/umc7th_mission/study/repository/RegionRepository/RegionRepository.java b/src/main/java/javalab/umc7th_mission/study/repository/RegionRepository/RegionRepository.java new file mode 100644 index 0000000..5d4a5ee --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/repository/RegionRepository/RegionRepository.java @@ -0,0 +1,7 @@ +package javalab.umc7th_mission.study.repository.RegionRepository; + +import javalab.umc7th_mission.study.domain.Region; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RegionRepository extends JpaRepository { +} diff --git a/src/main/java/javalab/umc7th_mission/study/repository/RestaurantRepository/FoodRepository.java b/src/main/java/javalab/umc7th_mission/study/repository/RestaurantRepository/FoodRepository.java new file mode 100644 index 0000000..2538674 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/repository/RestaurantRepository/FoodRepository.java @@ -0,0 +1,7 @@ +package javalab.umc7th_mission.study.repository.RestaurantRepository; + +import javalab.umc7th_mission.study.domain.Food; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FoodRepository extends JpaRepository { +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/FoodService/FoodValidationService.java b/src/main/java/javalab/umc7th_mission/study/service/FoodService/FoodValidationService.java new file mode 100644 index 0000000..5dcc426 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/FoodService/FoodValidationService.java @@ -0,0 +1,7 @@ +package javalab.umc7th_mission.study.service.FoodService; + +import java.util.List; + +public interface FoodValidationService { + boolean allCategoriesExist(List values); +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/FoodService/FoodValidationServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/FoodService/FoodValidationServiceImpl.java new file mode 100644 index 0000000..137290f --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/FoodService/FoodValidationServiceImpl.java @@ -0,0 +1,20 @@ +package javalab.umc7th_mission.study.service.FoodService; + +import javalab.umc7th_mission.study.domain.Food; +import javalab.umc7th_mission.study.repository.RestaurantRepository.FoodRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class FoodValidationServiceImpl implements FoodValidationService{ + FoodRepository foodRepository; + + @Override + public boolean allCategoriesExist(List values){ + return values.stream() + .allMatch(id -> foodRepository.existsById(id)); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandService.java b/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandService.java new file mode 100644 index 0000000..c679f9a --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandService.java @@ -0,0 +1,10 @@ +package javalab.umc7th_mission.study.service.MemberMissionService; + +import javalab.umc7th_mission.study.domain.mapping.MemberMission; +import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionRequestDTO; + +public interface MemberMissionCommandService { + MemberMission AddMemberMission(MemberMissionRequestDTO.AddMemberMissionDto request); + boolean isChallenging(Long memberId, Long missionId); +} + diff --git a/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandServiceImpl.java new file mode 100644 index 0000000..9103ab4 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandServiceImpl.java @@ -0,0 +1,51 @@ +package javalab.umc7th_mission.study.service.MemberMissionService; + +import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; +import javalab.umc7th_mission.study.apiPayload.exception.GeneralException; +import javalab.umc7th_mission.study.converter.MemberMissionConverter; +import javalab.umc7th_mission.study.domain.Member; +import javalab.umc7th_mission.study.domain.Mission; +import javalab.umc7th_mission.study.domain.enums.MissionStatus; +import javalab.umc7th_mission.study.domain.mapping.MemberMission; +import javalab.umc7th_mission.study.repository.MemberMissionRepository.MemberMissionRepository; +import javalab.umc7th_mission.study.repository.MemberRepository.MemberRepository; +import javalab.umc7th_mission.study.repository.MissionRepository.MissionRepository; +import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionRequestDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class MemberMissionCommandServiceImpl implements MemberMissionCommandService { + private final MemberMissionRepository memberMissionRepository; + private final MemberRepository memberRepository; + private final MissionRepository missionRepository; + + @Override + public MemberMission AddMemberMission(MemberMissionRequestDTO.AddMemberMissionDto request){ + Member member = memberRepository.findById(request.getMemberId()) + .orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); + + Mission mission = missionRepository.findById(Math.toIntExact(request.getMissionId())) + .orElseThrow(() -> new GeneralException(ErrorStatus.MISSION_NOT_FOUND)); + + + if(isChallenging(request.getMemberId(), request.getMissionId())){ + throw new GeneralException(ErrorStatus.MEMBER_MISSION_ALREADY_IN_CHALLENGING); + } + MemberMission membermission = MemberMissionConverter.toMemberMission(member, mission); + + return memberMissionRepository.save(membermission); + } + + @Override + public boolean isChallenging(Long memberId, Long missionId){ + MemberMission memberMission = memberMissionRepository.findMemberMissionByMemberIdAndMissionId(memberId, missionId); + + if(memberMission != null && memberMission.getStatus().equals(MissionStatus.CHALLENGING)){ + return true; + } + + return false; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/MemberService/MemberCommandService.java b/src/main/java/javalab/umc7th_mission/study/service/MemberService/MemberCommandService.java new file mode 100644 index 0000000..c91a132 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/MemberService/MemberCommandService.java @@ -0,0 +1,8 @@ +package javalab.umc7th_mission.study.service.MemberService; + +import javalab.umc7th_mission.study.domain.Member; +import javalab.umc7th_mission.study.web.dto.member.MemberRequestDTO; + +public interface MemberCommandService { + Member joinMember(MemberRequestDTO.JoinDto request); +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/MemberService/MemberCommandServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/MemberService/MemberCommandServiceImpl.java new file mode 100644 index 0000000..15e2723 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/MemberService/MemberCommandServiceImpl.java @@ -0,0 +1,42 @@ +package javalab.umc7th_mission.study.service.MemberService; + +import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; +import javalab.umc7th_mission.study.apiPayload.exception.GeneralException; +import javalab.umc7th_mission.study.converter.MemberConverter; +import javalab.umc7th_mission.study.converter.MemberFoodConverter; +import javalab.umc7th_mission.study.domain.Food; +import javalab.umc7th_mission.study.domain.mapping.MemberFood; +import javalab.umc7th_mission.study.repository.MemberRepository.MemberRepository; +import javalab.umc7th_mission.study.domain.Member; +import javalab.umc7th_mission.study.repository.RestaurantRepository.FoodRepository; +import javalab.umc7th_mission.study.web.dto.member.MemberRequestDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class MemberCommandServiceImpl implements MemberCommandService{ + private final MemberRepository memberRepository; + private final FoodRepository foodRepository; + + @Override + @Transactional + public Member joinMember(MemberRequestDTO.JoinDto request){ + Member newMember = MemberConverter.toMember(request); + + List foodList = request.getMemberFoodList().stream() + .map(category -> { + return foodRepository.findById(category).orElseThrow(() -> new GeneralException(ErrorStatus.FOOD_CATEGORY_NOT_FOUND)); + }).collect(Collectors.toList()); + List memberFoodList = MemberFoodConverter.toMemberFoodList(foodList); + + memberFoodList.forEach(memberFood -> {memberFood.setMember(newMember);}); + + return memberRepository.save(newMember); + } + +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/MissionService/MissionCommandService.java b/src/main/java/javalab/umc7th_mission/study/service/MissionService/MissionCommandService.java new file mode 100644 index 0000000..040bbc4 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/MissionService/MissionCommandService.java @@ -0,0 +1,8 @@ +package javalab.umc7th_mission.study.service.MissionService; + +import javalab.umc7th_mission.study.domain.Mission; +import javalab.umc7th_mission.study.web.dto.mission.MissionRequestDTO; + +public interface MissionCommandService { + Mission AddMission(MissionRequestDTO.AddMissionDto request); +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/MissionService/MissionCommandServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/MissionService/MissionCommandServiceImpl.java new file mode 100644 index 0000000..74aab7d --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/MissionService/MissionCommandServiceImpl.java @@ -0,0 +1,29 @@ +package javalab.umc7th_mission.study.service.MissionService; + +import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; +import javalab.umc7th_mission.study.apiPayload.exception.GeneralException; +import javalab.umc7th_mission.study.converter.MissionConverter; +import javalab.umc7th_mission.study.domain.Mission; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.repository.MissionRepository.MissionRepository; +import javalab.umc7th_mission.study.repository.RestaurantRepository.RestaurantRepository; +import javalab.umc7th_mission.study.web.dto.mission.MissionRequestDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class MissionCommandServiceImpl implements MissionCommandService { + private final RestaurantRepository restaurantRepository; + private final MissionRepository missionRepository; + + @Override + public Mission AddMission(MissionRequestDTO.AddMissionDto request){ + Restaurant restaurant = restaurantRepository.findById(request.getRestaurantId()) + .orElseThrow(() -> new GeneralException(ErrorStatus.RESTAURANT_NOT_FOUND)); + + Mission newMission = MissionConverter.toMission(request, restaurant); + + return missionRepository.save(newMission); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/RegionService/RegionValidationService.java b/src/main/java/javalab/umc7th_mission/study/service/RegionService/RegionValidationService.java new file mode 100644 index 0000000..398ca20 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/RegionService/RegionValidationService.java @@ -0,0 +1,7 @@ +package javalab.umc7th_mission.study.service.RegionService; + +import javalab.umc7th_mission.study.domain.Region; + +public interface RegionValidationService { + Region findById(Long regionId); +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/RegionService/RegionValidationServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/RegionService/RegionValidationServiceImpl.java new file mode 100644 index 0000000..bb8f922 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/RegionService/RegionValidationServiceImpl.java @@ -0,0 +1,21 @@ +package javalab.umc7th_mission.study.service.RegionService; + +import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; +import javalab.umc7th_mission.study.apiPayload.exception.GeneralException; +import javalab.umc7th_mission.study.domain.Region; +import javalab.umc7th_mission.study.repository.RegionRepository.RegionRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class RegionValidationServiceImpl implements RegionValidationService { + private final RegionRepository regionRepository; + + @Override + public Region findById(Long regionId){ + return regionRepository.findById(regionId). + orElseThrow(() -> new GeneralException(ErrorStatus.REGION_NOT_FOUND)); + } + +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantCommandService.java b/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantCommandService.java new file mode 100644 index 0000000..e968160 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantCommandService.java @@ -0,0 +1,8 @@ +package javalab.umc7th_mission.study.service.RestaurantService; + +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.web.dto.restaurant.RestaurantRequestDTO; + +public interface RestaurantCommandService { + Restaurant AddRestaurant(RestaurantRequestDTO.AddRestaurantDto request); +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantCommandServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantCommandServiceImpl.java new file mode 100644 index 0000000..add9585 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantCommandServiceImpl.java @@ -0,0 +1,26 @@ +package javalab.umc7th_mission.study.service.RestaurantService; + +import javalab.umc7th_mission.study.converter.RestaurantConverter; +import javalab.umc7th_mission.study.domain.Region; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.repository.RegionRepository.RegionRepository; +import javalab.umc7th_mission.study.repository.RestaurantRepository.RestaurantRepository; +import javalab.umc7th_mission.study.service.RegionService.RegionValidationService; +import javalab.umc7th_mission.study.web.dto.restaurant.RestaurantRequestDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class RestaurantCommandServiceImpl implements RestaurantCommandService{ + private final RestaurantRepository restaurantRepository; + private final RegionValidationService regionValidationService; + + @Override + public Restaurant AddRestaurant(RestaurantRequestDTO.AddRestaurantDto request){ + Region region = regionValidationService.findById(request.getRegionId()); + Restaurant newRestaurant = RestaurantConverter.toRestaurant(request, region); + return restaurantRepository.save(newRestaurant); + + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantQueryService.java b/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantValidationService.java similarity index 85% rename from src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantQueryService.java rename to src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantValidationService.java index cf0327b..73dd53b 100644 --- a/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantQueryService.java +++ b/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantValidationService.java @@ -5,7 +5,7 @@ import java.util.List; import java.util.Optional; -public interface RestaurantQueryService { +public interface RestaurantValidationService { Optional findRestaurant(Long id); List findRestaurantsByName(String name); diff --git a/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantQueryServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantValidationServiceImpl.java similarity index 92% rename from src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantQueryServiceImpl.java rename to src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantValidationServiceImpl.java index 4f67012..efbdc28 100644 --- a/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantQueryServiceImpl.java +++ b/src/main/java/javalab/umc7th_mission/study/service/RestaurantService/RestaurantValidationServiceImpl.java @@ -12,7 +12,7 @@ @Service @RequiredArgsConstructor @Transactional(readOnly = true) -public class RestaurantQueryServiceImpl implements RestaurantQueryService{ +public class RestaurantValidationServiceImpl implements RestaurantValidationService { private final RestaurantRepository restaurantRepository; @Override diff --git a/src/main/java/javalab/umc7th_mission/study/service/ReviewService/ReviewCommandService.java b/src/main/java/javalab/umc7th_mission/study/service/ReviewService/ReviewCommandService.java new file mode 100644 index 0000000..804af87 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/ReviewService/ReviewCommandService.java @@ -0,0 +1,8 @@ +package javalab.umc7th_mission.study.service.ReviewService; + +import javalab.umc7th_mission.study.domain.Review; +import javalab.umc7th_mission.study.web.dto.review.ReviewRequestDTO; + +public interface ReviewCommandService { + Review addReview(ReviewRequestDTO.AddReviewDto request); +} diff --git a/src/main/java/javalab/umc7th_mission/study/service/ReviewService/ReviewCommandServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/ReviewService/ReviewCommandServiceImpl.java new file mode 100644 index 0000000..fcaa46a --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/service/ReviewService/ReviewCommandServiceImpl.java @@ -0,0 +1,35 @@ +package javalab.umc7th_mission.study.service.ReviewService; + +import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; +import javalab.umc7th_mission.study.apiPayload.exception.GeneralException; +import javalab.umc7th_mission.study.converter.ReviewConverter; +import javalab.umc7th_mission.study.domain.Member; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.domain.Review; +import javalab.umc7th_mission.study.repository.MemberRepository.MemberRepository; +import javalab.umc7th_mission.study.repository.RestaurantRepository.RestaurantRepository; +import javalab.umc7th_mission.study.repository.ReviewRepository.ReviewRepository; +import javalab.umc7th_mission.study.web.dto.review.ReviewRequestDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ReviewCommandServiceImpl implements ReviewCommandService { + private final ReviewRepository reviewRepository; + private final MemberRepository memberRepository; + private final RestaurantRepository restaurantRepository; + + @Override + public Review addReview(ReviewRequestDTO .AddReviewDto request){ + Member member = memberRepository.findById(request.getMemberId()) + .orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND)); + + Restaurant restaurant = restaurantRepository.findById(request.getRestaurantId()) + .orElseThrow(() -> new GeneralException(ErrorStatus.RESTAURANT_NOT_FOUND)); + + Review newReview = ReviewConverter.toReview(request, member, restaurant); + + return reviewRepository.save(newReview); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/validation/annotation/ExistCategories.java b/src/main/java/javalab/umc7th_mission/study/validation/annotation/ExistCategories.java new file mode 100644 index 0000000..c064fc9 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/validation/annotation/ExistCategories.java @@ -0,0 +1,16 @@ +package javalab.umc7th_mission.study.validation.annotation; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import javalab.umc7th_mission.study.validation.validatior.CategoriesExistValidator; +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = CategoriesExistValidator.class) +@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExistCategories { + String message() default "해당하는 카테고리가 존재하지 않습니다."; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/src/main/java/javalab/umc7th_mission/study/validation/annotation/ExistRestaurant.java b/src/main/java/javalab/umc7th_mission/study/validation/annotation/ExistRestaurant.java new file mode 100644 index 0000000..a42f954 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/validation/annotation/ExistRestaurant.java @@ -0,0 +1,17 @@ +package javalab.umc7th_mission.study.validation.annotation; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import javalab.umc7th_mission.study.validation.validatior.RestaurantExistValidator; + +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = RestaurantExistValidator.class) +@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExistRestaurant { + String message() default "해당하는 식당이 존재하지 않습니다."; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/src/main/java/javalab/umc7th_mission/study/validation/validatior/CategoriesExistValidator.java b/src/main/java/javalab/umc7th_mission/study/validation/validatior/CategoriesExistValidator.java new file mode 100644 index 0000000..5443b83 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/validation/validatior/CategoriesExistValidator.java @@ -0,0 +1,36 @@ +package javalab.umc7th_mission.study.validation.validatior; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import javalab.umc7th_mission.study.service.FoodService.FoodValidationService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; +import javalab.umc7th_mission.study.repository.RestaurantRepository.FoodRepository; +import javalab.umc7th_mission.study.validation.annotation.ExistCategories; + + +import java.util.List; + +@Component +@RequiredArgsConstructor +public class CategoriesExistValidator implements ConstraintValidator> { + private final FoodValidationService foodValidationService; + + @Override + public void initialize(ExistCategories constraintAnnotation){ + ConstraintValidator.super.initialize(constraintAnnotation); + } + + @Override + public boolean isValid(List values, ConstraintValidatorContext context) { + boolean isValid = foodValidationService.allCategoriesExist(values); + + if(!isValid){ + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(ErrorStatus.FOOD_CATEGORY_NOT_FOUND.toString()).addConstraintViolation(); + } + + return isValid; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/validation/validatior/RestaurantExistValidator.java b/src/main/java/javalab/umc7th_mission/study/validation/validatior/RestaurantExistValidator.java new file mode 100644 index 0000000..2b19aea --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/validation/validatior/RestaurantExistValidator.java @@ -0,0 +1,37 @@ +package javalab.umc7th_mission.study.validation.validatior; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.repository.RestaurantRepository.RestaurantRepository; +import javalab.umc7th_mission.study.service.RestaurantService.RestaurantValidationService; +import javalab.umc7th_mission.study.validation.annotation.ExistCategories; +import javalab.umc7th_mission.study.validation.annotation.ExistRestaurant; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class RestaurantExistValidator implements ConstraintValidator { + private final RestaurantValidationService restaurantValidationService; + + @Override + public void initialize(ExistRestaurant constraintAnnotation){ + ConstraintValidator.super.initialize(constraintAnnotation); + } + + @Override + public boolean isValid(Long id, ConstraintValidatorContext context) { + boolean isValid = restaurantValidationService.findRestaurant(id).isPresent(); + + if(!isValid){ + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(ErrorStatus.RESTAURANT_NOT_FOUND.toString()).addConstraintViolation(); + } + + return isValid; + } + + +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/controller/MemberMissionRestController.java b/src/main/java/javalab/umc7th_mission/study/web/controller/MemberMissionRestController.java new file mode 100644 index 0000000..bdfab18 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/controller/MemberMissionRestController.java @@ -0,0 +1,28 @@ +package javalab.umc7th_mission.study.web.controller; + +import jakarta.validation.Valid; +import javalab.umc7th_mission.study.apiPayload.ApiResponse; +import javalab.umc7th_mission.study.converter.MemberMissionConverter; +import javalab.umc7th_mission.study.domain.mapping.MemberMission; +import javalab.umc7th_mission.study.service.MemberMissionService.MemberMissionCommandService; +import javalab.umc7th_mission.study.service.MemberMissionService.MemberMissionCommandServiceImpl; +import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionRequestDTO; +import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionResponseDTO; +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; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/member/missions") +public class MemberMissionRestController { + private final MemberMissionCommandService memberMissionCommandService; + + @PostMapping("/") + public ApiResponse add(@RequestBody @Valid MemberMissionRequestDTO.AddMemberMissionDto request){ + MemberMission memberMission = memberMissionCommandService.AddMemberMission(request); + return ApiResponse.onSuccess(MemberMissionConverter.toAddMemberMissionResultDTO(memberMission)); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/controller/MemberRestController.java b/src/main/java/javalab/umc7th_mission/study/web/controller/MemberRestController.java new file mode 100644 index 0000000..14807d6 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/controller/MemberRestController.java @@ -0,0 +1,27 @@ +package javalab.umc7th_mission.study.web.controller; + +import jakarta.validation.Valid; +import javalab.umc7th_mission.study.apiPayload.ApiResponse; +import javalab.umc7th_mission.study.converter.MemberConverter; +import javalab.umc7th_mission.study.domain.Member; +import javalab.umc7th_mission.study.service.MemberService.MemberCommandService; +import javalab.umc7th_mission.study.web.dto.member.MemberRequestDTO; +import javalab.umc7th_mission.study.web.dto.member.MemberResponseDTO; +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; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/members") +public class MemberRestController { + private final MemberCommandService memberCommandService; + + @PostMapping("/") + public ApiResponse join(@RequestBody @Valid MemberRequestDTO.JoinDto request){ + Member member = memberCommandService.joinMember(request); + return ApiResponse.onSuccess(MemberConverter.toJoinResultDTO(member)); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/controller/MissionRestController.java b/src/main/java/javalab/umc7th_mission/study/web/controller/MissionRestController.java new file mode 100644 index 0000000..a611d3b --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/controller/MissionRestController.java @@ -0,0 +1,27 @@ +package javalab.umc7th_mission.study.web.controller; + +import jakarta.validation.Valid; +import javalab.umc7th_mission.study.apiPayload.ApiResponse; +import javalab.umc7th_mission.study.converter.MissionConverter; +import javalab.umc7th_mission.study.domain.Mission; +import javalab.umc7th_mission.study.service.MissionService.MissionCommandService; +import javalab.umc7th_mission.study.web.dto.mission.MissionRequestDTO; +import javalab.umc7th_mission.study.web.dto.mission.MissionResponseDTO; +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; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/missions") +public class MissionRestController { + private final MissionCommandService missionCommandService; + + @PostMapping("/") + public ApiResponse add(@RequestBody @Valid MissionRequestDTO .AddMissionDto request){ + Mission mission = missionCommandService.AddMission(request); + return ApiResponse.onSuccess(MissionConverter.toAddMissionResultDTO(mission)); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/controller/RestaurantRestController.java b/src/main/java/javalab/umc7th_mission/study/web/controller/RestaurantRestController.java new file mode 100644 index 0000000..d7d6fad --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/controller/RestaurantRestController.java @@ -0,0 +1,27 @@ +package javalab.umc7th_mission.study.web.controller; + +import jakarta.validation.Valid; +import javalab.umc7th_mission.study.apiPayload.ApiResponse; +import javalab.umc7th_mission.study.converter.RestaurantConverter; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.service.RestaurantService.RestaurantCommandService; +import javalab.umc7th_mission.study.web.dto.restaurant.RestaurantRequestDTO; +import javalab.umc7th_mission.study.web.dto.restaurant.RestaurantResponseDTO; +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; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/region/restaurants") +public class RestaurantRestController { + private final RestaurantCommandService restaurantCommandService; + + @PostMapping("/") + public ApiResponse add(@RequestBody @Valid RestaurantRequestDTO.AddRestaurantDto request) { + Restaurant restaurant = restaurantCommandService.AddRestaurant(request); + return ApiResponse.onSuccess(RestaurantConverter.toAddRestaurantResultDTO(restaurant)); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/controller/ReviewRestController.java b/src/main/java/javalab/umc7th_mission/study/web/controller/ReviewRestController.java new file mode 100644 index 0000000..d1f5cff --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/controller/ReviewRestController.java @@ -0,0 +1,24 @@ +package javalab.umc7th_mission.study.web.controller; + +import jakarta.validation.Valid; +import javalab.umc7th_mission.study.apiPayload.ApiResponse; +import javalab.umc7th_mission.study.converter.ReviewConverter; +import javalab.umc7th_mission.study.domain.Review; +import javalab.umc7th_mission.study.service.ReviewService.ReviewCommandService; +import javalab.umc7th_mission.study.web.dto.review.ReviewRequestDTO; +import javalab.umc7th_mission.study.web.dto.review.ReviewResponseDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/reviews") +public class ReviewRestController { + private final ReviewCommandService reviewCommandService; + + @PostMapping("/") + public ApiResponse add(@RequestBody @Valid ReviewRequestDTO.AddReviewDto request){ + Review review = reviewCommandService.addReview(request); + return ApiResponse.onSuccess(ReviewConverter.toAddReviewResultDTO(review)); + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/dto/AvailableMissionDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/AvailableMissionDTO.java similarity index 86% rename from src/main/java/javalab/umc7th_mission/study/dto/AvailableMissionDTO.java rename to src/main/java/javalab/umc7th_mission/study/web/dto/AvailableMissionDTO.java index a787699..2b83c6f 100644 --- a/src/main/java/javalab/umc7th_mission/study/dto/AvailableMissionDTO.java +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/AvailableMissionDTO.java @@ -1,4 +1,4 @@ -package javalab.umc7th_mission.study.dto; +package javalab.umc7th_mission.study.web.dto; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/TempRequest.java b/src/main/java/javalab/umc7th_mission/study/web/dto/TempRequest.java new file mode 100644 index 0000000..72ac6bc --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/TempRequest.java @@ -0,0 +1,4 @@ +package javalab.umc7th_mission.study.web.dto; + +public class TempRequest { +} diff --git a/src/main/java/javalab/umc7th_mission/study/dto/TempResponse.java b/src/main/java/javalab/umc7th_mission/study/web/dto/TempResponse.java similarity index 90% rename from src/main/java/javalab/umc7th_mission/study/dto/TempResponse.java rename to src/main/java/javalab/umc7th_mission/study/web/dto/TempResponse.java index 4646d3a..c46a577 100644 --- a/src/main/java/javalab/umc7th_mission/study/dto/TempResponse.java +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/TempResponse.java @@ -1,4 +1,4 @@ -package javalab.umc7th_mission.study.dto; +package javalab.umc7th_mission.study.web.dto; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/member/MemberRequestDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/member/MemberRequestDTO.java new file mode 100644 index 0000000..a116b40 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/member/MemberRequestDTO.java @@ -0,0 +1,26 @@ +package javalab.umc7th_mission.study.web.dto.member; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import javalab.umc7th_mission.study.validation.annotation.ExistCategories; +import lombok.Getter; + +import java.util.Date; +import java.util.List; + +public class MemberRequestDTO { + + @Getter + public static class JoinDto{ + @NotBlank(message = "이름은 필수 항목입니다.") + String name; + @NotBlank(message = "주소는 필수 항목입니다.") + @Size(max = 100) + String address; + @NotNull(message = "생년월일은 필수 항목입니다.") + Date birth; + @ExistCategories + List memberFoodList; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/member/MemberResponseDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/member/MemberResponseDTO.java new file mode 100644 index 0000000..d0672ea --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/member/MemberResponseDTO.java @@ -0,0 +1,19 @@ +package javalab.umc7th_mission.study.web.dto.member; + +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; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.java new file mode 100644 index 0000000..f5a239a --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.java @@ -0,0 +1,20 @@ +package javalab.umc7th_mission.study.web.dto.member_mission; + +import jakarta.validation.constraints.NotNull; +import lombok.Getter; + +import java.time.LocalDate; + +public class MemberMissionRequestDTO { + @Getter + public static class AddMemberMissionDto{ + @NotNull(message = "회원 id는 필수 항목입니다.") + Long memberId; + + @NotNull(message = "미션 id는 필수 항목입니다.") + Long missionId; + + @NotNull(message = "회원 미션 시작 날짜는 필수 항목입니다.") + LocalDate startDate; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionResponseDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionResponseDTO.java new file mode 100644 index 0000000..03ac4ee --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionResponseDTO.java @@ -0,0 +1,19 @@ +package javalab.umc7th_mission.study.web.dto.member_mission; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +public class MemberMissionResponseDTO { + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class AddMemberMissionResultDTO{ + Long memberMissionId; + LocalDate createdAt; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/mission/MissionRequestDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/mission/MissionRequestDTO.java new file mode 100644 index 0000000..62b8506 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/mission/MissionRequestDTO.java @@ -0,0 +1,31 @@ +package javalab.umc7th_mission.study.web.dto.mission; + +import jakarta.validation.constraints.NotNull; +import javalab.umc7th_mission.study.domain.Restaurant; +import javalab.umc7th_mission.study.validation.annotation.ExistRestaurant; +import lombok.Getter; + +import java.time.LocalDate; + +public class MissionRequestDTO { + @Getter + public static class AddMissionDto{ + + @NotNull(message = "미션 이름은 필수 항목입니다.") + String name; + + @NotNull(message = "미션 내용은 필수 항목입니다.") + String content; + + @NotNull(message = "미션 포인트는 필수 항목입니다.") + Integer point; + + @NotNull(message = "미션 마감일은 필수 항목입니다.") + LocalDate deadline; + + @ExistRestaurant + Long restaurantId; + + + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/mission/MissionResponseDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/mission/MissionResponseDTO.java new file mode 100644 index 0000000..9356d18 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/mission/MissionResponseDTO.java @@ -0,0 +1,19 @@ +package javalab.umc7th_mission.study.web.dto.mission; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +public class MissionResponseDTO { + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class AddMissionResultDTO{ + Long missionId; + LocalDate createdAt; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/restaurant/RestaurantRequestDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/restaurant/RestaurantRequestDTO.java new file mode 100644 index 0000000..b108c63 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/restaurant/RestaurantRequestDTO.java @@ -0,0 +1,19 @@ +package javalab.umc7th_mission.study.web.dto.restaurant; + +import jakarta.validation.constraints.NotNull; +import javalab.umc7th_mission.study.domain.Restaurant; +import lombok.Getter; + +public class RestaurantRequestDTO { + @Getter + public static class AddRestaurantDto { + @NotNull(message = "식당 이름은 필수 항목입니다.") + String name; + @NotNull(message = "식당 유형은 필수 항목입니다.") + String type; + @NotNull(message = "식당 주소는 필수 항목입니다.") + String address; + @NotNull(message = "지역 id는 필수 항목입니다.") + Long regionId; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/restaurant/RestaurantResponseDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/restaurant/RestaurantResponseDTO.java new file mode 100644 index 0000000..e0c0827 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/restaurant/RestaurantResponseDTO.java @@ -0,0 +1,19 @@ +package javalab.umc7th_mission.study.web.dto.restaurant; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +public class RestaurantResponseDTO { + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class AddRestaurantResultDTO{ + Long restaurantId; + LocalDate createdAt; + } +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/review/ReviewRequestDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/review/ReviewRequestDTO.java new file mode 100644 index 0000000..c3ba9ab --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/review/ReviewRequestDTO.java @@ -0,0 +1,29 @@ +package javalab.umc7th_mission.study.web.dto.review; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import javalab.umc7th_mission.study.validation.annotation.ExistRestaurant; +import lombok.Getter; + + +public class ReviewRequestDTO { + @Getter + public static class AddReviewDto{ + + @NotNull(message = "별점은 필수 항목입니다.") + @Min(0) @Max(5) + Integer score; + + @Size(max=500, message="리뷰 내용은 500자 이내로 작성해야합니다.") + String content; + + @NotNull(message = "회원 id는 필수 항목입니다.") + Long memberId; + + @ExistRestaurant + Long restaurantId; + } + +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/review/ReviewResponseDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/review/ReviewResponseDTO.java new file mode 100644 index 0000000..1416872 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/review/ReviewResponseDTO.java @@ -0,0 +1,19 @@ +package javalab.umc7th_mission.study.web.dto.review; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +public class ReviewResponseDTO { + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class AddReviewResultDTO{ + Long reviewId; + LocalDateTime createdAt; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bb7de05..44ce406 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -16,5 +16,5 @@ spring: format_sql: true use_sql_comments: true hibernate: - ddl-auto: update + ddl-auto: create open-in-view: false \ No newline at end of file From 33db35e6db742cc6c5ffe74de48e4bdf19aef9fa Mon Sep 17 00:00:00 2001 From: InSooBeen Date: Sat, 23 Nov 2024 17:55:01 +0900 Subject: [PATCH 2/2] mission: add week8 mission Changes --- .../MemberMissionCommandService.java | 2 +- .../MemberMissionCommandServiceImpl.java | 14 +++----- .../annotation/IsMemberMissionNotStarted.java | 17 ++++++++++ .../IsMemberMissionNotStartedValidator.java | 33 +++++++++++++++++++ .../MemberMissionRequestDTO.java | 6 ++++ 5 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 src/main/java/javalab/umc7th_mission/study/validation/annotation/IsMemberMissionNotStarted.java create mode 100644 src/main/java/javalab/umc7th_mission/study/validation/validatior/IsMemberMissionNotStartedValidator.java diff --git a/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandService.java b/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandService.java index c679f9a..a9963c0 100644 --- a/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandService.java +++ b/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandService.java @@ -5,6 +5,6 @@ public interface MemberMissionCommandService { MemberMission AddMemberMission(MemberMissionRequestDTO.AddMemberMissionDto request); - boolean isChallenging(Long memberId, Long missionId); + boolean isExist(Long memberId, Long missionId); } diff --git a/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandServiceImpl.java b/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandServiceImpl.java index 9103ab4..66b7762 100644 --- a/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandServiceImpl.java +++ b/src/main/java/javalab/umc7th_mission/study/service/MemberMissionService/MemberMissionCommandServiceImpl.java @@ -5,7 +5,6 @@ import javalab.umc7th_mission.study.converter.MemberMissionConverter; import javalab.umc7th_mission.study.domain.Member; import javalab.umc7th_mission.study.domain.Mission; -import javalab.umc7th_mission.study.domain.enums.MissionStatus; import javalab.umc7th_mission.study.domain.mapping.MemberMission; import javalab.umc7th_mission.study.repository.MemberMissionRepository.MemberMissionRepository; import javalab.umc7th_mission.study.repository.MemberRepository.MemberRepository; @@ -29,23 +28,20 @@ public MemberMission AddMemberMission(MemberMissionRequestDTO.AddMemberMissionDt Mission mission = missionRepository.findById(Math.toIntExact(request.getMissionId())) .orElseThrow(() -> new GeneralException(ErrorStatus.MISSION_NOT_FOUND)); - - if(isChallenging(request.getMemberId(), request.getMissionId())){ - throw new GeneralException(ErrorStatus.MEMBER_MISSION_ALREADY_IN_CHALLENGING); - } MemberMission membermission = MemberMissionConverter.toMemberMission(member, mission); + + return memberMissionRepository.save(membermission); } @Override - public boolean isChallenging(Long memberId, Long missionId){ - MemberMission memberMission = memberMissionRepository.findMemberMissionByMemberIdAndMissionId(memberId, missionId); + public boolean isExist(Long memberId, Long missionId){ + MemberMission memberMission = memberMissionRepository.findMemberMissionByMemberIdAndMissionId(memberId, missionId); - if(memberMission != null && memberMission.getStatus().equals(MissionStatus.CHALLENGING)){ + if(memberMission != null){ return true; } - return false; } } diff --git a/src/main/java/javalab/umc7th_mission/study/validation/annotation/IsMemberMissionNotStarted.java b/src/main/java/javalab/umc7th_mission/study/validation/annotation/IsMemberMissionNotStarted.java new file mode 100644 index 0000000..896781d --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/validation/annotation/IsMemberMissionNotStarted.java @@ -0,0 +1,17 @@ +package javalab.umc7th_mission.study.validation.annotation; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import javalab.umc7th_mission.study.validation.validatior.IsMemberMissionNotStartedValidator; + +import java.lang.annotation.*; + +@Documented +@Constraint(validatedBy = IsMemberMissionNotStartedValidator.class) +@Target( { ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface IsMemberMissionNotStarted { + String message() default "해당 미션은 이미 진행중입니다."; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/src/main/java/javalab/umc7th_mission/study/validation/validatior/IsMemberMissionNotStartedValidator.java b/src/main/java/javalab/umc7th_mission/study/validation/validatior/IsMemberMissionNotStartedValidator.java new file mode 100644 index 0000000..7249903 --- /dev/null +++ b/src/main/java/javalab/umc7th_mission/study/validation/validatior/IsMemberMissionNotStartedValidator.java @@ -0,0 +1,33 @@ +package javalab.umc7th_mission.study.validation.validatior; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import javalab.umc7th_mission.study.apiPayload.code.status.ErrorStatus; +import javalab.umc7th_mission.study.service.MemberMissionService.MemberMissionCommandService; +import javalab.umc7th_mission.study.validation.annotation.IsMemberMissionNotStarted; +import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionRequestDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class IsMemberMissionNotStartedValidator implements ConstraintValidator { + private final MemberMissionCommandService memberMissionCommandService; + @Override + public void initialize(IsMemberMissionNotStarted constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } + + @Override + public boolean isValid(MemberMissionRequestDTO.AddMemberMissionDto request, ConstraintValidatorContext context) { + boolean isValid = memberMissionCommandService.isExist(request.getMemberId(), request.getMissionId()); + + if(isValid){ + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(ErrorStatus.MEMBER_MISSION_ALREADY_IN_CHALLENGING.toString()).addConstraintViolation(); + return false; + } + return true; + } + +} diff --git a/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.java b/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.java index f5a239a..7cfc0a9 100644 --- a/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.java +++ b/src/main/java/javalab/umc7th_mission/study/web/dto/member_mission/MemberMissionRequestDTO.java @@ -1,11 +1,17 @@ package javalab.umc7th_mission.study.web.dto.member_mission; import jakarta.validation.constraints.NotNull; +import javalab.umc7th_mission.study.validation.annotation.IsMemberMissionNotStarted; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import java.time.LocalDate; + public class MemberMissionRequestDTO { + @IsMemberMissionNotStarted @Getter public static class AddMemberMissionDto{ @NotNull(message = "회원 id는 필수 항목입니다.")