initial Release request #1
@@ -0,0 +1,38 @@
|
||||
package de.zendric.app.XpenselyServer.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.zendric.app.XpenselyServer.model.ExpenseList;
|
||||
import de.zendric.app.XpenselyServer.services.ExpenseListService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/lists")
|
||||
public class ExpenseListController {
|
||||
|
||||
@Autowired
|
||||
private ExpenseListService service;
|
||||
|
||||
@GetMapping
|
||||
public List<ExpenseList> getAllLists() {
|
||||
return service.getAllLists();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ExpenseList createList(@RequestBody ExpenseList list) {
|
||||
return service.createList(list);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public void deleteList(@PathVariable Long id) {
|
||||
service.deleteList(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.zendric.app.XpenselyServer.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
public class AppUser {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.zendric.app.XpenselyServer.model;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
public class Expense {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String description;
|
||||
private Double amount;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
private ExpenseList expenseList;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package de.zendric.app.XpenselyServer.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
public class ExpenseList {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@ManyToOne
|
||||
private AppUser owner;
|
||||
|
||||
@ManyToMany
|
||||
private List<AppUser> sharedWith;
|
||||
|
||||
@OneToMany(mappedBy = "expenseList", cascade = CascadeType.ALL)
|
||||
private List<Expense> expenses;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package de.zendric.app.XpenselyServer.repo;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import de.zendric.app.XpenselyServer.model.ExpenseList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExpenseListRepository extends JpaRepository<ExpenseList, Long> {
|
||||
List<ExpenseList> findByOwnerId(Long ownerId);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package de.zendric.app.XpenselyServer.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import de.zendric.app.XpenselyServer.model.ExpenseList;
|
||||
import de.zendric.app.XpenselyServer.repo.ExpenseListRepository;
|
||||
|
||||
@Service
|
||||
public class ExpenseListService {
|
||||
@Autowired
|
||||
private ExpenseListRepository repository;
|
||||
|
||||
public List<ExpenseList> getAllLists() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
public ExpenseList createList(ExpenseList list) {
|
||||
return repository.save(list);
|
||||
}
|
||||
|
||||
public void deleteList(Long id) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user