forked from Kernel360/f1-Yigil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create an api for access my page data
- Loading branch information
1 parent
23073b4
commit de3f288
Showing
7 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/kr/co/yigil/global/exception/BadRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.co.yigil.global.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BadRequestException extends RuntimeException { | ||
|
||
private final int code; | ||
private final String message; | ||
|
||
public BadRequestException(final ExceptionCode exceptionCode) { | ||
this.code = exceptionCode.getCode(); | ||
this.message = exceptionCode.getMessage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 20 additions & 1 deletion
21
backend/src/main/java/kr/co/yigil/member/application/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,34 @@ | ||
package kr.co.yigil.member.application; | ||
|
||
import static kr.co.yigil.global.exception.ExceptionCode.NOT_FOUND_MEMBER_ID; | ||
|
||
import java.util.List; | ||
import kr.co.yigil.global.exception.BadRequestException; | ||
import kr.co.yigil.member.domain.Member; | ||
import kr.co.yigil.member.domain.repository.MemberRepository; | ||
import kr.co.yigil.member.dto.request.MemberUpdateRequest; | ||
import kr.co.yigil.member.dto.response.MemberInfoResponse; | ||
import kr.co.yigil.member.dto.response.MemberUpdateResponse; | ||
import kr.co.yigil.post.domain.Post; | ||
import kr.co.yigil.post.domain.repository.PostRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
|
||
public MemberUpdateResponse updateMemberInfo(Long memberId, MemberUpdateRequest request) { | ||
private final MemberRepository memberRepository; | ||
private final PostRepository postRepository; | ||
|
||
public MemberInfoResponse getMemberInfo(final Long memberId) { | ||
Member member = memberRepository.findById(memberId) | ||
.orElseThrow(() -> new BadRequestException(NOT_FOUND_MEMBER_ID)); | ||
List<Post> postList = postRepository.findAllByMember(member); | ||
return MemberInfoResponse.from(member, postList); | ||
} | ||
|
||
public MemberUpdateResponse updateMemberInfo(final Long memberId, MemberUpdateRequest request) { | ||
return new MemberUpdateResponse(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/kr/co/yigil/member/dto/response/MemberInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package kr.co.yigil.member.dto.response; | ||
|
||
import java.util.List; | ||
import kr.co.yigil.member.domain.Member; | ||
import kr.co.yigil.post.domain.Post; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class MemberInfoResponse { | ||
|
||
private String nickname; | ||
|
||
private String profileImageUrl; | ||
|
||
private List<Post> postList; | ||
|
||
public static MemberInfoResponse from(final Member member, final List<Post> postList) { | ||
return new MemberInfoResponse(member.getNickname(), member.getProfileImageUrl(), postList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/kr/co/yigil/post/domain/repository/PostRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kr.co.yigil.post.domain.repository; | ||
|
||
import java.util.List; | ||
import kr.co.yigil.member.domain.Member; | ||
import kr.co.yigil.post.domain.Post; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostRepository extends JpaRepository <Post, Long> { | ||
|
||
List<Post> findAllByMember(Member member); | ||
} |