-
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 #18 from DDD-Community/develop
3차 배포
- Loading branch information
Showing
6 changed files
with
218 additions
and
42 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
48 changes: 48 additions & 0 deletions
48
src/main/java/com/dissonance/itit/dto/response/InfoPostRes.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,48 @@ | ||
package com.dissonance.itit.dto.response; | ||
|
||
import java.time.LocalDate; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class InfoPostRes { | ||
private final Long id; | ||
private final String imgUrl; | ||
private final String title; | ||
private final String remainingDays; | ||
|
||
public static List<InfoPostRes> of(List<InfoPostInfo> postInfos) { | ||
return postInfos.stream() | ||
.map(postInfo -> InfoPostRes.builder() | ||
.id(postInfo.id()) | ||
.imgUrl(postInfo.imgUrl()) | ||
.title(postInfo.title()) | ||
.remainingDays(calculateRemainingDays(postInfo.deadline())) | ||
.build()) | ||
.toList(); | ||
} | ||
|
||
private static String calculateRemainingDays(LocalDate deadline) { | ||
LocalDate today = LocalDate.now(); | ||
long daysLeft = ChronoUnit.DAYS.between(today, deadline); | ||
|
||
if (daysLeft > 0) { | ||
return "D-" + daysLeft; | ||
} else if (daysLeft == 0) { | ||
return "D-Day"; | ||
} else { | ||
return "마감"; | ||
} | ||
} | ||
|
||
public record InfoPostInfo( | ||
Long id, | ||
String imgUrl, | ||
String title, | ||
LocalDate deadline) { | ||
} | ||
} |
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