Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#4-create-project
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/sixgaezzang/sidepeek/projects/dto/response/MemberSummary.java
#	src/main/java/sixgaezzang/sidepeek/projects/service/ProjectService.java
  • Loading branch information
Sehee-Lee-01 committed Feb 21, 2024
2 parents 0426633 + 00d28c2 commit 3f29d3d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 19 deletions.
2 changes: 1 addition & 1 deletion sidepeek_backend_secret
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sixgaezzang.sidepeek.common.exception;

public interface ErrorCode {

int getCode();

String getMessage();

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public ResponseEntity<Void> save(@RequestBody ProjectSaveRequest request) {
@Operation(summary = "프로젝트 상세 조회")
@ApiResponse(responseCode = "200", description = "프로젝트 상세 조회 성공")
public ResponseEntity<ProjectResponse> getById(
// TODO: 로그인 아이디 추가
@PathVariable Long id
) {
ProjectResponse response = projectService.findById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Builder;
import sixgaezzang.sidepeek.projects.domain.member.Member;
import sixgaezzang.sidepeek.users.domain.User;
import sixgaezzang.sidepeek.users.dto.response.UserSummary;

@Builder
Expand All @@ -11,6 +12,14 @@ public record MemberSummary(
UserSummary userSummary
) {

public static MemberSummary from(Member member) {
User user = member.getUser();
UserSummary userSummaryResponse = (user == null)
? UserSummary.from(member.getNickname())
: UserSummary.from(user);
return MemberSummary.from(member, userSummaryResponse);
}

public static MemberSummary from(Member member, UserSummary userSummary) {
return MemberSummary.builder()
.id(member.getId())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sixgaezzang.sidepeek.projects.exception;

import sixgaezzang.sidepeek.common.exception.ErrorCode;

public enum ProjectErrorCode implements ErrorCode {

ID_NOT_EXISTING(2001, "해당 프로젝트가 존재하지 않습니다.");

private final int code;
private final String message;

ProjectErrorCode(int code, String message) {
this.code = code;
this.message = message;
}

@Override
public int getCode() {
return code;
}

@Override
public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sixgaezzang.sidepeek.projects.dto.response.OverviewImageSummary;
import sixgaezzang.sidepeek.projects.dto.response.ProjectResponse;
import sixgaezzang.sidepeek.projects.dto.response.ProjectSkillSummary;
import sixgaezzang.sidepeek.projects.exception.ProjectErrorCode;
import sixgaezzang.sidepeek.projects.repository.FileRepository;
import sixgaezzang.sidepeek.projects.repository.MemberRepository;
import sixgaezzang.sidepeek.projects.repository.ProjectRepository;
Expand Down Expand Up @@ -55,40 +56,29 @@ public Long save(ProjectSaveRequest projectSaveRequest) {

public ProjectResponse findById(Long id) {

// 프로젝트 가져오기
Project project = projectRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("해당 프로젝트가 존재하지 않습니다."));
.orElseThrow(
() -> new EntityNotFoundException(ProjectErrorCode.ID_NOT_EXISTING.getMessage()));

// 조회수 + 1
project.increaseViewCount();

// 프로젝트 개요에 사용될 File(Image) 가져오기
List<OverviewImageSummary> overviewImages = fileRepository.findAllByProjectAndType(
project, FileType.OVERVIEW_IMAGE)
.stream()
.map(OverviewImageSummary::from)
.toList();

// 프로젝트 id를 가진 프로젝트에 사용되는 Skill 가져오기
List<ProjectSkillSummary> techStacks = projectSkillRepository.findAllByProject(project)
.stream()
.map(ProjectSkillSummary::from)
.toList();

// 프로젝트 id를 가진 프로젝트 Member 가져오기
List<MemberSummary> members = memberRepository.findAllByProject(project)
.stream()
.map(this::createMemberSummary)
.map(MemberSummary::from)
.toList();

return ProjectResponse.from(project, overviewImages, techStacks, members);
}

private MemberSummary createMemberSummary(Member member) {
User user = member.getUser();
UserSummary userSummary = (user == null)
? UserSummary.from(member.getNickname())
: UserSummary.from(user);
return MemberSummary.from(member, userSummary);
}
}
3 changes: 0 additions & 3 deletions src/main/resources/db/data/afterMigrate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,4 @@ insert into project_skill(id, project_id, skill_id, category) values (22, 1, 2,
insert into project_skill(id, project_id, skill_id, category) values (23, 1, 3, '협업툴');
insert into project_skill(id, project_id, skill_id, category) values (24, 1, 4, '프론트');

-- FILE



0 comments on commit 3f29d3d

Please sign in to comment.