Skip to content

Commit 0149773

Browse files
authored
Merge pull request #3 from Wolfleader101/feature/more-exercises
Refactor Code Steps
2 parents 57269b4 + 6464978 commit 0149773

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ chmod +x ./mvnw
5050
For this exercise we will be adding a new endpoint to handle a simple GET request.
5151

5252
- Move to the `src/main/.../DemoController.java` file
53-
- Start writing the code to handle a simple GET request based on the javadoc comment.
53+
- Start writing the code to handle a simple GET request based on the javadoc comment.
5454
- Just press enter and wait a couple of seconds, Copilot will generate the code for you.
5555
- Alternatively, you can test the Copilot inline feature by pressing `ctrl/⌘ + i`. Then write in the text box the desired behaviour.
5656

@@ -60,7 +60,6 @@ You can now run the application and then test it with curl.
6060
2. Test with curl: `curl -v http://localhost:8080/hello?key=world`
6161
3. If you are using GitHub `Codespaces`, replace localhost:8080 with actual `Codespaces` url.
6262

63-
6463
### Exercise 2: Write a Test Case
6564

6665
There is an existing unit test `src/test/.../CopilotDemoApplicationTests.java`, run below command to test it.
@@ -106,7 +105,7 @@ Let's now create a new unit test for the case when no key is provided in the req
106105

107106
### Exercise 3: Building more functionalities
108107

109-
For this exercise, the code can either but in their own controller, or you can reuse the existing `DemoController.java`.
108+
For this exercise, reuse the existing `DemoController.java`.
110109

111110
Add the following endpoints using the help of Copilot, then also create the unit tests for every new operation. It is pretty easy with Copilot !
112111

@@ -148,11 +147,17 @@ Add the following endpoints using the help of Copilot, then also create the unit
148147
> Paste the above information and make it as detailed as possible in the Copilot chat text box.
149148
> Copilot will use by default the open file as context in order to generate the suggestion.
150149
150+
### Exercise 4: Refactor your endpoints
151+
152+
In exercise 3, we have created a few endpoints in the `DemoController.java` file. Now let's refactor the code to make it more readable and maintainable by moving those endpoints into separate controllers. With the `DemoController.java` file open, ask Copilot using the chat feature how to refactor those endpoints into separate files.
153+
154+
> **_NOTE:_** You can use the `@workspaces` command to give Copilot the context of the structure of the whole repo.
151155
152-
### Exercise 4: Building more integrations
156+
### Exercise 5: Building more integrations
153157

154158
We have tried out write coding for a few simple tasks earlier. Now let's explore more complex integrations.
155159

160+
> **_NOTE:_** You should follow the same pattern as the previous exercise and create each new endpoint in a separate controllers.
156161
157162
- **/tellmeajoke**:
158163

@@ -197,21 +202,33 @@ We have tried out write coding for a few simple tasks earlier. Now let's explore
197202
- Return a random country from the array
198203
- Return the country and its iso code
199204

200-
### Exercise 5: Document the code
205+
### Exercise 6: Adding in Swagger
206+
207+
Lets now add in Swagger to the project. This will involve installing the following dependency `springfox-boot-starter`. The version should be `3.0.0`.
208+
209+
Ask Copilot how you could achieve this. You can use the `@workspaces` command to give Copilot the context of the structure of the whole repo.
210+
211+
### Exercise 7: Refactor the code to follow REST principles
212+
213+
At this point in the previous exercises, we created a number of endpoints that are not following REST principles. Let's refactor the code to follow REST principles. You should also update the Swagger documentation, so that each endpoint has a summary and is grouped using tags.
214+
215+
Ask Copilot how you could achieve this. You can use the `@workspaces` command to give Copilot the context of the structure of the whole repo.
216+
217+
### Exercise 8: Document the code
201218

202219
Documenting code is always a boring and painful task. However, we can use Copilot to document it for us. In the chat, ask Copilot to add javadoc to all of your files.
203220

204221
You can use `@workspaces` to write documentation for the whole repo.
205222

206-
### Exercise 6: Verify Tests
223+
### Exercise 9: Verify Tests
207224

208225
Have you been building your Unit Tests along the way? If not this is the perfect time to take a breather and get Copilot to write some unit tests for you!
209226

210227
We will create automated tests to check that the functionality of the previous endpoints is correctly implemented. The tests should be together in the `CopilotDemoApplicationTests.java` file.
211228

212229
You can leverage Copilot to run the tests. There is a `/tests` command that you can directly run from Copilot Chat or by selecting the piece of code you want to create tests for and using the Copilot inline feature.
213230

214-
### Exercise 7: Create a Dockerfile
231+
### Exercise 10: Create a Dockerfile
215232

216233
Use the Dockerfile provided to create a docker image of the application. There are some comments in the Dockerfile that will help you to complete the exercise.
217234

@@ -227,10 +244,11 @@ With the previous exercises you have gone through some common activities that de
227244

228245
- Create new features in the code
229246
- Work with external APIs
247+
- Refactor an existing codebase
230248
- Create documentation
231249
- Create tests
232250

233-
However, there are many other things that Copilot can helkp you with. Feel free to explore other slash command in the Copilot chat like:
251+
However, there are many other things that Copilot can help you with. Feel free to explore other slash command in the Copilot chat like:
234252

235253
- `/fix`: to fix the problems in your code
236254
- `/explain`: for Copilot to explain you what the code does

0 commit comments

Comments
 (0)