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

feat : 사용자 닉네임으로 마이 페이지 조회 기능 구현 #275

Merged
merged 3 commits into from
Oct 12, 2023
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
@@ -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 @@ -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
@@ -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
Expand Up @@ -13,6 +13,7 @@
import com.graphy.backend.domain.project.dto.request.UpdateProjectRequest;
import com.graphy.backend.domain.project.dto.response.*;
import com.graphy.backend.domain.project.repository.ProjectRepository;
import com.graphy.backend.domain.project.repository.TagRepository;
import com.graphy.backend.global.chatgpt.dto.GptCompletionDto.GptCompletionRequest;
import com.graphy.backend.global.chatgpt.dto.GptCompletionDto.GptCompletionResponse;
import com.graphy.backend.global.chatgpt.service.GPTChatRestService;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class ProjectService {
private final CommentService commentService;
private final TagService tagService;
private final GPTChatRestService gptChatRestService;
private final TagRepository tagRepository;

// @PostConstruct
// public void initTag() throws IOException {
Expand Down Expand Up @@ -124,6 +126,12 @@ public GetMyPageResponse myPage(Member member) {
return GetMyPageResponse.of(member, projectInfoList);
}

public GetMyPageResponse myPageByNickname(String nickname) {
Member member = memberService.findMemberByNickname(nickname);
List<GetProjectInfoResponse> projectInfoList = this.findProjectInfoList(member.getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미처 못 봤었는데 이것도 페이징이 필요할 것 같은 생각이 드네요..! 급한 건이라 들어서 일단 approve 하겠습니다

return GetMyPageResponse.of(member, projectInfoList);
}


public Project getProjectById(Long id) {
return projectRepository.findById(id).orElseThrow(() -> new EmptyResultException(ErrorCode.PROJECT_DELETED_OR_NOT_EXIST));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
"/api/v1/auth/signin",
"/api/v1/auth/logout",
"/api/v1/projects",
"/api/v1/members/**",
"/swagger-ui/**").permitAll()
.antMatchers(HttpMethod.GET, "/api/v1/projects/{projectId}").permitAll()
.antMatchers(HttpMethod.GET, "/api/v1/comments/{commentId}").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import java.util.List;

import static org.hamcrest.Matchers.hasSize;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down Expand Up @@ -133,8 +134,8 @@ void getMyPageTest() throws Exception {
.followerCount(member1.getFollowerCount())
.followingCount(member1.getFollowingCount())
.getProjectInfoResponseList(Arrays.asList(
GetProjectInfoResponse.builder().id(1L).projectName("project1").description("description1").build(),
GetProjectInfoResponse.builder().id(2L).projectName("project2").description("description2").build()
GetProjectInfoResponse.builder().id(1L).projectName("project1").content("content1").build(),
GetProjectInfoResponse.builder().id(2L).projectName("project2").content("content2").build()
))
.build();

Expand All @@ -156,11 +157,11 @@ void getMyPageTest() throws Exception {

.andExpect(jsonPath("$.data.getProjectInfoResponseList[0].id").value(1))
.andExpect(jsonPath("$.data.getProjectInfoResponseList[0].projectName").value("project1"))
.andExpect(jsonPath("$.data.getProjectInfoResponseList[0].description").value("description1"))
.andExpect(jsonPath("$.data.getProjectInfoResponseList[0].content").value("content1"))

.andExpect(jsonPath("$.data.getProjectInfoResponseList[1].id").value(2))
.andExpect(jsonPath("$.data.getProjectInfoResponseList[1].projectName").value("project2"))
.andExpect(jsonPath("$.data.getProjectInfoResponseList[1].description").value("description2"))
.andExpect(jsonPath("$.data.getProjectInfoResponseList[1].content").value("content2"))

.andDo(document("members/myPage/find/success",
responseFields(
Expand All @@ -176,7 +177,7 @@ void getMyPageTest() throws Exception {

fieldWithPath("data.getProjectInfoResponseList[].id").description("프로젝트 ID"),
fieldWithPath("data.getProjectInfoResponseList[].projectName").description("프로젝트 이름"),
fieldWithPath("data.getProjectInfoResponseList[].description").description("프로젝트 설명")
fieldWithPath("data.getProjectInfoResponseList[].content").description("프로젝트 소개")
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void myPageTest() {
.projectName("project1")
.description("description1")
.thumbNail("thumb")
.content("content")
.content("content1")
.build();

Project project2 = Project.builder()
Expand All @@ -211,19 +211,19 @@ void myPageTest() {
.projectName("project2")
.description("description2")
.thumbNail("thumb")
.content("content")
.content("content2")
.build();

GetProjectInfoResponse response1 = GetProjectInfoResponse.builder()
.id(1L)
.projectName("project1")
.description("description1")
.content("content1")
.build();

GetProjectInfoResponse response2 = GetProjectInfoResponse.builder()
.id(2L)
.projectName("project2")
.description("description2")
.content("content2")
.build();

List<GetProjectInfoResponse> responseList = Arrays.asList(response1, response2);
Expand Down
Loading