Skip to content

Commit 7af4c41

Browse files
committed
0 parents  commit 7af4c41

File tree

14 files changed

+813
-0
lines changed

14 files changed

+813
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Spring Boot REST API Exercise
2+
3+
## Goal
4+
5+
The goal of this exercise is to learn how to use GitHub Copilot, using an exercise that consist of building a REST API using Spring Boot.
6+
7+
## Exercises
8+
9+
We have created a Spring Boot project with some files already created, you can find the project in the folder **exercisefiles/springboot**.
10+
11+
Let's start copiloting!!!
12+
13+
### 1. Create the code to handle a simple GET request
14+
15+
Move to the 'DemoController.java' file and start writing the code to handle a simple GET request. In this first exercise, we have provided a comment that describes the code you need to generate. Just press enter and wait a couple of seconds, Copilot will generate the code for you.
16+
17+
There is already a unit test implemented for this exercise, you can run it using the command `mvn test` before and after to validate that the code generated by Copilot is correct.
18+
19+
Then, create a new unit test for the case when no key is provided in the request.
20+
21+
After every exercise, feel free to package and run your application to test it.
22+
23+
Package: `mvn package`
24+
25+
Run: `mvn spring-boot:run`
26+
27+
Test: `curl -v http://localhost:8080/hello?key=world`
28+
29+
### 2. Dates comparison
30+
31+
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.
32+
33+
Additionally, create a unit test that validates the operation.
34+
35+
From now on, you will have to create the unit tests for every new operation. Wasn't it easy with Copilot?
36+
37+
### 3. Validate the format of a spanish phone
38+
39+
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.
40+
41+
### 4. Validate the format of a spanish DNI
42+
43+
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.
44+
45+
### 5. From color name to hexadecimal code
46+
47+
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
48+
49+
Hint: Use TDD. Start by creating the unit test and then implement the code.
50+
51+
### 6. Jokes creator
52+
53+
Create a new operation that call the API https://api.chucknorris.io/jokes/random and return the joke.
54+
55+
### 7. URL parsing
56+
57+
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.
58+
59+
### 8. List files and folders
60+
61+
List files and folders under a given path. The path should be a query parameter. The response should be in Json format.
62+
63+
### 9. Word counting
64+
65+
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.
66+
67+
### 10. Zipping
68+
69+
Create a zip file with the content of a given folder. The path of the folder should be a query parameter.
70+
71+
### 11. Containerize the application
72+
73+
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.
74+
75+
In order to build, run and test the docker image, you can use Copilot as well to generate the commands.
76+
77+
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.
78+
79+
Examples of steps to document: Build the container image, Run the container, Test the container.
80+
81+
82+
83+
84+
85+
86+
87+
88+

copilot-demo/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
61.1 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar

copilot-demo/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Build a java application image based on openjdk 17 and run it on port 8080

0 commit comments

Comments
 (0)