Skip to content

Commit

Permalink
Merge pull request #28 from dnd-side-project/feature/#23
Browse files Browse the repository at this point in the history
프로젝트 상세 조회 api 구현 #23
  • Loading branch information
woo0doo authored Feb 16, 2024
2 parents 47bcd7e + ff0044f commit f1ffea0
Show file tree
Hide file tree
Showing 53 changed files with 944 additions and 504 deletions.
1 change: 1 addition & 0 deletions src/docs/asciidoc/api/feedback.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

==== HTTP Requests
include::{snippets}/feedback/detail/http-request.adoc[]
- Path parameters +
include::{snippets}/feedback/detail/path-parameters.adoc[]

==== HTTP Response
Expand Down
3 changes: 3 additions & 0 deletions src/docs/asciidoc/api/like.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
=== 성공
==== HTTP Requests
include::{snippets}/like/react/http-request.adoc[]
- Path parameters +
include::{snippets}/like/react/path-parameters.adoc[]

==== HTTP Response
include::{snippets}/like/react/http-response.adoc[]
- Response body +
include::{snippets}/like/react/response-fields.adoc[]
22 changes: 20 additions & 2 deletions src/docs/asciidoc/api/project.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@
==== HTTP Requests
include::{snippets}/project/save/http-request.adoc[]

- *body*
- Request body +
include::{snippets}/project/save/request-parts.adoc[]
data
include::{snippets}/project/save/request-part-data-fields.adoc[]

==== HTTP Response
include::{snippets}/project/save/http-response.adoc[]
- Response body +
include::{snippets}/project/save/response-fields.adoc[]

[[project-detail]]
== 프로젝트 상세 조회

=== 성공

==== HTTP Requests
include::{snippets}/project/detail/http-request.adoc[]
- Path parameters +
include::{snippets}/project/detail/path-parameters.adoc[]

==== HTTP Response
include::{snippets}/project/detail/http-response.adoc[]
- Response body +
include::{snippets}/project/detail/response-fields.adoc[]

[[project-update]]
== 프로젝트 수정

Expand All @@ -27,13 +43,14 @@ include::{snippets}/project/save/response-fields.adoc[]
==== HTTP Requests
include::{snippets}/project/update/http-request.adoc[]

- *body*
- Request body +
include::{snippets}/project/update/request-parts.adoc[]
data
include::{snippets}/project/update/request-part-data-fields.adoc[]

==== HTTP Response
include::{snippets}/project/update/http-response.adoc[]
- Response body +
include::{snippets}/project/update/response-fields.adoc[]

[[project-delete]]
Expand All @@ -47,4 +64,5 @@ include::{snippets}/project/delete/http-request.adoc[]

==== HTTP Response
include::{snippets}/project/delete/http-response.adoc[]
- Response body +
include::{snippets}/project/delete/response-fields.adoc[]
3 changes: 3 additions & 0 deletions src/docs/asciidoc/api/scrap.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

==== HTTP Requests
include::{snippets}/scrap/click/http-request.adoc[]
- Path parameters +
include::{snippets}/scrap/click/path-parameters.adoc[]

==== HTTP Response
include::{snippets}/scrap/click/http-response.adoc[]
- Response body +
include::{snippets}/scrap/click/response-fields.adoc[]
3 changes: 2 additions & 1 deletion src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ endif::[]
:sectlinks:

include::api/auth.adoc[]
include::api/user.adoc[]
include::api/project.adoc[]
include::api/feedback.adoc[]
include::api/like.adoc[]
include::api/scrap.adoc[]
include::api/user.adoc[]
26 changes: 26 additions & 0 deletions src/main/java/com/sendback/domain/comment/entity/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sendback.domain.comment.entity;

import com.sendback.domain.project.entity.Project;
import com.sendback.global.common.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLDelete(sql = "UPDATE comment SET is_deleted = true WHERE id = ?")
public class Comment extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "project_id")
private Project project;

