Skip to content

Commit

Permalink
chore: change memo order id to created_date and id
Browse files Browse the repository at this point in the history
  • Loading branch information
comolove committed Nov 20, 2023
1 parent a5405ab commit 0f977cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,28 @@ public Memo create(Memo memo) {
@Override
public List<Memo> 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<Memo> 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<Memo> 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<Memo> 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);
}
Expand All @@ -103,14 +103,14 @@ public List<Memo> 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<Memo> 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);
}
Expand Down Expand Up @@ -180,10 +180,10 @@ public List<Memo> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<Answer> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0f977cf

Please sign in to comment.