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

[#46] FIX : 댓글 오류 수정 #47

Merged
merged 3 commits into from
Aug 21, 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
Expand Up @@ -3,12 +3,16 @@
import static com.fasterxml.jackson.annotation.JsonFormat.*;

import java.time.LocalDateTime;
import java.util.List;

import com.clover.habbittracker.domain.emoji.dto.EmojiResponse;
import com.fasterxml.jackson.annotation.JsonFormat;

public record CommentResponse(
Long id,
String content,

List<EmojiResponse> emojis,
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
LocalDateTime createDate,
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public interface CommentMapper {
@Mapping(source = "request.content", target = "content"),
@Mapping(source = "member", target = "member")
})
Comment toReply(CommentRequest request, Member member, Post post, Long commentId);
Comment toReply(CommentRequest request, Member member, Post post, Long parentId);

@Mappings({
@Mapping(source = "comment.createdAt", target = "createDate"),
@Mapping(source = "comment.updatedAt", target = "updateDate")
})
CommentResponse toCommentResponse(Comment comment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static DiaryResponse from(Diary diary) {
return DiaryResponse.builder()
.id(diary.getId())
.content(diary.getContent())
.createDate(diary.getCreatedAt())
.createDate(diary.getCreateDate())
.endUpdateDate(diary.getEndUpdateDate())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

import com.clover.habbittracker.domain.diary.entity.Diary;

public interface DiaryRepository extends JpaRepository<Diary,Long> {
public interface DiaryRepository extends JpaRepository<Diary, Long> {
@Query("""
SELECT d
FROM Diary d
WHERE d.member.id = :memberId
AND d.createdAt BETWEEN :start AND :end
ORDER BY d.createdAt DESC
AND d.createDate BETWEEN :start AND :end
ORDER BY d.createDate DESC
""")
List<Diary> findByMemberId(@Param("memberId") Long memberId, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
List<Diary> findByMemberId(@Param("memberId") Long memberId, @Param("start") LocalDateTime start,
@Param("end") LocalDateTime end);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static HabitResponse from(Habit habit) {
return HabitResponse.builder()
.id(habit.getId())
.content(habit.getContent())
.createDate(habit.getCreatedAt())
.createDate(habit.getCreateDate())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public static MyHabitResponse from(Habit habit, Map<String, LocalDateTime> dateM
return MyHabitResponse.builder()
.id(habit.getId())
.content(habit.getContent())
.createDate(habit.getCreatedAt())
.createDate(habit.getCreateDate())
.habitChecks(HabitCheckResponse.from(habit.getHabitChecks().stream()
.filter(habitCheck -> habitCheck.getCreatedAt().isBefore(dateMap.get("end")))
.filter(habitCheck -> habitCheck.getCreatedAt().isAfter(dateMap.get("start")))
.filter(habitCheck -> habitCheck.getCreateDate().isBefore(dateMap.get("end")))
.filter(habitCheck -> habitCheck.getCreateDate().isAfter(dateMap.get("start")))
.toList()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public List<MyHabitResponse> getMyList(Long memberId, String date) {
@Transactional
public HabitResponse updateMyHabit(Long habitId, HabitRequest request) {
Habit habit = habitRepository.findById(habitId)
.orElseThrow(()-> new HabitNotFoundException(habitId));
.orElseThrow(() -> new HabitNotFoundException(habitId));
habit.setContent(request.getContent());
return HabitResponse.from(habit);
}
Expand All @@ -68,21 +68,21 @@ public HabitResponse updateMyHabit(Long habitId, HabitRequest request) {
@Transactional
public void habitCheck(Long habitId, String date) {
Habit habit = habitRepository.findById(habitId)
.orElseThrow(()-> new HabitNotFoundException(habitId));
.orElseThrow(() -> new HabitNotFoundException(habitId));
LocalDate requestDate = DateUtil.getLocalDate(date);
if (!isToday(requestDate)) {
throw new HabitCheckExpiredException(habitId);
}

habitCheckRepository.findByHabitOrderByUpdatedAtDesc(habit)
.ifPresent(lastHabitCheck -> {
if (isToday(lastHabitCheck.getUpdatedAt().toLocalDate())) {
System.out.println(lastHabitCheck.getUpdatedAt());
if (isToday(lastHabitCheck.getUpdateDate().toLocalDate())) {
System.out.println(lastHabitCheck.getUpdateDate());
throw new HabitCheckDuplicateException(habitId);
}
});
habitCheckRepository.save(HabitCheck.builder().checked(true).habit(habit).build());
habit.setUpdatedAt(LocalDateTime.now());
habit.setUpdateDate(LocalDateTime.now());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static List<HabitCheckResponse> from(List<HabitCheck> habitChecks) {
return habitChecks.stream()
.map(habitCheck -> new HabitCheckResponse(
habitCheck.getId(),
habitCheck.getUpdatedAt()
habitCheck.getUpdateDate()
)).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public interface HabitCheckRepository extends JpaRepository<HabitCheck, Long> {
@Query("""
SELECT hc
FROM HabitCheck hc
WHERE hc.updatedAt = (
SELECT MAX(subHc.updatedAt)
WHERE hc.updateDate = (
SELECT MAX(subHc.updateDate)
FROM HabitCheck subHc
WHERE subHc.habit = :habit
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@ public interface PostMapper {
@Mappings({
@Mapping(source = "post.comments", target = "numOfComments", qualifiedByName = "commentsToSize"),
@Mapping(source = "post.emojis", target = "numOfEmojis", qualifiedByName = "emojisToSize"),
@Mapping(source = "post.createdAt", target = "createDate")
})
PostResponse toPostResponse(Post post);

@Mappings({
@Mapping(source = "post.member.id", target = "memberId"),
@Mapping(source = "post.createdAt", target = "createDate"),
@Mapping(source = "post.updatedAt", target = "updateDate")
})
@Mapping(source = "post.member.id", target = "memberId")
PostDetailResponse toPostDetail(Post post);

@Named("commentsToSize")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public List<Post> findAllPostsSummary(Pageable pageable, Post.Category category)
.where(eqCategory(category))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(post.createdAt.desc())
.orderBy(post.createDate.desc())
.fetch();
}

Expand Down Expand Up @@ -74,7 +74,7 @@ public Page<Post> searchPostBy(PostSearchCondition postSearchCondition, Pageable
)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(post.createdAt.desc())
.orderBy(post.createDate.desc())
.distinct()
.fetch();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public abstract class BaseEntity {

@CreatedDate
@Column(name = "created_date", updatable = false)
private LocalDateTime createdAt;
private LocalDateTime createDate;

@LastModifiedDate
@Column(name = "updated_date")
private LocalDateTime updatedAt;
private LocalDateTime updateDate;

private boolean deleted;

public void setUpdatedAt(LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
public void setUpdateDate(LocalDateTime updatedDate) {
this.updateDate = updatedDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ void createCommentTest() throws Exception {
.attributes(field("constraints", "아직 미정"))
),
responseFields(
fieldWithPath("code").type(STRING).description("결과 코드"),
fieldWithPath("message").type(STRING).description("결과 메시지"),
fieldWithPath("data.id").type(NUMBER).description("생성된 댓글 아이디"),
fieldWithPath("data.content").type(STRING).description("생성된 댓글 내용"),
fieldWithPath("data.createDate").type(STRING).description("댓글 생성 날짜"),
fieldWithPath("data.updateDate").type(STRING).description("댓글 최근 수정 날짜")
beneathPath("data").withSubsectionId("data"),
fieldWithPath("id").type(NUMBER).description("생성된 댓글 아이디"),
fieldWithPath("content").type(STRING).description("생성된 댓글 내용"),
fieldWithPath("emojis[]").type(ARRAY).description("댓글에 대한 이모지"),
fieldWithPath("createDate").type(STRING).description("댓글 생성 날짜"),
fieldWithPath("updateDate").type(STRING).description("댓글 최근 수정 날짜")
)));
}

Expand Down Expand Up @@ -111,12 +111,12 @@ void updateCommentTest() throws Exception {
.attributes(field("constraints", "아직 미정"))
),
responseFields(
fieldWithPath("code").type(STRING).description("결과 코드"),
fieldWithPath("message").type(STRING).description("결과 메시지"),
fieldWithPath("data.id").type(NUMBER).description("생성된 댓글 아이디"),
fieldWithPath("data.content").type(STRING).description("생성된 댓글 내용"),
fieldWithPath("data.createDate").type(STRING).description("댓글 생성 날짜"),
fieldWithPath("data.updateDate").type(STRING).description("댓글 최근 수정 날짜")
beneathPath("data").withSubsectionId("data"),
fieldWithPath("id").type(NUMBER).description("생성된 댓글 아이디"),
fieldWithPath("content").type(STRING).description("생성된 댓글 내용"),
fieldWithPath("emojis[]").type(ARRAY).description("댓글의 이모지"),
fieldWithPath("createDate").type(STRING).description("댓글 생성 날짜"),
fieldWithPath("updateDate").type(STRING).description("댓글 최근 수정 날짜")
)));
}

Expand Down Expand Up @@ -193,12 +193,12 @@ void getReplyListTest() throws Exception {
parameterWithName("commentId").description("답글을 조회 할 댓글 id")
),
responseFields(
fieldWithPath("code").type(STRING).description("결과 코드"),
fieldWithPath("message").type(STRING).description("결과 메시지"),
fieldWithPath("data[].id").type(NUMBER).description("회고록 아이디"),
fieldWithPath("data[].content").type(STRING).description("회고록 내용"),
fieldWithPath("data[].createDate").type(STRING).description("회고 등록 날짜"),
fieldWithPath("data[].updateDate").type(STRING).description("회고 수정 마감 날짜")
beneathPath("data").withSubsectionId("data"),
fieldWithPath("id").type(NUMBER).description("답글 아이디"),
fieldWithPath("content").type(STRING).description("답글 내용"),
fieldWithPath("emojis[]").type(ARRAY).description("댓글에 대한 이모지"),
fieldWithPath("createDate").type(STRING).description("답글 등록 날짜"),
fieldWithPath("updateDate").type(STRING).description("답글 수정 날짜")
)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ void findByMemberIdDateBetweenTest() {
.hasFieldOrProperty("id")
.hasFieldOrProperty("content");
if (previousDate != null) {
assertThat(diary.getCreatedAt()).isBeforeOrEqualTo(previousDate);
assertThat(diary.getCreateDate()).isBeforeOrEqualTo(previousDate);
}
previousDate = diary.getCreatedAt();
previousDate = diary.getCreateDate();
}
}

Expand Down
Loading