Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.

Feature/list articles - #21

Open
mariafanelli-ym wants to merge 3 commits into
laravelday2018workshop:masterfrom
mariafanelli-ym:feature/list_articles
Open

Feature/list articles#21
mariafanelli-ym wants to merge 3 commits into
laravelday2018workshop:masterfrom
mariafanelli-ym:feature/list_articles

Conversation

@mariafanelli-ym

Copy link
Copy Markdown

No description provided.

@damianopetrungaro damianopetrungaro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scusa per il ritardo, ecco qualche commento :)

$data = $listArticles();

return response()->json($data);
/*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenti non necessari, rimuovili tranquillamente :)

Comment thread routes/api.php
return $request->user;
});

Route::get('articles', 'ListArticlesController');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggerimento: puoi usare il fqcn importando la classe.

In questo modo se utilizzi un IDE e rinomini la classe o il namespace, automaticamente ti cambiera anche le rotte :)

Suggested change
Route::get('articles', 'ListArticlesController');
Route::get('articles', ListArticlesController::class);

Comment thread src/Article/Article.php
private $creationDate
private $id;

public function __construct(int $id, string $title, string $body, \DateTime $creationDate){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggerimento:
Per proteggere il tuo dominio dalle invarianti, puoi utilizzare dei value objects per assicurarti che ID, Title e Body siano validi.

Es:
Cosa succede se passo un id come 0?
Oppure un title come stringa vuota?

{
public function __invoke()
{
$listArticles = new ListArticles();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usa la dependency injection ed inietta lo usecase nel costruttore, cosí da rendere il controller testabile :)

    public function __invoke()
    {
		return response()->json(($this->listArticles)());
    }


use LaravelDay\Article\UseCase\ListArticles\ListArticles;

class ListArticlesController extends Controller

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manca un try catch per gestire gli errori.

Cosa succede se hai un errore di connessione al database?

Dove pensi di gestire l'errore?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants