dev #8
@@ -24,6 +24,8 @@ import de.zendric.app.xpensely_server.model.ExpenseChangeRequest;
|
|||||||
import de.zendric.app.xpensely_server.model.ExpenseInput;
|
import de.zendric.app.xpensely_server.model.ExpenseInput;
|
||||||
import de.zendric.app.xpensely_server.model.ExpenseList;
|
import de.zendric.app.xpensely_server.model.ExpenseList;
|
||||||
import de.zendric.app.xpensely_server.model.InviteRequest;
|
import de.zendric.app.xpensely_server.model.InviteRequest;
|
||||||
|
import de.zendric.app.xpensely_server.model.XpenselyStandardCategories;
|
||||||
|
import de.zendric.app.xpensely_server.services.CategoryService;
|
||||||
import de.zendric.app.xpensely_server.services.ExpenseListService;
|
import de.zendric.app.xpensely_server.services.ExpenseListService;
|
||||||
import de.zendric.app.xpensely_server.services.UserService;
|
import de.zendric.app.xpensely_server.services.UserService;
|
||||||
|
|
||||||
@@ -33,11 +35,14 @@ class ExpenseListController {
|
|||||||
|
|
||||||
private ExpenseListService expenseListService;
|
private ExpenseListService expenseListService;
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
private CategoryService categoryService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ExpenseListController(ExpenseListService expenseListService, UserService userService) {
|
public ExpenseListController(ExpenseListService expenseListService, UserService userService,
|
||||||
|
CategoryService categoryService) {
|
||||||
this.expenseListService = expenseListService;
|
this.expenseListService = expenseListService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.categoryService = categoryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
@@ -105,6 +110,8 @@ class ExpenseListController {
|
|||||||
throw new IllegalArgumentException("Owner does not exist.");
|
throw new IllegalArgumentException("Owner does not exist.");
|
||||||
}
|
}
|
||||||
expenseList.setOwner(existingOwner);
|
expenseList.setOwner(existingOwner);
|
||||||
|
XpenselyStandardCategories standardCategories = categoryService.getDefaultCategories();
|
||||||
|
expenseList.setXpenselyStandardCategories(standardCategories);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Owner is required.");
|
throw new IllegalArgumentException("Owner is required.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package de.zendric.app.xpensely_server.model.DTO;
|
|||||||
|
|
||||||
public class ExpenseListDTO {
|
public class ExpenseListDTO {
|
||||||
|
|
||||||
// TODO should combine the two categories two one;
|
// TODO should combine the two categories to one;
|
||||||
|
|
||||||
// private List<CategoryDTO> availableCategories;
|
// private List<CategoryDTO> availableCategories;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ public class ExpenseChangeRequest {
|
|||||||
private Double personalUseAmount;
|
private Double personalUseAmount;
|
||||||
private Double otherPersonAmount;
|
private Double otherPersonAmount;
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
|
private String category;
|
||||||
|
|
||||||
public Expense convertToExpense(Long userId, ExpenseList expenseList) {
|
public Expense convertToExpense(Long userId, ExpenseList expenseList) {
|
||||||
AppUser appUser = new AppUser();
|
AppUser appUser = new AppUser();
|
||||||
@@ -33,6 +34,7 @@ public class ExpenseChangeRequest {
|
|||||||
expense.setId(id);
|
expense.setId(id);
|
||||||
expense.setOwner(appUser);
|
expense.setOwner(appUser);
|
||||||
expense.setTitle(title);
|
expense.setTitle(title);
|
||||||
|
expense.setCategory(category);
|
||||||
|
|
||||||
return expense;
|
return expense;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class ExpenseInput {
|
|||||||
private Double otherPersonAmount;
|
private Double otherPersonAmount;
|
||||||
|
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
|
private String category;
|
||||||
|
|
||||||
private ExpenseList expenseList;
|
private ExpenseList expenseList;
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ public class ExpenseInput {
|
|||||||
expense.setId(id);
|
expense.setId(id);
|
||||||
expense.setOwner(appUser);
|
expense.setOwner(appUser);
|
||||||
expense.setTitle(title);
|
expense.setTitle(title);
|
||||||
|
expense.setCategory(category);
|
||||||
|
|
||||||
return expense;
|
return expense;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class XpenselyStandardCategories {
|
|||||||
@Id
|
@Id
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
|
||||||
@JoinColumn(name = "global_categories_id")
|
@JoinColumn(name = "global_categories_id")
|
||||||
private List<XpenselyStandardCategory> categories;
|
private List<XpenselyStandardCategory> categories;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.zendric.app.xpensely_server.preparation;
|
package de.zendric.app.xpensely_server.preparation;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
@@ -18,18 +19,22 @@ public class DataInitializer implements CommandLineRunner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {
|
||||||
if (!globalRepo.findById(1L).isPresent()) {
|
Optional<XpenselyStandardCategories> optional = globalRepo.findById(1L);
|
||||||
XpenselyStandardCategories global = new XpenselyStandardCategories();
|
|
||||||
global.setId(1L);
|
|
||||||
|
|
||||||
List<XpenselyStandardCategory> categories = List.of(
|
XpenselyStandardCategories global = optional.orElseGet(() -> {
|
||||||
new XpenselyStandardCategory(null, "Food", "#FF5733"),
|
XpenselyStandardCategories g = new XpenselyStandardCategories();
|
||||||
new XpenselyStandardCategory(null, "Transportation", "#33C3FF"),
|
g.setId(1L);
|
||||||
new XpenselyStandardCategory(null, "Entertainment", "#33FF57"),
|
return g;
|
||||||
new XpenselyStandardCategory(null, "Shopping", "#FF33A8"),
|
});
|
||||||
new XpenselyStandardCategory(null, "Bills", "#33FFEA"));
|
|
||||||
global.setCategories(categories);
|
List<XpenselyStandardCategory> categories = List.of(
|
||||||
globalRepo.save(global);
|
new XpenselyStandardCategory(null, "Food", "#FF5733"),
|
||||||
}
|
new XpenselyStandardCategory(null, "Transportation", "#33C3FF"),
|
||||||
|
new XpenselyStandardCategory(null, "Entertainment", "#33FF57"),
|
||||||
|
new XpenselyStandardCategory(null, "Shopping", "#FF33A8"),
|
||||||
|
new XpenselyStandardCategory(null, "Household", "#FFC733"),
|
||||||
|
new XpenselyStandardCategory(null, "Other", "#9D33FF"));
|
||||||
|
global.setCategories(categories);
|
||||||
|
globalRepo.save(global);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package de.zendric.app.xpensely_server.services;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import de.zendric.app.xpensely_server.model.XpenselyStandardCategories;
|
||||||
|
import de.zendric.app.xpensely_server.repo.XpenselyStandardCategoriesRepository;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CategoryService {
|
||||||
|
|
||||||
|
private final XpenselyStandardCategoriesRepository standardCategoriesRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public CategoryService(XpenselyStandardCategoriesRepository standardCategoriesRepo) {
|
||||||
|
this.standardCategoriesRepo = standardCategoriesRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XpenselyStandardCategories getDefaultCategories() {
|
||||||
|
return standardCategoriesRepo.findById(1L)
|
||||||
|
.orElseThrow(() -> new IllegalStateException("Standard categories not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -183,6 +183,7 @@ public class ExpenseListService {
|
|||||||
existingExpense.setOtherPersonAmount(updatedExpense.getOtherPersonAmount());
|
existingExpense.setOtherPersonAmount(updatedExpense.getOtherPersonAmount());
|
||||||
existingExpense.setDate(updatedExpense.getDate());
|
existingExpense.setDate(updatedExpense.getDate());
|
||||||
existingExpense.setOwner(updatedExpense.getOwner());
|
existingExpense.setOwner(updatedExpense.getOwner());
|
||||||
|
existingExpense.setCategory(updatedExpense.getCategory());
|
||||||
|
|
||||||
return expenseRepository.save(existingExpense);
|
return expenseRepository.save(existingExpense);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user