-
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.
* feature: 사용자 이름 중복 검사를 구현한다 * feature: 사용자 공개 범위 조회를 구현한다 * refactor: 사용자 도메인의 응답 DTO에 기본 생성자를 제거한다 * feature: Post에 업로드한 시간을 추가한다 * feature: 트래커 조회를 구현한다 * refactor: 트래커 일수를 설정으로 분리한다 * test: GetTrackerService의 테스트를 작성한다 * fix: 실패하는 테스트를 고친다 - 설정 파일에 새로 추가한 설정을 확인함
- Loading branch information
Showing
20 changed files
with
304 additions
and
23 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/daybyquest/post/application/GetTrackerService.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,52 @@ | ||
package daybyquest.post.application; | ||
|
||
import static java.time.LocalDateTime.now; | ||
import static java.util.stream.Collectors.counting; | ||
import static java.util.stream.Collectors.groupingBy; | ||
|
||
import daybyquest.post.dto.response.TrackerResponse; | ||
import daybyquest.post.query.PostDao; | ||
import daybyquest.post.query.SimplePostData; | ||
import daybyquest.user.domain.Users; | ||
import java.time.LocalDate; | ||
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 final Users users; | ||
|
||
private 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(trackerDays)); | ||
return new TrackerResponse(calculateTracker(simplePostData)); | ||
} | ||
|
||
private List<Long> calculateTracker(final List<SimplePostData> simplePostData) { | ||
final Map<LocalDate, Long> counts = simplePostData.stream() | ||
.collect(groupingBy((time) -> time.uploadedAt().toLocalDate(), counting())); | ||
|
||
return Stream.iterate(LocalDate.now(), date -> date.minusDays(1)) | ||
.limit(trackerDays) | ||
.map(time -> counts.getOrDefault(time, 0L) | ||
).toList(); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/daybyquest/post/dto/response/TrackerResponse.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,7 @@ | ||
package daybyquest.post.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record TrackerResponse(List<Long> tracker) { | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package daybyquest.post.query; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record SimplePostData(Long id, LocalDateTime uploadedAt) { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/daybyquest/user/application/CheckUsernameService.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,20 @@ | ||
package daybyquest.user.application; | ||
|
||
import daybyquest.user.domain.Users; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
public class CheckUsernameService { | ||
|
||
private final Users users; | ||
|
||
public CheckUsernameService(final Users users) { | ||
this.users = users; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public void invoke(final String username) { | ||
users.validateUniqueUsername(username); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/daybyquest/user/application/GetVisibilityService.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,23 @@ | ||
package daybyquest.user.application; | ||
|
||
import daybyquest.user.domain.User; | ||
import daybyquest.user.domain.Users; | ||
import daybyquest.user.dto.response.UserVisibilityResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
public class GetVisibilityService { | ||
|
||
private final Users users; | ||
|
||
public GetVisibilityService(final Users users) { | ||
this.users = users; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public UserVisibilityResponse invoke(final Long loginId) { | ||
final User user = users.getById(loginId); | ||
return UserVisibilityResponse.of(user); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/daybyquest/user/dto/response/UserVisibilityResponse.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,18 @@ | ||
package daybyquest.user.dto.response; | ||
|
||
import daybyquest.user.domain.User; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class UserVisibilityResponse { | ||
|
||
private final String visibility; | ||
|
||
private UserVisibilityResponse(final String visibility) { | ||
this.visibility = visibility; | ||
} | ||
|
||
public static UserVisibilityResponse of(final User user) { | ||
return new UserVisibilityResponse(user.getVisibility().toString()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ image: | |
base: | ||
user-identifier: base.png | ||
|
||
tracker: | ||
days: 60 | ||
|
||
spring: | ||
servlet: | ||
multipart: | ||
|
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,2 @@ | ||
ALTER TABLE `post` | ||
ADD `uploaded_at` datetime(6); |
Oops, something went wrong.