Add New Feature Code
Add new feature code with AI assistance¶
Objective¶
Now that you have an understanding of the application, let's use some prompt engineering to add a new feature to the Liatrio DevOps Knowledge Share application app. You will be tasked in this exercise to add a new method to a controller and implement a custom interface for a repository. You will be working with a file named PostController.java
located in dks-api/src/main/java/com/liatrio/dojo/devopsknowledgeshareapi/
.
Exercise #1¶
- Add a new method to the PostController: The first task is to add a new method named
putPost
to thePostController.java
. This method should handle HTTP PUT requests and update an existing post in the database.
🛑 Ensure that the newly added feature works as expected before moving on
Exercise #2¶
- Update functionality to allow for fine grained queries: Add functionality to GET posts by title, first name, link, etc
🛑 Ensure that the newly added feature works as expected before moving on
Tips¶
-
Understand the task: Before you start coding, make sure you understand what you're trying to achieve. This will help you formulate more specific and relevant prompts for GitHub Copilot.
-
Be specific with your prompts: GitHub Copilot works best when you give it specific prompts. For example, instead of asking "How to create a method?", you could ask "How to create a PUT method in a Spring Boot controller?" The more specific you are, the more likely you are to get a useful response.
-
Use the right terminology: Make sure you're using the correct technical terms in your prompts. If you're unsure about the terminology, do a quick search to confirm.
-
Break down complex tasks: If you're working on a complex task, try breaking it down into smaller parts and ask GitHub Copilot for help with each part. This can make the task more manageable and increase the chances of getting a useful response.
-
Experiment with different prompts: If you're not getting the response you want, try rephrasing your prompt or asking the question in a different way. GitHub Copilot learns from a wide range of sources, so different phrasing can lead to different responses.
-
Learn from the responses: Even if GitHub Copilot doesn't give you the exact code you need, the responses can still be educational. You can often learn new approaches or techniques from the code it generates.
Challenge¶
If you finish early, try to add exception handling to the putPost method. It should handle cases where the post to be updated does not exist in the database.