You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New operation under /diffdates that calculates the difference between two dates. The operation should receive two dates as parameter in format dd-MM-yyyy and return the difference in days.
94
+
For this exercise, the code can either but in their own controller, or you can reuse the existing `DemoController.java`
95
+
96
+
Add the following endpoints using the help of Copilot.
95
97
96
98
Additionally, create a unit test that validates the operation.
97
99
98
100
From now on, you will have to create the unit tests for every new operation. Wasn't it easy with Copilot?
99
101
100
-
### 3. Validate the format of a spanish phone
102
+
-**/DaysBetweenDates**:
103
+
104
+
- calculate days between two dates
105
+
- receive by query string two parameters `date1` and `date2`, and calculate the days between those two dates.
106
+
107
+
> **_NOTE:_** Use above information inside the Copilot inline feature. Press enter and wait for Copilot to suggest you the code.
108
+
109
+
-**/validatephonenumber**:
110
+
111
+
- receive by querystring a parameter called phoneNumber
112
+
- validate phoneNumber with Spanish format, for example `+34666777888`
113
+
- if phoneNumber is valid return true
114
+
115
+
> **_NOTE:_** Use above information inside a comment. Press enter and wait for Copilot to suggest you the code.
116
+
117
+
-**/validatespanishdni**:
118
+
119
+
- receive by querystring a parameter called dni
120
+
- calculate DNI letter
121
+
- if DNI is valid return "valid"
122
+
- if DNI is not valid return "invalid"
123
+
124
+
> **_NOTE:_** Use above information inside a comment. In this case, you may want to see multiple solutions from Copilot to pick the one that best fits the way to calculate the letter. In order to see the firs 10 suggestions from Copilot press `ctrl/⌘ + enter`.
125
+
126
+
-**/returncolorcode**:
127
+
128
+
- receive by querystring a parameter called color
129
+
- read colors.json file and return the rgba field
130
+
- get color var from querystring
131
+
- iterate for each color in colors.json to find the color
132
+
- return the code.hex field
133
+
134
+
> **_NOTE:_** Lets try Copilot chat now. Paste the above information and make it as detailed as possible in the Copilot chat text box. Copilot will use by default the open file as context in order to generate the suggestion.
101
135
102
-
Validate the format of a spanish phone number (+34 prefix, then 9 digits, starting with 6, 7 or 9). The operation should receive a phone number as parameter and return true if the format is correct, false otherwise.
136
+
-**/tellmeajoke**:
103
137
104
-
### 4. Validate the format of a spanish DNI
138
+
- Make a call to the joke api and return a random joke - https://api.chucknorris.io/jokes/random
105
139
106
-
Validate the format of a spanish DNI (8 digits and 1 letter). The operation should receive a DNI as parameter and return true if the format is correct, false otherwise.
140
+
> **_NOTE:_** Here's example where you might need to use you own knowledge and judgement
141
+
> to validate that Copilot follows best practices. Just because Copilot mimic
142
+
> what many developers do, doesn't always mean it's the correct way. You might need
143
+
> to be extra specific in your prompt to let Copilot know what's best practices.
107
144
108
-
### 5. From color name to hexadecimal code
145
+
-**/moviesbydirector**:
109
146
110
-
Based on existing colors.json file under resources, given the name of the color as path parameter, return the hexadecimal code. If the color is not found, return 404
147
+
- Receive by querystring a parameter called director
148
+
- Make a call to the movie api and return a list of movies of that director
149
+
- Return the full list of movies
111
150
112
-
Hint: Use TDD. Start by creating the unit test and then implement the code.
151
+
> **_NOTE:_** This will require to browse to https://www.omdbapi.com/apikey.aspxand request a FREE API Key
113
152
114
-
### 6. Jokes creator
153
+
-**/parseurl**:
115
154
116
-
Create a new operation that call the API https://api.chucknorris.io/jokes/random and return the joke.
155
+
- Retrieves a parameter from querystring called someurl
156
+
- Parse the url and return the protocol, host, port, path, querystring and hash
157
+
- Return the parsed host
117
158
118
-
### 7. URL parsing
159
+
> **_NOTE:_** Copilot can help you learn new frameworks.
119
160
120
-
Given a url as query parameter, parse it and return the protocol, host, port, path and query parameters. The response should be in Json format.
161
+
-**/listfiles**:
121
162
122
-
### 8. List files and folders
163
+
- Get the current directory
164
+
- Get the list of files in the current directory
165
+
- Return the list of files
123
166
124
-
List files and folders under a given path. The path should be a query parameter. The response should be in Json format.
167
+
> **_NOTE:_** Copilot can also help with these kind of commands locally. The feature is called Copilot in the CLI. You can learn more information about this feature [here](https://docs.github.com/en/copilot/github-copilot-in-the-cli/about-github-copilot-in-the-cli).
125
168
126
-
### 9. Word counting
169
+
-**/calculatememoryconsumption**:
127
170
128
-
Given the path of a file and count the number of occurrence of a provided word. The path and the word should be query parameters. The response should be in Json format.
171
+
- Return the memory consumption of the process in GB, rounded to 2 decimals
129
172
130
-
### 10. Zipping
173
+
-**/randomeuropeancountry**:
131
174
132
-
Create a zip file with the content of a given folder. The path of the folder should be a query parameter.
175
+
- Make an array of european countries and its iso codes
176
+
- Return a random country from the array
177
+
- Return the country and its iso code
133
178
134
-
### 11. Containerize the application
179
+
### Exercise 3: Document the code
180
+
181
+
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.
182
+
183
+
### Exercise 4: Verify Tests
184
+
185
+
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!
186
+
187
+
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.
188
+
189
+
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.
190
+
191
+
### Exercise 5: Create a Dockerfile
135
192
136
193
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.
137
194
138
195
In order to build, run and test the docker image, you can use Copilot as well to generate the commands.
139
196
140
-
For instance, create a DOCKER.md file where you can store the commands to build, run and test the docker image. You will notice that Copilot will also help you to document your project and commands.
197
+
For instance, create a DOCKER.md file where you can store the commands to build, run and test the docker image.
141
198
142
199
Examples of steps to document: Build the container image, Run the container, Test the container.
200
+
201
+
## Summary
202
+
203
+
With the previous exercises you have gone through some common activities that developers usually run:
204
+
205
+
- Create new features in the code
206
+
- Work with external APIs
207
+
- Create documentation
208
+
- Create tests
209
+
210
+
However, there are many other things that Copilot can helkp you with. Feel free to explore other slash command in the Copilot chat like:
211
+
212
+
-`/fix`: to fix the problems in your code
213
+
-`/explain`: for Copilot to explain you what the code does
0 commit comments