Skip to content

Commit

Permalink
Feature/#13 - 스택 조회 API에 프로젝트 정보 추가 (#43)
Browse files Browse the repository at this point in the history
* [#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 파일 트랙킹하지 않도록 수정
  • Loading branch information
leeeeeyeon authored Aug 18, 2022
1 parent 2240c6b commit 3685b7a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ HELP.md

aws.yml

application.properties

application-local.properties
2 changes: 1 addition & 1 deletion src/main/java/com/artistack/base/constant/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -131,7 +133,7 @@ public DataResponseDto<Object> 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<Object> getStack(@PathVariable Long projectId, @PathVariable String sequence) {
// validation
Expand Down Expand Up @@ -161,8 +163,8 @@ public DataResponseDto<Object> getStack(@PathVariable Long projectId, @PathVaria
+ "번거롭지만 dto는 .json 파일로 업로드해주세요..! 포스트맨에서 테스트할 때는, Content-Type을 application/json으로 설정하여 텍스트로 입력할 수 있습니다.<br>"
+ "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<Object> uploadProject(
@PathVariable Long prevProjectId,
@RequestPart(value = "video") MultipartFile video,
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/artistack/project/dto/ProjectDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> instrumentIds, Scope scope, Boolean isStackable) {
return ProjectDto.builder()
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/artistack/project/service/ProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -202,7 +203,8 @@ public List<UserDto> 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)
Expand All @@ -212,7 +214,9 @@ public List<UserDto> getPrevStackers(Long projectId) {

List<InstrumentDto> 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();
Expand All @@ -234,11 +238,12 @@ public List<UserDto> getNextStackers(Long projectId) {

List<InstrumentDto> 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);
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/artistack/user/dto/UserDto.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -38,6 +40,7 @@ public class UserDto {
private String description;
private String profileImgUrl;
private List<InstrumentDto> instruments;
private ProjectDto project;
private ProviderType providerType;
private Role role;

Expand Down Expand Up @@ -72,19 +75,22 @@ public static UserDto idResponse(User user) {
.build();
}


public static UserDto previewResponse(User user) {

return UserDto.builder()
.artistackId(user.getArtistackId())
.nickname(user.getNickname())
.profileImgUrl(user.getProfileImgUrl())
.build();
}

public static UserDto stackResponse(User user, List<InstrumentDto> instruments) {
public static UserDto stackResponse(User user, List<InstrumentDto> instruments, ProjectDto project) {
return UserDto.builder()
.nickname(user.getNickname())
.profileImgUrl(user.getProfileImgUrl())
.instruments(instruments)
.project(project)
.build();
}

Expand Down
27 changes: 0 additions & 27 deletions src/main/resources/application.properties

This file was deleted.

0 comments on commit 3685b7a

Please sign in to comment.