Skip to content

Commit

Permalink
�Api-Release-v0.0.2-10
Browse files Browse the repository at this point in the history
�Api-Release-v0.0.2-10
  • Loading branch information
imenuuu authored Dec 6, 2023
2 parents e1a82f4 + 0681fb5 commit 584c426
Show file tree
Hide file tree
Showing 49 changed files with 469 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
Expand All @@ -37,4 +39,11 @@ public CommonResponse<String> sendAlimTalk(@RequestParam AlimType alimType, @Req
return CommonResponse.onSuccess("알림톡 전송 성공");
}

@PostMapping("/alim-talk-execution")
public CommonResponse<String> sendAlimTalks(@RequestParam AlimType alimType, @RequestBody List<AlimTalkDto> alimTalks){
aligoInfraService.sendAlimTalks(alimTalks, alimType);
return CommonResponse.onSuccess("알림톡 전송 성공");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-11-30T13:55:53+0900",
date = "2023-12-05T09:50:48+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-11-30T13:55:54+0900",
date = "2023-12-05T09:50:48+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-11-30T17:29:40+0900",
date = "2023-12-05T09:50:48+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,10 +4,10 @@
import com.example.matchapi.user.dto.UserRes;
import com.example.matchapi.user.service.AuthService;
import com.example.matchcommon.annotation.ApiErrorCodeExample;
import com.example.matchcommon.annotation.DisableSecurity;
import com.example.matchcommon.exception.errorcode.RequestErrorCode;
import com.example.matchcommon.reponse.CommonResponse;
import com.example.matchdomain.user.exception.AdminLoginErrorCode;
import com.example.matchdomain.user.exception.UserLoginErrorCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -27,6 +27,7 @@
public class AdminAuthController {
private final AuthService authService;
@ApiErrorCodeExample({AdminLoginErrorCode.class, RequestErrorCode.class})
@DisableSecurity
@Operation(summary="ADMIN-00-01🔑 관리자 로그인", description= "회원가입 용 API 입니다.")
@PostMapping(value="/logIn")
public CommonResponse<UserRes.UserToken> logIn(@RequestBody @Valid UserReq.LogIn logIn){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@
import com.example.matchcommon.reponse.CommonResponse;
import com.example.matchdomain.banner.enums.BannerType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/admin/banners")
@Tag(name = "ADMIN-08-Banner💳 관리자 배너 관리 API")
public class AdminBannerController {
private final AdminBannerService adminBannerService;
@PostMapping("")
@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
@Operation(summary = "ADMIN-08-01 배너 업로드")
public CommonResponse<List<BannerRes.BannerList>> uploadBanner(
@RequestParam BannerType bannerType,
//@RequestPart BannerType bannerType,
@RequestPart MultipartFile bannerImage,
@RequestPart BannerReq.BannerUpload bannerUploadDto
){
System.out.println(bannerUploadDto.getContentsUrl());
return CommonResponse.onSuccess(adminBannerService.uploadBanner(bannerType, bannerImage, bannerUploadDto));
return CommonResponse.onSuccess(adminBannerService.uploadBanner(BannerType.EVENT, bannerImage, bannerUploadDto));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public DonationRes.DonationDetail getDonationDetail(DonationUser donationUser) {
.build();
}

public DonationHistory convertToDonationHistoryComplete(Long projectId, List<Long> donationUserLists) {
public DonationHistory convertToDonationHistoryComplete(Long projectId, List<Long> donationUserLists, List<String> item) {
return DonationHistory
.builder()
.projectId(projectId)
.historyStatus(HistoryStatus.COMPLETE)
.completeIdLists(donationUserLists)
.item(item.toString())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.matchapi.admin.donation.service;

import com.example.matchapi.admin.donation.converter.AdminDonationConverter;
import com.example.matchapi.common.lisetner.ExecutionEvent;
import com.example.matchapi.donation.dto.DonationReq;
import com.example.matchapi.donation.dto.DonationRes;
import com.example.matchapi.donation.helper.DonationHelper;
Expand All @@ -15,6 +16,8 @@
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.context.ApplicationEventPublisher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -30,8 +33,6 @@
import static com.example.matchcommon.constants.MatchStatic.FIRST_TIME;
import static com.example.matchcommon.constants.MatchStatic.LAST_TIME;
import static com.example.matchdomain.donation.entity.enums.DonationStatus.*;
import static com.example.matchdomain.donation.entity.enums.Execution.ALL;
import static com.example.matchdomain.donation.entity.enums.Execution.SOME;

@Service
@RequiredArgsConstructor
Expand All @@ -43,6 +44,9 @@ public class AdminDonationService {
private final S3UploadService s3UploadService;
private final ProjectAdaptor projectAdaptor;
private final HistoryImageRepository historyImageRepository;
@Autowired
private ApplicationEventPublisher eventPublisher;


@Transactional
public DonationRes.DonationInfo getDonationInfo() {
Expand Down Expand Up @@ -74,18 +78,29 @@ public DonationRes.DonationDetail getDonationDetail(Long donationId) {
}



@Transactional
public void enforceDonation(List<MultipartFile> imageLists, DonationReq.EnforceDonation enforceDonation) {
List<Long> someExecutionIds = getSomeExecutionIds(enforceDonation.getSomeExecutions());
List<Long> allDonationUserIds = new ArrayList<>(enforceDonation.getDonationUserLists());

DonationHistory donationHistory = donationHistoryAdaptor.saveDonationHistory(
adminDonationConverter.convertToDonationHistoryComplete(enforceDonation.getProjectId(), allDonationUserIds));
adminDonationConverter.convertToDonationHistoryComplete(enforceDonation.getProjectId(), allDonationUserIds, enforceDonation.getItem()));

saveDonationHistoryImages(imageLists, donationHistory.getId());

executePartialDonations(enforceDonation.getSomeExecutions());
executeSuccessfulDonations(excludeSomeExecutionIds(allDonationUserIds, someExecutionIds));
List<DonationUser> donationUsers = new ArrayList<>();

donationUsers.addAll(executePartialDonations(enforceDonation.getSomeExecutions()));
donationUsers.addAll(executeSuccessfulDonations(excludeSomeExecutionIds(allDonationUserIds, someExecutionIds)));

donationAdaptor.saveAll(donationUsers);

Project project = projectAdaptor.findById(enforceDonation.getProjectId());

ExecutionEvent event = new ExecutionEvent(this, donationUsers, project, enforceDonation.getItem());

eventPublisher.publishEvent(event);
}

private List<Long> getSomeExecutionIds(List<DonationReq.SomeExecution> someExecutions) {
Expand All @@ -94,16 +109,29 @@ private List<Long> getSomeExecutionIds(List<DonationReq.SomeExecution> someExecu
.collect(Collectors.toList());
}

private void executePartialDonations(List<DonationReq.SomeExecution> someExecutions) {
private List<DonationUser> executePartialDonations(List<DonationReq.SomeExecution> someExecutions) {
List<Long> someExecutionIds = getSomeExecutionIds(someExecutions);
List<DonationUser> partialDonationUsers = donationAdaptor.findByListIn(someExecutionIds);

for (DonationUser donationUser : partialDonationUsers) {
DonationReq.SomeExecution execution = findSomeExecutionByUserId(someExecutions, donationUser.getId());
donationUser.updateDonationExecution(PARTIAL_EXECUTION, execution.getAmount());
if(!donationUser.getDonationStatus().equals(EXECUTION_SUCCESS)) {
DonationReq.SomeExecution execution = findSomeExecutionByUserId(someExecutions, donationUser.getId());
donationUser.updateDonationExecution(PARTIAL_EXECUTION, execution.getAmount());
}
}

donationAdaptor.saveAll(partialDonationUsers);
return partialDonationUsers;
}

private List<DonationUser> executeSuccessfulDonations(List<Long> donationUserIds) {
List<DonationUser> successfulDonationUsers = donationAdaptor.findByListIn(donationUserIds);

for (DonationUser donationUser : successfulDonationUsers) {
if(!donationUser.getDonationStatus().equals(EXECUTION_SUCCESS)) {
donationUser.updateDonationExecution(EXECUTION_SUCCESS, (long) (donationUser.getPrice() * 0.9));
}
}
return successfulDonationUsers;
}

private DonationReq.SomeExecution findSomeExecutionByUserId(List<DonationReq.SomeExecution> someExecutions, Long userId) {
Expand All @@ -113,15 +141,6 @@ private DonationReq.SomeExecution findSomeExecutionByUserId(List<DonationReq.Som
.orElseThrow(() -> new IllegalArgumentException("Invalid user ID"));
}

private void executeSuccessfulDonations(List<Long> donationUserIds) {
List<DonationUser> successfulDonationUsers = donationAdaptor.findByListIn(donationUserIds);

for (DonationUser donationUser : successfulDonationUsers) {
donationUser.updateDonationExecution(EXECUTION_SUCCESS, (long) (donationUser.getPrice() * 0.9));
}

donationAdaptor.saveAll(successfulDonationUsers);
}

private List<Long> excludeSomeExecutionIds(List<Long> allIds, List<Long> excludeIds) {
return allIds.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
public class AdminProjectController {
private final ProjectService projectService;
@Operation(summary = "ADMIN-03-01💻 프로젝트 리스트 업로드 API.",description = "프로젝트 업로드 API 입니다.")
@PostMapping(value = "", consumes = {"multipart/form-data"}, produces = "application/json")
@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
@ApiErrorCodeExample({UserAuthErrorCode.class, RequestErrorCode.class, FileUploadException.class})
public CommonResponse<String> postProject(
@Parameter(description = "project 상세 내용입니다. type 은 application/json"
, content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE))
@Valid @RequestPart("project") ProjectReq.Project project,
@RequestPart("presentFile") MultipartFile presentFile,
@RequestPart("multipartFiles") List<MultipartFile> multipartFiles){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.example.matchapi.admin.user.controller;

import com.example.matchapi.donation.service.DonationService;
import com.example.matchapi.user.converter.UserConverter;
import com.example.matchapi.user.dto.UserRes;
import com.example.matchapi.user.service.UserService;
import com.example.matchcommon.annotation.ApiErrorCodeExample;
import com.example.matchcommon.reponse.CommonResponse;
import com.example.matchcommon.reponse.PageResponse;
import com.example.matchdomain.common.model.Status;
import com.example.matchdomain.donation.entity.DonationUser;
import com.example.matchdomain.user.entity.User;
import com.example.matchdomain.user.exception.UserAuthErrorCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
Expand All @@ -23,6 +27,8 @@
@Tag(name = "ADMIN-02 User👤 관리자 유저 관련 API 입니다.", description = "ADMIN 유저 관련 API 입니다.")
public class AdminUserController {
private final UserService userService;
private final DonationService donationService;
private final UserConverter userConverter;
@GetMapping("/info")
@ApiErrorCodeExample(UserAuthErrorCode.class)
@Operation(summary = "ADMIN-02-01👤 유저저 가입 현황파악 API.",description = "프로젝트 리스트 조회 API 입니다.")
Expand Down Expand Up @@ -51,4 +57,16 @@ public CommonResponse<UserRes.UserAdminDetail> getUserDetail(@PathVariable Long
UserRes.UserAdminDetail userAdminDetail = userService.getUserAdminDetail(userId);
return CommonResponse.onSuccess(userAdminDetail);
}

@GetMapping("/flame/{userId}")
@ApiErrorCodeExample(UserAuthErrorCode.class)
@Operation(summary = "ADMIN-02-04 유저 불꽃이 생성기록 조회" ,description = "유저 불꽃이 기록 조회")
public CommonResponse<PageResponse<List<UserRes.UserFlameListDto>>> getUserFlameList(@PathVariable Long userId,
@Parameter(description = "페이지", example = "0") @RequestParam(required = false, defaultValue = "0") @Min(value = 0) int page,
@Parameter(description = "페이지 사이즈", example = "10") @RequestParam(required = false, defaultValue = "10") int size){
User user = userService.findByUserId(userId);
Page<DonationUser> donationUsers = donationService.findByUserId(user, page, size);

return CommonResponse.onSuccess(new PageResponse<>(donationUsers.isLast(), donationUsers.getTotalElements(), userConverter.convertToFlameList(donationUsers.getContent())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.matchapi.common.lisetner;


import com.example.matchdomain.donation.entity.DonationUser;
import com.example.matchdomain.project.entity.Project;
import org.springframework.context.ApplicationEvent;

import java.util.ArrayList;
import java.util.List;

public class ExecutionEvent extends ApplicationEvent {
private final List<DonationUser> donationUsers;
private final Project project;
private final List<String> items;

public ExecutionEvent(Object source, List<DonationUser> donationUsers, Project project, List<String> items) {
super(source);
this.donationUsers = donationUsers;
this.project = project;
this.items = items;
}

public List<DonationUser> getDonationUsers() {
return donationUsers;
}

public Project getProject() {
return project;
}

public List<String> getItems(){
return items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.example.matchapi.common.lisetner;

import com.example.matchapi.user.service.AligoService;
import com.example.matchdomain.donation.entity.DonationUser;
import com.example.matchdomain.project.entity.Project;
import com.example.matchdomain.user.entity.User;
import com.example.matchinfrastructure.aligo.converter.AligoConverter;
import com.example.matchinfrastructure.aligo.dto.AlimType;
import com.example.matchinfrastructure.aligo.service.AligoInfraService;
import com.example.matchinfrastructure.match_aligo.dto.AlimTalkDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@RequiredArgsConstructor
@Slf4j
public class ExecutionEventListener {
private final AligoConverter aligoConverter;
private final AligoService aligoService;
@EventListener
@Async("event-listener")
public void onDonationExecution(ExecutionEvent event){
log.info("event start");
List<DonationUser> donationUsers = event.getDonationUsers();

Project project = event.getProject();

List<AlimTalkDto> alimTalkDtos = new ArrayList<>();

String article = getArticle(event.getItems());

for(DonationUser donationUser : donationUsers){
User user = donationUser.getUser();
alimTalkDtos.add(aligoConverter.convertToAlimTalkExecution(donationUser.getId(), user.getName(), user.getPhoneNumber(), article, project.getUsages()));
}

aligoService.sendAlimTalks(AlimType.EXECUTION, alimTalkDtos);
log.info("event finish");

}

private String getArticle(List<String> items) {
return items.get(0) + " 외 " + items.size() + "개";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Getter
@AllArgsConstructor
public enum UploadFolder {
EVENT("event"), NOTICE("notice");
EVENT("event"), NOTICE("notice"), BANNER("banner");

private final String folder;
}
Loading

0 comments on commit 584c426

Please sign in to comment.