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
|
@Entity
|
||||||
public class Staff {
|
public class Staff {
|
||||||
|
|
||||||
private String name, job;
|
private String name;
|
||||||
|
private JobType job;
|
||||||
private @Id @GeneratedValue Long id;
|
private @Id @GeneratedValue Long id;
|
||||||
|
|
||||||
protected Staff() {
|
protected Staff() {
|
||||||
// No-argument constructor for JPA
|
// No-argument constructor for JPA
|
||||||
}
|
}
|
||||||
|
|
||||||
public Staff(String name, String job) {
|
public Staff(String name, JobType job) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.job = job;
|
this.job = job;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +28,7 @@ public class Staff {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJob() {
|
public JobType getJob() {
|
||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ public class Staff {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJob(String job) {
|
public void setJob(JobType job) {
|
||||||
this.job = job;
|
this.job = job;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class StaffController {
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
public String addStaff(
|
public String addStaff(
|
||||||
@RequestParam String name,
|
@RequestParam String name,
|
||||||
@RequestParam String job,
|
@RequestParam JobType job,
|
||||||
Model model
|
Model model
|
||||||
) {
|
) {
|
||||||
Staff newStaff = new Staff(name, job);
|
Staff newStaff = new Staff(name, job);
|
||||||
|
@ -57,7 +57,7 @@ public class StaffController {
|
||||||
public String updateStaff(
|
public String updateStaff(
|
||||||
@PathVariable("id") Staff staff,
|
@PathVariable("id") Staff staff,
|
||||||
@RequestParam String name,
|
@RequestParam String name,
|
||||||
@RequestParam String job
|
@RequestParam JobType job
|
||||||
) {
|
) {
|
||||||
staff.setJob(job);
|
staff.setJob(job);
|
||||||
staff.setName(name);
|
staff.setName(name);
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="job">Beruf:</label>
|
<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>
|
</div>
|
||||||
<button class="btn btn-primary" type="submit">Speichern</button>
|
<button class="btn btn-primary" type="submit">Speichern</button>
|
||||||
<a th:href="@{/staff}"><button type="button" class="btn btn-danger">Abbrechen</button></a>
|
<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 />
|
<input class="form-control" type="text" name="name" required />
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="job">Beruf</label>
|
<label class="form-label" for="job">Beruf:</label>
|
||||||
<input class="form-control" type="text" name="job" required />
|
<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>
|
</div>
|
||||||
<button class="btn btn-primary" type="submit">Hinzufügen</button>
|
<button class="btn btn-primary" type="submit">Hinzufügen</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue