Skip to content

Commit

Permalink
feat(*): step 3
Browse files Browse the repository at this point in the history
feat(*): Add step 5


feat(*): Add step 3


feat: small enhancements


refactor(*): Update Postman collection
  • Loading branch information
aoudiamoncef authored and loicmathieu committed May 26, 2020
1 parent ac753da commit c442a38
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.Timed;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import javax.transaction.Transactional;
Expand All @@ -15,71 +17,78 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.List;

@Path("/bookmarks")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class BookmarkResource {
@ConfigProperty(name="greeting") String greeting;

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

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

@PostConstruct
void init(){
System.out.println("Hello " + greeting);
void init() {
LOGGER.info("Hello {}", greeting);
}


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

@GET
@Path("/{id}")
@Path("{id}")
@Operation(summary = "Get a bookmark")
@Counted(name = "get.count")
@Timed(name="get.time")
public Bookmark get(@PathParam("id") Long id) {
@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 = "create.count")
@Timed(name="create.time")
public Response create(Bookmark bookmark){
@Counted(name = "createBookmark.count")
@Timed(name = "createBookmark.time")
public Response createBookmark(Bookmark bookmark) {
bookmark.persist();
return Response.created(URI.create("/bookmarks/" + bookmark.id)).build();
return Response.status(Response.Status.CREATED).entity(bookmark).build();
}

@PUT
@Path("/{id}")
@Transactional
@Operation(summary = "Update a bookmark")
@Counted(name = "update.count")
@Timed(name="update.time")
public void update(Bookmark bookmark){
Bookmark existing = Bookmark.findById(bookmark.id);
existing.url = bookmark.url;
existing.description = bookmark.description;
existing.title = bookmark.title;
@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;
}

@DELETE
@Path("/{id}")
@Transactional
@Operation(summary = "Delete a bookmark")
@Counted(name = "delete.count")
@Timed(name="delete.time")
public void delete(@PathParam("id")Long id){
Bookmark existing = Bookmark.findById(id);
existing.delete();
@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();
}
}

This file was deleted.

1 change: 1 addition & 0 deletions bookmark-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ quarkus.datasource.username=quarkus
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

This file was deleted.

0 comments on commit c442a38

Please sign in to comment.