Skip to content

Commit

Permalink
⚡ : Admin 기부금 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
imenuuu committed Jan 18, 2024
1 parent 27b1341 commit a805824
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-01-17T03:34:23+0900",
date = "2024-01-17T19:31:30+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 11.0.19 (Oracle Corporation)"
)
public class AdminNoticeMapperImpl implements AdminNoticeMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-01-17T03:34:23+0900",
date = "2024-01-17T19:31:30+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 11.0.19 (Oracle Corporation)"
)
public class OrderMapperImpl implements OrderMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-01-17T03:34:23+0900",
date = "2024-01-17T19:31:30+0900",
comments = "version: 1.5.3.Final, compiler: javac, environment: Java 11.0.19 (Oracle Corporation)"
)
public class PaymentMapperImpl implements PaymentMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public CommonResponse<DonationRes.RegularInfoDto> getRegularInfo(){
}



@GetMapping("/{donationId}")
@ApiErrorCodeExample(UserAuthErrorCode.class)
@Operation(summary = "ADMIN-05-02 기부금 상세조회 API", description = "기부금 상세조회 API")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.matchapi.admin.donation.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.matchapi.admin.donation.service.AdminDonationService;
import com.example.matchapi.donation.dto.DonationRes;
import com.example.matchcommon.annotation.ApiErrorCodeExample;
import com.example.matchcommon.reponse.CommonResponse;
import com.example.matchdomain.user.exception.UserAuthErrorCode;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@RestController
@Tag(name = "ADMIN-05-Donation V2💸 관리자 기부금 관련 API 입니다.", description = "기부금 관련 API 입니다.")
@RequestMapping("/admin/v2/donations")
@RequiredArgsConstructor
public class AdminDonationV2Controller {
private final AdminDonationService adminDonationService;
@GetMapping("/regular")
@ApiErrorCodeExample(UserAuthErrorCode.class)
@Operation(summary = "ADMIN-05-01-01 V2 정기 결제 현황 파악", description = "정기 결제 현황파악")
public CommonResponse<DonationRes.RegularInfoV2Dto> getRegularInfoV2(){
return CommonResponse.onSuccess(adminDonationService.getRegularInfoV2());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,13 @@ public DonationRes.RegularInfoDto convertToRegularInfoDto(Long beforeCnt, Long u
.beforeMonthRegularAmount(beforeMonthRegularAmount)
.build();
}

public DonationRes.RegularInfoV2Dto convertToRegularInfoV2Dto(Long thisMonthRegularCnt, Long thisMonthOneTimeCnt, Long thisMonthStartCnt) {
return DonationRes.RegularInfoV2Dto
.builder()
.thisMonthRegularCnt(thisMonthRegularCnt)
.thisMonthOneTimeCnt(thisMonthOneTimeCnt)
.thisMonthStartCnt(thisMonthStartCnt)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.example.matchdomain.donation.entity.HistoryImage;
import com.example.matchdomain.donation.entity.RegularPayment;
import com.example.matchdomain.donation.entity.enums.RegularPayStatus;
import com.example.matchdomain.donation.entity.enums.RegularStatus;
import com.example.matchdomain.donation.repository.HistoryImageRepository;
import com.example.matchdomain.project.adaptor.ProjectAdaptor;
import com.example.matchdomain.project.entity.Project;
Expand All @@ -35,8 +36,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static com.example.matchcommon.constants.MatchStatic.FIRST_TIME;
import static com.example.matchcommon.constants.MatchStatic.LAST_TIME;
import static com.example.matchcommon.constants.MatchStatic.*;
import static com.example.matchdomain.donation.entity.enums.DonationStatus.*;

@Service
Expand Down Expand Up @@ -250,4 +250,26 @@ public Long countByUserId(Long userId) {
public List<DonationUser> findByUserId(Long userId) {
return donationAdaptor.findByUserId(userId);
}

public DonationRes.RegularInfoV2Dto getRegularInfoV2() {
List<DonationUser> donationUsers = donationAdaptor.getRegularDonationLists();
List<RegularPayment> regularPayments = paymentAdaptor.getRegularInfo();

Long thisMonthRegularCnt = 0L, thisMonthOneTimeCnt = 0L, thisMonthStartCnt = 0L;
LocalDate now = LocalDate.now();
for (DonationUser donationUser : donationUsers){
if(now.getMonthValue() == donationUser.getCreatedAt().getMonthValue() && now.getYear() == donationUser.getCreatedAt().getYear()){
if(donationUser.getRegularStatus().equals(RegularStatus.REGULAR)) thisMonthRegularCnt++;
else thisMonthOneTimeCnt++;
}
}

for (RegularPayment regularPayment : regularPayments){
if(now.getMonthValue() == regularPayment.getCreatedAt().getMonthValue() && now.getYear() == regularPayment.getCreatedAt().getYear()){
thisMonthStartCnt++;
}
}

return adminDonationConverter.convertToRegularInfoV2Dto(thisMonthRegularCnt, thisMonthOneTimeCnt, thisMonthStartCnt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,17 @@ public static class RegularInfoDto {

private String beforeMonthRegularAmount;
}

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class RegularInfoV2Dto {
private Long thisMonthRegularCnt;

private Long thisMonthOneTimeCnt;

private Long thisMonthStartCnt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.matchcommon.constants.enums;

public enum Version {
API_V1, API_V2, API_V3, API_V4, API_V5
}

0 comments on commit a805824

Please sign in to comment.