Skip to content

Commit

Permalink
refactor: 트래커 일수를 설정으로 분리한다
Browse files Browse the repository at this point in the history
  • Loading branch information
vectorch9 committed Nov 6, 2023
1 parent daa3413 commit 046aab7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/daybyquest/post/application/GetTrackerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,31 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GetTrackerService {

private static final long TRACKER_DAYS = 60L;

private final Users users;

private final PostDao postDao;

public GetTrackerService(final Users users, final PostDao postDao) {
private final long trackerDays;

public GetTrackerService(final Users users, final PostDao postDao,
@Value("${tracker.days}") final long trackerDays) {
this.users = users;
this.postDao = postDao;
this.trackerDays = trackerDays;
}

@Transactional(readOnly = true)
public TrackerResponse invoke(final Long loginId, final String username) {
final Long userId = users.getUserIdByUsername(username);
final List<SimplePostData> simplePostData = postDao
.findAllBySuccessAndUploadedAtAfter(userId, now().minusDays(TRACKER_DAYS));
.findAllBySuccessAndUploadedAtAfter(userId, now().minusDays(trackerDays));
return new TrackerResponse(calculateTracker(simplePostData));
}

Expand All @@ -42,7 +45,7 @@ private List<Long> calculateTracker(final List<SimplePostData> simplePostData) {
.collect(groupingBy((time) -> time.uploadedAt().toLocalDate(), counting()));

return Stream.iterate(LocalDate.now(), date -> date.minusDays(1))
.limit(TRACKER_DAYS)
.limit(trackerDays)
.map(time -> counts.getOrDefault(time, 0L)
).toList();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ image:
base:
user-identifier: base.png

tracker:
days: 60

spring:
servlet:
multipart:
Expand Down

0 comments on commit 046aab7

Please sign in to comment.