Merge pull request #44 from lumijiez/testing_branch
Make income/expense return created instance's id
This commit was merged in pull request #44.
This commit is contained in:
@@ -28,9 +28,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@@ -52,7 +50,7 @@ public class ExpenseController {
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
public ResponseEntity<Void> createNewExpense(@RequestBody @Valid ExpenseCreationDTO expenseDTO,
|
||||
public ResponseEntity<Map<String, Long>> createNewExpense(@RequestBody @Valid ExpenseCreationDTO expenseDTO,
|
||||
BindingResult bindingResult) {
|
||||
if(bindingResult.hasErrors())
|
||||
throw new TransactionNotCreatedException("Could not create new expense");
|
||||
@@ -68,7 +66,9 @@ public class ExpenseController {
|
||||
expense.setUser(user);
|
||||
|
||||
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");
|
||||
|
||||
@@ -28,9 +28,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@@ -52,7 +50,7 @@ public class IncomeController {
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
public ResponseEntity<Void> createNewIncome(@RequestBody @Valid IncomeCreationDTO incomeDTO,
|
||||
public ResponseEntity<Map<String, Long>> createNewIncome(@RequestBody @Valid IncomeCreationDTO incomeDTO,
|
||||
BindingResult bindingResult) {
|
||||
if(bindingResult.hasErrors())
|
||||
throw new TransactionNotCreatedException(ErrorResponse.from(bindingResult).getMessage());
|
||||
@@ -68,10 +66,12 @@ public class IncomeController {
|
||||
income.setUser(user);
|
||||
|
||||
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}")
|
||||
|
||||
Reference in New Issue
Block a user