Fix bugs caused by Expense/Income controllers

This commit is contained in:
DmitriiCravcenco
2023-10-04 08:57:52 +03:00
parent 5e0000d532
commit b396c1c137
14 changed files with 45 additions and 57 deletions

View File

@@ -2,7 +2,7 @@ package com.faf223.expensetrackerfaf.controller;
import com.faf223.expensetrackerfaf.model.Expense;
import com.faf223.expensetrackerfaf.service.ExpenseService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -13,10 +13,10 @@ import java.util.List;
@RestController
@RequestMapping("/expenses")
@RequiredArgsConstructor
public class ExpenseController {
@Autowired
private ExpenseService expenseService;
private final ExpenseService expenseService;
@GetMapping("/user/{userUuid}")
public ResponseEntity<List<Expense>> getExpensesByUser(@PathVariable String userUuid) {

View File

@@ -2,7 +2,7 @@ package com.faf223.expensetrackerfaf.controller;
import com.faf223.expensetrackerfaf.model.Income;
import com.faf223.expensetrackerfaf.service.IncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -13,9 +13,10 @@ import java.util.List;
@RestController
@RequestMapping("/incomes")
@RequiredArgsConstructor
public class IncomeController {
@Autowired
private IncomeService incomeService;
private final IncomeService incomeService;
@GetMapping("/user/{userUuid}")
public ResponseEntity<List<Income>> getIncomesByUser(@PathVariable String userUuid) {

View File

@@ -2,7 +2,7 @@ package com.faf223.expensetrackerfaf.controller;
import com.faf223.expensetrackerfaf.model.User;
import com.faf223.expensetrackerfaf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -11,13 +11,14 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
public class UserController {
@Autowired
private UserService userService;
private final UserService userService;
@GetMapping("/{userUuid}")
public ResponseEntity<User> getUser(@PathVariable String userUuid) {
// TODO: Create a DTO class that will be returned instead of User(password: null and uuid are returned inside of the user object)
User user = userService.getUserById(userUuid);
if (user != null) {
return ResponseEntity.ok(user);