Skip to content

Commit

Permalink
Merge branch 'develop' into J01-2-be-북마크-작업
Browse files Browse the repository at this point in the history
  • Loading branch information
SSUHYUNKIM authored Jan 3, 2025
2 parents f4d5fab + cdacc40 commit 29f2edc
Show file tree
Hide file tree
Showing 143 changed files with 3,697 additions and 235 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/ject/componote/domain/announcement/model/Title.java

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public MemberSignupResponse signup(final MemberSignupRequest request) {
}

final Member member = memberRepository.save(request.toMember());
fileService.moveImage(member.getProfileImage().getImage()); // 맘에 안듬...
fileService.moveImage(member.getProfileImage());
return MemberSignupResponse.from(member);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void updateProfileImage(final AuthPrincipal authPrincipal, final MemberPr
return;
}

fileService.moveImage(profileImage.getImage());
fileService.moveImage(profileImage);
member.updateProfileImage(profileImage);
memberRepository.save(member);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public record MemberSummaryResponse(String nickname, String profileImageUrl) {
public static MemberSummaryResponse from(MemberSummaryDao memberSummaryDao) {
return new MemberSummaryResponse(
memberSummaryDao.nickname().getValue(),
memberSummaryDao.profileImage().getImage().toUrl()
memberSummaryDao.profileImage().toUrl()
);
}
}
16 changes: 6 additions & 10 deletions src/main/java/ject/componote/domain/auth/model/ProfileImage.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package ject.componote.domain.auth.model;

import ject.componote.domain.auth.error.InvalidProfileImageExtensionException;
import ject.componote.domain.common.model.BaseImage;
import ject.componote.domain.common.model.AbstractImage;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;

