mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Use enum for job types
This commit is contained in:
parent
5aeaf01e0e
commit
6c8daa5287
6
src/main/java/catering/staff/JobType.java
Normal file
6
src/main/java/catering/staff/JobType.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package catering.staff;
|
||||
|
||||
public enum JobType {
|
||||
COOK,
|
||||
SERVICE
|
||||
}
|
|
@ -7,14 +7,15 @@ import jakarta.persistence.Id;
|
|||
@Entity
|
||||
public class Staff {
|
||||
|
||||
private String name, job;
|
||||
private String name;
|
||||
private JobType job;
|
||||
private @Id @GeneratedValue Long id;
|
||||
|
||||
protected Staff() {
|
||||
// No-argument constructor for JPA
|
||||
}
|
||||
|
||||
public Staff(String name, String job) {
|
||||
public Staff(String name, JobType job) {
|
||||
this.name = name;
|
||||
this.job = job;
|
||||
}
|
||||
|
@ -27,7 +28,7 @@ public class Staff {
|
|||
return name;
|
||||
}
|
||||
|
||||
public String getJob() {
|
||||
public JobType getJob() {
|
||||
return job;
|
||||
}
|
||||
|
||||
|
@ -36,7 +37,7 @@ public class Staff {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public void setJob(String job) {
|
||||
public void setJob(JobType job) {
|
||||
this.job = job;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class StaffController {
|
|||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public String addStaff(
|
||||
@RequestParam String name,
|
||||
@RequestParam String job,
|
||||
@RequestParam JobType job,
|
||||
Model model
|
||||
) {
|
||||
Staff newStaff = new Staff(name, job);
|
||||
|
@ -57,7 +57,7 @@ public class StaffController {
|
|||
public String updateStaff(
|
||||
@PathVariable("id") Staff staff,
|
||||
@RequestParam String name,
|
||||
@RequestParam String job
|
||||
@RequestParam JobType job
|
||||
) {
|
||||
staff.setJob(job);
|
||||
staff.setName(name);
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="job">Beruf:</label>
|
||||
<input class="form-control" type="text" th:field="*{job}" required />
|
||||
<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>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Speichern</button>
|
||||
<a th:href="@{/staff}"><button type="button" class="btn btn-danger">Abbrechen</button></a>
|
||||
|
|
|
@ -43,8 +43,10 @@
|
|||
<input class="form-control" type="text" name="name" required />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="job">Beruf</label>
|
||||
<input class="form-control" type="text" name="job" required />
|
||||
<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:text="${type}" required></option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue