Skip to content

Commit

Permalink
Merge branch 'feature' into BE/#269
Browse files Browse the repository at this point in the history
  • Loading branch information
baekhangyeol authored Nov 5, 2023
2 parents ab3c478 + 78efb68 commit 5935041
Show file tree
Hide file tree
Showing 25 changed files with 337 additions and 59 deletions.
4 changes: 4 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'

// LocalDataTime 역직렬화 문제 해결 패키지
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation 'com.fasterxml.jackson.core:jackson-databind'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graphy.backend.domain.bookmark.domain;
package com.graphy.backend.domain.comment.domain;

import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.recruitment.domain.Recruitment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.graphy.backend.domain.comment.dto.response;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.querydsl.core.annotations.QueryProjection;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -14,6 +17,9 @@
public class GetCommentWithMaskingResponse {
private String content;
private Long commentId;

@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime createdAt;
private String nickname;
private Long childCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

import com.graphy.backend.domain.job.dto.response.GetJobResponse;
import com.graphy.backend.domain.job.service.JobService;
import com.graphy.backend.global.common.PageRequest;
import com.graphy.backend.global.common.dto.PageRequest;
import com.graphy.backend.global.error.ErrorCode;
import com.graphy.backend.global.error.exception.EmptyResultException;
import com.graphy.backend.global.result.ResultCode;
import com.graphy.backend.global.result.ResultResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "EmploymentController", description = "신규 채용 공고 API")
@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.graphy.backend.domain.member.controller;

import com.graphy.backend.domain.auth.util.annotation.CurrentUser;
import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.member.dto.response.GetMemberResponse;
import com.graphy.backend.domain.member.dto.response.GetMyPageResponse;
import com.graphy.backend.domain.member.service.MemberService;
import com.graphy.backend.domain.auth.util.annotation.CurrentUser;
import com.graphy.backend.domain.project.service.ProjectService;
import com.graphy.backend.global.result.ResultCode;
import com.graphy.backend.global.result.ResultResponse;
Expand Down Expand Up @@ -39,4 +39,11 @@ public ResponseEntity<ResultResponse> myPage(@CurrentUser Member member) {
GetMyPageResponse result = projectService.myPage(member);
return ResponseEntity.ok(ResultResponse.of(ResultCode.MYPAGE_GET_SUCCESS, result));
}

