Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…Codiary into feature/#46-myDiary
  • Loading branch information
yumzen committed Aug 2, 2024
2 parents 8484733 + 913618f commit 10a428d
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static Post toPost(PostRequestDTO.CreatePostRequestDTO request) {
// List<Categories> categories = request.getPostCategory().stream()
// .map(Categories::new) // Assuming Categories has a constructor that accepts String
// .collect(Collectors.toList());

return Post.builder()
.postTitle(request.getPostTitle())
.postBody(request.getPostBody())
Expand All @@ -29,7 +28,6 @@ public static PostResponseDTO.CreatePostResultDTO toCreateResultDTO(Post post) {
// List<String> postCategories = post.getCategoriesList().stream()
// .map(Categories::getName)
// .collect(Collectors.toList());

return PostResponseDTO.CreatePostResultDTO.builder()
.postId(post.getPostId())
.memberId(post.getMember().getMemberId())
Expand Down Expand Up @@ -65,6 +63,7 @@ public static PostResponseDTO.UpdatePostResultDTO toUpdatePostResultDTO(Post pos
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.build();
}

Expand All @@ -87,6 +86,7 @@ public static PostResponseDTO.PostPreviewDTO toPostPreviewDTO(Post post) {
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.build();
Expand Down Expand Up @@ -127,6 +127,7 @@ public static PostResponseDTO.MemberPostPreviewDTO toMemberPostPreviewDTO(Post p
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.build();
Expand Down Expand Up @@ -167,6 +168,7 @@ public static PostResponseDTO.TeamPostPreviewDTO toTeamPostPreviewDTO(Post post)
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.build();
Expand Down Expand Up @@ -208,6 +210,7 @@ public static PostResponseDTO.MemberPostInProjectPreviewDTO toMemberPostInProjec
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.build();
Expand Down Expand Up @@ -248,6 +251,7 @@ public static PostResponseDTO.TeamPostInProjectPreviewDTO toTeamPostInProjectPre
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.build();
Expand Down Expand Up @@ -288,6 +292,7 @@ public static PostResponseDTO.MemberPostInTeamPreviewDTO toMemberPostInTeamPrevi
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.build();
Expand Down Expand Up @@ -330,6 +335,7 @@ public static PostResponseDTO.PostAdjacentDTO.PostAdjacentPreviewDTO toPostAdjac
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.createdAt(post.getCreatedAt())
.updatedAt(post.getUpdatedAt())
.build();
Expand Down Expand Up @@ -363,6 +369,7 @@ public static PostResponseDTO.UpdatePostResultDTO toSetPostCategoriesResultDTO(P
.map(author -> author.getMember().getMemberId())
.collect(Collectors.toSet()))
.postAccess(post.getPostAccess())
.postFileList(PostFileConverter.toPostFileListDTO(post.getPostFileList()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ public enum Gender {Male, Female}
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
private List<MemberCategory> memberCategoryList = new ArrayList<>();

@OneToOne(mappedBy = "member", cascade = CascadeType.ALL)
private MemberImage image;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.codiary.backend.global.domain.entity;

import jakarta.persistence.*;
import lombok.*;

@Getter
@Setter
@Builder
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class MemberImage {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_image_id", nullable = false, columnDefinition = "bigint")
private Long memberImageId;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@Column(name = "image_url", nullable = false, columnDefinition = "varchar(500)")
private String imageUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.codiary.backend.global.repository;

import com.codiary.backend.global.domain.entity.MemberImage;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberImageRepository extends JpaRepository<MemberImage, Long> {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codiary.backend.global.service.MemberService;

import com.codiary.backend.global.apiPayload.ApiResponse;
import com.codiary.backend.global.domain.entity.Member;
import com.codiary.backend.global.domain.entity.mapping.MemberCategory;
import com.codiary.backend.global.web.dto.Member.MemberRequestDTO;
import com.codiary.backend.global.web.dto.Member.MemberResponseDTO;
Expand All @@ -16,4 +17,8 @@ public interface MemberCommandService {
// 회원별 관심 카테고리탭 리스트 조회
List<MemberCategory> getMemberCategoryList(Long memberId);

public Member getRequester();

public ApiResponse<MemberResponseDTO.MemberImageDTO> setProfileImage(Member member, MemberRequestDTO.MemberProfileImageRequestDTO request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
import com.codiary.backend.global.apiPayload.code.status.SuccessStatus;
import com.codiary.backend.global.apiPayload.exception.GeneralException;
import com.codiary.backend.global.apiPayload.exception.handler.MemberHandler;
import com.codiary.backend.global.converter.PostFileConverter;
import com.codiary.backend.global.domain.entity.Member;
import com.codiary.backend.global.domain.entity.MemberImage;
import com.codiary.backend.global.domain.entity.PostFile;
import com.codiary.backend.global.domain.entity.Uuid;
import com.codiary.backend.global.domain.entity.mapping.MemberCategory;
import com.codiary.backend.global.jwt.JwtTokenProvider;
import com.codiary.backend.global.jwt.SecurityUtil;
import com.codiary.backend.global.jwt.TokenInfo;
import com.codiary.backend.global.repository.MemberCategoryRepository;
import com.codiary.backend.global.repository.MemberImageRepository;
import com.codiary.backend.global.repository.MemberRepository;
import com.codiary.backend.global.repository.UuidRepository;
import com.codiary.backend.global.s3.AmazonS3Manager;
import com.codiary.backend.global.web.dto.Member.MemberRequestDTO;
import com.codiary.backend.global.web.dto.Member.MemberResponseDTO;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,6 +30,7 @@
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
@RequiredArgsConstructor
Expand All @@ -33,7 +41,9 @@ public class MemberCommandServiceImpl implements MemberCommandService {
private final JwtTokenProvider jwtTokenProvider;
private final AuthenticationManagerBuilder authenticationManagerBuilder;
private final MemberCategoryRepository memberCategoryRepository;

private final UuidRepository uuidRepository;
private final AmazonS3Manager s3Manager;
private final MemberImageRepository memberImageRepository;


@Override
Expand Down Expand Up @@ -84,6 +94,7 @@ public ApiResponse<MemberResponseDTO.MemberTokenResponseDTO> login(MemberRequest
}
}

@Override
public Member getRequester() {
String userEmail = SecurityUtil.getCurrentMemberEmail();
System.out.println(userEmail);
Expand All @@ -107,4 +118,20 @@ public List<MemberCategory> getMemberCategoryList(Long memberId) {

}

@Override
public ApiResponse<MemberResponseDTO.MemberImageDTO> setProfileImage(Member member, MemberRequestDTO.MemberProfileImageRequestDTO request) {
String uuid = UUID.randomUUID().toString();
Uuid savedUuid = uuidRepository.save(Uuid.builder().uuid(uuid).build());
String fileUrl = s3Manager.uploadFile(s3Manager.generatePostName(savedUuid), request.getImage());

MemberImage memberImage = MemberImage.builder()
.imageUrl(fileUrl)
.member(member)
.build();

MemberImage savedImage = memberImageRepository.save(memberImage);
MemberResponseDTO.MemberImageDTO response = new MemberResponseDTO.MemberImageDTO(savedImage.getImageUrl());
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@
@RequestMapping("/members")
public class MemberController {

//private final MemberCommandService memberCommandService;
// Impl에 직접 연결하지 말고
// MemberCommandServiceImpl에 MemberCommandService를
// 상속시켜서 위 코드처럼 되도록 수정해주세요
private final MemberCommandService memberCommandService;
private final MemberCommandServiceImpl memberCommandServiceImpl;
private final FollowService followService;
private final MemberQueryService memberQueryService;

Expand All @@ -73,7 +68,7 @@ public ApiResponse<MemberResponseDTO.MemberTokenResponseDTO> login(@Valid @Reque
)
@PostMapping("/follow/{id}")
public ApiResponse<FollowResponseDto> follow(@PathVariable("id") Long toId) {
Member member = memberCommandServiceImpl.getRequester();
Member member = memberCommandService.getRequester();
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, followService.follow(toId, member));
}

Expand All @@ -83,7 +78,7 @@ public ApiResponse<FollowResponseDto> follow(@PathVariable("id") Long toId) {
)
@GetMapping("/follow/{id}")
public ApiResponse<Boolean> isFollowing(@PathVariable("id") Long toId) {
Member member = memberCommandServiceImpl.getRequester();
Member member = memberCommandService.getRequester();
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, followService.isFollowing(toId, member));
}

Expand All @@ -93,7 +88,7 @@ public ApiResponse<Boolean> isFollowing(@PathVariable("id") Long toId) {
)
@GetMapping("/following")
public ApiResponse<List<MemberSumResponseDto>> getFollowings() {
Member member = memberCommandServiceImpl.getRequester();
Member member = memberCommandService.getRequester();
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, followService.getFollowings(member));
}

Expand All @@ -103,14 +98,14 @@ public ApiResponse<List<MemberSumResponseDto>> getFollowings() {
)
@GetMapping("/follower")
public ApiResponse<List<MemberSumResponseDto>> getFollowers() {
Member member = memberCommandServiceImpl.getRequester();
Member member = memberCommandService.getRequester();
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, followService.getFollowers(member));
}


@GetMapping("/posts")
public ApiResponse<PostResponseDTO.MemberPostPreviewListDTO> getMyDiaries(@PageableDefault(size=6) Pageable pageable){
Member member = memberCommandServiceImpl.getRequester();
Member member = memberCommandService.getRequester();
Page<Post> posts = memberQueryService.getMyPosts(member, pageable);
return ApiResponse.onSuccess(SuccessStatus.MEMBER_OK, PostConverter.toMemberPostPreviewListDTO(posts));
}
Expand Down Expand Up @@ -168,4 +163,13 @@ public ApiResponse<MemberResponseDTO.MemberCategoryListDTO> getMemberCategoryLis

}

@PatchMapping(path = "/profile-image", consumes = "multipart/form-data")
@Operation(
summary = "프로필 사진 설정"
)
public ApiResponse<MemberResponseDTO.MemberImageDTO> setProfileImage(@ModelAttribute MemberRequestDTO.MemberProfileImageRequestDTO request) {
Member member = memberCommandService.getRequester();

return memberCommandService.setProfileImage(member, request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import com.codiary.backend.global.apiPayload.exception.handler.MemberHandler;
import com.codiary.backend.global.domain.entity.Member;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;

Expand Down Expand Up @@ -53,4 +56,12 @@ public UsernamePasswordAuthenticationToken toAuthentication() {
}
}

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public static class MemberProfileImageRequestDTO {
private MultipartFile image;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.codiary.backend.global.jwt.TokenInfo;
import com.codiary.backend.global.web.dto.Bookmark.BookmarkResponseDTO;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -73,4 +74,13 @@ public static class MemberCategoryDTO {
LocalDateTime createdAt;
}

@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class MemberImageDTO {
String url;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ public static class PostPreviewDTO { // Post 조회
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
PostAccess postAccess;
PostFileResponseDTO.PostFileListDTO postFileList;
LocalDateTime createdAt;
LocalDateTime updatedAt;
PostAccess postAccess;
}

@Getter
Expand Down Expand Up @@ -97,6 +98,7 @@ public static class MemberPostPreviewDTO { // 저자별 Post 조회
String postCategory;
Set<Long> coauthorIds;
PostAccess postAccess;
PostFileResponseDTO.PostFileListDTO postFileList;
LocalDateTime createdAt;
LocalDateTime updatedAt;
}
Expand Down Expand Up @@ -130,6 +132,7 @@ public static class TeamPostPreviewDTO { // 팀별 Post 조회
String postCategory;
Set<Long> coauthorIds;
PostAccess postAccess;
PostFileResponseDTO.PostFileListDTO postFileList;
LocalDateTime createdAt;
LocalDateTime updatedAt;
}
Expand Down Expand Up @@ -162,6 +165,7 @@ public static class MemberPostInProjectPreviewDTO { // 프로젝트별 저자의
String postCategory;
Set<Long> coauthorIds;
PostAccess postAccess;
PostFileResponseDTO.PostFileListDTO postFileList;
LocalDateTime createdAt;
LocalDateTime updatedAt;
}
Expand Down Expand Up @@ -194,6 +198,7 @@ public static class TeamPostInProjectPreviewDTO { // 프로젝트별 팀의 Post
String postCategory;
Set<Long> coauthorIds;
PostAccess postAccess;
PostFileResponseDTO.PostFileListDTO postFileList;
LocalDateTime createdAt;
LocalDateTime updatedAt;
}
Expand Down Expand Up @@ -226,6 +231,7 @@ public static class MemberPostInTeamPreviewDTO { // 팀별 멤버의 Post 조회
String postCategory;
Set<Long> coauthorIds;
PostAccess postAccess;
PostFileResponseDTO.PostFileListDTO postFileList;
LocalDateTime createdAt;
LocalDateTime updatedAt;
}
Expand Down Expand Up @@ -268,9 +274,10 @@ public static class PostAdjacentPreviewDTO {
Boolean postStatus;
String postCategory;
Set<Long> coauthorIds;
PostAccess postAccess;
PostFileResponseDTO.PostFileListDTO postFileList;
LocalDateTime createdAt;
LocalDateTime updatedAt;
PostAccess postAccess;
}
}

Expand Down

0 comments on commit 10a428d

Please sign in to comment.