-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/ui-payment-history and ui-purchase-credit (#119)
* feature/ui-payment-history * feature/ui purchase credit and ui payment history --------- Co-authored-by: Thống <work@thongdanghoang.id.vn>
- Loading branch information
1 parent
7247c55
commit a63d02b
Showing
33 changed files
with
858 additions
and
435 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
sep490-commons/api/src/main/java/sep490/common/api/enums/StatusPayment.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,6 @@ | ||
package sep490.common.api.enums; | ||
|
||
public enum StatusPayment { | ||
SUCCESS, | ||
FAILED | ||
} |
4 changes: 4 additions & 0 deletions
4
sep490-enterprise/src/main/java/enterprise/dtos/PaymentCriteriaDTO.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,4 @@ | ||
package enterprise.dtos; | ||
|
||
public record PaymentCriteriaDTO(String criteria) { | ||
} |
17 changes: 17 additions & 0 deletions
17
sep490-enterprise/src/main/java/enterprise/dtos/PaymentDTO.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,17 @@ | ||
package enterprise.dtos; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import jakarta.validation.constraints.NotNull; | ||
import sep490.common.api.enums.StatusPayment; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
public record PaymentDTO( | ||
UUID id, | ||
@JsonFormat(pattern = "dd/MM/yyyy") LocalDateTime createdDate, | ||
StatusPayment status, | ||
@NotNull long amount | ||
) { | ||
} |
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
13 changes: 13 additions & 0 deletions
13
sep490-enterprise/src/main/java/enterprise/mappers/PaymentMapper.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,13 @@ | ||
package enterprise.mappers; | ||
|
||
import enterprise.dtos.PaymentDTO; | ||
import enterprise.entities.PaymentEntity; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.MappingConstants; | ||
|
||
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) | ||
public interface PaymentMapper { | ||
|
||
PaymentDTO paymentEntityToPaymentDTO(PaymentEntity paymentEntity); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
sep490-enterprise/src/main/java/enterprise/rest/PaymentController.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,35 @@ | ||
package enterprise.rest; | ||
|
||
import commons.springfw.impl.mappers.CommonMapper; | ||
import enterprise.dtos.PaymentCriteriaDTO; | ||
import enterprise.dtos.PaymentDTO; | ||
import enterprise.mappers.PaymentMapper; | ||
import enterprise.services.PaymentService; | ||
import green_buildings.commons.api.dto.SearchCriteriaDTO; | ||
import green_buildings.commons.api.dto.SearchResultDTO; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/payment") | ||
@RequiredArgsConstructor | ||
public class PaymentController { | ||
|
||
private final PaymentService paymentService; | ||
private final PaymentMapper paymentMapper; | ||
|
||
@PostMapping("/search") | ||
public ResponseEntity<SearchResultDTO<PaymentDTO>> searchPayment(@RequestBody SearchCriteriaDTO<PaymentCriteriaDTO> searchCriteria) { | ||
var pageable = CommonMapper.toPageable(searchCriteria.page(), searchCriteria.sort()); | ||
var searchResults = paymentService.search(searchCriteria, pageable); | ||
return ResponseEntity.ok( | ||
CommonMapper.toSearchResultDTO( | ||
searchResults, | ||
paymentMapper::paymentEntityToPaymentDTO)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
sep490-enterprise/src/main/java/enterprise/rest/WalletController.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,31 @@ | ||
package enterprise.rest; | ||
|
||
import commons.springfw.impl.securities.UserContextData; | ||
import enterprise.dtos.BuildingDTO; | ||
import green_buildings.commons.api.exceptions.BusinessException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
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.RestController; | ||
|
||
import java.util.Collections; | ||
import java.util.Objects; | ||
|
||
@RestController | ||
@RequestMapping("/wallet") | ||
@RequiredArgsConstructor | ||
public class WalletController { | ||
|
||
@GetMapping("/balance") | ||
public ResponseEntity<Void> getBalance(@AuthenticationPrincipal UserContextData userContextData) { | ||
//TODO: Must Authentication => get Id Enterpirse => get Wallet => get Balence | ||
if (Objects.nonNull(userContextData.getEnterpriseId())) { | ||
throw new BusinessException(StringUtils.EMPTY, "error.user.already.belongs.to.enterprise", Collections.emptyList()); | ||
} | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
sep490-enterprise/src/main/java/enterprise/services/PaymentService.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,13 @@ | ||
package enterprise.services; | ||
|
||
import enterprise.dtos.PaymentCriteriaDTO; | ||
import enterprise.entities.PaymentEntity; | ||
import green_buildings.commons.api.dto.SearchCriteriaDTO; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
|
||
public interface PaymentService { | ||
|
||
Page<PaymentEntity> search(SearchCriteriaDTO<PaymentCriteriaDTO> searchCriteria, Pageable pageable); | ||
} |
7 changes: 7 additions & 0 deletions
7
sep490-enterprise/src/main/java/enterprise/services/WalletService.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,7 @@ | ||
package enterprise.services; | ||
|
||
import enterprise.entities.WalletEntity; | ||
|
||
public interface WalletService { | ||
WalletEntity getBalance(); | ||
} |
35 changes: 35 additions & 0 deletions
35
sep490-enterprise/src/main/java/enterprise/services/impl/PaymentServiceImpl.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,35 @@ | ||
package enterprise.services.impl; | ||
|
||
import commons.springfw.impl.utils.SecurityUtils; | ||
import enterprise.dtos.PaymentCriteriaDTO; | ||
import enterprise.entities.PaymentEntity; | ||
import enterprise.repositories.PaymentRepository; | ||
import enterprise.services.PaymentService; | ||
import green_buildings.commons.api.dto.SearchCriteriaDTO; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@Slf4j | ||
@Transactional(rollbackOn = Throwable.class) | ||
@RequiredArgsConstructor | ||
public class PaymentServiceImpl implements PaymentService { | ||
private final PaymentRepository payRepo; | ||
|
||
@Override | ||
public Page<PaymentEntity> search(SearchCriteriaDTO<PaymentCriteriaDTO> searchCriteria, Pageable pageable) { | ||
// UUID enterpriseId = SecurityUtils.getCurrentUserEnterpriseId().orElseThrow(); | ||
return payRepo.findByName( | ||
searchCriteria.criteria().criteria(), | ||
// enterpriseId, | ||
pageable); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
sep490-enterprise/src/main/java/enterprise/services/impl/WalletServiceImpl.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,28 @@ | ||
package enterprise.services.impl; | ||
|
||
import commons.springfw.impl.utils.SecurityUtils; | ||
import enterprise.entities.WalletEntity; | ||
import enterprise.repositories.WalletRepository; | ||
import enterprise.services.WalletService; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@Slf4j | ||
@Transactional(rollbackOn = Throwable.class) | ||
@RequiredArgsConstructor | ||
public class WalletServiceImpl implements WalletService { | ||
private final WalletRepository walRepo; | ||
@Override | ||
public WalletEntity getBalance(){ | ||
// UUID enterpriseId = SecurityUtils.getCurrentUserEnterpriseId().orElseThrow(); | ||
//TODO are here | ||
|
||
return new WalletEntity(); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
sep490-enterprise/src/main/resources/db/migration/V0.0.1.2__AddFieldAtPaymentEntity.sql
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,2 @@ | ||
ALTER TABLE payments ADD status VARCHAR(255) NOT NULL; | ||
ALTER TABLE payments ADD amount BIGINT NOT NULL; |
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
Oops, something went wrong.