Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

develop 반영 #95

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io.oeid.mogakgo.core.properties.swagger.error.SwaggerUserErrorExamples;
import io.oeid.mogakgo.domain.user.presentation.dto.req.UserSignUpApiRequest;
import io.oeid.mogakgo.domain.user.presentation.dto.res.UserPublicApiResponse;
import io.oeid.mogakgo.domain.user.presentation.dto.res.UserSignUpApiResponse;
import io.oeid.mogakgo.exception.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -51,4 +52,16 @@ ResponseEntity<UserSignUpApiResponse> userSignUpApi(
examples = @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND))),
})
ResponseEntity<Void> userDeleteApi(@Parameter(hidden = true) Long userId);

@Operation(summary = "회원 조회 [회원 가입]", description = "회원 가입시 회원 정보를 조회할 때 사용하는 API")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원 조회 성공",
content = @Content(schema = @Schema(implementation = UserPublicApiResponse.class))),
@ApiResponse(responseCode = "404", description = "해당 유저가 존재하지 않음",
content = @Content(
mediaType = APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ErrorResponse.class),
examples = @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND))),
})
ResponseEntity<UserPublicApiResponse> userGetApi(@Parameter(hidden = true) Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.oeid.mogakgo.domain.achievement.domain.enums;

public enum AchievementType {
ONCE

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.oeid.mogakgo.domain.project.exception.ProjectException;
import io.oeid.mogakgo.domain.project.infrastructure.ProjectJpaRepository;
import io.oeid.mogakgo.domain.project.presentation.dto.req.ProjectCreateReq;
import io.oeid.mogakgo.domain.project_join_req.domain.entity.ProjectJoinRequest;
import io.oeid.mogakgo.domain.project_join_req.exception.ProjectJoinRequestException;
import io.oeid.mogakgo.domain.project_join_req.infrastruture.ProjectJoinRequestJpaRepository;
import io.oeid.mogakgo.domain.project_join_req.presentation.projectJoinRequestRes;
Expand Down Expand Up @@ -96,8 +97,9 @@ public CursorPaginationResult<projectJoinRequestRes> getJoinRequest(
}

// 프로젝트 참가 요청 조회

return projectJoinRequestJpaRepository.findByConditionWithPagination(
null, projectId, null, null);
null, projectId, null, pageable);
}

