mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Use proper terminology for Staff and Employee
Staff is plural. The singular should be employee or a synonym. Co-authored-by: Mathis Kral <mathis_tiberius.kral@mailbox.tu-dresden.de>
This commit is contained in:
parent
a90a8cc051
commit
4f1ed1f134
|
@ -1,6 +1,6 @@
|
|||
package catering.order;
|
||||
|
||||
import catering.staff.Staff;
|
||||
import catering.staff.Employee;
|
||||
import org.javamoney.moneta.Money;
|
||||
import org.salespointframework.order.Cart;
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
public class CustomCart extends Cart {
|
||||
private final Set<Staff> staff;
|
||||
private final Set<Employee> staff;
|
||||
private OrderType orderType;
|
||||
private LocalDateTime start;
|
||||
private LocalDateTime finish;
|
||||
|
@ -30,23 +30,23 @@ public class CustomCart extends Cart {
|
|||
/**
|
||||
* Adds an employee to the cart
|
||||
*/
|
||||
public boolean addStaff(Staff staff) {
|
||||
for (Staff myStaff : this.staff) {
|
||||
if (myStaff.equals(staff)) {
|
||||
public boolean addEmployee(Employee employee) {
|
||||
for (Employee myEmployee : this.staff) {
|
||||
if (myEmployee.equals(employee)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return this.staff.add(staff);
|
||||
return this.staff.add(employee);
|
||||
}
|
||||
|
||||
public Set<Staff> getStaff() {
|
||||
public Set<Employee> getStaff() {
|
||||
return staff;
|
||||
}
|
||||
|
||||
public boolean removeStaff(Staff staff) {
|
||||
for (Staff myStaff : this.staff) {
|
||||
if (myStaff.equals(staff)) {
|
||||
return this.staff.remove(myStaff);
|
||||
public boolean removeEmployee(Employee employee) {
|
||||
for (Employee myEmployee : this.staff) {
|
||||
if (myEmployee.equals(employee)) {
|
||||
return this.staff.remove(myEmployee);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -56,8 +56,8 @@ public class CustomCart extends Cart {
|
|||
* Add staff to order (analogous to cart.addItemsTo(order))
|
||||
*/
|
||||
public CustomOrder addStaffTo(CustomOrder order) {
|
||||
for (Staff staff : this.staff) {
|
||||
order.addStaff(staff);
|
||||
for (Employee employee : this.staff) {
|
||||
order.addEmployee(employee);
|
||||
}
|
||||
|
||||
return order;
|
||||
|
@ -102,7 +102,7 @@ public class CustomCart extends Cart {
|
|||
public MonetaryAmount getPrice() {
|
||||
MonetaryAmount total = super.getPrice();
|
||||
|
||||
for (int i = 0; i < staff.size(); i++) { // TODO: get this from staff itself
|
||||
for (int i = 0; i < staff.size(); i++) { // TODO: get this from employee itself
|
||||
total = total.add(Money.of(getDurationInHoursTimesRate(12.0), "EUR"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package catering.order;
|
||||
|
||||
import catering.staff.Staff;
|
||||
import catering.staff.Employee;
|
||||
import jakarta.persistence.*;
|
||||
import org.javamoney.moneta.Money;
|
||||
import org.salespointframework.order.Order;
|
||||
|
@ -21,7 +21,7 @@ public class CustomOrder extends Order {
|
|||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@ManyToMany
|
||||
private Set<Staff> staff;
|
||||
private Set<Employee> staff;
|
||||
private OrderType orderType = OrderType.SOMETHING_ELSE;
|
||||
private LocalDateTime start;
|
||||
private LocalDateTime finish;
|
||||
|
@ -51,18 +51,18 @@ public class CustomOrder extends Order {
|
|||
/**
|
||||
* Adds an employee to the order and adds a new {@Link ChangeLine} containing the costs
|
||||
*/
|
||||
public boolean addStaff(Staff staff) {
|
||||
public boolean addEmployee(Employee employee) {
|
||||
MonetaryAmount cost = Money.of(12.0, "EUR")
|
||||
.multiply(getDurationInHours(this.start, this.finish)); // TODO: Get salary from staff
|
||||
.multiply(getDurationInHours(this.start, this.finish)); // TODO: Get salary from employee
|
||||
|
||||
if (this.staff.add(staff)) {
|
||||
super.addChargeLine(cost, staff.getId().toString());
|
||||
if (this.staff.add(employee)) {
|
||||
super.addChargeLine(cost, employee.getId().toString());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<Staff> getStaff() {
|
||||
public Set<Employee> getStaff() {
|
||||
return staff;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package catering.order;
|
||||
|
||||
import catering.staff.Staff;
|
||||
import catering.staff.Employee;
|
||||
import catering.staff.StaffManagement;
|
||||
import org.salespointframework.catalog.Product;
|
||||
import org.salespointframework.inventory.UniqueInventory;
|
||||
|
@ -94,31 +94,31 @@ public class OrderController {
|
|||
model.addAttribute("items", cart.stream().collect(Collectors.toList()));
|
||||
model.addAttribute("totalPrice", cart.getPrice());
|
||||
model.addAttribute("invItems", inventory.findAll().stream().collect(Collectors.toList()));
|
||||
Set<Staff> myStaff = new HashSet<>();
|
||||
Set<Employee> myStaff = new HashSet<>();
|
||||
staffManagement.findAll().forEach(myStaff::add);
|
||||
model.addAttribute("allStaff", myStaff);
|
||||
|
||||
return "event";
|
||||
}
|
||||
|
||||
@PostMapping("/event/addStaff")
|
||||
@PostMapping("/event/addEmployee")
|
||||
@PreAuthorize("hasRole('CUSTOMER')")
|
||||
String addStaffToCart(@RequestParam("sid") long staffId, @ModelAttribute("event") CustomCart cart) {
|
||||
Staff staff = staffManagement.findById(staffId).get();
|
||||
String addEmployeeToCart(@RequestParam("sid") long employeeId, @ModelAttribute("event") CustomCart cart) {
|
||||
Employee employee = staffManagement.findById(employeeId).get();
|
||||
|
||||
if (cart.getStaff().contains(staff)) {
|
||||
if (cart.getStaff().contains(employee)) {
|
||||
return "redirect:/event";
|
||||
}
|
||||
|
||||
cart.addStaff(staff);
|
||||
cart.addEmployee(employee);
|
||||
return "redirect:/event";
|
||||
}
|
||||
|
||||
@PostMapping("/event/removeStaff")
|
||||
@PostMapping("/event/removeEmployee")
|
||||
@PreAuthorize("hasRole('CUSTOMER')")
|
||||
String removeStaffFromCart(@RequestParam("sid") long staffId, @ModelAttribute("event") CustomCart cart) {
|
||||
Staff staff = staffManagement.findById(staffId).get();
|
||||
cart.removeStaff(staff);
|
||||
String removeEmployeeFromCart(@RequestParam("sid") long employeeId, @ModelAttribute("event") CustomCart cart) {
|
||||
Employee employee = staffManagement.findById(employeeId).get();
|
||||
cart.removeEmployee(employee);
|
||||
|
||||
return "redirect:/event";
|
||||
}
|
||||
|
|
|
@ -5,17 +5,17 @@ import jakarta.persistence.GeneratedValue;
|
|||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Staff {
|
||||
public class Employee {
|
||||
|
||||
private String name;
|
||||
private JobType job;
|
||||
private @Id @GeneratedValue Long id;
|
||||
|
||||
protected Staff() {
|
||||
protected Employee() {
|
||||
// No-argument constructor for JPA
|
||||
}
|
||||
|
||||
public Staff(String name, JobType job) {
|
||||
public Employee(String name, JobType job) {
|
||||
this.name = name;
|
||||
this.job = job;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class Staff {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Staff other) {
|
||||
if (obj instanceof Employee other) {
|
||||
return id.equals(other.id);
|
||||
}
|
||||
return false;
|
|
@ -27,31 +27,31 @@ public class StaffController {
|
|||
|
||||
@PostMapping("/staff/remove")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String removeStaff(@RequestParam("id") Staff staff, Model model) {
|
||||
staffManagement.deleteStaff(staff.getId());
|
||||
public String removeEmployee(@RequestParam("id") Employee employee, Model model) {
|
||||
staffManagement.delete(employee.getId());
|
||||
return "redirect:/staff";
|
||||
}
|
||||
|
||||
@PostMapping("/staff/add")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String addStaff(@RequestParam String name, @RequestParam JobType job) {
|
||||
staffManagement.save(new Staff(name, job));
|
||||
public String addEmployee(@RequestParam String name, @RequestParam JobType job) {
|
||||
staffManagement.save(new Employee(name, job));
|
||||
return "redirect:/staff";
|
||||
}
|
||||
|
||||
@GetMapping("/staff/edit/{id}")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String editStaff(@PathVariable("id") Staff staff, Model model) {
|
||||
model.addAttribute("staff", staff);
|
||||
public String editEmployee(@PathVariable("id") Employee employee, Model model) {
|
||||
model.addAttribute("employee", employee);
|
||||
return "edit-staff";
|
||||
}
|
||||
|
||||
@PostMapping("/staff/edit/{id}")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String updateStaff(@PathVariable("id") Staff staff, @RequestParam String name, @RequestParam JobType job) {
|
||||
staff.setJob(job);
|
||||
staff.setName(name);
|
||||
staffManagement.save(staff);
|
||||
public String updateEmployee(@PathVariable("id") Employee employee, @RequestParam String name, @RequestParam JobType job) {
|
||||
employee.setJob(job);
|
||||
employee.setName(name);
|
||||
staffManagement.save(employee);
|
||||
return "redirect:/staff";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,19 +17,19 @@ public class StaffManagement {
|
|||
this.staffRepository = staffRepository;
|
||||
}
|
||||
|
||||
public Optional<Staff> findById(Long id) {
|
||||
public Optional<Employee> findById(Long id) {
|
||||
return staffRepository.findById(id);
|
||||
}
|
||||
|
||||
public Staff save(Staff staff) {
|
||||
return staffRepository.save(staff);
|
||||
public Employee save(Employee employee) {
|
||||
return staffRepository.save(employee);
|
||||
}
|
||||
|
||||
public Streamable<Staff> findAll() {
|
||||
public Streamable<Employee> findAll() {
|
||||
return staffRepository.findAll();
|
||||
}
|
||||
|
||||
public void deleteStaff(Long id) {
|
||||
public void delete(Long id) {
|
||||
staffRepository.deleteById(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ package catering.staff;
|
|||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.util.Streamable;
|
||||
|
||||
interface StaffRepository extends CrudRepository<Staff, Long> {
|
||||
interface StaffRepository extends CrudRepository<Employee, Long> {
|
||||
|
||||
@Override
|
||||
Streamable<Staff> findAll();
|
||||
Streamable<Employee> findAll();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<form th:object="${staff}" method="post">
|
||||
<form th:object="${employee}" method="post">
|
||||
<input type="hidden" th:field="*{id}" />
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="name">Name:</label>
|
||||
|
@ -16,7 +16,7 @@
|
|||
<div class="mb-3">
|
||||
<label class="form-label" for="job">Beruf:</label>
|
||||
<select name="job" class="form-select">
|
||||
<option th:each="type : ${T(catering.staff.JobType).values()}" th:value="${type}" th:selected="${type.name() == staff.job.name()}" th:text="${type}" required></option>
|
||||
<option th:each="type : ${T(catering.staff.JobType).values()}" th:value="${type}" th:selected="${type.name() == employee.job.name()}" th:text="${type}" required></option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Speichern</button>
|
||||
|
|
|
@ -61,13 +61,13 @@
|
|||
<th>Typ</th>
|
||||
<th>Preis</th>
|
||||
<th></th>
|
||||
<tr th:each="staff : ${event.getStaff()}">
|
||||
<td th:text="${staff.getName()}">Name</td>
|
||||
<td th:text="${staff.getJob()}">Job</td>
|
||||
<td th:text="${event.getDurationInHoursTimesRate(12.0)} + '€'">Preis</td> <!--TODO: get from staff-->
|
||||
<tr th:each="employee : ${event.getStaff()}">
|
||||
<td th:text="${employee.getName()}">Name</td>
|
||||
<td th:text="${employee.getJob()}">Job</td>
|
||||
<td th:text="${event.getDurationInHoursTimesRate(12.0)} + '€'">Preis</td> <!--TODO: get from employee-->
|
||||
<td>
|
||||
<form method="post" th:action="@{/event/removeStaff}">
|
||||
<input type="hidden" th:value="${staff.getId()}" name="sid"/>
|
||||
<form method="post" th:action="@{/event/removeEmployee}">
|
||||
<input type="hidden" th:value="${employee.getId()}" name="sid"/>
|
||||
<button class="btn btn-danger" type="submit">Angestellten entfernen</button>
|
||||
</form>
|
||||
</td>
|
||||
|
@ -116,14 +116,14 @@
|
|||
<th>Verfügbar</th>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr th:each="staff : ${allStaff}">
|
||||
<td th:text="${staff.getName()}">Name</td>
|
||||
<td th:text="${staff.getJob()}">Job</td>
|
||||
<td th:text="'12€/h'">12€</td> <!--TODO: get from staff-->
|
||||
<td style="color: green" th:text="Verfügbar">Verfügbar</td> <!--TODO: get from staff-->
|
||||
<tr th:each="employee : ${allStaff}">
|
||||
<td th:text="${employee.getName()}">Name</td>
|
||||
<td th:text="${employee.getJob()}">Job</td>
|
||||
<td th:text="'12€/h'">12€</td> <!--TODO: get from employee-->
|
||||
<td style="color: green" th:text="Verfügbar">Verfügbar</td> <!--TODO: get from employee-->
|
||||
<td>
|
||||
<form th:action="@{/event/addStaff}" method="post">
|
||||
<input type="hidden" name="sid" th:value="${staff.getId()}"/>
|
||||
<form th:action="@{/event/addEmployee}" method="post">
|
||||
<input type="hidden" name="sid" th:value="${employee.getId()}"/>
|
||||
<input class="btn btn-primary" type="submit" th:value="Hinzufügen"/>
|
||||
</form>
|
||||
</td>
|
||||
|
|
|
@ -18,17 +18,17 @@
|
|||
<th></th>
|
||||
</tr>
|
||||
|
||||
<tr th:each="staff : ${staff}">
|
||||
<td th:text="${staff.name}">Max</td>
|
||||
<td th:text="${staff.job}">Koch</td>
|
||||
<tr th:each="employee : ${staff}">
|
||||
<td th:text="${employee.name}">Max</td>
|
||||
<td th:text="${employee.job}">Koch</td>
|
||||
<td>
|
||||
<a th:href="@{'/staff/edit/' + ${staff.id}}"
|
||||
<a th:href="@{'/staff/edit/' + ${employee.id}}"
|
||||
><button class="btn btn-warning">Bearbeiten</button></a
|
||||
>
|
||||
</td>
|
||||
<td>
|
||||
<form th:action="@{/staff/remove}" method="post">
|
||||
<input type="hidden" th:name="id" th:value="${staff.id}" />
|
||||
<input type="hidden" th:name="id" th:value="${employee.id}" />
|
||||
<button type="submit" class="btn btn-danger">Entfernen</button>
|
||||
</form>
|
||||
</td>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package catering.order;
|
||||
|
||||
import catering.staff.JobType;
|
||||
import catering.staff.Staff;
|
||||
import catering.staff.Employee;
|
||||
import catering.staff.StaffManagement;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -54,7 +54,7 @@ public class OrderControllerIntegrationTests {
|
|||
UserAccount myUser;
|
||||
UserAccount admin;
|
||||
CustomCart myCart;
|
||||
Staff myStaff;
|
||||
Employee myEmployee;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
@ -63,8 +63,8 @@ public class OrderControllerIntegrationTests {
|
|||
Password.UnencryptedPassword.of("12345"), Role.of("CUSTOMER"));
|
||||
}
|
||||
|
||||
myStaff = new Staff("Sabrina", JobType.SERVICE);
|
||||
staffManagement.addStaff(myStaff);
|
||||
myEmployee = new Employee("Sabrina", JobType.SERVICE);
|
||||
staffManagement.save(myEmployee);
|
||||
|
||||
myUser = userAccountManagement.findByUsername("andi").get();
|
||||
admin = userAccountManagement.findByUsername("admin").get();
|
||||
|
@ -188,9 +188,9 @@ public class OrderControllerIntegrationTests {
|
|||
|
||||
@Test
|
||||
@WithMockUser(username = "andi", roles = "CUSTOMER")
|
||||
void addStaff() throws Exception {
|
||||
mvc.perform(post("/event/addStaff")
|
||||
.param("sid", myStaff.getId().toString()))
|
||||
void addEmployee() throws Exception {
|
||||
mvc.perform(post("/event/addEmployee")
|
||||
.param("sid", myEmployee.getId().toString()))
|
||||
.andExpect(redirectedUrl("/event"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package catering.order;
|
||||
|
||||
import catering.staff.JobType;
|
||||
import catering.staff.Staff;
|
||||
import catering.staff.Employee;
|
||||
import catering.staff.StaffManagement;
|
||||
import org.javamoney.moneta.Money;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -20,14 +20,14 @@ import static org.assertj.core.api.Assertions.*;
|
|||
public class OrderUnitTests {
|
||||
@Autowired
|
||||
StaffManagement staffManagement;
|
||||
Staff staff;
|
||||
Employee employee;
|
||||
CustomOrder order;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
staff = new Staff("Peter Muffin", JobType.COOK);
|
||||
staffManagement.addStaff(staff);
|
||||
employee = new Employee("Peter Muffin", JobType.COOK);
|
||||
staffManagement.save(employee);
|
||||
|
||||
order = new CustomOrder(UserAccount.UserAccountIdentifier.of("12345"),
|
||||
new CustomCart(OrderType.RENT_A_COOK,
|
||||
|
@ -42,10 +42,10 @@ public class OrderUnitTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void addStaffToOrder() {
|
||||
order.addStaff(staff);
|
||||
void addEmployeeToOrder() {
|
||||
order.addEmployee(employee);
|
||||
|
||||
// test if staff was added
|
||||
// test if employee was added
|
||||
assertThat(order.getStaff()).hasSize(1);
|
||||
|
||||
// test if ChargeLine is correct
|
||||
|
@ -59,9 +59,9 @@ public class OrderUnitTests {
|
|||
Money.of(0.6, "EUR")),
|
||||
Quantity.of(10));
|
||||
|
||||
order.addStaff(staff);
|
||||
order.addEmployee(employee);
|
||||
|
||||
// test if staff was added
|
||||
// test if employee was added
|
||||
assertThat(order.getStaff()).hasSize(1);
|
||||
assertThat(order.getOrderLines().stream().count()).isEqualTo(1);
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class OrderUnitTests {
|
|||
assertThat(order.getTotal()).isEqualTo(Money.of(11.0 * 12.0 + 10.0 * 0.6, "EUR"));
|
||||
|
||||
// test for duplication
|
||||
order.addStaff(staff);
|
||||
order.addEmployee(employee);
|
||||
assertThat(order.getStaff()).hasSize(1);
|
||||
assertThat(order.getOrderLines().stream().count()).isEqualTo(1);
|
||||
assertThat(order.getChargeLines().stream().count()).isEqualTo(1);
|
||||
|
|
|
@ -34,12 +34,12 @@ class StaffControllerIntegrationTests {
|
|||
@Autowired
|
||||
private StaffManagement staffManagement;
|
||||
|
||||
Staff defaultEmployee;
|
||||
Employee defaultEmployee;
|
||||
Long defaultEmployeeId;
|
||||
|
||||
@BeforeEach
|
||||
void setup() throws Exception {
|
||||
defaultEmployee = staffManagement.save(new Staff("Dieter Baum", JobType.COOK));
|
||||
defaultEmployee = staffManagement.save(new Employee("Dieter Baum", JobType.COOK));
|
||||
defaultEmployeeId = defaultEmployee.getId();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue