Skip to content

dzatrifork/java-copilot-demo

Repository files navigation

OUTLINE:

Service that holds and manages user data.

Tech stack

  • Quarkus
  • Microservice
  • Java
  • Firebase
  • Docker

Endpoints

  • POST user { name, age, profession }
  • GET user { name, age, profession }
  • PATCH user/{id}/name
  • PATCH user/{id}/age
  • PATCH user/{id}/profession
    • (Make ChatGPT give me an enum of possible professions)

Presentation

Steps:

  • Create patch endpoint for professions
    • Update UserRepository with updateUserProfession
    • Create Profession enum (Generate enums from ChatGPT)
      • Profession fromString(String profession)
      • Create @JsonValue String toString()
    • Create ProfessionInput with Profession as input value
    • Update UserInput with Profession profession
    • update UserRepository.createUser with profession
    • Update UserService updateUserProfession(String id, Profession profession)
    • Generate endpoint in UserResource
    • Update UserRepositoryTest
      • Write test for assertUserExists
      • Try and let Copilot write more tests
        • testCreateUserWithNullName
        • testCreateUserWithEmptyName
      • Fix Illegal argument exception missing
    • (OPTIONAL) Create UserServiceTest
  • Use ChatGPT with code interpreter
    • to refactoring suggestions for UserService: "Do you have any suggestions for refactoring in this file?"
    • to write documentation for UserResource: "Please write documentation as markdown for the endpoints defined in this code"
  • Use HuggingChat with web search
    • Write ContextRequestFilter: "In Java, using the Quarkus framework, give me a ContainerRequestFilter that checks the input for bad words"
    • Write BadRequestMapper: "In Java give me a BadRequestException ExceptionMapper that translates the exception into a response"

Curls for testing:

Create user

curl --location 'http://localhost:8080/user' \
--header 'Content-Type: application/json' \
--data '{
"name": "Ben",
"age": 23,
"profession": "TEACHER"
}'

Get user

curl --location 'http://localhost:8080/user/O6phXT1wP2lCCeH6icG6'

Patch Name

curl --location --request PATCH 'http://localhost:8080/user/O6phXT1wP2lCCeH6icG6/name' \
--header 'Content-Type: application/json' \
--data '{
    "name": "David"
}'

Patch profession

curl --location --request PATCH 'http://localhost:8080/user/O6phXT1wP2lCCeH6icG6/profession' \
--header 'Content-Type: application/json' \
--data '{
    "profession": "CHEF"
}'

About

Demo repo for presentation on using github copilot and ChatGPT for development in Java

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published