private User getUser(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import static io.oeid.mogakgo.domain.project_join_req.domain.entity.QProjectJoinRequest.projectJoinRequest;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.oeid.mogakgo.common.base.CursorPaginationInfoReq;
import io.oeid.mogakgo.common.base.CursorPaginationResult;
import io.oeid.mogakgo.domain.project_join_req.domain.entity.ProjectJoinRequest;
import io.oeid.mogakgo.domain.project_join_req.domain.entity.enums.RequestStatus;
import io.oeid.mogakgo.domain.project_join_req.presentation.projectJoinRequestRes;
import io.oeid.mogakgo.domain.user.presentation.dto.res.UserPreviewRes;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
Expand All @@ -24,21 +23,28 @@ public class ProjectJoinRequestRepositoryCustomImpl implements ProjectJoinReques
public CursorPaginationResult<projectJoinRequestRes> findByConditionWithPagination(
Long senderId, Long projectId, RequestStatus requestStatus, CursorPaginationInfoReq pageable
) {
List<projectJoinRequestRes> result = jpaQueryFactory.select(
Projections.constructor(
projectJoinRequestRes.class,
projectJoinRequest.id,
Projections.constructor(
UserPreviewRes.class,
projectJoinRequest.sender.id,
projectJoinRequest.sender.username,
projectJoinRequest.sender.avatarUrl
),
projectJoinRequest.requestStatus
)
)
.from(projectJoinRequest)
.join(projectJoinRequest.sender)
// List<projectJoinRequestRes> result = jpaQueryFactory.select(
// Projections.constructor(
// projectJoinRequestRes.class,
// projectJoinRequest.id,
// projectJoinRequest.sender,
// projectJoinRequest.requestStatus
// )
// )
// .from(projectJoinRequest)
// .join(projectJoinRequest.sender)
// .where(
// cursorIdCondition(pageable.getCursorId()),
// senderIdEq(senderId),
// projectIdEq(projectId),
// requestStatusEq(requestStatus)
// )
// .limit(pageable.getPageSize() + 1)
// .fetch();

List<ProjectJoinRequest> entities = jpaQueryFactory.selectFrom(projectJoinRequest)
.join(projectJoinRequest.sender).fetchJoin()
.leftJoin(projectJoinRequest.sender.achievement).fetchJoin()
.where(
cursorIdCondition(pageable.getCursorId()),
senderIdEq(senderId),
Expand All @@ -48,6 +54,14 @@ public CursorPaginationResult<projectJoinRequestRes> findByConditionWithPaginati
.limit(pageable.getPageSize() + 1)
.fetch();

List<projectJoinRequestRes> result = entities.stream().map(
projectJoinRequest -> new projectJoinRequestRes(
projectJoinRequest.getId(),
projectJoinRequest.getSender(),
projectJoinRequest.getRequestStatus()
)
).toList();

return CursorPaginationResult.fromDataWithExtraItemForNextCheck(result,
pageable.getPageSize());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.oeid.mogakgo.domain.project_join_req.presentation;

import io.oeid.mogakgo.domain.project_join_req.domain.entity.enums.RequestStatus;
import io.oeid.mogakgo.domain.user.presentation.dto.res.UserPreviewRes;
import io.oeid.mogakgo.domain.user.domain.User;
import io.oeid.mogakgo.domain.user.presentation.dto.res.UserPublicApiResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

Expand All @@ -12,15 +13,15 @@ public class projectJoinRequestRes {
@Schema(description = "프로젝트 요청 ID")
private Long id;
@Schema(description = "요청자 정보 미리보기")
private UserPreviewRes senderPreview;
private UserPublicApiResponse senderPreview;
@Schema(description = "요청 상태")
private RequestStatus requestStatus;

public projectJoinRequestRes(
Long id, UserPreviewRes senderPreview, RequestStatus requestStatus
Long id, User user, RequestStatus requestStatus
) {
this.id = id;
this.senderPreview = senderPreview;
this.senderPreview = UserPublicApiResponse.from(user);
this.requestStatus = requestStatus;
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/oeid/mogakgo/domain/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class User {
@Column(name = "signup_yn")
private Boolean signupYn;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "achievement_id")
private Achievement achievement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import io.oeid.mogakgo.common.swagger.template.UserSwagger;
import io.oeid.mogakgo.domain.user.application.UserService;
import io.oeid.mogakgo.domain.user.presentation.dto.req.UserSignUpApiRequest;
import io.oeid.mogakgo.domain.user.presentation.dto.res.UserPublicApiResponse;
import io.oeid.mogakgo.domain.user.presentation.dto.res.UserSignUpApiResponse;
import jakarta.annotation.Nullable;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -22,8 +23,14 @@ public class UserController implements UserSwagger {

private final UserService userService;

@GetMapping
public ResponseEntity<UserPublicApiResponse> userGetApi(@UserId Long userId) {
var response = userService.getUserProfile(userId);
return ResponseEntity.ok(UserPublicApiResponse.fromByUserProfile(response));
}

@PatchMapping("/sign")
public ResponseEntity<UserSignUpApiResponse> userSignUpApi(@UserId @Nullable Long userId,
public ResponseEntity<UserSignUpApiResponse> userSignUpApi(@UserId Long userId,
@RequestBody @Valid UserSignUpApiRequest apiRequest) {
var response = userService.userSignUp(apiRequest.toRequest(userId));
return ResponseEntity.ok(UserSignUpApiResponse.from(response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class UserSignUpApiRequest {
@NotBlank(message = "username은 필수입니다.")
private String username;

@Schema(description = "원하는 직군", example = "[\"BACKEND\", \"FRONTEND\"]", implementation = List.class, minLength = 1, maxLength = 3)
@Schema(description = "원하는 직군", example = "[\"BACKEND\", \"FRONTEND\"]", minLength = 1, maxLength = 3)
@Size(min = 1, max = 3, message = "wantedJobs는 1개 이상 3개 이하로 선택해야 합니다.")
private List<String> wantedJobs;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.oeid.mogakgo.domain.user.presentation.dto.res;

import io.oeid.mogakgo.domain.user.application.dto.res.UserProfileResponse;
import io.oeid.mogakgo.domain.user.domain.User;
import io.oeid.mogakgo.domain.user.domain.UserDevelopLanguageTag;
import io.oeid.mogakgo.domain.user.domain.UserWantedJobTag;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Schema(description = "회원 프로필 조회 응답")
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class UserPublicApiResponse {
@Schema(description = "회원 식별자", example = "1")
private final long id;
@Schema(description = "회원명", example = "거루")
private final String username;
@Schema(description = "깃허브 ID", example = "tidavid1")
private final String githubId;
@Schema(description = "아바타 URL", example = "https://avatars.githubusercontent.com/u/85854384?v=4")
private final String avatarUrl;
@Schema(description = "깃허브 URL", example = "https://github.com/tidavid1")
private final String githubUrl;
@Schema(description = "소개", example = "안녕하세요", nullable = true)
private final String bio;
@Schema(description = "잔디 비율", example = "0.5")
private final double jandiRate;
@Schema(description = "업적 제목", example = "이세계 개발자")
private final String achievementTitle;
@Schema(description = "개발 언어", example = "[\"JAVA\", \"KOTLIN\"]")
private final List<String> developLanguages;
@Schema(description = "원하는 직군", example = "[\"BACKEND\", \"FRONTEND\"]")
private final List<String> wantedJobs;

public static UserPublicApiResponse fromByUserProfile(UserProfileResponse response) {
return new UserPublicApiResponse(
response.getId(),
response.getUsername(),
response.getGithubId(),
response.getAvatarUrl(),
response.getGithubUrl(),
response.getBio(),
response.getJandiRate(),
response.getAchievementTitle(),
response.getDevelopLanguages().stream().map(Enum::name).toList(),
response.getWantedJobs().stream().map(Enum::name).toList()
);
}

public static UserPublicApiResponse from(User user) {
return new UserPublicApiResponse(
user.getId(),
user.getUsername(),
user.getGithubId(),
user.getAvatarUrl(),
user.getGithubUrl(),
user.getBio(),
user.getJandiRate(),
user.getAchievement() != null ? user.getAchievement().getTitle() : null,
user.getUserDevelopLanguageTags().stream()
.map(UserDevelopLanguageTag::getDevelopLanguage).map(Enum::name).toList(),
user.getUserWantedJobTags().stream()
.map(UserWantedJobTag::getWantedJob).map(Enum::name)
.toList()
);
}

}
Loading