Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.loicmathieu.bookmarkit;

import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Readiness;

@Readiness
public class AppHealthCheck implements HealthCheck {

@Override
public HealthCheckResponse call() {
return HealthCheckResponse.builder().name("bookmark").withData("is", "always").up().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package fr.loicmathieu.bookmarkit;

import io.quarkus.hibernate.orm.panache.PanacheEntity;

import javax.persistence.Entity;

@Entity
public class Bookmark {
public class Bookmark extends PanacheEntity {
public String title;
public String url;
public String description;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
package fr.loicmathieu.bookmarkit;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.Timed;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.jboss.logging.Logger;

import javax.annotation.PostConstruct;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
Expand All @@ -12,23 +25,69 @@
@Consumes(MediaType.APPLICATION_JSON)
public class BookmarkResource {

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

@ConfigProperty(name = "greeting")
private String greeting;

@PostConstruct
void init() {
LOGGER.infof("Hello %s", greeting);
}


@GET
@Operation(summary = "List all bookmarks")
@Counted(name = "listBookmarks.count")
@Timed(name = "listBookmarks.time")
public List<Bookmark> listBookmarks() {
throw new UnsupportedOperationException("not yet implemented");
return Bookmark.listAll();
}

public Bookmark getBookmark(Long id) {
throw new UnsupportedOperationException("not yet implemented");
@GET
@Path("{id}")
@Operation(summary = "Get a bookmark")
@Counted(name = "getBookmark.count")
@Timed(name = "getBookmark.time")
public Bookmark getBookmark(@PathParam("id") Long id) {
return Bookmark.findById(id);
}

@POST
@Transactional
@Operation(summary = "Create a bookmark")
@Counted(name = "createBookmark.count")
@Timed(name = "createBookmark.time")
public Response createBookmark(Bookmark bookmark) {
throw new UnsupportedOperationException("not yet implemented");
bookmark.persist();
return Response.status(Response.Status.CREATED).entity(bookmark).build();
}

public Response updateBookmark(Bookmark bookmark, Long id) {
throw new UnsupportedOperationException("not yet implemented");
@PUT
@Path("{id}")
@Transactional
@Operation(summary = "Update a bookmark")
@Counted(name = "updateBookmark.count")
@Timed(name = "updateBookmark.time")
public void updateBookmark(Bookmark bookmark, @PathParam("id") Long id) {
Bookmark entity = Bookmark.findById(id);
entity.description = bookmark.description;
entity.location = bookmark.location;
entity.title = bookmark.title;
entity.url = bookmark.url;
}

public Response deleteBookmark(Long id) {
throw new UnsupportedOperationException("not yet implemented");
@DELETE
@Path("{id}")
@Transactional
@Operation(summary = "Delete a bookmark")
@Counted(name = "deleteBookmark.count")
@Timed(name = "deleteBookmark.time")
public Response deleteBookmark(@PathParam("id") Long id) {
Bookmark bookmark = Bookmark.findById(id);
if (bookmark != null) {
bookmark.delete();
}
return Response.noContent().build();
}
}
3 changes: 3 additions & 0 deletions bookmark-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ quarkus.datasource.password=quarkus
# drop and create the database at startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.sql-load-script=import.sql

greeting=World
%dev.greeting=Dev