- used for tests
- no DB implenention for prod
This commit is contained in:
djmil 2023-07-20 12:31:04 +02:00
parent 198b49dd8f
commit 38f86076c2
6 changed files with 47 additions and 7 deletions

View File

@ -8,7 +8,7 @@ group = 'djmil'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
sourceCompatibility = '20'
}
repositories {
@ -18,8 +18,26 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.data:spring-data-jdbc'
testImplementation 'com.h2database:h2'
}
tasks.named('test') {
useJUnitPlatform()
}
// This section causes useful test output to go to the terminal.
test {
testLogging {
events "passed", "skipped", "failed" //, "standardOut", "standardError"
showExceptions true
exceptionFormat "full"
showCauses true
showStackTraces true
// Change to `true` for more verbose test output
showStandardStreams = false
}
}

View File

@ -1,5 +1,6 @@
package djmil.cashcard;
public record CashCard(Long id, Double amount) {
import org.springframework.data.annotation.Id;
public record CashCard(@Id Long id, Double amount) {
}

View File

@ -6,17 +6,26 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Optional;
@RestController
@RequestMapping("/cashcards")
public class CashCardController {
private CashCardRepository cashCardRepository;
public CashCardController(CashCardRepository cashCardRepository) {
this.cashCardRepository = cashCardRepository;
}
@GetMapping("/{requestedId}")
public ResponseEntity<CashCard> findById(@PathVariable Long requestedId) {
if (requestedId.equals(99L)) {
CashCard cashCard = new CashCard(99L, 123.45);
return ResponseEntity.ok(cashCard);
Optional<CashCard> cashCardOptional = cashCardRepository.findById(requestedId);
if (cashCardOptional.isPresent()) {
return ResponseEntity.ok(cashCardOptional.get());
} else {
return ResponseEntity.notFound().build();
}
}
}
}

View File

@ -0,0 +1,6 @@
package djmil.cashcard;
import org.springframework.data.repository.CrudRepository;
public interface CashCardRepository extends CrudRepository<CashCard, Long> {
}

View File

@ -0,0 +1 @@
INSERT INTO CASH_CARD(ID, AMOUNT) VALUES (99, 123.45);

View File

@ -0,0 +1,5 @@
CREATE TABLE cash_card
(
ID BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
AMOUNT NUMBER NOT NULL DEFAULT 0
);