Skip to main content

3 posts tagged with "rest"

View All Tags

· 2 min read

In my Quarkus application, I encountered a hiccup with the Panache ORM while implementing and testing a REST service. Specifically, I faced a test failure related to the automatic update of a specifications list after deleting an element from the JSON/Entity. In this blog post, I'll walk you through the issue and demonstrate how GitHub Copilot came to the rescue, streamlining the implementation of a solution.

The Challenge:

The JSON schema for my REST service looked like this:

{
"id": 1,
"name": "Fanatic Falcon",
"description": "Slalom board",
"specifications" : [
{"id": 10, "name": "Falcom 100", "volume": 100},
{"id": 11, "name": "Falcom 110", "volume": 110},
{"id": 12, "name": "Falcom 120", "volume": 120}
]
```
}

I had a test verifying the number of specifications after the deletion of one of them. However, the Panache ORM didn't automatically update the specifications list after deletion, leading to a failing test.

The Solution:

To address this issue, I needed to implement business logic to delete specifications in the database that were not present in the JSON payload. I documented the logic in a comment and collaborated with GitHub Copilot to generate the code.

Here's a snippet of the code:

...

// if the number of specifications in the existing board is different than the number of specifications in the updated board
// it means that some specifications have been removed, so we need to delete them
// for this we meed to loop on existing specifications and see if they are in the updated board
// if they are not add them to a list of specs to delete
// then use removeAll on existing board specifications
List<BoardSpecification> specsToDelete = new ArrayList<>();
for (BoardSpecification existingSpec : existingBoard.specifications) {
boolean found = false;
for (BoardSpecification spec : board.specifications) {
if (existingSpec.id.equals(spec.id)) {
found = true;
}
}
if (!found) {
specsToDelete.add(existingSpec);
}
}
existingBoard.specifications.removeAll(specsToDelete);
existingBoard.persist();

...

Check out the video below to witness how I leveraged GitHub Copilot to easily implement the business logic.

Once again, GitHub Copilot has proven to be an invaluable coding companion, significantly enhancing my efficiency and helping me overcome challenges in my coding journey. With its assistance, I navigated through the intricacies of the Panache ORM and successfully resolved the test failure, ensuring the seamless functionality of my Quarkus application.

· 7 min read

Quarkus: Simplifying Cloud File Uploads

In many projects, facilitating user uploads to cloud services is a common requirement. In my current project, I find myself inviting users to seamlessly upload various files, such as profile pictures, GPS track files, or session photos, to the WindR.org site. To enhance my understanding, I've opted to employ multiple cloud providers —Microsoft Azure Blob Storage, Amazon S3, Google Cloud Storage— allowing me to test and compare their functionalities.

This article guides you through the process of:

  1. Creating a REST service for file uploads using RESTEasy Reactive in Quarkus.
  2. Uploading files to the cloud from a Quarkus application.

To complement this discussion, a complete code example is available on GitHub. This resource serves as a practical reference for learning and experimentation.

GitHub Repository: Quarkus: Uploading Image to the Cloud

· 3 min read

Introduction

In this project you will learn how to use the MapR-DB JSON REST API to:

Create and Delete tables Create, Read, Update and Delete documents (CRUD) MapR Extension Package 5.0 (MEP) introduced the MapR-DB JSON REST API that allow application to use REST to interact with MapR-DB JSON.

You can find information about the MapR-DB JSON REST API in the documentation: Using the MapR-DB JSON REST API