rename directories

This commit is contained in:
2025-07-14 17:02:31 +08:00
parent 742c8f5931
commit 0c8d6cbd06
21 changed files with 523 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package com.example.money_transfer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MoneyTransferApplication {
public static void main(String[] args) {
SpringApplication.run(MoneyTransferApplication.class, args);
}
}

View File

@ -0,0 +1,66 @@
package com.example.money_transfer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import lombok.Data;
import java.util.Map;
import java.util.HashMap;
@RestController
public class MoneyTransferController {
// Global accounts variable
private static final Map<String, Map<String, Double>> accounts = new HashMap<String, Map<String, Double>>() {{
put("1", new HashMap<String, Double>() {{ put("amount", 1000.0); }});
put("2", new HashMap<String, Double>() {{ put("amount", 1000.0); }});
}};
@PostMapping("/transfer")
public ResponseEntity<?> transfer(@RequestBody TransferRequest request) {
if (request.getAmount() <= 0) {
return ResponseEntity.badRequest().body(
new TransferErrorResponse("FAILED", "Amount must be greater than 0")
);
}
System.out.println("Transfer request: " + request);
System.out.println("Accounts: " + accounts);
return ResponseEntity.ok(
new TransferResponse(request.getAmount(), request.getSender(), request.getReceiver())
);
}
@Data
public static class TransferRequest {
private Double amount;
private String sender;
private String receiver;
}
@Data
public static class TransferResponse {
private Double amount;
private String sender;
private String receiver;
public TransferResponse(Double amount, String sender, String receiver) {
this.amount = amount;
this.sender = sender;
this.receiver = receiver;
}
}
@Data
public static class TransferErrorResponse {
private String error;
private String message;
public TransferErrorResponse(String error, String message) {
this.error = error;
this.message = message;
}
}
}

View File

@ -0,0 +1,2 @@
spring.application.name=money-transfer
server.port=8001

View File

@ -0,0 +1,13 @@
package com.example.money_transfer;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MoneyTransferApplicationTests {
@Test
void contextLoads() {
}
}