@EqualsAndHashCode
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
public class ProfileImage {
public class ProfileImage extends AbstractImage {
private static final List<String> ALLOWED_IMAGE_EXTENSIONS = Arrays.asList("jpg", "jpeg", "png");
private static final ProfileImage DEFAULT_PROFILE_IMAGE = ProfileImage.from("/profiles/default-profile-image.png");

private final BaseImage image;

private ProfileImage(final BaseImage image) {
this.image = image;
public ProfileImage(final String objectKey) {
super(objectKey);
}

public static ProfileImage from(final String objectKey) {
Expand All @@ -33,6 +29,6 @@ public static ProfileImage from(final String objectKey) {
throw new InvalidProfileImageExtensionException(extension);
}

return new ProfileImage(BaseImage.from(objectKey));
return new ProfileImage(objectKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
public class ProfileImageConverter implements AttributeConverter<ProfileImage, String> {
@Override
public String convertToDatabaseColumn(final ProfileImage attribute) {
return attribute.getImage()
.getObjectKey();
return attribute.getObjectKey();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ject.componote.domain.bookmark.dao;

import ject.componote.domain.bookmark.domain.Bookmark;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BookmarkRepository extends JpaRepository<Bookmark, Long> {
boolean existsByComponentIdAndMemberId(final Long componentId, final Long memberId);
}
103 changes: 101 additions & 2 deletions src/main/java/ject/componote/domain/comment/api/CommentController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,111 @@
package ject.componote.domain.comment.api;

import jakarta.validation.Valid;
import ject.componote.domain.auth.model.AuthPrincipal;
import ject.componote.domain.auth.model.Authenticated;
import ject.componote.domain.auth.model.User;
import ject.componote.domain.comment.application.CommentService;
import ject.componote.domain.comment.dto.create.request.CommentCreateRequest;
import ject.componote.domain.comment.dto.create.response.CommentCreateResponse;
import ject.componote.domain.comment.dto.find.response.CommentFindByComponentResponse;
import ject.componote.domain.comment.dto.find.response.CommentFindByMemberResponse;
import ject.componote.domain.comment.dto.update.request.CommentUpdateRequest;
import ject.componote.domain.common.dto.response.PageResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/comments")
@RequiredArgsConstructor
@RestController
public class CommentController {
private static final int DEFAULT_MEMBER_COMMENT_PAGE_SIZE = 8;
private static final int DEFAULT_COMPONENT_COMMENT_PAGE_SIZE = 5;
private static final int DEFAULT_REPLY_PAGE_SIZE = 5;

private final CommentService commentService;

@PostMapping("/comments")
@User
public ResponseEntity<?> create(
@Authenticated final AuthPrincipal authPrincipal,
@RequestBody @Valid final CommentCreateRequest commentCreateRequest
) {
final CommentCreateResponse commentCreateResponse = commentService.create(authPrincipal, commentCreateRequest);
return ResponseEntity.ok(commentCreateResponse);
}

@GetMapping("/members/comments")
@User
public ResponseEntity<PageResponse<CommentFindByMemberResponse>> getCommentsByMemberId(
@Authenticated final AuthPrincipal authPrincipal,
@PageableDefault(size = DEFAULT_MEMBER_COMMENT_PAGE_SIZE) final Pageable pageable
) {
final PageResponse<CommentFindByMemberResponse> pageResponse = commentService.getCommentsByMemberId(authPrincipal, pageable);
return ResponseEntity.ok(pageResponse);
}

@GetMapping("/components/{componentId}/comments")
public ResponseEntity<PageResponse<CommentFindByComponentResponse>> getCommentsByComponentId(
@Authenticated final AuthPrincipal authPrincipal,
@PathVariable("componentId") final Long componentId,
@PageableDefault(size = DEFAULT_COMPONENT_COMMENT_PAGE_SIZE) final Pageable pageable
) {
final PageResponse<CommentFindByComponentResponse> pageResponse = commentService.getCommentsByComponentId(authPrincipal, componentId, pageable);
return ResponseEntity.ok(pageResponse);
}

@GetMapping("/comments/{parentId}/replies")
public ResponseEntity<?> getRepliesByCommentId(
@Authenticated final AuthPrincipal authPrincipal,
@PathVariable("parentId") final Long parentId,
@PageableDefault(size = DEFAULT_REPLY_PAGE_SIZE) final Pageable pageable
) {
final PageResponse<?> pageResponse = commentService.getRepliesByComponentId(authPrincipal, parentId, pageable);
return ResponseEntity.ok(pageResponse);
}

@PutMapping("/comments/{commentId}")
@User
public ResponseEntity<Void> update(@Authenticated final AuthPrincipal authPrincipal,
@PathVariable("commentId") final Long commentId,
@RequestBody @Valid final CommentUpdateRequest commentUpdateRequest) {
commentService.update(authPrincipal, commentId, commentUpdateRequest);
return ResponseEntity.noContent()
.build();
}

@PostMapping("/comments/{commentId}/likes")
@User
public ResponseEntity<Void> likeComment(@Authenticated final AuthPrincipal authPrincipal,
@PathVariable("commentId") final Long commentId) {
commentService.likeComment(authPrincipal, commentId);
return ResponseEntity.noContent()
.build();
}

@DeleteMapping("/comments/{commentId}/likes")
@User
public ResponseEntity<Void> unlikeComment(@Authenticated final AuthPrincipal authPrincipal,
@PathVariable("commentId") final Long commentId) {
commentService.unlikeComment(authPrincipal, commentId);
return ResponseEntity.noContent()
.build();
}

@DeleteMapping("/comments/{commentId}")
@User
public ResponseEntity<Void> delete(@Authenticated final AuthPrincipal authPrincipal,
@PathVariable("commentId") final Long commentId) {
commentService.delete(authPrincipal, commentId);
return ResponseEntity.noContent()
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ject.componote.domain.comment.application;

import ject.componote.domain.comment.domain.Comment;
import ject.componote.domain.comment.dto.create.request.CommentCreateRequest;
import ject.componote.domain.comment.error.InvalidCommentCreateStrategyException;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.function.Predicate;

@RequiredArgsConstructor
public enum CommentCreationStrategy {
GENERAL_WITHOUT_IMAGE(
request -> request.parentId() == null && request.imageObjectKey() == null,
(request, memberId) ->
Comment.createWithoutImage(request.componentId(), memberId, request.content())
),
GENERAL_WITH_IMAGE(
request -> request.parentId() == null && request.imageObjectKey() != null,
(request, memberId) ->
Comment.createWithImage(request.componentId(), memberId, request.content(), request.imageObjectKey())
),
REPLY_WITHOUT_IMAGE(
request -> request.parentId() != null && request.imageObjectKey() == null,
(request, memberId) ->
Comment.createReplyWithoutImage(request.componentId(), memberId, request.parentId(), request.content())
),
REPLY_WITH_IMAGE(
request -> request.parentId() != null && request.imageObjectKey() != null,
(request, memberId) ->
Comment.createReplyWithImage(request.componentId(), memberId, request.parentId(), request.content(), request.imageObjectKey())
);

private final Predicate<CommentCreateRequest> condition;
private final CommentCreationFunction creationFunction;

public static Comment createBy(final CommentCreateRequest request, final Long memberId) {
return Arrays.stream(values())
.filter(type -> type.condition.test(request))
.findFirst()
.orElseThrow(InvalidCommentCreateStrategyException::new)
.creationFunction.create(request, memberId);
}

@FunctionalInterface
private interface CommentCreationFunction {
Comment create(final CommentCreateRequest request, final Long memberId);
}
}
Loading

0 comments on commit 29f2edc

Please sign in to comment.