Skip to content

Commit c442a38

Browse files
aoudiamoncefloicmathieu
authored andcommitted
feat(*): step 3
feat(*): Add step 5 feat(*): Add step 3 feat: small enhancements refactor(*): Update Postman collection
1 parent ac753da commit c442a38

File tree

4 files changed

+38
-85
lines changed

4 files changed

+38
-85
lines changed

bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/BookmarkResource.java

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.eclipse.microprofile.metrics.annotation.Counted;
55
import org.eclipse.microprofile.metrics.annotation.Timed;
66
import org.eclipse.microprofile.openapi.annotations.Operation;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
79

810
import javax.annotation.PostConstruct;
911
import javax.transaction.Transactional;
@@ -15,71 +17,78 @@
1517
import javax.ws.rs.Path;
1618
import javax.ws.rs.PathParam;
1719
import javax.ws.rs.Produces;
18-
import javax.ws.rs.core.Context;
1920
import javax.ws.rs.core.MediaType;
2021
import javax.ws.rs.core.Response;
21-
import java.net.URI;
2222
import java.util.List;
2323

2424
@Path("/bookmarks")
2525
@Produces(MediaType.APPLICATION_JSON)
2626
@Consumes(MediaType.APPLICATION_JSON)
2727
public class BookmarkResource {
28-
@ConfigProperty(name="greeting") String greeting;
28+
29+
private static final Logger LOGGER = LoggerFactory.getLogger(BookmarkResource.class);
30+
31+
@ConfigProperty(name = "greeting")
32+
private String greeting;
2933

3034
@PostConstruct
31-
void init(){
32-
System.out.println("Hello " + greeting);
35+
void init() {
36+
LOGGER.info("Hello {}", greeting);
3337
}
3438

39+
3540
@GET
3641
@Operation(summary = "List all bookmarks")
37-
@Counted(name = "listAll.count")
38-
@Timed(name="listAll.time")
39-
public List<Bookmark> listAll(){
42+
@Counted(name = "listBookmarks.count")
43+
@Timed(name = "listBookmarks.time")
44+
public List<Bookmark> listBookmarks() {
4045
return Bookmark.listAll();
4146
}
4247

4348
@GET
44-
@Path("/{id}")
49+
@Path("{id}")
4550
@Operation(summary = "Get a bookmark")
46-
@Counted(name = "get.count")
47-
@Timed(name="get.time")
48-
public Bookmark get(@PathParam("id") Long id) {
51+
@Counted(name = "getBookmark.count")
52+
@Timed(name = "getBookmark.time")
53+
public Bookmark getBookmark(@PathParam("id") Long id) {
4954
return Bookmark.findById(id);
5055
}
5156

5257
@POST
5358
@Transactional
5459
@Operation(summary = "Create a bookmark")
55-
@Counted(name = "create.count")
56-
@Timed(name="create.time")
57-
public Response create(Bookmark bookmark){
60+
@Counted(name = "createBookmark.count")
61+
@Timed(name = "createBookmark.time")
62+
public Response createBookmark(Bookmark bookmark) {
5863
bookmark.persist();
59-
return Response.created(URI.create("/bookmarks/" + bookmark.id)).build();
64+
return Response.status(Response.Status.CREATED).entity(bookmark).build();
6065
}
6166

6267
@PUT
6368
@Path("/{id}")
6469
@Transactional
6570
@Operation(summary = "Update a bookmark")
66-
@Counted(name = "update.count")
67-
@Timed(name="update.time")
68-
public void update(Bookmark bookmark){
69-
Bookmark existing = Bookmark.findById(bookmark.id);
70-
existing.url = bookmark.url;
71-
existing.description = bookmark.description;
72-
existing.title = bookmark.title;
71+
@Counted(name = "updateBookmark.count")
72+
@Timed(name = "updateBookmark.time")
73+
public void updateBookmark(Bookmark bookmark, @PathParam("id") Long id) {
74+
Bookmark entity = Bookmark.findById(id);
75+
entity.description = bookmark.description;
76+
entity.location = bookmark.location;
77+
entity.title = bookmark.title;
78+
entity.url = bookmark.url;
7379
}
7480

7581
@DELETE
7682
@Path("/{id}")
7783
@Transactional
7884
@Operation(summary = "Delete a bookmark")
79-
@Counted(name = "delete.count")
80-
@Timed(name="delete.time")
81-
public void delete(@PathParam("id")Long id){
82-
Bookmark existing = Bookmark.findById(id);
83-
existing.delete();
85+
@Counted(name = "deleteBookmark.count")
86+
@Timed(name = "deleteBookmark.time")
87+
public Response deleteBookmark(@PathParam("id") Long id) {
88+
Bookmark bookmark = Bookmark.findById(id);
89+
if (bookmark != null) {
90+
bookmark.delete();
91+
}
92+
return Response.noContent().build();
8493
}
8594
}

bookmark-service/src/main/java/fr/loicmathieu/bookmarkit/MyHealCheck.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

bookmark-service/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ quarkus.datasource.username=quarkus
55
quarkus.datasource.password=quarkus
66
# drop and create the database at startup (use `update` to only update the schema)
77
quarkus.hibernate-orm.database.generation=drop-and-create
8+
quarkus.hibernate-orm.sql-load-script=import.sql
89

910
greeting=World
1011
%dev.greeting=Dev

bookmark-service/src/test/java/fr/loicmathieu/bookmarkit/BookmarkStep2Test.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)