-
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: Refine wallet, payment component
- Loading branch information
Tran Gia Bao
committed
Feb 15, 2025
1 parent
f6d2013
commit 922d111
Showing
13 changed files
with
84 additions
and
36 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
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
18 changes: 8 additions & 10 deletions
18
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 |
---|---|---|
@@ -1,30 +1,28 @@ | ||
package enterprise.rest; | ||
|
||
import commons.springfw.impl.securities.UserContextData; | ||
import green_buildings.commons.api.exceptions.BusinessException; | ||
import enterprise.services.WalletService; | ||
import green_buildings.commons.api.security.UserRole; | ||
import jakarta.annotation.security.RolesAllowed; | ||
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("/api/wallet") | ||
@RequiredArgsConstructor | ||
public class WalletController { | ||
|
||
private final WalletService walletService; | ||
|
||
@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(); | ||
@RolesAllowed(UserRole.RoleNameConstant.ENTERPRISE_OWNER) | ||
public ResponseEntity<Long> getBalance(@AuthenticationPrincipal UserContextData userContextData) { | ||
return ResponseEntity.ok().body(walletService.getBalance()); | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package enterprise.services; | ||
|
||
import enterprise.entities.WalletEntity; | ||
|
||
public interface WalletService { | ||
WalletEntity getBalance(); | ||
Long getBalance(); | ||
} |
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
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
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
15 changes: 15 additions & 0 deletions
15
sep490-frontend/src/app/modules/enterprise/services/wallet.service.ts
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,15 @@ | ||
import {HttpClient} from '@angular/common/http'; | ||
import {Injectable} from '@angular/core'; | ||
import {Observable} from 'rxjs'; | ||
import {AppRoutingConstants} from '../../../app-routing.constant'; | ||
|
||
@Injectable() | ||
export class WalletService { | ||
constructor(private readonly httpClient: HttpClient) {} | ||
|
||
public getWalletBalance(): Observable<number> { | ||
return this.httpClient.get<number>( | ||
`${AppRoutingConstants.ENTERPRISE_API_URL}/wallet/balance` | ||
); | ||
} | ||
} |
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