Skip to content

Commit

Permalink
Merge pull request #30 from dnd-side-project/feature/#27
Browse files Browse the repository at this point in the history
내가 등록한 프로젝트 조회 및 이전 api 점검 /#27
  • Loading branch information
strangehoon authored Feb 16, 2024
2 parents 2f371c5 + 6f627b4 commit edcc826
Show file tree
Hide file tree
Showing 24 changed files with 403 additions and 27 deletions.
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

testImplementation "org.testcontainers:testcontainers:1.19.0"

//querydsl dependencies 추가(스프링부트 3.0 이상)
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
}

tasks.named('test') {
Expand Down Expand Up @@ -108,4 +114,12 @@ bootJar {
from("${asciidoctor.outputDir}") {
into 'static/docs'
}
}

def querydslSrcDir = 'src/main/generated'
clean {
delete file(querydslSrcDir)
}
tasks.withType(JavaCompile) {
options.generatedSourceOutputDirectory = file(querydslSrcDir)
}
18 changes: 18 additions & 0 deletions src/docs/asciidoc/api/auth.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@
=== 성공
==== HTTP Requests
include::{snippets}/login-kakao-success/http-request.adoc[]

- Query parameters

include::{snippets}/login-kakao-success/query-parameters.adoc[]

==== HTTP Response
- Response body
include::{snippets}/login-kakao-success/http-response.adoc[]
include::{snippets}/login-kakao-success/response-fields.adoc[]



=== 실패(1070)
==== HTTP Requests
include::{snippets}/login-kakao-failure/http-request.adoc[]

- Query parameters

include::{snippets}/login-kakao-failure/query-parameters.adoc[]



==== HTTP Response
- Response body
include::{snippets}/login-kakao-failure/http-response.adoc[]
include::{snippets}/login-kakao-failure/response-fields.adoc[]

Expand All @@ -30,20 +41,24 @@ include::{snippets}/login-kakao-failure/response-fields.adoc[]
=== 성공
==== HTTP Requests
include::{snippets}/login-google-success/http-request.adoc[]
- Query parameters
include::{snippets}/login-google-success/query-parameters.adoc[]

==== HTTP Response
include::{snippets}/login-google-success/http-response.adoc[]
- Response body
include::{snippets}/login-google-success/response-fields.adoc[]


=== 실패(1070)
==== HTTP Requests
include::{snippets}/login-google-failure/http-request.adoc[]
- Query parameters
include::{snippets}/login-google-failure/query-parameters.adoc[]

==== HTTP Response
include::{snippets}/login-google-failure/http-response.adoc[]
- Response body
include::{snippets}/login-google-failure/response-fields.adoc[]

'''
Expand All @@ -53,10 +68,12 @@ include::{snippets}/login-google-failure/response-fields.adoc[]
=== 성공
==== HTTP Requests
include::{snippets}/reissue-token/http-request.adoc[]
- Request body
include::{snippets}/reissue-token/request-fields.adoc[]

==== HTTP Response
include::{snippets}/reissue-token/http-response.adoc[]
- Response body
include::{snippets}/reissue-token/response-fields.adoc[]

'''
Expand All @@ -69,6 +86,7 @@ include::{snippets}/logout-social/http-request.adoc[]

==== HTTP Response
include::{snippets}/logout-social/http-response.adoc[]
- Response body
include::{snippets}/logout-social/response-fields.adoc[]

'''
50 changes: 50 additions & 0 deletions src/docs/asciidoc/api/user.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
=== 성공
==== HTTP Requests
include::{snippets}/signUpKakao-success/http-request.adoc[]
- Request body
include::{snippets}/signUpKakao-success/request-fields.adoc[]

==== HTTP Response
include::{snippets}/signUpKakao-success/http-response.adoc[]
- Response body
include::{snippets}/signUpKakao-success/response-fields.adoc[]

'''
Expand All @@ -19,9 +21,57 @@ include::{snippets}/signUpKakao-success/response-fields.adoc[]
=== 성공
==== HTTP Requests
include::{snippets}/checkUserNickname-success/http-request.adoc[]
- Query parameters
include::{snippets}/checkUserNickname-success/query-parameters.adoc[]

==== HTTP Response
include::{snippets}/checkUserNickname-success/http-response.adoc[]
- Response body
include::{snippets}/checkUserNickname-success/response-fields.adoc[]

'''

[[get-userInfo]]
== 내 정보 조회하기
=== 성공
==== HTTP Requests
include::{snippets}/getUserInfo-success/http-request.adoc[]


==== HTTP Response
include::{snippets}/getUserInfo-success/http-response.adoc[]
- Response body
include::{snippets}/getUserInfo-success/response-fields.adoc[]


'''

[[get-updateInfo]]
== 내 정보 수정하기
=== 성공
==== HTTP Requests
include::{snippets}/updateUserInfo-success/http-request.adoc[]

- Request body
include::{snippets}/updateUserInfo-success/request-fields.adoc[]

==== HTTP Response
include::{snippets}/getUserInfo-success/http-response.adoc[]
- Response body
include::{snippets}/getUserInfo-success/response-fields.adoc[]

'''

[[get-registeredProjects]]
== 내가 등록한 프로젝트들 조회
=== 성공
==== HTTP Requests
include::{snippets}/getRegisteredProjects-success/http-request.adoc[]

- Query parameters
include::{snippets}/getRegisteredProjects-success/query-parameters.adoc[]

==== HTTP Response
include::{snippets}/getRegisteredProjects-success/http-response.adoc[]
- Response body
include::{snippets}/getRegisteredProjects-success/response-fields.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.sendback.domain.auth.dto.response.TokensResponseDto;
import com.sendback.domain.user.entity.User;
import com.sendback.domain.user.repository.UserRepository;
import com.sendback.domain.user.entity.SocialType;
import com.sendback.global.config.jwt.JwtProvider;
import com.sendback.global.exception.type.SignInException;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.sendback.domain.auth.dto.response.TokensResponseDto;
import com.sendback.domain.user.entity.User;
import com.sendback.domain.user.repository.UserRepository;
import com.sendback.global.config.redis.RedisService;
import com.sendback.global.config.jwt.JwtProvider;
import com.sendback.global.exception.type.SignInException;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private Project(
this.endedAt = endedAt;
this.progress = progress;
this.projectParticipantCount = new ProjectParticipantCount(plannerCount, frontendCount, backendCount, designCount);
this.projectPull = new ProjectPull(pullUpCnt, isPulledUp, pullEndAt);
this.projectPull = new ProjectPull(isPulledUp, pullUpCnt, pullEndAt);
this.isFinished = isFinished;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@AllArgsConstructor
public class ProjectPull {

private boolean pullUpCnt;
private long isPulledUp;
private Long pullUpCnt;
private boolean isPulledUp;
private LocalDateTime pullEndAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public enum ProjectExceptionType implements ExceptionType {
NOT_PROJECT_AUTHOR(4020, "프로젝트 작성자가 아닙니다."),
NOT_FOUND_DELETE_IMAGE_URL(4030, "삭제하려는 이미지 경로가 올바르지 않습니다."),
DELETED_PROJECT(4040, "삭제된 프로젝트입니다."),
IMAGE_SIZE_OVER(4050, "이미지는 최대 5장까지 가능합니다.");
IMAGE_SIZE_OVER(4050, "이미지는 최대 5장까지 가능합니다."),

NOT_FOUND_FIELD(4060, "필드가 올바르지 않습니다.");

private final int statusCode;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import com.sendback.domain.project.entity.Project;
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;

public interface ProjectRepository extends JpaRepository<Project, Long> {
public interface ProjectRepository extends JpaRepository<Project, Long>, ProjectRepositoryCustom {
Long countByUserId(Long userId);
List<Project> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.sendback.domain.project.repository;

import com.sendback.domain.user.dto.response.RegisteredProjectResponseDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface ProjectRepositoryCustom {

Page<RegisteredProjectResponseDto> findAllProjectsByMe(Pageable pageable, Long userId, Boolean isFinished);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.sendback.domain.project.repository;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.sendback.domain.user.dto.response.QRegisteredProjectResponseDto;
import com.sendback.domain.user.dto.response.RegisteredProjectResponseDto;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import java.util.List;
import static com.sendback.domain.project.entity.QProject.project;

@RequiredArgsConstructor
public class ProjectRepositoryImpl implements ProjectRepositoryCustom {

private final JPAQueryFactory queryFactory;

@Override
public Page<RegisteredProjectResponseDto> findAllProjectsByMe(Pageable pageable, Long userId, Boolean check) {

List<RegisteredProjectResponseDto> content = queryFactory
.select(new QRegisteredProjectResponseDto(
project.id.as("projectId"),
project.title,
project.progress.stringValue(),
project.summary,
project.fieldName.stringValue(),
project.createdAt,
project.projectPull.pullUpCnt
))
.from(project)
.where(project.user.id.eq(userId),
project.isFinished.eq(check),
project.isDeleted.eq(false))
.orderBy(project.createdAt.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

int total = queryFactory
.selectFrom(project)
.where(project.user.id.eq(userId),
project.isFinished.eq(check),
project.isDeleted.eq(false))
.fetch().size();

return new PageImpl<>(content, pageable, total);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.sendback.domain.user.dto.request.SignUpRequestDto;
import com.sendback.domain.user.dto.request.UpdateUserInfoRequestDto;
import com.sendback.domain.user.dto.response.RegisteredProjectResponseDto;
import com.sendback.domain.user.dto.response.UpdateUserInfoResponseDto;
import com.sendback.domain.user.dto.response.UserInfoResponseDto;
import com.sendback.domain.user.service.UserService;
import com.sendback.global.common.ApiResponse;
import com.sendback.global.common.CustomPage;
import com.sendback.global.common.UserId;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -45,4 +47,10 @@ public ApiResponse<UserInfoResponseDto> getUserInfo(@UserId Long userId) {
public ApiResponse<UpdateUserInfoResponseDto> updateUserInfo(@UserId Long userId, @RequestBody UpdateUserInfoRequestDto updateUserInfoRequestDto) {
return ApiResponse.success(userService.updateUserInfo(userId, updateUserInfoRequestDto));
}

@GetMapping("/me/project")
public ApiResponse<CustomPage<RegisteredProjectResponseDto>> getRegisteredProjects(@UserId Long userId, @RequestParam int page,
@RequestParam int size, @RequestParam int sort) {
return ApiResponse.success(userService.getRegisteredProjects(userId, page, size, sort));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.sendback.domain.user.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.querydsl.core.annotations.QueryProjection;
import java.time.LocalDateTime;
import java.util.List;

public record RegisteredProjectResponseDto (
Long projectId,
String title,
String progress,
String summary,
String field,
@JsonFormat(pattern = "yyyy.MM.dd")
LocalDateTime createdAt,
Long pullUpCnt
){
@QueryProjection
public RegisteredProjectResponseDto(
Long projectId,
String title,
String progress,
String summary,
String field,
LocalDateTime createdAt,
Long pullUpCnt
) {
this.projectId = projectId;
this.title = title;
this.progress = progress;
this.summary = summary;
this.field = field;
this.createdAt = createdAt;
this.pullUpCnt = pullUpCnt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public enum UserExceptionType implements ExceptionType {
NOT_FOUND_SOCIAL_TYPE(2030, "유효하지 않은 socail type 형식입니다."),
NOT_FOUND_LEVEL(2040, "유효하지 않은 level 형식입니다."),
INVALID_NICKNAME(2050, "닉네임은 한글, 영어(2~8자) 이내로 입력해주세요."),
NOT_FOUND_USER(2060, "유저를 찾을 수 없습니다.");

NOT_FOUND_USER(2060, "유저를 찾을 수 없습니다."),
DUPLICATED_NICKNAME(2070, "중복된 유저 닉네임입니다.");
private final int statusCode;
private final String message;

Expand Down
Loading

0 comments on commit edcc826

Please sign in to comment.