Skip to content

Commit 6ed2ab0

Browse files
committed
feat: add Room, RoomBuilder, and related enums for room management
1 parent 429b982 commit 6ed2ab0

File tree

7 files changed

+246
-0
lines changed

7 files changed

+246
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.soujava.demos.mongodb.document;
2+
3+
public enum CleanStatus {
4+
CLEAN,
5+
DIRTY,
6+
INSPECTION_NEEDED
7+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package org.soujava.demos.mongodb.document;
2+
3+
import jakarta.nosql.Column;
4+
import jakarta.nosql.Entity;
5+
import jakarta.nosql.Id;
6+
7+
import java.util.Objects;
8+
9+
@Entity
10+
public class Room {
11+
12+
@Id
13+
private String id;
14+
15+
@Column
16+
private int number;
17+
18+
@Column
19+
private RoomType type;
20+
21+
@Column
22+
private RoomStatus status;
23+
24+
@Column
25+
private CleanStatus cleanStatus;
26+
27+
@Column
28+
private boolean smokingAllowed;
29+
30+
@Column
31+
private boolean underMaintenance;
32+
33+
34+
public Room() {
35+
}
36+
37+
public Room(String id, int number,
38+
RoomType type, RoomStatus status,
39+
CleanStatus cleanStatus,
40+
boolean smokingAllowed, boolean underMaintenance) {
41+
this.id = id;
42+
this.number = number;
43+
this.type = type;
44+
this.status = status;
45+
this.cleanStatus = cleanStatus;
46+
this.smokingAllowed = smokingAllowed;
47+
this.underMaintenance = underMaintenance;
48+
}
49+
50+
public String getId() {
51+
return id;
52+
}
53+
54+
public int getNumber() {
55+
return number;
56+
}
57+
58+
public RoomType getType() {
59+
return type;
60+
}
61+
62+
public RoomStatus getStatus() {
63+
return status;
64+
}
65+
66+
public CleanStatus getCleanStatus() {
67+
return cleanStatus;
68+
}
69+
70+
public boolean isSmokingAllowed() {
71+
return smokingAllowed;
72+
}
73+
74+
public boolean isUnderMaintenance() {
75+
return underMaintenance;
76+
}
77+
78+
79+
@Override
80+
public boolean equals(Object o) {
81+
if (o == null || getClass() != o.getClass()) {
82+
return false;
83+
}
84+
Room room = (Room) o;
85+
return Objects.equals(id, room.id);
86+
}
87+
88+
@Override
89+
public int hashCode() {
90+
return Objects.hashCode(id);
91+
}
92+
93+
@Override
94+
public String toString() {
95+
return "Room{" +
96+
"id='" + id + '\'' +
97+
", roomNumber=" + number +
98+
", type=" + type +
99+
", status=" + status +
100+
", cleanStatus=" + cleanStatus +
101+
", smokingAllowed=" + smokingAllowed +
102+
", underMaintenance=" + underMaintenance +
103+
'}';
104+
}
105+
106+
107+
public static RoomBuilder builder() {
108+
return new RoomBuilder();
109+
}
110+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.soujava.demos.mongodb.document;
2+
3+
public class RoomBuilder {
4+
private String id;
5+
private int roomNumber;
6+
private RoomType type;
7+
private RoomStatus status;
8+
private CleanStatus cleanStatus;
9+
private boolean smokingAllowed;
10+
private boolean underMaintenance;
11+
12+
public RoomBuilder id(String id) {
13+
this.id = id;
14+
return this;
15+
}
16+
17+
public RoomBuilder roomNumber(int roomNumber) {
18+
this.roomNumber = roomNumber;
19+
return this;
20+
}
21+
22+
public RoomBuilder type(RoomType type) {
23+
this.type = type;
24+
return this;
25+
}
26+
27+
public RoomBuilder status(RoomStatus status) {
28+
this.status = status;
29+
return this;
30+
}
31+
32+
public RoomBuilder cleanStatus(CleanStatus cleanStatus) {
33+
this.cleanStatus = cleanStatus;
34+
return this;
35+
}
36+
37+
public RoomBuilder smokingAllowed(boolean smokingAllowed) {
38+
this.smokingAllowed = smokingAllowed;
39+
return this;
40+
}
41+
42+
public RoomBuilder underMaintenance(boolean underMaintenance) {
43+
this.underMaintenance = underMaintenance;
44+
return this;
45+
}
46+
47+
public Room build() {
48+
return new Room(id, roomNumber, type, status, cleanStatus, smokingAllowed, underMaintenance);
49+
}
50+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.soujava.demos.mongodb.document;
2+
3+
import jakarta.data.repository.Param;
4+
import jakarta.data.repository.Query;
5+
import jakarta.data.repository.Repository;
6+
import jakarta.data.repository.Save;
7+
8+
import java.util.List;
9+
10+
@Repository
11+
public interface RoomRepository {
12+
13+
@Query("WHERE type = 'VIP_SUITE' AND status = 'AVAILABLE' AND underMaintenance = false")
14+
List<Room> findVipRoomsReadyForGuests();
15+
16+
@Query(" WHERE type <> 'VIP_SUITE' AND status = 'AVAILABLE' AND cleanStatus = 'CLEAN'")
17+
List<Room> findAvailableStandardRooms();
18+
19+
@Query("WHERE cleanStatus <> 'CLEAN' AND status <> 'OUT_OF_SERVICE'")
20+
List<Room> findRoomsNeedingCleaning();
21+
22+
@Query("WHERE smokingAllowed = true AND status = 'AVAILABLE'")
23+
List<Room> findAvailableSmokingRooms();
24+
25+
@Save
26+
void save(List<Room> rooms);
27+
28+
@Save
29+
Room newRoom(Room room);
30+
void deleteBy();
31+
32+
@Query("WHERE type = :type")
33+
List<Room> findByType(@Param("type") String type);
34+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.soujava.demos.mongodb.document;
2+
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
import jakarta.inject.Inject;
5+
6+
@ApplicationScoped
7+
public class RoomService {
8+
9+
private final RoomRepository repository;
10+
11+
@Inject
12+
public RoomService(RoomRepository repository) {
13+
this.repository = repository;
14+
}
15+
16+
/**
17+
* Default constructor for CDI.
18+
*/
19+
RoomService() {
20+
this.repository = null;
21+
}
22+
23+
public void newRoom(Room room) {
24+
repository.newRoom(room);
25+
}
26+
27+
28+
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.soujava.demos.mongodb.document;
2+
3+
public enum RoomStatus {
4+
AVAILABLE,
5+
RESERVED,
6+
UNDER_MAINTENANCE,
7+
OUT_OF_SERVICE
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.soujava.demos.mongodb.document;
2+
3+
public enum RoomType {
4+
STANDARD,
5+
DELUXE,
6+
SUITE,
7+
VIP_SUITE
8+
}

0 commit comments

Comments
 (0)