@Operation(summary = "get myPage by nickname", description = "사용자 닉네임으로 마이페이지 조회")
@GetMapping("/mypage/{nickname}")
public ResponseEntity<ResultResponse> mypageByNickname(@PathVariable String nickname) {
GetMyPageResponse result = projectService.myPageByNickname(nickname);
return ResponseEntity.ok(ResultResponse.of(ResultCode.MYPAGE_GET_SUCCESS, result));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.graphy.backend.domain.member.domain.Member;
import lombok.*;

import java.io.Serializable;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
public class GetMemberResponse {
public class GetMemberResponse implements Serializable {
private String nickname;
private String email;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.graphy.backend.domain.member.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

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

public interface MemberRepository extends JpaRepository<Member, Long>, MemberCustomRepository {
Optional<Member> findByEmail(String email);
List<Member> findMemberByNicknameStartingWith(String nickname);

Optional<Member> findFirstByNickname(String nickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ public Member findMemberByEmail(String email) {
() -> new EmptyResultException(MEMBER_NOT_EXIST)
);
}

public Member findMemberByNickname(String nickname) {
return memberRepository.findFirstByNickname(nickname).orElseThrow(
() -> new EmptyResultException(MEMBER_NOT_EXIST)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.graphy.backend.domain.message.dto.response.GetMessageDetailResponse;
import com.graphy.backend.domain.message.dto.response.GetMessageResponse;
import com.graphy.backend.domain.message.service.MessageService;
import com.graphy.backend.global.common.PageRequest;
import com.graphy.backend.global.common.dto.PageRequest;
import com.graphy.backend.global.result.ResultCode;
import com.graphy.backend.global.result.ResultResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.notification.dto.response.GetNotificationResponse;
import com.graphy.backend.domain.notification.service.NotificationService;
import com.graphy.backend.global.common.PageRequest;
import com.graphy.backend.global.common.dto.PageRequest;
import com.graphy.backend.global.result.ResultCode;
import com.graphy.backend.global.result.ResultResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.graphy.backend.domain.notification.dto.NotificationDto;
import com.graphy.backend.domain.notification.dto.response.GetNotificationResponse;
import com.graphy.backend.domain.notification.repository.NotificationRepository;
import com.graphy.backend.global.common.PageRequest;
import com.graphy.backend.global.common.dto.PageRequest;
import com.graphy.backend.global.error.exception.BusinessException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.graphy.backend.domain.project.controller;

import com.graphy.backend.domain.auth.util.annotation.CurrentUser;
import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.project.dto.request.CreateProjectRequest;
import com.graphy.backend.domain.project.dto.request.GetProjectPlanRequest;
Expand All @@ -10,8 +11,7 @@
import com.graphy.backend.domain.project.dto.response.GetProjectResponse;
import com.graphy.backend.domain.project.dto.response.UpdateProjectResponse;
import com.graphy.backend.domain.project.service.ProjectService;
import com.graphy.backend.domain.auth.util.annotation.CurrentUser;
import com.graphy.backend.global.common.PageRequest;
import com.graphy.backend.global.common.dto.PageRequest;
import com.graphy.backend.global.error.ErrorCode;
import com.graphy.backend.global.error.exception.EmptyResultException;
import com.graphy.backend.global.result.ResultCode;
Expand All @@ -22,14 +22,19 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static org.springframework.http.HttpHeaders.SET_COOKIE;

@Tag(name = "ProjectController", description = "프로젝트 관련 API")
@RestController
@RequestMapping("api/v1/projects")
Expand Down Expand Up @@ -86,8 +91,23 @@ public ResponseEntity<ResultResponse> projectList(PageRequest pageRequest, @Curr

@Operation(summary = "findProject", description = "프로젝트 상세 조회")
@GetMapping("/{projectId}")
public ResponseEntity<ResultResponse> projectDetails(@PathVariable Long projectId) {
public ResponseEntity<ResultResponse> projectDetails(@PathVariable Long projectId, HttpServletRequest request) {
GetProjectDetailResponse result = projectService.findProjectById(projectId);
Cookie cookie = projectService.addViewCount(request, projectId);
ResponseCookie responseCookie = ResponseCookie.from(cookie.getName(), cookie.getValue())
.path(cookie.getPath())
.maxAge(cookie.getMaxAge())
.build();

return ResponseEntity.ok()
.header(SET_COOKIE, responseCookie.toString())
.body(ResultResponse.of(ResultCode.PROJECT_GET_SUCCESS, result));
}

@Operation(summary = "findProjectRank", description = "프로젝트 랭킹 조회")
@GetMapping("/rank")
public ResponseEntity<ResultResponse> projectRankList() {
List<GetProjectDetailResponse> result = projectService.findTopRankingProjectList();
return ResponseEntity.ok(ResultResponse.of(ResultCode.PROJECT_GET_SUCCESS, result));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.graphy.backend.domain.comment.domain.Comment;
import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.project.dto.request.UpdateProjectRequest;
import com.graphy.backend.global.common.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -53,24 +54,29 @@ public class Project extends BaseEntity {

private String thumbNail;

@Column(nullable = true)
@Column(nullable = false)
@ColumnDefault("0")
private int likeCount = 0;

public void updateProject(String projectName, String content,
String description, Tags tags,
String thumbNail) {
this.projectName = projectName;
this.content = content;
this.description = description;
this.thumbNail = thumbNail;
@Column(nullable = false)
@ColumnDefault("0")
private int viewCount = 0;

public void updateProject(UpdateProjectRequest dto, Tags tags) {
this.projectName = dto.getProjectName();
this.content = dto.getContent();
this.description = dto.getDescription();
this.thumbNail = dto.getThumbNail();
projectTags.clear();
addTag(tags);
}

public void updateLikeCount(int amount) {
this.likeCount += amount;
}
public void addViewCount() {
this.viewCount++;
}

public void addTag(Tags tags) {
projectTags.add(this, tags);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package com.graphy.backend.domain.project.dto.response;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.graphy.backend.domain.comment.dto.response.GetCommentWithMaskingResponse;
import com.graphy.backend.domain.member.dto.response.GetMemberResponse;
import com.graphy.backend.domain.project.domain.Project;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

import static com.graphy.backend.domain.member.dto.response.GetMemberResponse.*;
import static com.graphy.backend.domain.member.dto.response.GetMemberResponse.from;


@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GetProjectDetailResponse {
public class GetProjectDetailResponse implements Serializable {

private Long id;

Expand All @@ -29,6 +37,8 @@ public class GetProjectDetailResponse {

private List<GetCommentWithMaskingResponse> commentsList;

@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime createdAt;

private List<String> techTags;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.graphy.backend.domain.project.dto.response;

import com.graphy.backend.domain.project.domain.Project;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
Expand All @@ -13,13 +16,13 @@ public class GetProjectInfoResponse {

private String projectName;

private String description;
private String content;

public static GetProjectInfoResponse from(Project project) {
return GetProjectInfoResponse.builder()
.id(project.getId())
.projectName(project.getProjectName())
.description(project.getDescription())
.content(project.getContent())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.graphy.backend.domain.project.dto.response;

import com.graphy.backend.domain.project.domain.Project;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GetProjectRankingResponse {
private Long id;
private String projectName;
private int viewCount;
private int likeCount;

public static GetProjectRankingResponse from(Project project) {
return GetProjectRankingResponse.builder()
.id(project.getId())
.projectName(project.getProjectName())
.viewCount(project.getViewCount())
.likeCount(project.getLikeCount())
.build();
}
}
Loading

0 comments on commit 5935041

Please sign in to comment.