Skip to content
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

Suggestions for Improvements #37

Open
VimKanzoGH opened this issue Oct 5, 2022 · 2 comments
Open

Suggestions for Improvements #37

VimKanzoGH opened this issue Oct 5, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@VimKanzoGH
Copy link

VimKanzoGH commented Oct 5, 2022

Hello, @JustSteveKing thank you for this great package once again and also for the quick fixes from yesterday. I was thinking about some ways you could improve the package. Below is an example:

I'm working on an app that consumes solely on an API developed in Laravel, now for crud operations like Post management, I would have to create a Transport Request class for all the crud operations which is how the current package works (I stand to be corrected). I would have wished to just create one class e.g UpsertPosts or PostTransporter which will take care of all the crud operations instead of creating different classes for Create, Read, Update and Delete.

In the end, I would love to be able to do something like this:

<?php

namespace App\Http\Controllers;

$post = PostTransporter::build()
->method('Post') or ->post (making it possible to overwrite the method via this constructor
->send();

Also instead of adding ->withData(['title' => $request->title]), I would like to be able to pass the data instead inside the PostTransporter class to keep things clean maybe via the constructor like so:

<?php

declare(strict_types=1);

namespace App\Transporter\Requests\Sour\Posts;

use JustSteveKing\Transporter\Request;
use App\Http\Requests\UpsertPostRequest;

class Post extends Request
{
    protected string $method = 'GET';
    protected string $path = '/v1/post/{id}';


    public function __construct(UpsertPostRequest $request) {
        'title' => $request->id,
        'description' => $request->description,
        'release_date' => $request->release_date,
    }

    public function rules(): array
    {
        return [
            'title' => 'required',
            'description' => 'required',
            'release_date' => 'required',
            'rating' => 'required',
            'ticket_price' => 'required',
            'country' => 'required',
            'genre' => 'required',
            'photo' => 'required',
        ];
    }
}

NB: So one can define the validation rule via the function above or just import their validation request as I did in the construct

I hope I was able to explain myself well. This would have been super amazing to have. Once again thanks for all the hard work.

@JustSteveKing
Copy link
Owner

These are some cool ideas!

@JustSteveKing JustSteveKing self-assigned this Oct 5, 2022
@JustSteveKing JustSteveKing added the enhancement New feature or request label Oct 5, 2022
@VimKanzoGH
Copy link
Author

Hello @JustSteveKing Sorry forgot one more thing. Pagination One should be able to do something like this if it does not already exist:

<?php

declare(strict_types=1);

namespace App\Transporter\Requests\Sour\Posts;

use JustSteveKing\Transporter\Request;
use App\Http\Requests\UpsertPostRequest;

class Post extends Request
{
    protected string $method = 'GET';
    protected string $path = '/v1/post?page='; //being able to paginate

And in my controller I would do something like so:

<?php

declare(strict_types=1);

namespace App\Transporter\Requests\Sour\Posts;

class PostController extends Controller
{
 public function index($page = 1)
    {
        $posts = ListPosts::build()->appendPath($page)->send();
        if ($posts->status() == 200) {
            $posts = $posts->json('payload');
           return view('post.index', compact('posts'));
        } else {
            return redirect()->route('login')->with('error', 'You are not authorized to view this page');
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants