Make income/expense return created instance's id #44
@@ -28,9 +28,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.Month;
|
import java.time.Month;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -52,7 +50,7 @@ public class ExpenseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public ResponseEntity<Void> createNewExpense(@RequestBody @Valid ExpenseCreationDTO expenseDTO,
|
public ResponseEntity<Map<String, Long>> createNewExpense(@RequestBody @Valid ExpenseCreationDTO expenseDTO,
|
||||||
BindingResult bindingResult) {
|
BindingResult bindingResult) {
|
||||||
if(bindingResult.hasErrors())
|
if(bindingResult.hasErrors())
|
||||||
throw new TransactionNotCreatedException("Could not create new expense");
|
throw new TransactionNotCreatedException("Could not create new expense");
|
||||||
@@ -68,7 +66,9 @@ public class ExpenseController {
|
|||||||
expense.setUser(user);
|
expense.setUser(user);
|
||||||
|
|
||||||
expenseService.createOrUpdate(expense);
|
expenseService.createOrUpdate(expense);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
Map<String, Long> response = new HashMap<>();
|
||||||
|
response.put("expenseId", expense.getId());
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new TransactionNotCreatedException("Could not create new expense");
|
throw new TransactionNotCreatedException("Could not create new expense");
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.Month;
|
import java.time.Month;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -52,7 +50,7 @@ public class IncomeController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public ResponseEntity<Void> createNewIncome(@RequestBody @Valid IncomeCreationDTO incomeDTO,
|
public ResponseEntity<Map<String, Long>> createNewIncome(@RequestBody @Valid IncomeCreationDTO incomeDTO,
|
||||||
BindingResult bindingResult) {
|
BindingResult bindingResult) {
|
||||||
if(bindingResult.hasErrors())
|
if(bindingResult.hasErrors())
|
||||||
throw new TransactionNotCreatedException(ErrorResponse.from(bindingResult).getMessage());
|
throw new TransactionNotCreatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||||
@@ -68,10 +66,12 @@ public class IncomeController {
|
|||||||
income.setUser(user);
|
income.setUser(user);
|
||||||
|
|
||||||
incomeService.createOrUpdate(income);
|
incomeService.createOrUpdate(income);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).build();
|
Map<String, Long> response = new HashMap<>();
|
||||||
|
response.put("incomeId", income.getId());
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new TransactionNotCreatedException("Could not create new expense");
|
throw new TransactionNotCreatedException("Could not create new income");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/update/{id}")
|
@PatchMapping("/update/{id}")
|
||||||
|
|||||||
Reference in New Issue
Block a user