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

merge: 9주차 작업 master에 반영 #77

Merged
merged 5 commits into from
Nov 1, 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 @@ -8,6 +8,7 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand Down Expand Up @@ -35,7 +36,7 @@ public ResponseEntity<SuccessResponse<Void>> updateComment(
@Parameter(description = "수정할 댓글 ID", required = true)
@PathVariable Long commentId,
@Parameter(description = "댓글 수정 정보", required = true)
@RequestBody CommentRequest commentRequest) {
@RequestBody @Valid CommentRequest commentRequest) {
Long memberId = memberDetails.getId();

commentService.updateComment(memberId, commentId, commentRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
Expand Down Expand Up @@ -309,7 +310,7 @@ public ResponseEntity<SuccessResponse<Void>> createComment(
@Parameter(description = "댓글을 작성할 일기 ID", required = true)
@PathVariable Long diaryId,
@Parameter(description = "댓글 작성 정보", required = true)
@RequestBody CommentRequest commentRequest) {
@RequestBody @Valid CommentRequest commentRequest) {
Long memberId = memberDetails.getId();

commentService.createComment(memberId, diaryId, commentRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public ResponseEntity<SuccessResponse> updateFiles(
@PathVariable Long diaryId,
@Parameter(description = "인증된 사용자 정보", hidden = true)
@AuthenticationPrincipal MemberDetails memberDetails,
@Parameter(description = "수정할 파일 목록", required = true)
@RequestPart List<MultipartFile> files
@Parameter(description = "수정할 파일 목록")
@RequestPart(required = false) List<MultipartFile> files
) {
fileService.updateFiles(diaryId, memberDetails.getId(), files);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import com.potatocake.everymoment.entity.Category;
import com.potatocake.everymoment.entity.Member;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import org.hibernate.validator.constraints.Length;

@Getter
public class CategoryCreateRequest {

@Length(max = 50)
@NotEmpty
@Size(max = 50, message = "카테고리명은 50자를 초과할 수 없습니다")
@NotEmpty(message = "카테고리명은 필수입니다")
private String categoryName;

public Category toEntity(Member member) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.potatocake.everymoment.dto.request;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Getter;

@Getter
public class CommentRequest {

@NotEmpty(message = "댓글 내용을 입력해 주세요.")
@NotBlank(message = "댓글 내용은 필수입니다")
@Size(max = 250, message = "댓글은 250자를 초과할 수 없습니다")
private String content;

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ public List<String> getCategories() {
: Collections.emptyList();
}

public boolean hasFilter() {
return (keyword != null && !keyword.isEmpty()) ||
(emoji != null && !emoji.isEmpty()) ||
(category != null && !category.isEmpty()) ||
date != null ||
from != null ||
until != null ||
isBookmark != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DiaryManualCreateRequest {
@Size(max = 50, message = "장소명은 50자를 초과할 수 없습니다")
private String locationName;

@Size(max = 200, message = "주소는 200자를 초과할 수 없습니다")
@Size(max = 250, message = "주소는 250자를 초과할 수 없습니다")
private String address;

private boolean isBookmark;
Expand All @@ -24,7 +24,7 @@ public class DiaryManualCreateRequest {
@Size(max = 10, message = "이모지는 10자를 초과할 수 없습니다")
private String emoji;

@Size(max = 5000, message = "일기 내용은 5000자를 초과할 수 없습니다")
@Size(max = 15000, message = "일기 내용은 15,000자를 초과할 수 없습니다")
private String content;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.potatocake.everymoment.dto.request;

import com.potatocake.everymoment.dto.LocationPoint;
import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.Getter;
Expand All @@ -25,7 +24,7 @@ public class DiaryPatchRequest {
@Size(max = 10, message = "이모지는 10자를 초과할 수 없습니다")
private String emoji;

@Size(max = 5000, message = "일기 내용은 5000자를 초과할 수 없습니다")
@Size(max = 15000, message = "일기 내용은 15,000자를 초과할 수 없습니다")
private String content;

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.potatocake.everymoment.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Getter;

@Getter
public class FcmTokenRequest {

@NotBlank(message = "FCM 토큰은 필수입니다.")
@Size(max = 512, message = "FCM 토큰은 512자를 넘을 수 없습니다.")
private String fcmToken;

@NotBlank(message = "디바이스 ID는 필수입니다.")
@Size(max = 512, message = "디바이스 ID는 512자를 넘을 수 없습니다.")
private String deviceId;

}
4 changes: 3 additions & 1 deletion src/main/java/com/potatocake/everymoment/entity/Comment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.potatocake.everymoment.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
Expand All @@ -19,7 +20,7 @@
@AllArgsConstructor
@Getter
@Builder
public class Comment extends BaseTimeEntity{
public class Comment extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -33,6 +34,7 @@ public class Comment extends BaseTimeEntity{
private Diary diary;

@Lob
@Column(nullable = false, columnDefinition = "TEXT")
private String content;

public void updateContent(String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -27,11 +26,10 @@ public class DeviceToken extends BaseTimeEntity {
@JoinColumn(nullable = false)
private Member member;

@Column(nullable = false)
@Column(length = 512, nullable = false)
private String fcmToken;

@Column(nullable = false)
@Lob
@Column(length = 512, nullable = false)
private String deviceId;

@Builder
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/potatocake/everymoment/entity/Diary.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Diary extends BaseTimeEntity {
@JoinColumn(nullable = false)
private Member member;

@Lob
@Column(columnDefinition = "TEXT")
private String content;

@Column(nullable = false)
Expand All @@ -43,7 +43,7 @@ public class Diary extends BaseTimeEntity {
@Column(length = 50, nullable = false)
private String locationName;

@Column(length = 50, nullable = false)
@Column(length = 250, nullable = false)
private String address;

@Lob
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/potatocake/everymoment/entity/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -25,7 +24,7 @@ public class File extends BaseTimeEntity {
@ManyToOne(fetch = FetchType.LAZY)
private Diary diary;

@Lob
@Column(length = 2083, nullable = false)
private String imageUrl;

@Column(name = "\"order\"")
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/potatocake/everymoment/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -35,7 +34,7 @@ public class Member extends BaseTimeEntity {
@Column(nullable = false, length = 50)
private String nickname;

@Lob
@Column(length = 2083, nullable = false)
private String profileImageUrl;

@Column(nullable = false)
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/com/potatocake/everymoment/service/DiaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.potatocake.everymoment.repository.DiaryRepository;
import com.potatocake.everymoment.repository.FileRepository;
import com.potatocake.everymoment.repository.MemberRepository;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -134,15 +135,33 @@ public MyDiariesResponse getMyDiaries(Long memberId, DiaryFilterRequest diaryFil
List<String> categories = diaryFilterRequest.getCategories();
List<String> emojis = diaryFilterRequest.getEmojis();

Specification<Diary> spec = DiarySpecification.filterDiaries(
diaryFilterRequest.getKeyword(),
emojis,
categories,
diaryFilterRequest.getDate(),
diaryFilterRequest.getFrom(),
diaryFilterRequest.getUntil(),
diaryFilterRequest.getIsBookmark())
.and((root, query, builder) -> builder.equal(root.get("member"), currentMember));
Specification<Diary> spec;

if(!diaryFilterRequest.hasFilter()){
LocalDate today = LocalDate.now();

spec = DiarySpecification.filterDiaries(
diaryFilterRequest.getKeyword(),
emojis,
categories,
today,
diaryFilterRequest.getFrom(),
diaryFilterRequest.getUntil(),
diaryFilterRequest.getIsBookmark())
.and((root, query, builder) -> builder.equal(root.get("member"), currentMember));
}

else{
spec = DiarySpecification.filterDiaries(
diaryFilterRequest.getKeyword(),
emojis,
categories,
diaryFilterRequest.getDate(),
diaryFilterRequest.getFrom(),
diaryFilterRequest.getUntil(),
diaryFilterRequest.getIsBookmark())
.and((root, query, builder) -> builder.equal(root.get("member"), currentMember));
}

diaryPage = diaryRepository.findAll(spec,
PageRequest.of(diaryFilterRequest.getKey(), diaryFilterRequest.getSize()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static Specification<Diary> filterDiaries(
if (keyword != null) {
predicate = builder.and(predicate, builder.like(root.get("content"), "%" + keyword + "%"));
}

if (emojis != null && !emojis.isEmpty()) {
predicate = builder.and(predicate, root.get("emoji").in(emojis));
}
Expand All @@ -35,13 +36,15 @@ public static Specification<Diary> filterDiaries(
predicate = builder.and(predicate, categoryJoin.get("categoryName").in(categories));
}

LocalDate filterDate = (date != null) ? date : LocalDate.now();
predicate = builder.and(predicate, builder.equal(root.get("createAt").as(LocalDate.class), filterDate));
if(date != null){
predicate = builder.and(predicate, builder.equal(root.get("createAt").as(LocalDate.class), date));
}

if (from != null && until != null) {
predicate = builder.and(predicate,
builder.between(root.get("createAt"), from, until));
builder.between(root.get("createAt"), from, until.plusDays(1)));
}

if (isBookmark != null) {
predicate = builder.and(predicate, builder.equal(root.get("isBookmark"), isBookmark));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public void updateFiles(Long diaryId, Long memberId, List<MultipartFile> files)

fileRepository.deleteByDiary(diary);

uploadFiles(diaryId, memberId, files);
if (files != null && !files.isEmpty()) {
uploadFiles(diaryId, memberId, files);
}
}

}
Loading