Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -12,7 +11,6 @@
import org.springframework.web.bind.annotation.RestController;
import site.dogether.auth.resolver.Authenticated;
import site.dogether.common.controller.dto.response.ApiResponse;
import site.dogether.dailytodocertification.entity.DailyTodoCertification;
import site.dogether.memberactivity.controller.v1.dto.response.GetMyActivityStatsAndCertificationsApiResponseV1;
import site.dogether.memberactivity.controller.v1.dto.response.GetMyChallengeGroupActivityStatsApiResponseV1;
import site.dogether.memberactivity.controller.v1.dto.response.GetMyGroupCertificationsApiResponseV1;
Expand All @@ -22,7 +20,7 @@
import site.dogether.memberactivity.service.dto.ChallengeGroupInfoDto;
import site.dogether.memberactivity.service.dto.DailyTodoCertificationActivityDto;
import site.dogether.memberactivity.service.dto.FindMyProfileDto;
import site.dogether.memberactivity.service.dto.GroupedCertificationsDto;
import site.dogether.memberactivity.service.dto.MyActivityStatsAndCertificationsDto;
import site.dogether.memberactivity.service.dto.MyCertificationStatsDto;
import site.dogether.memberactivity.service.dto.MyRankInChallengeGroupDto;

Expand Down Expand Up @@ -61,28 +59,23 @@ public ResponseEntity<ApiResponse<GetMyActivityStatsAndCertificationsApiResponse
@RequestParam(required = false) final String status,
@PageableDefault(size = 50) final Pageable pageable
) {
final MyCertificationStatsDto myCertificationStats = memberActivityService.getMyTotalCertificationStats(memberId);
final Slice<DailyTodoCertification> certifications = memberActivityService.getCertificationsByStatus(memberId, status, pageable);
final MyActivityStatsAndCertificationsDto myActivityStatsAndCertifications = memberActivityService.getMyActivityStatsAndCertifications(memberId, sortBy, status, pageable);

if (sortBy.equals("TODO_COMPLETED_AT")) {
final List<GroupedCertificationsDto> groupedCertifications = memberActivityService.certificationsGroupedByCertificatedAt(certifications.getContent());

return ResponseEntity.ok(success(new GetMyActivityStatsAndCertificationsApiResponseV1(
GetMyActivityStatsAndCertificationsApiResponseV1.MyCertificationStats.from(myCertificationStats),
GetMyActivityStatsAndCertificationsApiResponseV1.CertificationsGroupedByCertificatedAt.fromList(groupedCertifications),
GetMyActivityStatsAndCertificationsApiResponseV1.MyCertificationStats.from(myActivityStatsAndCertifications.myCertificationStats()),
GetMyActivityStatsAndCertificationsApiResponseV1.CertificationsGroupedByCertificatedAt.fromList(myActivityStatsAndCertifications.groupedCertifications()),
null,
GetMyActivityStatsAndCertificationsApiResponseV1.PageInfo.from(certifications)
GetMyActivityStatsAndCertificationsApiResponseV1.PageInfo.from(myActivityStatsAndCertifications.certifications())
)));
}

// sortBy = GROUP_CREATED_AT
final List<GroupedCertificationsDto> groupedCertifications = memberActivityService.certificationsGroupedByGroupCreatedAt(certifications.getContent());

return ResponseEntity.ok(success(new GetMyActivityStatsAndCertificationsApiResponseV1(
GetMyActivityStatsAndCertificationsApiResponseV1.MyCertificationStats.from(myCertificationStats),
GetMyActivityStatsAndCertificationsApiResponseV1.MyCertificationStats.from(myActivityStatsAndCertifications.myCertificationStats()),
null,
GetMyActivityStatsAndCertificationsApiResponseV1.CertificationsGroupedByGroupCreatedAt.fromList(groupedCertifications),
GetMyActivityStatsAndCertificationsApiResponseV1.PageInfo.from(certifications)
GetMyActivityStatsAndCertificationsApiResponseV1.CertificationsGroupedByGroupCreatedAt.fromList(myActivityStatsAndCertifications.groupedCertifications()),
GetMyActivityStatsAndCertificationsApiResponseV1.PageInfo.from(myActivityStatsAndCertifications.certifications())
)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import site.dogether.memberactivity.service.dto.FindMyProfileDto;
import site.dogether.memberactivity.service.dto.GroupedCertificationsDto;
import site.dogether.memberactivity.service.dto.GroupedCertificationsResultDto;
import site.dogether.memberactivity.service.dto.MyActivityStatsAndCertificationsDto;
import site.dogether.memberactivity.service.dto.MyCertificationStatsDto;
import site.dogether.memberactivity.service.dto.MyRankInChallengeGroupDto;
import site.dogether.reminder.service.TodoActivityReminderService;
Expand Down Expand Up @@ -201,7 +202,29 @@ public MyCertificationStatsDto getMyCertificationStatsInChallengeGroup(final Lon
);
}

public MyCertificationStatsDto getMyTotalCertificationStats(final Long memberId) {
public MyActivityStatsAndCertificationsDto getMyActivityStatsAndCertifications(
final Long memberId,
final String sortBy,
final String status,
final Pageable pageable
) {
final MyCertificationStatsDto myCertificationStats = getMyTotalCertificationStats(memberId);
final Slice<DailyTodoCertification> certifications = getCertificationsByStatus(memberId, status, pageable);

List<GroupedCertificationsDto> groupedCertifications = new ArrayList<>();

if (sortBy.equals("TODO_COMPLETED_AT")) {
groupedCertifications = certificationsGroupedByCertificatedAt(certifications.getContent());
}

if (sortBy.equals("GROUP_CREATED_AT")) {
groupedCertifications = certificationsGroupedByGroupCreatedAt(certifications.getContent());
}

return new MyActivityStatsAndCertificationsDto(myCertificationStats, certifications, groupedCertifications);
}

private MyCertificationStatsDto getMyTotalCertificationStats(final Long memberId) {
final Member member = getMember(memberId);

return dailyTodoStatsRepository.findByMember(member)
Expand All @@ -213,7 +236,7 @@ public MyCertificationStatsDto getMyTotalCertificationStats(final Long memberId)
.orElseGet(() -> new MyCertificationStatsDto(0, 0, 0));
}

public Slice<DailyTodoCertification> getCertificationsByStatus(final Long memberId, final String status, final Pageable pageable) {
private Slice<DailyTodoCertification> getCertificationsByStatus(final Long memberId, final String status, final Pageable pageable) {
final Member member = getMember(memberId);

if (status != null && !status.isBlank()) {
Expand All @@ -224,7 +247,7 @@ public Slice<DailyTodoCertification> getCertificationsByStatus(final Long member
return dailyTodoCertificationRepository.findAllByDailyTodo_MemberOrderByCreatedAtDesc(member, pageable);
}

public List<GroupedCertificationsDto> certificationsGroupedByCertificatedAt(final List<DailyTodoCertification> certifications) {
private List<GroupedCertificationsDto> certificationsGroupedByCertificatedAt(final List<DailyTodoCertification> certifications) {
return certifications.stream()
.collect(Collectors.groupingBy(certification -> certification.getCreatedAt().toLocalDate().format(DATE_FORMATTER)))
.entrySet().stream()
Expand Down Expand Up @@ -252,7 +275,7 @@ private DailyTodoCertificationInfoDto certificationInfo(final DailyTodoCertifica
);
}

public List<GroupedCertificationsDto> certificationsGroupedByGroupCreatedAt(final List<DailyTodoCertification> certifications) {
private List<GroupedCertificationsDto> certificationsGroupedByGroupCreatedAt(final List<DailyTodoCertification> certifications) {
return certifications.stream()
.collect(Collectors.groupingBy(certification -> certification.getDailyTodo().getChallengeGroup()))
.entrySet().stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package site.dogether.memberactivity.service.dto;

import org.springframework.data.domain.Slice;
import site.dogether.dailytodocertification.entity.DailyTodoCertification;

import java.util.List;

public record MyActivityStatsAndCertificationsDto(
MyCertificationStatsDto myCertificationStats,
Slice<DailyTodoCertification> certifications,
List<GroupedCertificationsDto> groupedCertifications
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import site.dogether.memberactivity.service.dto.DailyTodoCertificationInfoDto;
import site.dogether.memberactivity.service.dto.FindMyProfileDto;
import site.dogether.memberactivity.service.dto.GroupedCertificationsDto;
import site.dogether.memberactivity.service.dto.MyActivityStatsAndCertificationsDto;
import site.dogether.memberactivity.service.dto.MyCertificationStatsDto;
import site.dogether.memberactivity.service.dto.MyRankInChallengeGroupDto;

Expand Down Expand Up @@ -152,7 +153,7 @@ void getMemberAllStatsSortedByTodoCompletedAtV1() throws Exception {

final Slice<DailyTodoCertification> slice = new SliceImpl<>(List.of(), PageRequest.of(0, 50), false);

final List<GroupedCertificationsDto> certificationsGroupedByCertificatedAt = List.of(
final List<GroupedCertificationsDto> certifications = List.of(
new GroupedCertificationsDto(
"2025.05.01",
List.of(
Expand Down Expand Up @@ -181,14 +182,10 @@ void getMemberAllStatsSortedByTodoCompletedAtV1() throws Exception {
)
);

given(memberActivityService.getMyTotalCertificationStats(any()))
.willReturn(stats);
final MyActivityStatsAndCertificationsDto dto = new MyActivityStatsAndCertificationsDto(stats, slice, certifications);

given(memberActivityService.getCertificationsByStatus(any(), any(), any()))
.willReturn(slice);

given(memberActivityService.certificationsGroupedByCertificatedAt(any()))
.willReturn(certificationsGroupedByCertificatedAt);
given(memberActivityService.getMyActivityStatsAndCertifications(any(), any(), any(), any()))
.willReturn(dto);

mockMvc.perform(
MockMvcRequestBuilders.get("/api/v1/my/activity")
Expand Down Expand Up @@ -283,7 +280,7 @@ void getMemberAllStatsSortedByGroupCreatedAtV1() throws Exception {

final Slice<DailyTodoCertification> slice = new SliceImpl<>(List.of(), PageRequest.of(0, 50), false);

final List<GroupedCertificationsDto> certificationsGroupedByGroupCreatedAt = List.of(
final List<GroupedCertificationsDto> certifications = List.of(
new GroupedCertificationsDto(
"스쿼트 챌린지",
List.of(
Expand Down Expand Up @@ -312,14 +309,10 @@ void getMemberAllStatsSortedByGroupCreatedAtV1() throws Exception {
)
);

given(memberActivityService.getMyTotalCertificationStats(any()))
.willReturn(stats);

given(memberActivityService.getCertificationsByStatus(any(), any(), any()))
.willReturn(slice);
final MyActivityStatsAndCertificationsDto dto = new MyActivityStatsAndCertificationsDto(stats, slice, certifications);

given(memberActivityService.certificationsGroupedByGroupCreatedAt(any()))
.willReturn(certificationsGroupedByGroupCreatedAt);
given(memberActivityService.getMyActivityStatsAndCertifications(any(), any(), any(), any()))
.willReturn(dto);

mockMvc.perform(
MockMvcRequestBuilders.get("/api/v1/my/activity")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void getMyCertificationsV2() throws Exception {

mockMvc.perform(
MockMvcRequestBuilders.get("/api/v2/my/certifications")
.param("sortBy", "TODO_COMPLETED_AT")
.param("sortBy", "CERTIFICATED_AT")
.param("status", "APPROVE")
.param("page", "0")
.header("Authorization", "Bearer access_token")
Expand Down
Loading