1+ package bitxon .micronaut .controller ;
2+
3+ import static bitxon .api .constant .Constants .DIRTY_TRICK_HEADER ;
4+ import static bitxon .api .constant .Constants .DirtyTrick .FAIL_TRANSFER ;
5+
6+ import javax .validation .Valid ;
7+ import java .util .List ;
8+ import java .util .Random ;
9+
10+ import bitxon .api .model .Account ;
11+ import bitxon .api .model .MoneyTransfer ;
12+ import io .micronaut .core .annotation .Nullable ;
13+ import io .micronaut .http .HttpStatus ;
14+ import io .micronaut .http .annotation .Body ;
15+ import io .micronaut .http .annotation .Controller ;
16+ import io .micronaut .http .annotation .Get ;
17+ import io .micronaut .http .annotation .Header ;
18+ import io .micronaut .http .annotation .PathVariable ;
19+ import io .micronaut .http .annotation .Post ;
20+ import io .micronaut .http .annotation .Status ;
21+
22+
23+ @ Controller ("/accounts" )
24+ public class AccountController {
25+
26+ @ Get
27+ public List <Account > getAll () {
28+ return List .of ();
29+ }
30+
31+ @ Get ("/{id}" )
32+ public Account getById (@ PathVariable ("id" ) Long id ) {
33+ return Account .builder ().id (id ).build ();
34+ }
35+
36+ @ Post
37+ public Account create (@ Body @ Valid Account account ) {
38+ return Account .builder ()
39+ .id (new Random ().nextLong (0 , Long .MAX_VALUE ))
40+ .email (account .getEmail ())
41+ .currency (account .getCurrency ())
42+ .moneyAmount (account .getMoneyAmount ())
43+ .build ();
44+ }
45+
46+ @ Post ("/transfers" )
47+ @ Status (HttpStatus .NO_CONTENT )
48+ public void create (@ Body @ Valid MoneyTransfer transfer ,
49+ @ Header (value = DIRTY_TRICK_HEADER ) @ Nullable String dirtyTrick ) {
50+
51+ }
52+ }
0 commit comments