-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from Team-BC-1/feat/userRefund
Feat/user refund
- Loading branch information
Showing
12 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/bc1/gream/domain/admin/dto/request/AdminRefundPassResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package bc1.gream.domain.admin.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
@JsonIgnoreProperties | ||
public record AdminRefundPassResponseDto() { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/bc1/gream/domain/admin/dto/response/AdminRefundPassRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package bc1.gream.domain.admin.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
@JsonIgnoreProperties | ||
public record AdminRefundPassRequestDto() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/bc1/gream/domain/user/dto/request/UserPointRefundRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package bc1.gream.domain.user.dto.request; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder // 테스트용 | ||
public record UserPointRefundRequestDto( | ||
Long point, | ||
String bank, | ||
String accountNumber | ||
) { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/bc1/gream/domain/user/dto/response/UserPointRefundResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package bc1.gream.domain.user.dto.response; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record UserPointRefundResponseDto( | ||
Long refundPoint, | ||
Long userPoint | ||
) { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/bc1/gream/domain/user/mapper/RefundMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package bc1.gream.domain.user.mapper; | ||
|
||
import bc1.gream.domain.user.dto.response.UserPointRefundResponseDto; | ||
import bc1.gream.domain.user.entity.Refund; | ||
import bc1.gream.domain.user.entity.User; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper | ||
public interface RefundMapper { | ||
|
||
RefundMapper INSTANCE = Mappers.getMapper(RefundMapper.class); | ||
|
||
@Mapping(expression = "java(refund.getPoint())", target = "refundPoint") | ||
@Mapping(expression = "java(user.getPoint())", target = "userPoint") | ||
UserPointRefundResponseDto toUserPointRefundResponseDto(Refund refund, User user); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/bc1/gream/domain/user/service/command/RefundCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package bc1.gream.domain.user.service.command; | ||
|
||
import bc1.gream.domain.admin.dto.request.AdminRefundPassResponseDto; | ||
import bc1.gream.domain.user.dto.request.UserPointRefundRequestDto; | ||
import bc1.gream.domain.user.dto.response.UserPointRefundResponseDto; | ||
import bc1.gream.domain.user.entity.Refund; | ||
import bc1.gream.domain.user.entity.User; | ||
import bc1.gream.domain.user.mapper.RefundMapper; | ||
import bc1.gream.domain.user.repository.RefundRepository; | ||
import bc1.gream.domain.user.service.UserService; | ||
import bc1.gream.domain.user.service.query.RefundQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RefundCommandService { | ||
|
||
private final RefundRepository refundRepository; | ||
private final RefundQueryService refundQueryService; | ||
private final UserService userService; | ||
|
||
@Transactional | ||
public UserPointRefundResponseDto refundsPoint(User user, UserPointRefundRequestDto requestDto) { | ||
User findUser = userService.findUser(user.getLoginId()); | ||
|
||
Refund refund = Refund.builder() | ||
.point(requestDto.point()) | ||
.bank(requestDto.bank()) | ||
.accountNumber(requestDto.accountNumber()) | ||
.user(findUser) | ||
.build(); | ||
|
||
findUser.decreasePoint(requestDto.point()); | ||
|
||
Refund savedRefund = refundRepository.save(refund); | ||
|
||
return RefundMapper.INSTANCE.toUserPointRefundResponseDto(savedRefund, findUser); | ||
} | ||
|
||
@Transactional | ||
public AdminRefundPassResponseDto approveRefund(Long id) { | ||
Refund refund = refundQueryService.findRefund(id); | ||
|
||
refundRepository.delete(refund); | ||
|
||
return new AdminRefundPassResponseDto(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters