-
-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for posting content via a REST API (#793)
* WIP * Adds posting to create article. * Adds rate limiting of 6 requests per minute to API. * WIP * Adds tests for api token jobs. * Tweaks * Tweaks * CS * CS * Dump schema * Handle duplicate GitHub ID upon registration (#782) * Added check inside the create method of the RegisterController to find duplicate github ID * Added error message saying "We already found a user with the given GitHub account....... * fixed failing test * fixed stycli errors * styleci fixes * styleci fixes * more styleci fixes * wip Co-authored-by: Dries Vints <[email protected]> * Update sponsors * Upgrade tailwind to v3 (#795) * update dependencies * update classes * remove classes duplication * resolve conflict * Remove dependency Co-authored-by: faissaloux <[email protected]> * wip Co-authored-by: Dries Vints <[email protected]> Co-authored-by: Efe Omoregie <[email protected]> Co-authored-by: Joe Dixon <[email protected]> Co-authored-by: faissaloux <[email protected]>
- Loading branch information
1 parent
dac19fb
commit 3e13297
Showing
25 changed files
with
683 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Settings; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\CreateApiTokenRequest; | ||
use App\Http\Requests\DeleteApiTokenRequest; | ||
use App\Jobs\CreateApiToken; | ||
use App\Jobs\DeleteApiToken; | ||
use Illuminate\Auth\Middleware\Authenticate; | ||
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 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\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 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\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 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\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
/** | ||
* @mixin \App\Models\Article | ||
*/ | ||
class ArticleResource extends JsonResource | ||
{ | ||
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(), | ||
'submitted_at' => $this->submittedAt(), | ||
'created_at' => $this->createdAt(), | ||
'updated_at' => $this->updatedAt(), | ||
]; | ||
} | ||
} |
This file contains 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,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
/** | ||
* @mixin \App\Models\User | ||
*/ | ||
class AuthorResource extends JsonResource | ||
{ | ||
public function toArray($request): array | ||
{ | ||
return [ | ||
'id' => $this->getKey(), | ||
'email' => $this->emailAddress(), | ||
'username' => $this->username(), | ||
'name' => $this->name(), | ||
'bio' => $this->bio(), | ||
'twitter_handle' => $this->twitter(), | ||
'github_username' => $this->githubUsername(), | ||
]; | ||
} | ||
} |
This file contains 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; | ||
|
||
/** | ||
* @mixin \App\Models\Tag | ||
*/ | ||
class TagResource extends JsonResource | ||
{ | ||
public function toArray($request): array | ||
{ | ||
return [ | ||
'id' => $this->getKey(), | ||
'name' => $this->name(), | ||
'slug' => $this->slug(), | ||
]; | ||
} | ||
} |
This file contains 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,24 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
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 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,24 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
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 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 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 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.