Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
user
committed
Nov 15, 2018
1 parent
3318c28
commit 37d7131
Showing
5 changed files
with
64 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
creditcard-app/src/main/java/pl/jkan/creditcard/CreditCardConfiguration.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 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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
creditcard-app/src/main/java/pl/jkan/creditcard/CreditCardController.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,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()); | ||
} | ||
} | ||
} |
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 @@ | ||
server.port=8012 |