Skip to content

Commit

Permalink
Merge pull request #236 from TEAMMatchDev/Api-Release
Browse files Browse the repository at this point in the history
Batch 수정사항 배포
  • Loading branch information
imenuuu authored Dec 21, 2023
2 parents c515fc8 + 7f17fa8 commit fa7e367
Show file tree
Hide file tree
Showing 79 changed files with 1,412 additions and 488 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-12-05T09:50:48+0900",
date = "2023-12-07T09:51:10+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 = "2023-12-05T09:50:48+0900",
date = "2023-12-07T13:17:18+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 = "2023-12-05T09:50:48+0900",
date = "2023-12-07T13:17:18+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 @@ -4,6 +4,7 @@
import com.example.matchapi.banner.dto.BannerReq;
import com.example.matchapi.banner.dto.BannerRes;
import com.example.matchcommon.reponse.CommonResponse;
import com.example.matchcommon.reponse.PageResponse;
import com.example.matchdomain.banner.enums.BannerType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -29,11 +30,36 @@ public class AdminBannerController {
@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
@Operation(summary = "ADMIN-08-01 배너 업로드")
public CommonResponse<List<BannerRes.BannerList>> uploadBanner(
//@RequestPart BannerType bannerType,
@RequestPart MultipartFile bannerImage,
@RequestPart BannerReq.BannerUpload bannerUploadDto
@RequestPart("bannerUploadDto") BannerReq.BannerUpload bannerUploadDto
){
System.out.println(bannerUploadDto.getContentsUrl());
return CommonResponse.onSuccess(adminBannerService.uploadBanner(BannerType.EVENT, bannerImage, bannerUploadDto));
}

@GetMapping("")
@Operation(summary = "ADMIN-08-02 배너 조회")
public CommonResponse<PageResponse<List<BannerRes.BannerAdminListDto>>> getBannerLists(
@Parameter(description = "페이지", example = "0") @RequestParam(required = false, defaultValue = "0") int page,
@Parameter(description = "페이지 사이즈", example = "10") @RequestParam(required = false, defaultValue = "10") int size

){
return CommonResponse.onSuccess(adminBannerService.getBannerLists(page, size));
}

@DeleteMapping("/{bannerId}")
@Operation(summary = "ADMIN-08-03 배너 삭제")
public CommonResponse<String> deleteBanner(@PathVariable Long bannerId){
adminBannerService.deleteBanner(bannerId);
return CommonResponse.onSuccess("삭제 성공");
}

@PatchMapping("/{bannerId}")
@Operation(summary = "ADMIN-08-04 배너 수정")
public CommonResponse<String> patchBanner(
@PathVariable Long bannerId,
@RequestPart(value = "bannerImage", required = false) MultipartFile bannerImage,
@RequestPart("bannerPatchDto") BannerReq.BannerPatchDto bannerPatchDto){
adminBannerService.patchBanner(bannerId, bannerPatchDto, bannerImage);
return CommonResponse.onSuccess("수정 성공");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import com.example.matchapi.banner.converter.BannerConverter;
import com.example.matchapi.banner.dto.BannerReq;
import com.example.matchapi.banner.dto.BannerRes;
import com.example.matchcommon.reponse.PageResponse;
import com.example.matchdomain.banner.adaptor.BannerAdaptor;
import com.example.matchdomain.banner.entity.Banner;
import com.example.matchdomain.banner.enums.BannerType;
import com.example.matchdomain.banner.repository.BannerRepository;
import com.example.matchinfrastructure.config.s3.S3UploadService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -20,7 +21,6 @@
@Service
@RequiredArgsConstructor
public class AdminBannerService {
private final BannerRepository bannerRepository;
private final BannerConverter bannerConverter;
private final S3UploadService s3UploadService;
private final BannerAdaptor bannerAdaptor;
Expand All @@ -31,7 +31,7 @@ public List<BannerRes.BannerList> uploadBanner(BannerType bannerType,
MultipartFile bannerImage,
BannerReq.BannerUpload bannerUploadDto) {
String bannerImg = s3UploadService.uploadBannerImage(bannerImage);
bannerRepository.save(bannerConverter.convertToBannerUpload(bannerType, bannerImg, bannerUploadDto));
bannerAdaptor.save(bannerConverter.convertToBannerUpload(bannerType, bannerImg, bannerUploadDto));
return cachingBannerList();
}

Expand All @@ -41,4 +41,29 @@ public List<BannerRes.BannerList> cachingBannerList() {

return bannerConverter.convertToBannerList(banners);
}

@Transactional
public void deleteBanner(Long bannerId) {
Banner banner = bannerAdaptor.findById(bannerId);
s3UploadService.deleteFile(banner.getBannerImg());
bannerAdaptor.deleteById(bannerId);
}

@Transactional
public void patchBanner(Long bannerId, BannerReq.BannerPatchDto bannerPatchDto, MultipartFile bannerImage) {
Banner banner = bannerAdaptor.findById(bannerId);
if(bannerPatchDto.isEditImage()){
s3UploadService.deleteFile(banner.getBannerImg());
String imgUrl = s3UploadService.uploadBannerImage(bannerImage);
banner.updateBanner(bannerPatchDto.getName(), banner.getStartDate(), banner.getEndDate(), imgUrl);
}else{
banner.updateBanner(bannerPatchDto.getName(), banner.getStartDate(), banner.getEndDate(), banner.getBannerImg());
}
bannerAdaptor.save(banner);
}

public PageResponse<List<BannerRes.BannerAdminListDto>> getBannerLists(int page, int size) {
Page<Banner> banners = bannerAdaptor.getBannerLists(page, size);
return new PageResponse<>(banners.isLast(), banners.getSize(), bannerConverter.convertToBannerLists(banners.getContent()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public CommonResponse<DonationRes.DonationInfo> getDonationInfo(){
return CommonResponse.onSuccess(info);
}

@GetMapping("/regular")
@ApiErrorCodeExample(UserAuthErrorCode.class)
@Operation(summary = "ADMIN-05-01-01 정기 결제 현황 파악", description = "정기 결제 현황파악")
public CommonResponse<DonationRes.RegularInfoDto> getRegularInfo(){
return CommonResponse.onSuccess(adminDonationService.getRegularInfo());
}



@GetMapping("/{donationId}")
@ApiErrorCodeExample(UserAuthErrorCode.class)
@Operation(summary = "ADMIN-05-02 기부금 상세조회 API", description = "기부금 상세조회 API")
Expand Down Expand Up @@ -91,4 +100,5 @@ public CommonResponse<PageResponse<List<DonationRes.ProjectDonationDto>>> getPro
Project project = projectService.findByProjectId(projectId);
return CommonResponse.onSuccess(adminDonationService.getProjectDonationLists(project, page, size));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,22 @@ private DonationRes.ProjectDonationDto convertToDonationInfo(DonationUser result
.userName(result.getUser().getName())
.amount(result.getPrice())
.importedAmount((int) (result.getPrice()*0.1))
.waitingSortingAmount(result.getDonationStatus().equals(DonationStatus.PARTIAL_EXECUTION) ? result.getExecutionPrice() : (long) (result.getPrice() * 0.9))
.waitingSortingAmount(result.getDonationStatus().equals(DonationStatus.PARTIAL_EXECUTION) ? (long) (result.getPrice() * 0.9 - result.getExecutionPrice()) : (long) (result.getPrice() * 0.9))
.partialAmount(result.getExecutionPrice())
.build();
}

public DonationRes.RegularInfoDto convertToRegularInfoDto(Long beforeCnt, Long underCnt, Long successCnt, String successAmount, Long regularCnt, String totalAmount, Long beforeMonthRegularCnt, String beforeMonthRegularAmount) {
return DonationRes.RegularInfoDto
.builder()
.beforeCnt(beforeCnt)
.underCnt(underCnt)
.successCnt(successCnt)
.successAmount(successAmount)
.regularCnt(regularCnt)
.regularAmount(totalAmount)
.beforeMonthRegularCnt(beforeMonthRegularCnt)
.beforeMonthRegularAmount(beforeMonthRegularAmount)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
import com.example.matchcommon.reponse.PageResponse;
import com.example.matchdomain.donation.adaptor.DonationAdaptor;
import com.example.matchdomain.donation.adaptor.DonationHistoryAdaptor;
import com.example.matchdomain.donation.adaptor.RegularPaymentAdaptor;
import com.example.matchdomain.donation.entity.DonationHistory;
import com.example.matchdomain.donation.entity.DonationUser;
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.repository.HistoryImageRepository;
import com.example.matchdomain.project.adaptor.ProjectAdaptor;
import com.example.matchdomain.project.entity.Project;
import com.example.matchinfrastructure.config.s3.S3UploadService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
Expand All @@ -25,6 +29,7 @@
import javax.transaction.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -43,9 +48,9 @@ public class AdminDonationService {
private final AdminDonationConverter adminDonationConverter;
private final S3UploadService s3UploadService;
private final ProjectAdaptor projectAdaptor;
private final RegularPaymentAdaptor paymentAdaptor;
private final HistoryImageRepository historyImageRepository;
@Autowired
private ApplicationEventPublisher eventPublisher;
private final ApplicationEventPublisher eventPublisher;


@Transactional
Expand All @@ -57,6 +62,7 @@ public DonationRes.DonationInfo getDonationInfo() {
int oneDayDonationAmount = 0;
int weekendDonationAmount = 0;
int monthlyDonationAmount = 0;
int totalDonationAmount = 0;
for (DonationUser donationUser : donationUsers) {
if(donationUser.getCreatedAt().isAfter(LocalDateTime.parse(localDate+FIRST_TIME))&&donationUser.getCreatedAt().isBefore(LocalDateTime.parse(localDate+LAST_TIME))){
oneDayDonationAmount += donationUser.getPrice();
Expand All @@ -67,9 +73,10 @@ public DonationRes.DonationInfo getDonationInfo() {
if(donationUser.getCreatedAt().isAfter(LocalDateTime.parse(localDate.with(TemporalAdjusters.firstDayOfMonth())+FIRST_TIME))&&donationUser.getCreatedAt().isBefore( LocalDateTime.parse(localDate.with(TemporalAdjusters.lastDayOfMonth())+LAST_TIME))){
monthlyDonationAmount += donationUser.getPrice();
}
totalDonationAmount += donationUser.getPrice();
}

return new DonationRes.DonationInfo(donationHelper.parsePriceComma(oneDayDonationAmount),donationHelper.parsePriceComma(weekendDonationAmount),donationHelper.parsePriceComma(monthlyDonationAmount));
return new DonationRes.DonationInfo(donationHelper.parsePriceComma(oneDayDonationAmount),donationHelper.parsePriceComma(weekendDonationAmount),donationHelper.parsePriceComma(monthlyDonationAmount), donationHelper.parsePriceComma(totalDonationAmount));
}

public DonationRes.DonationDetail getDonationDetail(Long donationId) {
Expand Down Expand Up @@ -181,4 +188,62 @@ public PageResponse<List<DonationRes.ProjectDonationDto>> getProjectDonationList

return new PageResponse<>(donationUsers.isLast(),donationUsers.getTotalElements(), adminDonationConverter.convertToDonationLists(donationUsers.getContent()));
}

@Transactional
@Cacheable(value = "regularInfo", cacheManager = "redisCacheManager")
public DonationRes.RegularInfoDto getRegularInfo() {
List<DonationUser> donationUsers = donationAdaptor.getRegularDonationLists();
List<RegularPayment> regularPayments = paymentAdaptor.getRegularInfo();

Long beforeCnt = 0L, underCnt = 0L, successCnt = 0L, successAmount = 0L;
Long regularCnt = 0L, totalAmount = 0L;
Long beforeMonthRegularCnt = 0L, beforeMonthRegularAmount = 0L;
YearMonth previousMonth = YearMonth.now().minusMonths(1);


for(DonationUser donationUser : donationUsers){
switch (donationUser.getDonationStatus()){
case EXECUTION_SUCCESS:
case PARTIAL_EXECUTION:
successAmount += donationUser.getExecutionPrice();
successCnt++;
break;
case EXECUTION_BEFORE:
beforeCnt++;
break;
case EXECUTION_UNDER:
underCnt++;
break;
case EXECUTION_REFUND:
break;
}

if(donationUser.getRegularPaymentId()!=null) {
YearMonth creationMonth = YearMonth.from(donationUser.getCreatedAt());
if (creationMonth.equals(previousMonth)) {
beforeMonthRegularAmount += donationUser.getPrice();
beforeMonthRegularCnt++;
}
}
}

for (RegularPayment payment : regularPayments) {
if (payment.getRegularPayStatus().equals(RegularPayStatus.PROCEEDING)) {
regularCnt++;
totalAmount += payment.getAmount();
}
}

return adminDonationConverter.convertToRegularInfoDto(beforeCnt, underCnt, successCnt, donationHelper.parsePriceComma(
Math.toIntExact(successAmount)), regularCnt, donationHelper.parsePriceComma(Math.toIntExact(totalAmount)), beforeMonthRegularCnt, donationHelper.parsePriceComma(
Math.toIntExact(beforeMonthRegularAmount)));
}

public Long countByUserId(Long userId) {
return paymentAdaptor.countByUserId(userId);
}

public List<DonationUser> findByUserId(Long userId) {
return donationAdaptor.findByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ public CommonResponse<String> uploadEventList(@RequestBody EventUploadReq eventU
return CommonResponse.onSuccess("업로드 성공");
}

@DeleteMapping("/{eventId}")
@Operation(summary = "ADMIN-09-02 이벤트 삭제")
public CommonResponse<String> deleteEvent(@PathVariable Long eventId){
adminEventService.deleteEvent(eventId);
return CommonResponse.onSuccess("삭제 성공");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import com.example.matchapi.common.model.ContentsList;
import com.example.matchapi.common.util.MessageHelper;
import com.example.matchapi.event.converter.EventConverter;
import com.example.matchapi.event.service.EventService;
import com.example.matchcommon.annotation.RedissonLock;
import com.example.matchcommon.constants.enums.Topic;
import com.example.matchdomain.event.adaptor.EventAdaptor;
import com.example.matchdomain.event.adaptor.EventContentAdaptor;
import com.example.matchdomain.event.entity.Event;
import com.example.matchdomain.event.entity.EventContent;
import com.example.matchdomain.event.repository.EventContentRepository;
import com.example.matchdomain.event.repository.EventRepository;
import com.example.matchinfrastructure.config.s3.S3UploadService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -25,16 +25,17 @@
@Service
@RequiredArgsConstructor
public class AdminEventService {
private final EventRepository eventRepository;
private final EventContentRepository eventContentRepository;
private final EventConverter eventConverter;
private final EventService eventService;
private final MessageHelper messageHelper;
@RedissonLock(LockName = "이벤트 업로드", key = "#eventUploadReq")
private final EventAdaptor eventAdaptor;
private final EventContentAdaptor eventContentAdaptor;
private final S3UploadService s3UploadService;

@Transactional
@CacheEvict(value = "eventCache", allEntries = true, cacheManager = "ehcacheManager")
public void uploadEventList(EventUploadReq eventUploadReq) {

Event event = eventRepository.save(eventConverter.convertToEventUpload(eventUploadReq, eventUploadReq.getThumbnail()));
Event event = eventAdaptor.save(eventConverter.convertToEventUpload(eventUploadReq, eventUploadReq.getThumbnail()));

Long eventId = event.getId();

Expand All @@ -48,10 +49,22 @@ public void uploadEventList(EventUploadReq eventUploadReq) {
}
}

eventContentRepository.saveAll(eventContents);
eventContentAdaptor.saveAll(eventContents);

messageHelper.helpFcmMessage(EVENT_UPLOAD_BODY, Topic.EVENT_UPLOAD, event.getId());
}


@Transactional
@CacheEvict(value = "eventCache", allEntries = true, cacheManager = "ehcacheManager")
public void deleteEvent(Long eventId) {
Event event = eventAdaptor.findByEvent(eventId);
List<EventContent> eventContents = event.getEventContents();
for(EventContent eventContent : eventContents){
if(eventContent.getContentsType().equals(IMG)){
s3UploadService.deleteFile(eventContent.getContents());
}
}
eventAdaptor.deleteByEventId(eventId);
}
}
Loading

0 comments on commit fa7e367

Please sign in to comment.