Skip to content

Commit

Permalink
Merge pull request #165 from deanblackborough/v2.07.0
Browse files Browse the repository at this point in the history
v2.07.0
  • Loading branch information
deanblackborough authored Feb 2, 2020
2 parents 7e866dc + a62e2c9 commit 8be5313
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 130 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/

## [v2.07.0] - 2020-02-01
### Added
- We have added a GET 'auth/check' endpoint; faster check for the Costs to Expect App.

### Changed
- We have updated the dependencies for the API.
- We have enabled URL compression.
- We now return the user id on sign-in, saves a second request for the Costs to Expect App.
- We have updated the README, adding links to the App `readme` and `changelog`.
- We have tweaked two middleware classes to improve performance slightly.

### Fixed
- The HTTP verb was incorrect for the 'auth/user' endpoint.

## [v2.06.0] - 2020-01-18
### Added
- We have added a configuration option to control API registrations.
Expand Down
56 changes: 33 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,41 @@ Costs to Expect is a service which focuses on tracking and forecasting expenses.
The Costs to Expect API is the backbone of the service and is not going to be
limited to expenses; however, we figured that is was an excellent place to start.

### The App
The [alpha](https://app.costs-to-expect.com) for the service is online, we are
hoping to release the public alpha at the start of April 2020. Please check
the [app.costs-to-expect.com/roadmap](https://app.costs-to-expect.com/roadmap)
and changelog to see how we are getting on
[app.costs-to-expect.com/changelog](https://app.costs-to-expect.com/changelog)

### The Website
A small part of the service is tracking the costs to raise a child in the UK,
more detail can be found at [Costs to Expect](https://www.costs-to-expect.com).

The [alpha](https://app.costs-to-expect.com) for the service is online, we are
hoping to have a beta ready or early 2020, please check
[app.costs-to-expect.com](https://app.costs-to-expect.com)

## Set up

I'm going to assume you are using Docker, if not you should be able to work out what you need to run for your
development setup, go to the project root directory and run the below.
I'm going to assume you are using Docker, if not you should be able to work out
what you need to run for your development setup, go to the project root
directory and run the below.

### Environment

* Run `docker-compose build`
* Run `docker-compose up`

### App
### API

We now have a working environment, lets set up the app. There are two Docker services, `api` and `mysql`, we need to
exec into the `api` service to set up our app.
We now have a working environment, lets set up the app. There are two Docker
services, `api` and `mysql`, we need to exec into the `api` service to set up
our app.

First, let us check we are trying to access the right place, run `docker-compose exec api ls`. You should see a list
of the files and directories at the root of our project, if you can see artisan, you are in the right place,
otherwise see where you are and adjust accordingly.
First, let us check we are trying to access the right place,
run `docker-compose exec api ls`. You should see a list of the files and
directories at the root of our project, if you can see artisan, you are in
the right place, otherwise see where you are and adjust accordingly.

Now we need to set up the app by setting our .env, installing our dependencies and then running any migrations and
install Passport.
Now we need to set up the app by setting our .env, installing our dependencies
and then running any migrations and install Passport.

* Copy the `.env.example` file and name the copy `.env`, set your environment settings
* `docker-compose exec api composer install`
Expand All @@ -59,8 +66,8 @@ case of a validation error, 422, the fields array will contain the validation er

## Headers

Responses will include multiple headers, the table details the purpose behind some of the
custom headers.
Responses will include multiple headers, the table details the purpose behind
some of the custom headers.

| Header | Purpose |
| :--- | :--- |
Expand All @@ -78,16 +85,17 @@ custom headers.

## Routes

Access to a route will be limited based upon your permitted resource types. When you
create a resource type you have full access to everything below, additionally, the same
is true if you are assigned to a resource type.
Access to a route will be limited based upon your permitted resource types.
When you create a resource type you have full access to everything below,
additionally, the same is true if you are assigned to a resource type.

| HTTP Verb(s) | Route |
| :--- | :--- |
| GET/HEAD | v2/ |
| OPTIONS | v2/ |
| POST | v2/auth/login |
| POST | v2/auth/register |
| GET/HEAD | v2/auth/check |
| GET/HEAD | v2/auth/user |
| GET/HEAD | v2/changelog |
| OPTIONS | v2/changelog |
Expand Down Expand Up @@ -155,10 +163,12 @@ is true if you are assigned to a resource type.

## Summary routes

Eventually, there will be a summary route for every API GET endpoint. Until that point, the summary routes
that exists are detailed below. Some use GET parameters to breakdown the data, one example being
`v2/summary/resource-types/{resource_type_id}/items`. Review the OPTIONS request for each summary
route to see the supported parameters, these should largely match the non summary route.
Eventually, there will be a summary route for every API GET endpoint. Until
that point, the summary routes that exists are detailed below. Some use GET
parameters to breakdown the data, one example being
`v2/summary/resource-types/{resource_type_id}/items`. Review the OPTIONS
request for each summary route to see the supported parameters, these should
largely match the non summary route.

| HTTP Verb(s) | Route |
| :--- | :--- |
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/PassportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function login()

return response()->json(
[
'id' => Auth::id(),
'type' => 'Bearer',
'token' => $token->accessToken,
'created' => $token->token->created_at,
Expand All @@ -47,6 +48,11 @@ public function login()
}
}

public function check()
{
return response()->json(['auth' => Auth::guard('api')->check()], 200);
}

/**
* Register with the API will return the token
*
Expand Down
14 changes: 9 additions & 5 deletions app/Http/Middleware/ConvertGetParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Hashids\Hashids;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

/**
Expand All @@ -18,8 +19,8 @@ class ConvertGetParameters
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
Expand All @@ -34,9 +35,12 @@ public function handle($request, Closure $next)
'resource-type' => new Hashids($config['resource_type'], $min_length),
];

foreach ($parameters as $param => $hasher) {
if ($request->query($param) !== null) {
$id = $hasher->decode($request->query($param));
$params_to_convert = array_keys($parameters);

foreach ($params_to_convert as $param) {
$param_value = $request->query($param);
if ($param_value !== null) {
$id = $parameters[$param]->decode($param_value);
if (is_array($id) && array_key_exists(0, $id)) {
$request->request->add([$param => $id[0]]);
} else {
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Middleware/ConvertRouteParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public function handle($request, Closure $next)
'item_type_id' => new Hashids($config['item_type'], $min_length),
];

foreach ($route_params as $param => $hasher) {
if ($request->route($param) !== null) {
$id = $hasher->decode($request->route($param));
$params_to_convert = array_keys($route_params);

foreach ($params_to_convert as $param) {
$param_value = $request->route($param);
if ($param_value !== null) {
$id = $route_params[$param]->decode($param_value);
if (is_array($id) && array_key_exists(0, $id)) {
$request->route()->setParameter($param, $id[0]);
} else {
Expand Down
Loading

0 comments on commit 8be5313

Please sign in to comment.