Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Feb 9, 2025
1 parent cc6b0ab commit 69afbb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/com/melloware/quarkus/panache/CarResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class CarResource {
@APIResponse(responseCode = "404", description = "Car not found")
})
public Car getSingle(@PathParam("id") @Min(value = 0) Long id) {
LOG.infof("Get Car: %s", id);
Car entity = Car.findById(id);
if (entity == null) {
throw new NotFoundException("Car with id of " + id + " does not exist.");
Expand All @@ -69,9 +70,11 @@ public Car getSingle(@PathParam("id") @Min(value = 0) Long id) {
@Operation(summary = "Get all manufacturers", description = "Returns a list of distinct car manufacturers")
@APIResponse(responseCode = "200", description = "Success")
public List<String> getManufacturers() {
LOG.infof("Get Unique Manufacturers...");
return Car.find("select distinct make from Car order by make").project(String.class).list();
}


@POST
@Transactional
@Operation(summary = "Create a new car", description = "Creates a new car entry")
Expand All @@ -80,6 +83,7 @@ public List<String> getManufacturers() {
@APIResponse(responseCode = "422", description = "Invalid car data provided")
})
public Response create(@Valid Car car) {
LOG.infof("Create Car: %s", car);
if (car.id != null) {
// 422 Unprocessable Entity
throw new WebApplicationException("Id was invalidly set on request.", 422);
Expand All @@ -97,9 +101,11 @@ public Response create(@Valid Car car) {
@APIResponse(responseCode = "404", description = "Car not found")
})
public Car update(@PathParam("id") @Min(value = 0) Long id, @Valid Car car) {
LOG.infof("Update Car: %s", id);
Car entity = Car.findById(id);
if (entity == null) {
throw new NotFoundException("Car with id of " + id + " does not exist.");

}

// would normally use ModelMapper here: https://modelmapper.org/
Expand All @@ -122,6 +128,7 @@ public Car update(@PathParam("id") @Min(value = 0) Long id, @Valid Car car) {
@APIResponse(responseCode = "404", description = "Car not found")
})
public Response delete(@PathParam("id") @Min(value = 0) Long id) {
LOG.infof("Delete Car: %s", id);
Car entity = Car.findById(id);
if (entity == null) {
throw new NotFoundException("Car with id of " + id + " does not exist.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#################
quarkus.log.level=INFO
quarkus.log.console.async=true
quarkus.http.access-log.enabled=false
quarkus.http.access-log.enabled=true

#################
### DATABASE ###
Expand Down

0 comments on commit 69afbb7

Please sign in to comment.