Skip to content
/ otp Public

A small example of ports and adapters architecture in Java. Only meant as a modelling exercise.

Notifications You must be signed in to change notification settings

j0a0m4/otp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Otp Service

Routes

POST /v1/users

Creates a new user by providing a valid email.
Returns a new userId in the body and Location header.

Request

{
  "email": "[email protected]"
}

Response

{
  "userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b"
}

Try it

curl -d '{"email": "[email protected]"}' \
 -H "Content-Type: application/json" \
 -X POST http://localhost:8080/v1/users

POST /v1/otp

Creates a new otp for a given userId.
Returns a new 6 digit otp and expiration metadata.

Request

{
  "userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b"
}

Response

{
  "userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b",
  "otp": "988569",
  "expiration": {
    "expiresIn": 30,
    "measurementUnit": "Seconds"
  },
  "creationTime": "2024-08-22T19:42:09.522528Z"
}

Try it out

curl -d '{"userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b"}' \
 -H "Content-Type: application/json" \
 -X POST http://localhost:8080/v1/otp

POST /v1/verifications

Verify status of otp for a given userId.
Returns the otp status.

Request

{
  "userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b",
  "otp": "988569"
}

Response

{
  "userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b",
  "otp": "988569",
  "otpStatus": "ACCEPTED",
  "timestamp": "2024-08-22T19:42:37.077639Z"
}

Try it out

curl -d '{"userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b", "otp": "988569"}' \
 -H "Content-Type: application/json" \
 -X POST http://localhost:8080/v1/verifications

Setup

Containers

On Mac, with colima you need to create a symlink for testcontainers to work

sudo ln -s $HOME/.colima/docker.sock /var/run/docker.sock

Environment Variables

You need to bind a valid mongoDB connection string to variable $DB_URI

About

A small example of ports and adapters architecture in Java. Only meant as a modelling exercise.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages