Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ jobs:
- name: Generate Application Key
run: php artisan key:generate

- name: Generate OAuth2 Keys
run: php artisan passport:keys

- name: Tests
run: ./vendor/bin/pest
127 changes: 127 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Key-Value Versions

## Local Setup

- `git clone https://github.com/dumindu/key-value-versions.git`
- `cd key-value-versions/key-value-versions-app`
- `composer install`
- `npm install && npm run build`
- `cp .env.example .env`
- `php artisan key:generate`
- `php artisan passport:keys`
- ` ./vendor/bin/sail up`
- `./vendor/bin/sail artisan migrate`

> 💡 Need to run Docker.

## Web Dashboard

![Laravel Web Dashboard](key-value-versions-app/public/images/web-dashboard.png)

### Pages

- Register
- Login
- Profile Settings

## API Endpoints

> Use [Yaak](https://yaak.app) to access the Open API documentation/ setup in the [__openapi](__openapi) folder.

### 1. User Registration

#### Endpoint

`[POST] api/v1/register`

#### Headers

- Accept: `application/json`

#### Request Body

```json
{
"name": "User Name",
"email": "user@email.com",
"password": "some_password",
"password_confirmation": "some_password"
}
```

### 2. Get Oauth2 Tokens

#### Endpoint

`[POST] oauth/token`

#### Headers

- Accept: `application/json`

#### Request Body

```json
{
"grant_type": "password",
"client_id": "01989503-1ce8-735f-a487-0729ef4f1d1b",
"client_secret": "WqkuICsupCfBL1xLt71TfBSaaLVlaiTd0iMSudpu",
"username": "user@email.com",
"password": "some_password",
"scope": "*"
}
```

### 3. Create New Key/Value

#### Endpoint

`[POST] /api/v1/keys`

#### Headers

- Accept: `application/json`
- Authorization: `Bearer <access-token>`

#### Request Body

```json
{
"key": "001",
"value": "value 001"
}
```

### 4. Get All Keys With Latest Values

#### Endpoint

`[GET] /api/v1/keys`

#### Headers

- Accept: `application/json`
- Authorization: `Bearer <access-token>`

### 5. Get A Key With Latest Value

#### Endpoint

`[GET] /api/v1/keys/{key}`

#### Headers

- Accept: `application/json`
- Authorization: `Bearer <access-token>`

### 6. Get A Key With All Values

#### Endpoint

`[GET] /api/v1/keys/{key}/history`

#### Headers

- Accept: `application/json`
- Authorization: `Bearer <access-token>`

22 changes: 22 additions & 0 deletions key-value-versions-app/app/Http/Middleware/ForceJsonResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class ForceJsonResponse
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$request->headers->set('Accept', 'application/json');

return $next($request);
}
}
5 changes: 5 additions & 0 deletions key-value-versions-app/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Middleware\ForceJsonResponse;
use App\Http\Middleware\HandleAppearance;
use App\Http\Middleware\HandleInertiaRequests;
use Illuminate\Foundation\Application;
Expand All @@ -23,6 +24,10 @@
HandleInertiaRequests::class,
AddLinkHeadersForPreloadedAssets::class,
]);

$middleware->api(append: [
ForceJsonResponse::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.