diff --git a/src/main/java/Funssion/Inforum/domain/post/memo/repository/MemoRepositoryJdbc.java b/src/main/java/Funssion/Inforum/domain/post/memo/repository/MemoRepositoryJdbc.java index 7551f341..615c7336 100644 --- a/src/main/java/Funssion/Inforum/domain/post/memo/repository/MemoRepositoryJdbc.java +++ b/src/main/java/Funssion/Inforum/domain/post/memo/repository/MemoRepositoryJdbc.java @@ -69,28 +69,28 @@ public Memo create(Memo memo) { @Override public List findAllByDaysOrderByLikes(DateType period, Long pageNum, Long memoCnt) { String sql = "select * from post.memo where created_date > current_date - CAST(? AS INTERVAL) and is_temporary = false " + - "order by likes desc, id desc " + + "order by likes desc, created_date desc, id desc, id desc " + "limit ? offset ?"; return template.query(sql, memoRowMapper(), period.getInterval(), memoCnt, pageNum * memoCnt); } @Override public List findAllOrderById(Long pageNum, Long memoCnt) { - String sql = "select * from post.memo where is_temporary = false order by id desc " + + String sql = "select * from post.memo where is_temporary = false order by created_date desc, id desc " + "limit ? offset ?"; return template.query(sql, memoRowMapper(), memoCnt, pageNum * memoCnt); } @Override public List findAllByUserIdOrderById(Long userId, Long pageNum, Long resultCntPerPage) { - String sql = "select * from post.memo where author_id = ? and is_temporary = false order by id desc limit ? offset ?"; + String sql = "select * from post.memo where author_id = ? and is_temporary = false order by created_date desc, id desc limit ? offset ?"; return template.query(sql, memoRowMapper(), userId, resultCntPerPage, resultCntPerPage*pageNum); } @Override public List findAllLikedMemosByUserId(Long userId, Long pageNum, Long resultCntPerPage) { String sql = "select * from post.memo i join member.like l on i.id = l.post_id and l.post_type = 'MEMO' " + - "where l.user_id = ? and is_temporary = false order by i.id desc " + + "where l.user_id = ? and is_temporary = false order by i.created_date desc, id desc " + "limit ? offset ?"; return template.query(sql, memoRowMapper(), userId, resultCntPerPage, resultCntPerPage*pageNum); } @@ -103,14 +103,14 @@ public List findAllByTagsOrderByMatchesAndLikes(Long memoId) { "AND NOT id = ? " + "AND is_temporary = false " + "GROUP BY id " + - "ORDER BY COUNT(tag_element) desc, likes desc, id desc"; + "ORDER BY COUNT(tag_element) desc, likes desc, created_date desc, id desc"; return template.query(sql, memoRowMapper(), memoId, memoId); } @Override public List findAllDraftMemosByUserId(Long userId) { - String sql = "select * from post.memo where author_id = ? and is_temporary = true order by id desc"; + String sql = "select * from post.memo where author_id = ? and is_temporary = true order by created_date desc, id desc"; return template.query(sql, memoRowMapper(), userId); } @@ -180,10 +180,10 @@ public List findAllByTag(String tagText, Long userId, OrderType orderType, private static String getOrderBySql(OrderType orderType) { switch (orderType) { case HOT -> { - return " order by likes desc, id desc "; + return " order by likes desc, created_date desc, id desc "; } case NEW -> { - return " order by id desc "; + return " order by created_date desc, id desc "; } } throw new BadRequestException("Invalid orderType value"); diff --git a/src/main/java/Funssion/Inforum/domain/post/qna/repository/AnswerRepositoryImpl.java b/src/main/java/Funssion/Inforum/domain/post/qna/repository/AnswerRepositoryImpl.java index 6a54dae4..edf663c2 100644 --- a/src/main/java/Funssion/Inforum/domain/post/qna/repository/AnswerRepositoryImpl.java +++ b/src/main/java/Funssion/Inforum/domain/post/qna/repository/AnswerRepositoryImpl.java @@ -57,7 +57,7 @@ public List getAnswersOfQuestion(Long loginId, Long questionId) { +" on A.id = DL.post_id " +" left join (select post_id from member.like where user_id = ? and post_type = '"+ PostType.ANSWER+"') AS L" +" on A.id = L.post_id" - +" order by A.is_selected desc, (A.likes - A.dislikes) desc, created_date desc"; + +" order by A.is_selected desc, (A.likes - A.dislikes) desc, created_date desc, id desc"; return template.query(sql,answerLikeRowMapper(), questionId, loginId, loginId); } diff --git a/src/main/java/Funssion/Inforum/domain/post/qna/repository/QuestionRepositoryImpl.java b/src/main/java/Funssion/Inforum/domain/post/qna/repository/QuestionRepositoryImpl.java index 94ec1785..40bd73ab 100644 --- a/src/main/java/Funssion/Inforum/domain/post/qna/repository/QuestionRepositoryImpl.java +++ b/src/main/java/Funssion/Inforum/domain/post/qna/repository/QuestionRepositoryImpl.java @@ -293,9 +293,9 @@ public Question updateLikesInQuestion(Long questionId, Sign sign) { private String getSortedSql(OrderType orderBy){ switch (orderBy){ case HOT: - return "order by likes desc, created_date desc "; + return "order by likes desc, created_date desc, id desc "; case NEW: - return "order by created_date desc "; + return "order by created_date desc, id desc "; case ANSWERS: return "order by answers desc "; case SOLVED: