23 lines
1.2 KiB
Java
23 lines
1.2 KiB
Java
package com.moyi.controlplane.wallet;
|
|||
|
|
|
||
|
|
import com.moyi.controlplane.auth.AuthController;
|
||
|
|
import jakarta.servlet.http.HttpServletRequest;
|
||
|
|
import java.util.Map;
|
||
|
|
import java.util.UUID;
|
||
|
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/api/admin")
|
||
|
|
public class WalletController {
|
||
|
|
private final WalletService wallet;
|
||
|
|
public WalletController(WalletService wallet) { this.wallet=wallet; }
|
||
|
|
public record GrantRequest(UUID requestId, String amount, String reason) {}
|
||
|
|
@GetMapping("/wallets")
|
||
|
|
public Map<String,Object> balances(HttpServletRequest request) { return Map.of("wallets",wallet.balances(AuthController.sessionToken(request))); }
|
||
|
|
@GetMapping("/users/{id}/wallet")
|
||
|
|
public Map<String,Object> entries(@PathVariable UUID id,HttpServletRequest request) { return Map.of("entries",wallet.entries(AuthController.sessionToken(request),id)); }
|
||
|
|
@PostMapping("/users/{id}/wallet/grants")
|
||
|
|
public Map<String,Object> grant(@PathVariable UUID id,@RequestBody GrantRequest input,HttpServletRequest request) {
|
||
|
|
return wallet.grant(AuthController.sessionToken(request),id,input.requestId(),input.amount(),input.reason(),AuthController.meta(request));
|
||
|
|
}
|
||
|
|
}
|