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:
Simon Bruder 2023-11-23 16:57:44 +01:00
parent a90a8cc051
commit 4f1ed1f134
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
13 changed files with 92 additions and 92 deletions

View file

@ -1,6 +1,6 @@
package catering.order; package catering.order;
import catering.staff.Staff; import catering.staff.Employee;
import org.javamoney.moneta.Money; import org.javamoney.moneta.Money;
import org.salespointframework.order.Cart; import org.salespointframework.order.Cart;
@ -11,7 +11,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class CustomCart extends Cart { public class CustomCart extends Cart {
private final Set<Staff> staff; private final Set<Employee> staff;
private OrderType orderType; private OrderType orderType;
private LocalDateTime start; private LocalDateTime start;
private LocalDateTime finish; private LocalDateTime finish;
@ -30,23 +30,23 @@ public class CustomCart extends Cart {
/** /**
* Adds an employee to the cart * Adds an employee to the cart
*/ */
public boolean addStaff(Staff staff) { public boolean addEmployee(Employee employee) {
for (Staff myStaff : this.staff) { for (Employee myEmployee : this.staff) {
if (myStaff.equals(staff)) { if (myEmployee.equals(employee)) {
return false; return false;
} }
} }
return this.staff.add(staff); return this.staff.add(employee);
} }
public Set<Staff> getStaff() { public Set<Employee> getStaff() {
return staff; return staff;
} }
public boolean removeStaff(Staff staff) { public boolean removeEmployee(Employee employee) {
for (Staff myStaff : this.staff) { for (Employee myEmployee : this.staff) {
if (myStaff.equals(staff)) { if (myEmployee.equals(employee)) {
return this.staff.remove(myStaff); return this.staff.remove(myEmployee);
} }
} }
return false; return false;
@ -56,8 +56,8 @@ public class CustomCart extends Cart {
* Add staff to order (analogous to cart.addItemsTo(order)) * Add staff to order (analogous to cart.addItemsTo(order))
*/ */
public CustomOrder addStaffTo(CustomOrder order) { public CustomOrder addStaffTo(CustomOrder order) {
for (Staff staff : this.staff) { for (Employee employee : this.staff) {
order.addStaff(staff); order.addEmployee(employee);
} }
return order; return order;
@ -102,7 +102,7 @@ public class CustomCart extends Cart {
public MonetaryAmount getPrice() { public MonetaryAmount getPrice() {
MonetaryAmount total = super.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")); total = total.add(Money.of(getDurationInHoursTimesRate(12.0), "EUR"));
} }

View file

@ -1,6 +1,6 @@
package catering.order; package catering.order;
import catering.staff.Staff; import catering.staff.Employee;
import jakarta.persistence.*; import jakarta.persistence.*;
import org.javamoney.moneta.Money; import org.javamoney.moneta.Money;
import org.salespointframework.order.Order; import org.salespointframework.order.Order;
@ -21,7 +21,7 @@ public class CustomOrder extends Order {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
@ManyToMany @ManyToMany
private Set<Staff> staff; private Set<Employee> staff;
private OrderType orderType = OrderType.SOMETHING_ELSE; private OrderType orderType = OrderType.SOMETHING_ELSE;
private LocalDateTime start; private LocalDateTime start;
private LocalDateTime finish; 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 * 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") 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)) { if (this.staff.add(employee)) {
super.addChargeLine(cost, staff.getId().toString()); super.addChargeLine(cost, employee.getId().toString());
return true; return true;
} }
return false; return false;
} }
public Set<Staff> getStaff() { public Set<Employee> getStaff() {
return staff; return staff;
} }

View file

@ -1,6 +1,6 @@
package catering.order; package catering.order;
import catering.staff.Staff; import catering.staff.Employee;
import catering.staff.StaffManagement; import catering.staff.StaffManagement;
import org.salespointframework.catalog.Product; import org.salespointframework.catalog.Product;
import org.salespointframework.inventory.UniqueInventory; import org.salespointframework.inventory.UniqueInventory;
@ -94,31 +94,31 @@ public class OrderController {
model.addAttribute("items", cart.stream().collect(Collectors.toList())); model.addAttribute("items", cart.stream().collect(Collectors.toList()));
model.addAttribute("totalPrice", cart.getPrice()); model.addAttribute("totalPrice", cart.getPrice());
model.addAttribute("invItems", inventory.findAll().stream().collect(Collectors.toList())); model.addAttribute("invItems", inventory.findAll().stream().collect(Collectors.toList()));
Set<Staff> myStaff = new HashSet<>(); Set<Employee> myStaff = new HashSet<>();
staffManagement.findAll().forEach(myStaff::add); staffManagement.findAll().forEach(myStaff::add);
model.addAttribute("allStaff", myStaff); model.addAttribute("allStaff", myStaff);
return "event"; return "event";
} }
@PostMapping("/event/addStaff") @PostMapping("/event/addEmployee")
@PreAuthorize("hasRole('CUSTOMER')") @PreAuthorize("hasRole('CUSTOMER')")
String addStaffToCart(@RequestParam("sid") long staffId, @ModelAttribute("event") CustomCart cart) { String addEmployeeToCart(@RequestParam("sid") long employeeId, @ModelAttribute("event") CustomCart cart) {
Staff staff = staffManagement.findById(staffId).get(); Employee employee = staffManagement.findById(employeeId).get();
if (cart.getStaff().contains(staff)) { if (cart.getStaff().contains(employee)) {
return "redirect:/event"; return "redirect:/event";
} }
cart.addStaff(staff); cart.addEmployee(employee);
return "redirect:/event"; return "redirect:/event";
} }
@PostMapping("/event/removeStaff") @PostMapping("/event/removeEmployee")
@PreAuthorize("hasRole('CUSTOMER')") @PreAuthorize("hasRole('CUSTOMER')")
String removeStaffFromCart(@RequestParam("sid") long staffId, @ModelAttribute("event") CustomCart cart) { String removeEmployeeFromCart(@RequestParam("sid") long employeeId, @ModelAttribute("event") CustomCart cart) {
Staff staff = staffManagement.findById(staffId).get(); Employee employee = staffManagement.findById(employeeId).get();
cart.removeStaff(staff); cart.removeEmployee(employee);
return "redirect:/event"; return "redirect:/event";
} }

View file

@ -5,17 +5,17 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@Entity @Entity
public class Staff { public class Employee {
private String name; private String name;
private JobType job; private JobType job;
private @Id @GeneratedValue Long id; private @Id @GeneratedValue Long id;
protected Staff() { protected Employee() {
// No-argument constructor for JPA // No-argument constructor for JPA
} }
public Staff(String name, JobType job) { public Employee(String name, JobType job) {
this.name = name; this.name = name;
this.job = job; this.job = job;
} }
@ -43,7 +43,7 @@ public class Staff {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof Staff other) { if (obj instanceof Employee other) {
return id.equals(other.id); return id.equals(other.id);
} }
return false; return false;

View file

@ -27,31 +27,31 @@ public class StaffController {
@PostMapping("/staff/remove") @PostMapping("/staff/remove")
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")
public String removeStaff(@RequestParam("id") Staff staff, Model model) { public String removeEmployee(@RequestParam("id") Employee employee, Model model) {
staffManagement.deleteStaff(staff.getId()); staffManagement.delete(employee.getId());
return "redirect:/staff"; return "redirect:/staff";
} }
@PostMapping("/staff/add") @PostMapping("/staff/add")
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")
public String addStaff(@RequestParam String name, @RequestParam JobType job) { public String addEmployee(@RequestParam String name, @RequestParam JobType job) {
staffManagement.save(new Staff(name, job)); staffManagement.save(new Employee(name, job));
return "redirect:/staff"; return "redirect:/staff";
} }
@GetMapping("/staff/edit/{id}") @GetMapping("/staff/edit/{id}")
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")
public String editStaff(@PathVariable("id") Staff staff, Model model) { public String editEmployee(@PathVariable("id") Employee employee, Model model) {
model.addAttribute("staff", staff); model.addAttribute("employee", employee);
return "edit-staff"; return "edit-staff";
} }
@PostMapping("/staff/edit/{id}") @PostMapping("/staff/edit/{id}")
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")
public String updateStaff(@PathVariable("id") Staff staff, @RequestParam String name, @RequestParam JobType job) { public String updateEmployee(@PathVariable("id") Employee employee, @RequestParam String name, @RequestParam JobType job) {
staff.setJob(job); employee.setJob(job);
staff.setName(name); employee.setName(name);
staffManagement.save(staff); staffManagement.save(employee);
return "redirect:/staff"; return "redirect:/staff";
} }
} }

View file

@ -17,19 +17,19 @@ public class StaffManagement {
this.staffRepository = staffRepository; this.staffRepository = staffRepository;
} }
public Optional<Staff> findById(Long id) { public Optional<Employee> findById(Long id) {
return staffRepository.findById(id); return staffRepository.findById(id);
} }
public Staff save(Staff staff) { public Employee save(Employee employee) {
return staffRepository.save(staff); return staffRepository.save(employee);
} }
public Streamable<Staff> findAll() { public Streamable<Employee> findAll() {
return staffRepository.findAll(); return staffRepository.findAll();
} }
public void deleteStaff(Long id) { public void delete(Long id) {
staffRepository.deleteById(id); staffRepository.deleteById(id);
} }

View file

@ -3,8 +3,8 @@ package catering.staff;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.data.util.Streamable; import org.springframework.data.util.Streamable;
interface StaffRepository extends CrudRepository<Staff, Long> { interface StaffRepository extends CrudRepository<Employee, Long> {
@Override @Override
Streamable<Staff> findAll(); Streamable<Employee> findAll();
} }

View file

@ -7,7 +7,7 @@
</head> </head>
<body> <body>
<div layout:fragment="content"> <div layout:fragment="content">
<form th:object="${staff}" method="post"> <form th:object="${employee}" method="post">
<input type="hidden" th:field="*{id}" /> <input type="hidden" th:field="*{id}" />
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="name">Name:</label> <label class="form-label" for="name">Name:</label>
@ -16,7 +16,7 @@
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="job">Beruf:</label> <label class="form-label" for="job">Beruf:</label>
<select name="job" class="form-select"> <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> </select>
</div> </div>
<button class="btn btn-primary" type="submit">Speichern</button> <button class="btn btn-primary" type="submit">Speichern</button>

View file

@ -61,13 +61,13 @@
<th>Typ</th> <th>Typ</th>
<th>Preis</th> <th>Preis</th>
<th></th> <th></th>
<tr th:each="staff : ${event.getStaff()}"> <tr th:each="employee : ${event.getStaff()}">
<td th:text="${staff.getName()}">Name</td> <td th:text="${employee.getName()}">Name</td>
<td th:text="${staff.getJob()}">Job</td> <td th:text="${employee.getJob()}">Job</td>
<td th:text="${event.getDurationInHoursTimesRate(12.0)} + '€'">Preis</td> <!--TODO: get from staff--> <td th:text="${event.getDurationInHoursTimesRate(12.0)} + '€'">Preis</td> <!--TODO: get from employee-->
<td> <td>
<form method="post" th:action="@{/event/removeStaff}"> <form method="post" th:action="@{/event/removeEmployee}">
<input type="hidden" th:value="${staff.getId()}" name="sid"/> <input type="hidden" th:value="${employee.getId()}" name="sid"/>
<button class="btn btn-danger" type="submit">Angestellten entfernen</button> <button class="btn btn-danger" type="submit">Angestellten entfernen</button>
</form> </form>
</td> </td>
@ -116,14 +116,14 @@
<th>Verfügbar</th> <th>Verfügbar</th>
<td></td> <td></td>
</tr> </tr>
<tr th:each="staff : ${allStaff}"> <tr th:each="employee : ${allStaff}">
<td th:text="${staff.getName()}">Name</td> <td th:text="${employee.getName()}">Name</td>
<td th:text="${staff.getJob()}">Job</td> <td th:text="${employee.getJob()}">Job</td>
<td th:text="'12€/h'">12€</td> <!--TODO: get from staff--> <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 staff--> <td style="color: green" th:text="Verfügbar">Verfügbar</td> <!--TODO: get from employee-->
<td> <td>
<form th:action="@{/event/addStaff}" method="post"> <form th:action="@{/event/addEmployee}" method="post">
<input type="hidden" name="sid" th:value="${staff.getId()}"/> <input type="hidden" name="sid" th:value="${employee.getId()}"/>
<input class="btn btn-primary" type="submit" th:value="Hinzufügen"/> <input class="btn btn-primary" type="submit" th:value="Hinzufügen"/>
</form> </form>
</td> </td>

View file

@ -18,17 +18,17 @@
<th></th> <th></th>
</tr> </tr>
<tr th:each="staff : ${staff}"> <tr th:each="employee : ${staff}">
<td th:text="${staff.name}">Max</td> <td th:text="${employee.name}">Max</td>
<td th:text="${staff.job}">Koch</td> <td th:text="${employee.job}">Koch</td>
<td> <td>
<a th:href="@{'/staff/edit/' + ${staff.id}}" <a th:href="@{'/staff/edit/' + ${employee.id}}"
><button class="btn btn-warning">Bearbeiten</button></a ><button class="btn btn-warning">Bearbeiten</button></a
> >
</td> </td>
<td> <td>
<form th:action="@{/staff/remove}" method="post"> <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> <button type="submit" class="btn btn-danger">Entfernen</button>
</form> </form>
</td> </td>

View file

@ -1,7 +1,7 @@
package catering.order; package catering.order;
import catering.staff.JobType; import catering.staff.JobType;
import catering.staff.Staff; import catering.staff.Employee;
import catering.staff.StaffManagement; import catering.staff.StaffManagement;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -54,7 +54,7 @@ public class OrderControllerIntegrationTests {
UserAccount myUser; UserAccount myUser;
UserAccount admin; UserAccount admin;
CustomCart myCart; CustomCart myCart;
Staff myStaff; Employee myEmployee;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
@ -63,8 +63,8 @@ public class OrderControllerIntegrationTests {
Password.UnencryptedPassword.of("12345"), Role.of("CUSTOMER")); Password.UnencryptedPassword.of("12345"), Role.of("CUSTOMER"));
} }
myStaff = new Staff("Sabrina", JobType.SERVICE); myEmployee = new Employee("Sabrina", JobType.SERVICE);
staffManagement.addStaff(myStaff); staffManagement.save(myEmployee);
myUser = userAccountManagement.findByUsername("andi").get(); myUser = userAccountManagement.findByUsername("andi").get();
admin = userAccountManagement.findByUsername("admin").get(); admin = userAccountManagement.findByUsername("admin").get();
@ -188,9 +188,9 @@ public class OrderControllerIntegrationTests {
@Test @Test
@WithMockUser(username = "andi", roles = "CUSTOMER") @WithMockUser(username = "andi", roles = "CUSTOMER")
void addStaff() throws Exception { void addEmployee() throws Exception {
mvc.perform(post("/event/addStaff") mvc.perform(post("/event/addEmployee")
.param("sid", myStaff.getId().toString())) .param("sid", myEmployee.getId().toString()))
.andExpect(redirectedUrl("/event")); .andExpect(redirectedUrl("/event"));
} }

View file

@ -1,7 +1,7 @@
package catering.order; package catering.order;
import catering.staff.JobType; import catering.staff.JobType;
import catering.staff.Staff; import catering.staff.Employee;
import catering.staff.StaffManagement; import catering.staff.StaffManagement;
import org.javamoney.moneta.Money; import org.javamoney.moneta.Money;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -20,14 +20,14 @@ import static org.assertj.core.api.Assertions.*;
public class OrderUnitTests { public class OrderUnitTests {
@Autowired @Autowired
StaffManagement staffManagement; StaffManagement staffManagement;
Staff staff; Employee employee;
CustomOrder order; CustomOrder order;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
staff = new Staff("Peter Muffin", JobType.COOK); employee = new Employee("Peter Muffin", JobType.COOK);
staffManagement.addStaff(staff); staffManagement.save(employee);
order = new CustomOrder(UserAccount.UserAccountIdentifier.of("12345"), order = new CustomOrder(UserAccount.UserAccountIdentifier.of("12345"),
new CustomCart(OrderType.RENT_A_COOK, new CustomCart(OrderType.RENT_A_COOK,
@ -42,10 +42,10 @@ public class OrderUnitTests {
} }
@Test @Test
void addStaffToOrder() { void addEmployeeToOrder() {
order.addStaff(staff); order.addEmployee(employee);
// test if staff was added // test if employee was added
assertThat(order.getStaff()).hasSize(1); assertThat(order.getStaff()).hasSize(1);
// test if ChargeLine is correct // test if ChargeLine is correct
@ -59,9 +59,9 @@ public class OrderUnitTests {
Money.of(0.6, "EUR")), Money.of(0.6, "EUR")),
Quantity.of(10)); 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.getStaff()).hasSize(1);
assertThat(order.getOrderLines().stream().count()).isEqualTo(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")); assertThat(order.getTotal()).isEqualTo(Money.of(11.0 * 12.0 + 10.0 * 0.6, "EUR"));
// test for duplication // test for duplication
order.addStaff(staff); order.addEmployee(employee);
assertThat(order.getStaff()).hasSize(1); assertThat(order.getStaff()).hasSize(1);
assertThat(order.getOrderLines().stream().count()).isEqualTo(1); assertThat(order.getOrderLines().stream().count()).isEqualTo(1);
assertThat(order.getChargeLines().stream().count()).isEqualTo(1); assertThat(order.getChargeLines().stream().count()).isEqualTo(1);

View file

@ -34,12 +34,12 @@ class StaffControllerIntegrationTests {
@Autowired @Autowired
private StaffManagement staffManagement; private StaffManagement staffManagement;
Staff defaultEmployee; Employee defaultEmployee;
Long defaultEmployeeId; Long defaultEmployeeId;
@BeforeEach @BeforeEach
void setup() throws Exception { 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(); defaultEmployeeId = defaultEmployee.getId();
} }