-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from msdio/feature/backend/longTyping-sort
긴글 목록 정렬 기능 구현
- Loading branch information
Showing
6 changed files
with
67 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/com/project/tamago/common/enums/SortOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.project.tamago.common.enums; | ||
|
||
import org.springframework.data.domain.Sort; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum SortOrder { | ||
LATEST("latest"), | ||
OLDEST("oldest"), | ||
VIEW_COUNT("viewCount"); | ||
|
||
private final String desc; | ||
|
||
SortOrder(String desc) { | ||
this.desc = desc; | ||
} | ||
|
||
public static Sort getSort(String sortBy) { | ||
if (LATEST.desc.equals(sortBy)) { | ||
return Sort.by("createdDate").descending().and(Sort.by("updatedDate").descending()); | ||
} | ||
if (OLDEST.desc.equals(sortBy)) { | ||
return Sort.by("createdDate").ascending().and(Sort.by("updatedDate").ascending()); | ||
} | ||
if (VIEW_COUNT.desc.equals(sortBy)) { | ||
return Sort.by("viewCount").descending().and(Sort.by("updatedDate").descending()); | ||
} | ||
throw new IllegalArgumentException("Invalid sortBy parameter: " + sortBy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters