Skip to content

Commit

Permalink
feat: small fixes implementation at Oracle NoSQL
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <[email protected]>
  • Loading branch information
otaviojava committed Oct 13, 2024
1 parent b95bb25 commit 4524178
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependencies>
<dependency>
<groupId>org.eclipse.jnosql.databases</groupId>
<artifactId>jnosql-mongodb</artifactId>
<artifactId>jnosql-oracle-nosql</artifactId>
<version>${jnosql.version}</version>
</dependency>
<dependency>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/soujava/samples/hotel/Guest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import jakarta.nosql.Column;
import jakarta.nosql.Embeddable;
import jakarta.nosql.Entity;

@Embeddable
@Entity
public record Guest (@Column String documentNumber, @Column String name) {
}
2 changes: 1 addition & 1 deletion src/main/java/org/soujava/samples/hotel/Hotel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface Hotel {
void checkOut(Room room);

@Find
Optional<Room> reservation(@By(org.soujava.samples.hotel._Room.NUMBER) int number);
Optional<Room> reservation(@By(org.soujava.samples.hotel._Room.NUMBER) String number);

Page<Room> findBy(PageRequest pageRequest);
}
11 changes: 9 additions & 2 deletions src/main/java/org/soujava/samples/hotel/HotelResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@

import jakarta.data.page.PageRequest;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import java.util.List;
import java.util.logging.Logger;

@Path("/hotels")
@ApplicationScoped
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class HotelResource {

private static final Logger LOGGER = Logger.getLogger(HotelResource.class.getName());

private final Hotel hotel;

@Inject
public HotelResource(Hotel hotel) {
this.hotel = hotel;
}
Expand All @@ -43,7 +50,7 @@ public List<Room> rooms(@QueryParam("page") @DefaultValue("1") int page,

@GET
@Path("/{number}")
public Room reservation(@PathParam("number") int number) {
public Room reservation(@PathParam("number") String number) {
LOGGER.info("Finding reservation: " + number);
return hotel.reservation(number)
.orElseThrow(() -> new WebApplicationException("Room not found", Response.Status.NOT_FOUND));
Expand All @@ -57,7 +64,7 @@ public Room checkIn(Room room) {

@DELETE
@Path("/{number}")
public void checkOut(@PathParam("number") int number) {
public void checkOut(@PathParam("number") String number) {
LOGGER.info("Check out: " + number);
var room = hotel.reservation(number)
.orElseThrow(() -> new WebApplicationException("Room not found", Response.Status.NOT_FOUND));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/soujava/samples/hotel/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import jakarta.nosql.Id;

@Entity
public record Room (@Id int number, @Column Guest guest) {
public record Room (@Id String number, @Column Guest guest) {

}

0 comments on commit 4524178

Please sign in to comment.