-
-
Notifications
You must be signed in to change notification settings - Fork 659
Add support for posting content via a REST API #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7869b53
WIP
lukeraymonddowning d0a4bdf
Adds posting to create article.
lukeraymonddowning a91227b
Adds rate limiting of 6 requests per minute to API.
lukeraymonddowning a99e9de
WIP
lukeraymonddowning 4cfcbd3
Adds tests for api token jobs.
lukeraymonddowning c093eaa
Tweaks
lukeraymonddowning 430c5ca
Tweaks
lukeraymonddowning dcc40e2
CS
lukeraymonddowning 7985ec4
CS
lukeraymonddowning 40c790f
Dump schema
driesvints 2d90923
Handle duplicate GitHub ID upon registration (#782)
marvelefe 8688866
Update sponsors
driesvints 6ff98e4
Upgrade tailwind to v3 (#795)
joedixon a873c54
Merge branch 'main' into post_via_api
lukeraymonddowning 3337086
wip
driesvints File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Settings; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\DeleteApiTokenRequest; | ||
use App\Http\Requests\CreateApiTokenRequest; | ||
use App\Jobs\CreateApiToken; | ||
use App\Jobs\DeleteApiToken; | ||
use Illuminate\Auth\Middleware\Authenticate; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class ApiTokenController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware(Authenticate::class); | ||
} | ||
|
||
public function store(CreateApiTokenRequest $request) | ||
{ | ||
$this->dispatchSync(new CreateApiToken(Auth::user(), $request->name())); | ||
|
||
return redirect()->route('settings.profile'); | ||
} | ||
|
||
public function destroy(DeleteApiTokenRequest $request) | ||
{ | ||
$this->dispatchSync(new DeleteApiToken(Auth::user(), $request->id())); | ||
|
||
return redirect()->route('settings.profile'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class CreateApiTokenRequest extends FormRequest | ||
{ | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'name' => ['required', 'string', 'max:255'] | ||
]; | ||
} | ||
|
||
public function name(): string | ||
{ | ||
return (string) $this->get('name'); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class DeleteApiTokenRequest extends FormRequest | ||
{ | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
'id' => ['required', 'exists:personal_access_tokens,id'], | ||
]; | ||
} | ||
|
||
public function id(): string | ||
{ | ||
return (string) $this->get('id'); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class ArticleResource extends JsonResource | ||
{ | ||
/** | ||
* @param \Illuminate\Http\Request $request | ||
*/ | ||
public function toArray($request): array | ||
{ | ||
return [ | ||
'id' => $this->getKey(), | ||
'url' => route('articles.show', $this->slug()), | ||
'title' => $this->title(), | ||
'body' => $this->body(), | ||
'original_url' => $this->originalUrl(), | ||
'author' => AuthorResource::make($this->author()), | ||
'tags' => TagResource::collection($this->tags()), | ||
'is_submitted' => $this->isSubmitted(), | ||
'created_at' => $this->createdAt(), | ||
'updated_at' => $this->updatedAt(), | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class AuthorResource extends JsonResource | ||
{ | ||
/** | ||
* @param \Illuminate\Http\Request $request | ||
*/ | ||
public function toArray($request): array | ||
{ | ||
return [ | ||
'id' => $this->getKey(), | ||
'email' => $this->emailAddress(), | ||
'name' => $this->name(), | ||
'bio' => $this->bio(), | ||
'twitter_handle' => $this->twitter(), | ||
'github_username' => $this->githubUsername(), | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class TagResource extends JsonResource | ||
{ | ||
/** | ||
* @param \Illuminate\Http\Request $request | ||
*/ | ||
public function toArray($request): array | ||
{ | ||
return [ | ||
'id' => $this->getKey(), | ||
'name' => $this->name(), | ||
'slug' => $this->slug(), | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class CreateApiToken implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function __construct( | ||
private User $user, | ||
private string $name, | ||
) | ||
{ | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
$this->user->createToken($this->name); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class DeleteApiToken implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function __construct(private User $user, private int $tokenId) | ||
{ | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
$this->user->tokens()->where('id', $this->tokenId)->delete(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.