Skip to content

Commit

Permalink
Update: 출금 요청, 정산내역 조회 등 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed Jun 16, 2024
1 parent f9a2ca5 commit 710336b
Show file tree
Hide file tree
Showing 43 changed files with 866 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AdminPGREQController {

@GetMapping("/all")
public ResponseEntity<ApiResult<Page<PGREQDetailFindResponseDto>>> getAllPictureGenerateRequest(
@RequestParam @NotNull int page,
@RequestParam @NotNull @Min(0) int page,
@RequestParam @NotNull @Min(1) int size,
@RequestParam(defaultValue = "id") String sortBy,
@RequestParam(defaultValue = "asc") String direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.application.service.PictureGenerateWorkService;
import com.gt.genti.dto.admin.response.PGRESUpdateByAdminResponseDto;
import com.gt.genti.dto.admin.request.PGRESUpdateAdminInChargeRequestDto;
import com.gt.genti.dto.admin.response.PGRESSubmitByAdminResponseDto;
import com.gt.genti.dto.admin.response.PGRESUpdateAdminInChargeResponseDto;
import com.gt.genti.dto.common.request.CommonPictureKeyUpdateRequestDto;
import com.gt.genti.dto.common.response.CommonPictureUrlResponseDto;
import com.gt.genti.other.auth.UserDetailsImpl;

import jakarta.validation.Valid;
Expand All @@ -27,17 +30,24 @@ public class AdminPGRESController {
private final PictureGenerateWorkService pictureGenerateWorkService;

@PostMapping("/{pictureGenerateResponseId}/submit")
public ResponseEntity<ApiResult<PGRESUpdateByAdminResponseDto>> submit(
public ResponseEntity<ApiResult<PGRESSubmitByAdminResponseDto>> submit(
@PathVariable Long pictureGenerateResponseId) {
return success(pictureGenerateWorkService.submitFinal(pictureGenerateResponseId));
}

@PostMapping("/{pictureGenerateResponseId}/pictures")
public ResponseEntity<ApiResult<Boolean>> updatePictureList(
public ResponseEntity<ApiResult<List<CommonPictureUrlResponseDto>>> updatePictureList(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody @Valid List<CommonPictureKeyUpdateRequestDto> reuqestDtoList,
@PathVariable Long pictureGenerateResponseId) {
return success(pictureGenerateWorkService.updatePictureListCreatedByAdmin(userDetails.getUser(), reuqestDtoList,
pictureGenerateResponseId));
}

@PostMapping("/{pictureGenerateResponseId}/admin-in-charge")
public ResponseEntity<ApiResult<PGRESUpdateAdminInChargeResponseDto>> updateAdminInCharge(
@PathVariable Long pictureGenerateResponseId,
@RequestBody PGRESUpdateAdminInChargeRequestDto requestDto) {
return success(pictureGenerateWorkService.updateAdminInCharge(pictureGenerateResponseId, requestDto));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Objects;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -46,17 +48,13 @@ public ResponseEntity<ApiResult<Boolean>> changeUserRole(@PathVariable Long user

@GetMapping("/users")
public ResponseEntity<ApiResult<Page<UserFindByAdminResponseDto>>> getAllUserInfo(
@RequestParam(value = "role") @ValidUserRole @NotNull String role,
@RequestParam(value = "role", defaultValue = "ALL") @ValidUserRole @NotNull String role,
@RequestParam(value = "page") @NotNull @Min(0) int page,
@RequestParam(value = "size") @NotNull @Min(1) int size
) {
Page<UserFindByAdminResponseDto> result;
if (Objects.equals(role, "ALL")) {
result = userService.getAllUserInfo(page, size);
} else {
result = userService.getAllUserInfo(UserRole.valueOf(role), page, size);
}
return success(result);
Pageable pageable = PageRequest.of(page, size);

return success(userService.getAllUserInfo(pageable, role));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.gt.genti.adapter.in.web.admin;

import static com.gt.genti.other.util.ApiUtils.*;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.dto.admin.response.WithdrawCompletionResponseDto;
import com.gt.genti.dto.admin.response.WithdrawFindResponseDto;
import com.gt.genti.other.auth.UserDetailsImpl;
import com.gt.genti.other.valid.ValidWithdrawStatus;
import com.gt.genti.service.WithdrawService;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/admin/withdraw-requests")
@RequiredArgsConstructor
public class AdminWithdrawRequestController {
private final WithdrawService withDrawService;

@GetMapping("")
public ResponseEntity<ApiResult<Page<WithdrawFindResponseDto>>> getAllWithdrawList(
@RequestParam(name = "page") @NotNull @Min(0) int page,
@RequestParam(name = "size") @NotNull @Min(1) int size,
@RequestParam(name = "sortBy", defaultValue = "createdAt") String sortBy,
@RequestParam(name = "direction", defaultValue = "desc") String direction,
@RequestParam(name = "status", defaultValue = "ALL") @ValidWithdrawStatus String status
) {
Sort.Direction sortDirection = Sort.Direction.fromString(direction);
Pageable pageable = PageRequest.of(page, size, Sort.by(sortDirection, sortBy));

return success(withDrawService.getAllWithdrawRequests(pageable, status));
}

@PostMapping("{withdrawRequestId}")
public ResponseEntity<ApiResult<WithdrawCompletionResponseDto>> complete(
@PathVariable(name = "withdrawRequestId") Long withdrawRequestId,
@AuthenticationPrincipal UserDetailsImpl userDetails
) {
return success(withDrawService.complete(withdrawRequestId, userDetails.getUser()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.gt.genti.adapter.in.web.creator;

import static com.gt.genti.other.util.ApiUtils.*;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.dto.creator.response.WithdrawCreateResponseDto;
import com.gt.genti.other.auth.UserDetailsImpl;
import com.gt.genti.service.WithdrawService;

import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/creators/withdraw")
@RequiredArgsConstructor
public class CreatorWithdrawController {
private final WithdrawService withDrawService;

@PostMapping("")
public ResponseEntity<ApiResult<WithdrawCreateResponseDto>> createWithdrawRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails) {

return success(withDrawService.create(userDetails.getUser()));
}

@GetMapping("")
public ResponseEntity<ApiResult<List<WithdrawCreateResponseDto>>> getWithdrawRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails) {

return success(withDrawService.findWithdrawList(userDetails.getUser()));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,41 @@

import static com.gt.genti.other.util.ApiUtils.*;

import java.util.List;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.dto.SettlementFindResponseDto;
import com.gt.genti.dto.creator.response.SettlementAndWithdrawPageResponseDto;
import com.gt.genti.other.auth.UserDetailsImpl;
import com.gt.genti.service.SettlementService;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/creators")
@RequestMapping("/api/creators/settlements")
@RequiredArgsConstructor
public class SettlementController {
private final SettlementService settlementService;
@GetMapping("/settlements")
public ResponseEntity<ApiResult<List<SettlementFindResponseDto>>> getMySettlements(
@AuthenticationPrincipal UserDetailsImpl userDetails) {
//TODO 출금내역또한 나와야한다.
// edited at 2024-05-19
// author 서병렬

return success(settlementService.getAllSettlements(userDetails.getUser()));
@GetMapping("")
public ResponseEntity<ApiResult<SettlementAndWithdrawPageResponseDto>> getMySettlements(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestParam @NotNull @Min(0) int page,
@RequestParam @NotNull @Min(1) int size,
@RequestParam(defaultValue = "createdAt") String sortBy,
@RequestParam(defaultValue = "desc") String direction
) {
Sort.Direction sortDirection = Sort.Direction.fromString(direction);
Pageable pageable = PageRequest.of(page, size, Sort.by(sortDirection, sortBy));
return success(settlementService.getAllSettlements(userDetails.getUser(), pageable));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.domain.enums.PictureGenerateResponseStatus;
import com.gt.genti.dto.PGREQDetailFindResponseDto;
import com.gt.genti.dto.admin.response.PGRESUpdateByAdminResponseDto;
import com.gt.genti.dto.admin.request.PGRESUpdateAdminInChargeRequestDto;
import com.gt.genti.dto.admin.response.PGRESSubmitByAdminResponseDto;
import com.gt.genti.dto.admin.response.PGRESUpdateAdminInChargeResponseDto;
import com.gt.genti.dto.common.request.CommonPictureKeyUpdateRequestDto;
import com.gt.genti.dto.common.response.CommonPictureUrlResponseDto;
import com.gt.genti.dto.creator.request.MemoUpdateRequestDto;
import com.gt.genti.dto.creator.response.PGREQBriefFindByCreatorResponseDto;
import com.gt.genti.dto.creator.response.PGRESUpdateByCreatorResponseDto;
import com.gt.genti.error.DomainErrorCode;
import com.gt.genti.error.ExpectedException;
import com.gt.genti.other.util.PictureEntityUtils;
import com.gt.genti.other.util.TimeUtils;
import com.gt.genti.repository.CreatorRepository;
import com.gt.genti.repository.DepositRepository;
Expand Down Expand Up @@ -162,40 +166,40 @@ public PGRESUpdateByCreatorResponseDto submitToAdmin(User user, Long pictureGene
if (!Objects.equals(foundPGRES.getCreator().getId(), foundCreator.getId())) {
throw ExpectedException.withLogging(DomainErrorCode.NotAssignedToMe);
}

pictureService.findPictureCreatedByCreatorByPictureGenerateResponse(foundPGRES);

foundPGRES.creatorSubmit();

Duration elapsedDuration = foundPGRES.getCreatorElapsedTime();

Duration elapsedDuration = foundPGRES.creatorSubmitAndGetElaspedTime();
if (elapsedDuration.compareTo(Duration.ofHours(TimeUtils.PGRES_LIMIT_HOUR)) > 0) {
throw ExpectedException.withLogging(DomainErrorCode.ExpiredPictureGenerateRequest);
}
Long reward = calculateReward(elapsedDuration.toMinutes());

Long reword = calculateReward(elapsedDuration.toMinutes());
createSettlementAndDeposit(foundPGRES, elapsedDuration, reward, foundCreator);

return PGRESUpdateByCreatorResponseDto.builder()
.elapsedTime(getTimeString(elapsedDuration))
.reward(reward)
.build();
}

private void createSettlementAndDeposit(PictureGenerateResponse foundPGRES, Duration elapsedDuration, Long reward,
Creator foundCreator) {
Settlement settlement = Settlement.builder()
.pictureGenerateResponse(foundPGRES)
.elapsedMinutes(elapsedDuration.toMinutes())
.reward(reword)
.reward(reward)
.build();

settlementRepository.save(settlement);
Deposit foundDeposit = depositRepository.findByUser(user)
.orElseThrow(() -> ExpectedException.withLogging(DomainErrorCode.DepositNotFound));

foundDeposit.add(reword);
Deposit foundDeposit = depositRepository.findByCreator(foundCreator)
.orElseThrow(() -> ExpectedException.withLogging(DomainErrorCode.DepositNotFound));
foundDeposit.add(reward);
foundCreator.completeTask();

return PGRESUpdateByCreatorResponseDto.builder()
.elapsedTime(getTimeString(elapsedDuration))
.reward(reword)
.build();
}

@Transactional
public PGRESUpdateByAdminResponseDto submitFinal(Long pictureGenerateResponseId) {
public PGRESSubmitByAdminResponseDto submitFinal(Long pictureGenerateResponseId) {
PictureGenerateResponse foundPGRES = findPGRES(pictureGenerateResponseId);
List<PictureCompleted> pictureCompletedList = pictureService.findAllPictureCompletedByPictureGenerateResponse(
foundPGRES);
Expand All @@ -213,12 +217,13 @@ public PGRESUpdateByAdminResponseDto submitFinal(Long pictureGenerateResponseId)
// edited at 2024-05-21
// author 서병렬

return PGRESUpdateByAdminResponseDto.builder()
return PGRESSubmitByAdminResponseDto.builder()
.id(foundPGRES.getId())
.elapsedTime(getTimeString(elapsedDuration))
.build();
}

public Boolean updatePictureListCreatedByAdmin(User uploader,
public List<CommonPictureUrlResponseDto> updatePictureListCreatedByAdmin(User uploader,
List<CommonPictureKeyUpdateRequestDto> requestDtoList,
Long pictureGenerateResponseId) {
PictureGenerateResponse foundPGRES = pictureGenerateResponseRepository.findById(
Expand All @@ -237,8 +242,9 @@ public Boolean updatePictureListCreatedByAdmin(User uploader,
.requester(foundPGRES.getRequest().getRequester())
.uploader(uploader).build()
).toList();
pictureService.updatePictures(commandList);
return true;
return pictureService.updatePictures(commandList)
.stream().map(PictureEntityUtils::toCommonResponse)
.toList();
}

public List<PGREQDetailFindResponseDto> getPictureGenerateRequestDetail3(User user) {
Expand Down Expand Up @@ -269,5 +275,24 @@ private Creator findCreatorByUserId(Long id) {
return creatorRepository.findByUserId(id)
.orElseThrow(() -> ExpectedException.withLogging(DomainErrorCode.CreatorNotFound));
}

@Transactional
public PGRESUpdateAdminInChargeResponseDto updateAdminInCharge(Long pgresId,
PGRESUpdateAdminInChargeRequestDto requestDto) {
PictureGenerateResponse foundPGRES = findPGRES(pgresId);
List<PictureGenerateResponseStatus> canUpdateStatus = List.of(
PictureGenerateResponseStatus.SUBMITTED_FIRST,
PictureGenerateResponseStatus.ADMIN_IN_PROGRESS);
if (!canUpdateStatus.contains(foundPGRES.getStatus())) {
throw ExpectedException.withLogging(DomainErrorCode.PGRESStateException,
foundPGRES.getStatus().getResponse());
}
foundPGRES.updateInChargeAdmin(requestDto.getAdminInCharge());
return PGRESUpdateAdminInChargeResponseDto.builder()
.id(foundPGRES.getId())
.adminInCharge(foundPGRES.getAdminInCharge())
.status(foundPGRES.getStatus())
.build();
}
}

Loading

0 comments on commit 710336b

Please sign in to comment.