private boolean isDeleted = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FeedbackController {

private final FeedbackService feedbackService;

@PostMapping("/{projectId}/feedback")
@PostMapping("/{projectId}/feedbacks")
public ApiResponse<FeedbackIdResponseDto> saveFeedback(
@UserId Long userId,
@PathVariable Long projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public record FeedbackDetailResponseDto(
String endedAt,
Long projectId,
String projectTitle,
String field,
String fieldName,
String progress
) {
public static FeedbackDetailResponseDto of(Feedback feedback) {
public static FeedbackDetailResponseDto from(Feedback feedback) {
Project project = feedback.getProject();
User user = project.getUser();
return new FeedbackDetailResponseDto(
Expand All @@ -43,7 +43,7 @@ public static FeedbackDetailResponseDto of(Feedback feedback) {
feedback.getEndedAt().toString(),
project.getId(),
project.getTitle(),
project.getField().getName(),
project.getFieldName().getName(),
project.getProgress().toString()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public FeedbackDetailResponseDto getFeedbackDetail(Long projectId, Long feedback
projectService.getProjectById(projectId);
Feedback feedback = getFeedback(feedbackId);

return FeedbackDetailResponseDto.of(feedback);
return FeedbackDetailResponseDto.from(feedback);
}

public Feedback getFeedback(Long feedbackId) {
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/com/sendback/domain/field/entity/Field.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sendback.domain.field.entity;

import com.sendback.domain.user.entity.User;
import com.sendback.global.common.constants.FieldName;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -16,25 +17,20 @@ public class Field {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;
@Enumerated(EnumType.STRING)
private FieldName name;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Builder
private Field(String name, User user) {
private Field(FieldName name, User user) {
this.name = name;
this.user = user;
}

public static Field of(String name) {
return Field.builder()
.name(name)
.build();
}

public static Field of(String name, User user) {
public static Field of(FieldName name, User user) {
return Field.builder()
.name(name)
.user(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import com.sendback.domain.field.entity.Field;
import com.sendback.domain.field.repository.FieldRepository;
import com.sendback.global.exception.type.NotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static com.sendback.domain.field.exception.FieldExceptionType.NOT_FOUND_FIELD;

@Service
@RequiredArgsConstructor
Expand All @@ -16,9 +14,6 @@ public class FieldService {

private final FieldRepository fieldRepository;

public Field getFieldByName(String name) {
return fieldRepository.findByName(name).orElseThrow(() -> new NotFoundException(NOT_FOUND_FIELD));
}
@Transactional
public List<Field> saveAll(List<Field> fieldList) {
return fieldRepository.saveAll(fieldList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import com.sendback.domain.project.entity.Project;
import com.sendback.domain.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface LikeRepository extends JpaRepository<Like, Long> {

Optional<Like> findByUserAndProject(User user, Project project);
boolean existsByUserAndProjectAndIsDeletedIsFalse(User user, Project project);
Long countByProjectIn(List<Project> projects);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import com.sendback.domain.project.dto.request.SaveProjectRequestDto;
import com.sendback.domain.project.dto.request.UpdateProjectRequestDto;
import com.sendback.domain.project.dto.response.ProjectDetailResponseDto;
import com.sendback.domain.project.dto.response.ProjectIdResponseDto;
import com.sendback.domain.project.service.ProjectService;
import com.sendback.global.common.ApiResponse;
import com.sendback.global.common.UserId;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -23,6 +26,20 @@ public class ProjectController {

private final ProjectService projectService;

@GetMapping("/{projectId}")
private ApiResponse<ProjectDetailResponseDto> getProjectDetail(
@PathVariable Long projectId
) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

if (authentication.getPrincipal() == "anonymousUser") {
return success(projectService.getProjectDetail(null , projectId));
}

Long userId = (Long) authentication.getPrincipal();
return success(projectService.getProjectDetail(userId, projectId));
}

@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public ApiResponse<ProjectIdResponseDto> saveProject(
@UserId Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record SaveProjectRequestDto(
@NotBlank(message = "제목은 비워둘 수 없습니다.")
String title,
@NotBlank(message = "분야는 비워둘 수 없습니다.")
String field,
String fieldName,
@Size(max = 1_000, message = "설명은 글자 수가 최대 1,000자 입니다.")
@NotBlank(message = "설명은 비워둘 수 없습니다.")
String content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public record UpdateProjectRequestDto(
@NotBlank(message = "제목은 비워둘 수 없습니다.")
String title,
@NotBlank(message = "분야는 비워둘 수 없습니다.")
String field,
String fieldName,
@Size(max = 1_000, message = "설명은 글자 수가 최대 1,000자 입니다.")
@NotBlank(message = "설명은 비워둘 수 없습니다.")
String content,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.sendback.domain.project.dto.response;

import com.sendback.domain.project.entity.Project;
import com.sendback.domain.project.entity.ProjectImage;
import com.sendback.domain.user.entity.User;

import java.util.List;

import static com.sendback.global.util.CustomDateUtil.customDateFormat;

public record ProjectDetailResponseDto(
Long userId,
String username,
String userLevel,
String profileImageUrl,
Long projectId,
String title,
String fieldName,
String content,
String demoSiteUrl,
String progress,
List<String> projectImageUrl,
Long frontendCount,
Long backendCount,
Long designerCount,
Long plannerCount,
Long likeCount,
Long scrapCount,
Long commentCount,
String createdAt,
String startedAt,
String endedAt,
boolean isAuthor,
boolean isCheckedLike,
boolean isCheckedScrap
) {
public static ProjectDetailResponseDto of(Project project, boolean isAuthor, boolean isCheckedLike, boolean isCheckedScrap) {
User user = project.getUser();
return new ProjectDetailResponseDto(
user.getId(),
user.getNickname(),
user.getLevel().getName(),
user.getProfileImageUrl(),
project.getId(),
project.getTitle(),
project.getFieldName().getName(),
project.getContent(),
project.getDemoSiteUrl(),
project.getProgress().getValue(),
project.getProjectImages().stream().map(ProjectImage::getImageUrl).toList(),
project.getProjectParticipantCount().getFrontendCount(),
project.getProjectParticipantCount().getBackendCount(),
project.getProjectParticipantCount().getDesignCount(),
project.getProjectParticipantCount().getPlannerCount(),
project.getLikes().stream().filter(like -> !like.isDeleted()).count(),
project.getScraps().stream().filter(scrap -> !scrap.isDeleted()).count(),
project.getComments().stream().filter(comment -> !comment.isDeleted()).count(),
customDateFormat(project.getCreatedAt()),
project.getStartedAt().toString(),
project.getEndedAt().toString(),
isAuthor,
isCheckedLike,
isCheckedScrap
);
}
}
12 changes: 7 additions & 5 deletions src/main/java/com/sendback/domain/project/entity/Progress.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
@Getter
@AllArgsConstructor
public enum Progress {
PLANNING, DEVELOPING, REFACTORING;
PLANNING("기획중"), DEVELOPING("개발중"), REFACTORING("리팩토링중");

private final String value;

public static Progress toEnum(String progress) {
return switch (progress.toUpperCase()) {
case "PLANNING" -> PLANNING;
case "DEVELOPING" -> DEVELOPING;
case "REFACTORING" -> REFACTORING;
return switch (progress) {
case "기획중" -> PLANNING;
case "개발중" -> DEVELOPING;
case "리팩토링중" -> REFACTORING;

default -> throw new NotFoundException(NOT_FOUND_PROGRESS);
};
Expand Down
Loading

0 comments on commit f1ffea0

Please sign in to comment.