From 3685b7a3b9a1d3eacb4489c0b7cf261748ad73bd Mon Sep 17 00:00:00 2001 From: leeeeeyeon Date: Thu, 18 Aug 2022 18:41:02 +0900 Subject: [PATCH] =?UTF-8?q?Feature/#13=20-=20=EC=8A=A4=ED=83=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=EC=97=90=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80=20(#43)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [#4] feat: 프로젝트 게시 API * [#13] feat: 스택 조회 API * [#13] style: Swagger 파라미터 dataType 변경 * Merge branch 'dev' of github.com:leeeeeyeon/artistack-server into feature/#13 * Merge branch 'dev' of github.com:leeeeeyeon/artistack-server into feature/#13 * [#13] feat: 해당 유저가 쌓은 프로젝트 정보 추가 * [#13] refactor: 사용하지 않는 메서드 제거 * [#13] chore: gitignore 파일 트랙킹하지 않도록 수정 --- .gitignore | 2 ++ .../com/artistack/base/constant/Code.java | 2 +- .../project/controller/ProjectController.java | 10 ++++--- .../com/artistack/project/dto/ProjectDto.java | 16 +++++++++++ .../project/service/ProjectService.java | 15 +++++++---- .../java/com/artistack/user/dto/UserDto.java | 8 +++++- src/main/resources/application.properties | 27 ------------------- 7 files changed, 42 insertions(+), 38 deletions(-) delete mode 100644 src/main/resources/application.properties diff --git a/.gitignore b/.gitignore index 5694a43..7fcb194 100644 --- a/.gitignore +++ b/.gitignore @@ -69,4 +69,6 @@ HELP.md aws.yml +application.properties + application-local.properties \ No newline at end of file diff --git a/src/main/java/com/artistack/base/constant/Code.java b/src/main/java/com/artistack/base/constant/Code.java index 2f50e6e..9ec6b47 100644 --- a/src/main/java/com/artistack/base/constant/Code.java +++ b/src/main/java/com/artistack/base/constant/Code.java @@ -37,9 +37,9 @@ public enum Code { PREV_PROJECT_NOT_EXIST(2204, HttpStatus.BAD_REQUEST, "Previous project doesn't exist"), PREV_PROJECT_NOT_STACKABLE(2205, HttpStatus.BAD_REQUEST, "Previous project isn't stackable"), INVALID_SEQUENCE(2206, HttpStatus.BAD_REQUEST, "Invalid sequence"), + PROJECT_LIKE_EXIST(2207, HttpStatus.BAD_REQUEST, "Project Like already exist"), PROJECT_LIKE_NOT_EXIST(2208, HttpStatus.BAD_REQUEST, "Project Like doesn't exist"), - INVALID_INSTRUMENT(2301, HttpStatus.BAD_REQUEST, "Invalid instrument"), MULTI_INSTRUMENT_ERROR(2302, HttpStatus.BAD_REQUEST, "Cannot use multi instrument"), diff --git a/src/main/java/com/artistack/project/controller/ProjectController.java b/src/main/java/com/artistack/project/controller/ProjectController.java index 5fe40bb..571fac2 100644 --- a/src/main/java/com/artistack/project/controller/ProjectController.java +++ b/src/main/java/com/artistack/project/controller/ProjectController.java @@ -9,9 +9,11 @@ import com.artistack.util.SecurityUtil; import io.swagger.annotations.ApiImplicitParams; import java.util.List; -import java.util.Optional; + import lombok.RequiredArgsConstructor; +import java.util.Optional; + import io.swagger.annotations.ApiImplicitParam; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Schema; @@ -131,7 +133,7 @@ public DataResponseDto deleteLikeProject( @ApiOperation(value = "스택 조회") @ApiImplicitParams( value = { @ApiImplicitParam(name = "projectId", value = "현재 프로젝트 id", required = true, dataType = "long", paramType = "path"), - @ApiImplicitParam(name = "sequence", value = "순서 (prev와 next만 가능)", required = true, dataType = "string", paramType = "path")}) + @ApiImplicitParam(name = "sequence", value = "순서(prev or next)", required = true, dataType = "string", paramType = "path")}) @GetMapping("/{projectId}/{sequence}") public DataResponseDto getStack(@PathVariable Long projectId, @PathVariable String sequence) { // validation @@ -161,8 +163,8 @@ public DataResponseDto getStack(@PathVariable Long projectId, @PathVaria + "번거롭지만 dto는 .json 파일로 업로드해주세요..! 포스트맨에서 테스트할 때는, Content-Type을 application/json으로 설정하여 텍스트로 입력할 수 있습니다.
" + "scope는 0부터 시작하며, 숫자, 문자열 중 편한 것을 선택하여 입력해주세요. 0은 전체 공개(PUBLIC), 1은 비공개(PRIVATE)입니다." ) - @ApiImplicitParam(name = "prevProjectId", value = "이전 프로젝트 id", dataType = "integer", defaultValue = "0") - @PostMapping(value = "/{prevProjectId}",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @ApiImplicitParam(name = "prevProjectId", value = "이전 프로젝트 id", dataType = "long", defaultValue = "0") + @PostMapping(value = "/{prevProjectId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public DataResponseDto uploadProject( @PathVariable Long prevProjectId, @RequestPart(value = "video") MultipartFile video, diff --git a/src/main/java/com/artistack/project/dto/ProjectDto.java b/src/main/java/com/artistack/project/dto/ProjectDto.java index c469b65..e4c2b5a 100644 --- a/src/main/java/com/artistack/project/dto/ProjectDto.java +++ b/src/main/java/com/artistack/project/dto/ProjectDto.java @@ -93,6 +93,22 @@ public static ProjectDto projectResponse(Project project, ProjectInstrumentRepos } + public static ProjectDto stackResponse(Project project) { + return ProjectDto.builder() + .videoUrl(project.getVideoUrl()) + .title(project.getTitle()) + .description(project.getDescription()) + .bpm(project.getBpm()) + .codeFlow(project.getCodeFlow()) + .scope(project.getScope()) + .isStackable(project.getIsStackable()) + .viewCount(project.getViewCount()) + .prevProjectId(project.getPrevProjectId()) + .likeCount(project.getLikeCount()) + .stackCount(project.getStackCount()) + .build(); + } + public static ProjectDto insertProject(String title, String description, String bpm, String codeFlow, List instrumentIds, Scope scope, Boolean isStackable) { return ProjectDto.builder() diff --git a/src/main/java/com/artistack/project/service/ProjectService.java b/src/main/java/com/artistack/project/service/ProjectService.java index 3e3d69f..6e15ae4 100644 --- a/src/main/java/com/artistack/project/service/ProjectService.java +++ b/src/main/java/com/artistack/project/service/ProjectService.java @@ -19,6 +19,7 @@ import com.artistack.util.SecurityUtil; import java.io.IOException; import java.util.ArrayList; + import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -176,7 +177,7 @@ public String insertProject(Long prevProjectId, MultipartFile video, ProjectDto for (Long instrumentId : instrumentIds) { Instrument instrument = instrumentRepository.findById(instrumentId) .orElseThrow(() -> new GeneralException(Code.INVALID_INSTRUMENT, - "Controller validation failed - API 담당자에게 말해주세요!")); + "올바른 악기를 선택해 주세요.")); projectInstrumentRepository.save( new InstrumentDto(instrument.getId(), instrument.getName(), instrument.getImgUrl()) .toEntity(project, instrument) @@ -202,7 +203,8 @@ public List getPrevStackers(Long projectId) { Long prevProjectId = projectRepository.findById(projectId) .orElseThrow(() -> new GeneralException(Code.PROJECT_NOT_FOUND, "프로젝트를 찾을 수 없습니다.")) - .getPrevProjectId(); + .getPrevProjectId(); + while (prevProjectId != 0) { Project project = projectRepository.findById(prevProjectId) @@ -212,7 +214,9 @@ public List getPrevStackers(Long projectId) { List instruments = getInstrumentDtoFromProject(project); - UserDto userDto = UserDto.stackResponse(user, instruments); + ProjectDto projectDto = ProjectDto.stackResponse(project); + + UserDto userDto = UserDto.stackResponse(user, instruments, projectDto); stackers.add(userDto); prevProjectId = project.getPrevProjectId(); @@ -234,11 +238,12 @@ public List getNextStackers(Long projectId) { List instruments = getInstrumentDtoFromProject(project); - // userDto는 ListInstrumentDto(id, name, imgUrl인데 id만 반환할거임)를 사용 User user = userRepository.findById(userId) .orElseThrow(() -> new GeneralException(Code.USER_NOT_FOUND, "유저를 찾을 수 없습니다.")); - UserDto userDto = UserDto.stackResponse(user, instruments); + ProjectDto projectDto = ProjectDto.stackResponse(project); + + UserDto userDto = UserDto.stackResponse(user, instruments, projectDto); stackers.add(userDto); } diff --git a/src/main/java/com/artistack/user/dto/UserDto.java b/src/main/java/com/artistack/user/dto/UserDto.java index ec3dcdb..c4b5f94 100644 --- a/src/main/java/com/artistack/user/dto/UserDto.java +++ b/src/main/java/com/artistack/user/dto/UserDto.java @@ -1,5 +1,6 @@ package com.artistack.user.dto; + import static com.artistack.user.constant.UserConstraint.ARTISTACK_ID_MAX_LENGTH; import static com.artistack.user.constant.UserConstraint.ARTISTACK_ID_MIN_LENGTH; import static com.artistack.user.constant.UserConstraint.DESCRIPTION_MAX_LENGTH; @@ -13,6 +14,7 @@ import com.artistack.instrument.dto.InstrumentDto; import com.artistack.instrument.repository.UserInstrumentRepository; import com.artistack.oauth.constant.ProviderType; +import com.artistack.project.dto.ProjectDto; import com.artistack.user.constant.Role; import com.artistack.user.domain.User; import com.artistack.user.repository.UserRepository; @@ -38,6 +40,7 @@ public class UserDto { private String description; private String profileImgUrl; private List instruments; + private ProjectDto project; private ProviderType providerType; private Role role; @@ -72,7 +75,9 @@ public static UserDto idResponse(User user) { .build(); } + public static UserDto previewResponse(User user) { + return UserDto.builder() .artistackId(user.getArtistackId()) .nickname(user.getNickname()) @@ -80,11 +85,12 @@ public static UserDto previewResponse(User user) { .build(); } - public static UserDto stackResponse(User user, List instruments) { + public static UserDto stackResponse(User user, List instruments, ProjectDto project) { return UserDto.builder() .nickname(user.getNickname()) .profileImgUrl(user.getProfileImgUrl()) .instruments(instruments) + .project(project) .build(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 39e5c12..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,27 +0,0 @@ -# profile -spring.profiles.include=dev - -# MySQL -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect - -# port -server.port=8080 - -# test -server.servlet.encoding.force-response=true - -# aws -cloud.aws.region.static=ap-northeast-2 -cloud.aws.s3.bucket=artistack-bucket - -spring.servlet.multipart.max-file-size=1GB -spring.servlet.multipart.max-request-size=1GB - -cloud.aws.stack.auto=false -logging.level.com.amazonaws.util.EC2MetadataUtils=error - -# test -server.servlet.encoding.force-response=true - -# swagger -spring.mvc.pathmatch.matching-strategy=ant_path_matcher \ No newline at end of file