Skip to content

Commit

Permalink
add Credit Card Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Nov 15, 2018
1 parent 3318c28 commit 37d7131
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
12 changes: 12 additions & 0 deletions creditcard-app/pom.xml
Expand Up @@ -7,7 +7,19 @@
<version>1.0-SNAPSHOT</version>
<name>creditcard-app</name>
<url>http://maven.apache.org</url>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
6 changes: 5 additions & 1 deletion creditcard-app/src/main/java/pl/jkan/creditcard/App.java
@@ -1,9 +1,13 @@
package pl.jkan.creditcard;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringApplication;

@SpringBootApplication
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
SpringApplication.run(App.class, args);
}
}
@@ -0,0 +1,17 @@
package pl.jkan.creditcard;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;

@Configuration
class CreditCardConfiguration {

@Bean
public CreditCardApi creditcardApi() {
CreditCardRepository repo = new CreditCardRepository();
CreditCard c1 = new CreditCard("1234");
repo.add(c1);

return new CreditCardApi(repo);
}
}
@@ -0,0 +1,29 @@
package pl.jkan.creditcard;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
@RestController
@RequestMapping("/api/cards")
class CreditCardController {

private CreditCardApi api;

@Autowired
public CreditCardController(CreditCardApi api) {
this.api = api;
}

@GetMapping("/{number}")
public String balance() {
return "200 zł";
}

@PostMapping("/{number}/{money}")
public void withdraw(@PathVariable String number, @PathVariable double money) {
try {
api.withdraw(number, money);
} catch (Throwable e) {
System.out.println(e.getMessage());
}
}
}
1 change: 1 addition & 0 deletions creditcard-app/src/main/resources/application.properties
@@ -0,0 +1 @@
server.port=8012

0 comments on commit 37d7131

Please sign in to comment.