-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountController.java
More file actions
48 lines (36 loc) · 1.6 KB
/
Copy pathAccountController.java
File metadata and controls
48 lines (36 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.neflodev.expensestrackerapi.web;
import com.neflodev.expensestrackerapi.dto.account.AccountCreateParams;
import com.neflodev.expensestrackerapi.dto.account.AccountDto;
import com.neflodev.expensestrackerapi.dto.general.IdBody;
import com.neflodev.expensestrackerapi.service.AccountService;
import com.neflodev.expensestrackerapi.util.CustomUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("accounts/")
public class AccountController {
private final AccountService service;
public AccountController(AccountService service) {
this.service = service;
}
@GetMapping("/me")
public ResponseEntity<List<AccountDto>> getRetrieveUserAccounts(){
String currentUserName = CustomUtils.retrieveSessionUsername();
return ResponseEntity.ok(service.retrieveUserAccounts(currentUserName));
}
@GetMapping("/currencies")
public ResponseEntity<List<String>> getRetrieveAvailableCurrencies(){
return ResponseEntity.ok(service.retrieveAvailableCurrencies());
}
@PostMapping("/")
public ResponseEntity<IdBody> postCreateAccount(@RequestBody AccountCreateParams params){
String currentUserName = CustomUtils.retrieveSessionUsername();
return ResponseEntity.ok(service.createAccount(currentUserName, params));
}
@DeleteMapping("/{accountId}")
public ResponseEntity<Void> deleteAccount(@PathVariable("accountId") Long accountId){
service.deleteAccount(accountId);
return ResponseEntity.ok().build();
}
}