https://github.com/j0a0m4/otp
A small example of ports and adapters architecture in Java. Only meant as a modelling exercise.
https://github.com/j0a0m4/otp
api java rest-api spring-boot
Last synced: 2 months ago
JSON representation
A small example of ports and adapters architecture in Java. Only meant as a modelling exercise.
- Host: GitHub
- URL: https://github.com/j0a0m4/otp
- Owner: j0a0m4
- Created: 2024-08-23T00:51:19.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-23T02:17:13.000Z (almost 2 years ago)
- Last Synced: 2025-02-17T19:22:01.854Z (over 1 year ago)
- Topics: api, java, rest-api, spring-boot
- Language: Java
- Homepage:
- Size: 62.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```json
{
"email": "example@test.com"
}
```
#### Response
```json
{
"userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b"
}
```
#### Try it
```shell
curl -d '{"email": "example@test.com"}' \
-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
```json
{
"userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b"
}
```
#### Response
```json
{
"userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b",
"otp": "988569",
"expiration": {
"expiresIn": 30,
"measurementUnit": "Seconds"
},
"creationTime": "2024-08-22T19:42:09.522528Z"
}
```
#### Try it out
```shell
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
```json
{
"userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b",
"otp": "988569"
}
```
### Response
```json
{
"userId": "3419e0d7-ff9b-4a99-a3f4-b567fdff3a2b",
"otp": "988569",
"otpStatus": "ACCEPTED",
"timestamp": "2024-08-22T19:42:37.077639Z"
}
```
#### Try it out
```shell
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
```shell
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`