-
Notifications
You must be signed in to change notification settings - Fork 12
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
Feat/blog tag schema #185
Feat/blog tag schema #185
Conversation
- Refatorado get e update para update_all - Refatorado get e delete para delete_all.
lib/pescarte/blog/blog.ex
Outdated
@@ -0,0 +1,55 @@ | |||
defmodule Pescarte.Blog.Blog do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repito, o contexto blog só expõe a API pública que será usada no frontend ou em outros contextos. Funções de CRUD não deveriam ir nesse contexto.
exemplo de funções do contexto blog:
- fetch_recent_posts
- register new post (envolve criar as tags, criar o post no banco, conectar o post com as tags)
- mark_post_for_cancelation
funções de CRUD de uma entidade pura devem ser centralizadas no arquivo que define essa entidade, no caso Blog.Entity.Tag
lib/pescarte/blog/blog.ex
Outdated
|> Repo.update_all(set: Map.to_list(attrs)) | ||
|> case do | ||
{0, _} -> {:error, :not_found} | ||
{_, _} -> {:ok, :updated} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uma tupla de ok necessariamente retorna um valor concreto.
na query de update e delete vc pode usar a diretiva select
, dessa forma o valor atualizado ou deletado vai ser retornado, com o estamos atualizando e deletando apenas 1 entrada, o retorno de sucesso seria:
{1, [entidade]}
, onde a função entoa vai retornar {:ok, entidade}
no caso do delete a gente não precisa da entidade, então pode retornar apenas :ok
puro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
além disso a função update_all
não atualiza o campo updated_at
de timestamp da tabela, então esse campo precisa ser listado manualmente ali na lista de alterações do set
@@ -0,0 +1,24 @@ | |||
defmodule Pescarte.Blog.Entity.Tag do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seria interessante ter uma documentação simples do que essa entidade representa no sistema
- atualização no updated_at e retorno da entidade do update_tag. - delete_tag agora só retorna ok quando é realizado com sucesso.
obrigada pelo trabalho querido |
* main: fix: conflict Feat/pgtr (#195) Feat/landing new (#194) fix: correct agenda title to display month dynamically from CSV data (#198) Feat/footer fixed (#197) Feat/blog posts migration (#186) fix: correct receiver and sender email addresses and generate confirmation email (#193) Feat/blog tag schema (#185) Fix/membros (#192) feat: correctly redirects to landing page after sending email contact fix: correctly start finch adapter for tesla (resend uses it :clown:) oh my god... (#191) Feat/equipes images (#187) wip: adjust table columns and data display (#189) Feat/cards landing (#188) fix: add route to contact form on landing page feat: introduce Result monad type feat: implement design system primitives feat/contato (#182) Belarba/criar entidade nomes comuns de peixe (#172)
Descrição
Nessa PR foi adicionado a tabela e o model da tag. Contexto: Blog
Além do crud básico da tag
Pontos para atenção
Possui migrations?