-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/12 chapter8 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/12 chapter8 #13
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/umc9th/domain/category/repository/CategoryRepository.java
This file contains hidden or 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,7 @@ | ||
| package com.example.umc9th.domain.category.repository; | ||
|
|
||
| import com.example.umc9th.domain.category.entity.Category; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface CategoryRepository extends JpaRepository<Category, Long> { | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/example/umc9th/domain/mission/controller/MissionController.java
This file contains hidden or 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,37 @@ | ||
| package com.example.umc9th.domain.mission.controller; | ||
|
|
||
| import com.example.umc9th.domain.mission.dto.MissionRequestDto; | ||
| import com.example.umc9th.domain.mission.dto.MissionResponseDto; | ||
| import com.example.umc9th.domain.mission.service.MissionService; | ||
| import com.example.umc9th.domain.review.dto.ReviewRequestDto; | ||
| import com.example.umc9th.domain.review.dto.ReviewResponseDto; | ||
| import com.example.umc9th.global.apiPayload.ApiResponse; | ||
| import com.example.umc9th.global.apiPayload.code.status.GeneralSuccessCode; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/missions") | ||
| @Tag(name = "๋ฏธ์ ") | ||
| public class MissionController { | ||
| private final MissionService missionService; | ||
|
|
||
| @Operation( | ||
| summary = "๋ฏธ์ ์ถ๊ฐ", | ||
| description = "๊ด๋ฆฌ์์ฉ") | ||
| @PostMapping("/admin") | ||
| public ApiResponse<String> addMission(@RequestBody MissionRequestDto.CreateMission req) { | ||
| return ApiResponse.onSuccess(GeneralSuccessCode._CREATED, missionService.createMission(req)); | ||
| } | ||
|
|
||
| @Operation( | ||
| summary = "์ฌ์ฉ์ ๋ฏธ์ ์ถ๊ฐ", | ||
| description = "์ฌ์ฉ์๊ฐ ๊ฐ๊ฒ ๋ฏธ์ ์ ๋ณธ์ธ์ ๋์ ๋ฏธ์ ์ ์ถ๊ฐํฉ๋๋ค.") | ||
| @PostMapping("/{mission-id}") | ||
| public ApiResponse<MissionResponseDto.AddUserMission> addMission(@RequestParam @PathVariable("mission-id")Long missionId) { | ||
| return ApiResponse.onSuccess(GeneralSuccessCode._CREATED, missionService.addUserMission(missionId)); | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/umc9th/domain/mission/dto/MissionRequestDto.java
This file contains hidden or 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,19 @@ | ||
| package com.example.umc9th.domain.mission.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| public class MissionRequestDto { | ||
| private MissionRequestDto() {} | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public static class CreateMission{ | ||
| private Integer point; | ||
| private String content; | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/umc9th/domain/mission/dto/MissionResponseDto.java
This file contains hidden or 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 com.example.umc9th.domain.mission.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| public class MissionResponseDto { | ||
| private MissionResponseDto() {} | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @AllArgsConstructor | ||
| public static class AddUserMission{ | ||
| private Long missionId; | ||
| private String content; | ||
| private String createdAt; | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/umc9th/domain/mission/service/MissionService.java
This file contains hidden or 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,9 @@ | ||
| package com.example.umc9th.domain.mission.service; | ||
|
|
||
| import com.example.umc9th.domain.mission.dto.MissionRequestDto; | ||
| import com.example.umc9th.domain.mission.dto.MissionResponseDto; | ||
|
|
||
| public interface MissionService { | ||
| String createMission(MissionRequestDto.CreateMission req); | ||
| MissionResponseDto.AddUserMission addUserMission(Long missionId); | ||
| } |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/example/umc9th/domain/mission/service/MissionServiceImpl.java
This file contains hidden or 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 com.example.umc9th.domain.mission.service; | ||
|
|
||
| import com.example.umc9th.domain.mission.dto.MissionRequestDto; | ||
| import com.example.umc9th.domain.mission.dto.MissionResponseDto; | ||
| import com.example.umc9th.domain.mission.entity.Mission; | ||
| import com.example.umc9th.domain.mission.entity.UserMission; | ||
| import com.example.umc9th.domain.mission.repository.MissionRepository; | ||
| import com.example.umc9th.domain.mission.repository.UserMissionRepository; | ||
| import com.example.umc9th.domain.store.repository.StoreRepository; | ||
| import com.example.umc9th.domain.user.repository.UserRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class MissionServiceImpl implements MissionService{ | ||
| private final MissionRepository missionRepository; | ||
| private final StoreRepository storeRepository; | ||
| private final UserRepository userRepository; | ||
| private final UserMissionRepository userMissionRepository; | ||
|
|
||
| @Override | ||
| public String createMission(MissionRequestDto.CreateMission req) { | ||
| Mission mission = Mission.builder() | ||
| .store(storeRepository.getReferenceById(1L)) | ||
| .content(req.getContent()) | ||
| .point(req.getPoint()) | ||
| .build(); | ||
|
|
||
| missionRepository.save(mission); | ||
|
|
||
| return mission.getId().toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public MissionResponseDto.AddUserMission addUserMission(Long missionId) { | ||
| UserMission um = UserMission.builder() | ||
| .user(userRepository.getReferenceById(1L)) | ||
| .mission(missionRepository.getReferenceById(missionId)) | ||
| .build(); | ||
|
|
||
| userMissionRepository.save(um); | ||
|
|
||
| return MissionResponseDto.AddUserMission.builder() | ||
| .missionId(missionId) | ||
| .content(um.getMission().getContent()) | ||
| .createdAt(um.getMission().getCreatedAt().toString()) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/umc9th/domain/review/dto/ReviewRequestDto.java
This file contains hidden or 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 com.example.umc9th.domain.review.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ReviewRequestDto { | ||
| private ReviewRequestDto() {} | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public static class Create{ | ||
| private Long storeId; | ||
| private String content; | ||
| private Float star; | ||
| private List<String> reviewImages; | ||
| } | ||
| } |
This file contains hidden or 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
3 changes: 2 additions & 1 deletion
3
src/main/java/com/example/umc9th/domain/review/service/ReviewService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/umc9th/global/annotation/ExistCategories.java
This file contains hidden or 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 com.example.umc9th.global.annotation; | ||
|
|
||
| import com.example.umc9th.global.validator.CategoryValidator; | ||
| import jakarta.validation.Constraint; | ||
| import jakarta.validation.Payload; | ||
|
|
||
| import java.lang.annotation.*; | ||
|
|
||
| /** | ||
| * @Documented : ์ฌ์ฉ์ ์ ์ ์ด๋ ธํ ์ด์ | ||
| * @Target : ์ด๋ ธํ ์ด์ ์ ์ฉ ๋ฒ์ | ||
| * @Retention : ์ด๋ ธํ ์ด์ ์๋ช ์ฃผ๊ธฐ | ||
| */ | ||
| @Documented | ||
| @Constraint(validatedBy = CategoryValidator.class) | ||
| @Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface ExistCategories { | ||
| //์ฌ๊ธฐ์ ๋ํดํธ ๋ฉ์์ง๋ฅผ ์ค์ ํฉ๋๋ค. | ||
| String message() default "ํด๋น ์์์ด ์กด์ฌํ์ง ์์ต๋๋ค."; | ||
| Class<?>[] groups() default {}; | ||
| Class<? extends Payload>[] payload() default {}; | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/example/umc9th/global/apiPayload/code/status/CategoryErrorCode.java
This file contains hidden or 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 com.example.umc9th.global.apiPayload.code.status; | ||
|
|
||
| import com.example.umc9th.global.apiPayload.code.BaseErrorCode; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum CategoryErrorCode implements BaseErrorCode { | ||
| CATEGORY_NOT_EXISTED(HttpStatus.NOT_FOUND,"CATEGORY_400","์กด์ฌํ์ง ์๋ ์นดํ ๊ณ ๋ฆฌ์ ๋๋ค."); | ||
|
|
||
| private final HttpStatus httpStatus; | ||
| private final String code; | ||
| private final String message; | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/umc9th/global/validator/CategoryValidator.java
This file contains hidden or 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,35 @@ | ||
| package com.example.umc9th.global.validator; | ||
|
|
||
| import com.example.umc9th.domain.category.repository.CategoryRepository; | ||
| import com.example.umc9th.global.annotation.ExistCategories; | ||
| import com.example.umc9th.global.apiPayload.code.status.CategoryErrorCode; | ||
| import jakarta.validation.ConstraintValidator; | ||
| import jakarta.validation.ConstraintValidatorContext; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class CategoryValidator implements ConstraintValidator<ExistCategories, List<Long>> { | ||
|
|
||
| private final CategoryRepository categoryRepository; | ||
|
|
||
| @Override | ||
| public void initialize(ExistCategories constraintAnnotation) { | ||
| ConstraintValidator.super.initialize(constraintAnnotation); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isValid(List<Long> values, ConstraintValidatorContext context) { | ||
| boolean isValid = values.stream().allMatch(categoryRepository::existsById); | ||
|
|
||
| if(!isValid){ | ||
| context.disableDefaultConstraintViolation(); // ๋ํดํธ ๋ฉ์ธ์ง ์ด๊ธฐํ | ||
| context.buildConstraintViolationWithTemplate(CategoryErrorCode.CATEGORY_NOT_EXISTED.getMessage()) | ||
| .addConstraintViolation(); // ์๋ก์ด ๋ฉ์ธ์ง๋ก ๋ฎ์ด์ฐ๊ธฐ | ||
| } | ||
| return isValid; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.