-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/responsive-landing
- Loading branch information
Showing
27 changed files
with
919 additions
and
214 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 |
---|---|---|
|
@@ -192,4 +192,4 @@ | |
width: 12.25rem; | ||
height: 3.8rem; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,7 +18,8 @@ config :flop, repo: Pescarte.Database.Repo.Replica | |
|
||
config :pescarte, fetch_pesagro_cotacoes: !!System.get_env("FETCH_PESAGRO_COTACOES") | ||
|
||
config :pescarte, PescarteWeb, receiver_email: "[email protected]" | ||
config :pescarte, PescarteWeb, sender_email: "[email protected]" | ||
config :pescarte, PescarteWeb, receiver_email: "[email protected]" | ||
|
||
config :pescarte, | ||
ecto_repos: [Pescarte.Database.Repo], | ||
|
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,76 @@ | ||
defmodule Pescarte.Blog.Entity.Tag do | ||
@moduledoc """ | ||
A entidade `Tag` fornece um CRUD básico para a mesma e é responsável por categorizar os posts do contexto Blog, para filtragem e pesquisa. | ||
""" | ||
|
||
use Pescarte, :model | ||
|
||
alias Pescarte.Database.Types.PublicId | ||
|
||
@type t :: %Tag{nome: binary, id: binary} | ||
|
||
@required_fields ~w(nome)a | ||
|
||
@primary_key {:id, PublicId, autogenerate: true} | ||
schema "blog_tag" do | ||
field :nome, :string | ||
|
||
timestamps() | ||
end | ||
|
||
@spec changeset(Tag.t(), map) :: changeset | ||
def changeset(%Tag{} = tag, attrs) do | ||
tag | ||
|> cast(attrs, @required_fields) | ||
|> validate_required(@required_fields) | ||
|> unique_constraint(:nome) | ||
end | ||
|
||
@spec list_tags() :: {:ok, list(Tag.t())} | {:error, term()} | ||
def list_tags do | ||
Repo.replica().all(Tag) | ||
end | ||
|
||
@spec fetch_tag_by_id(String.t()) :: {:ok, Tag.t()} | {:error, term()} | ||
def fetch_tag_by_id(id) do | ||
Pescarte.Database.fetch(Tag, id) | ||
end | ||
|
||
@spec fetch_tag_by_name(String.t()) :: {:ok, Tag.t()} | {:error, term()} | ||
def fetch_tag_by_name(nome) do | ||
Pescarte.Database.fetch_by(Tag, nome: nome) | ||
end | ||
|
||
@spec create_tag(map()) :: {:ok, Tag.t()} | {:error, changeset} | ||
def create_tag(attrs) do | ||
%Tag{} | ||
|> changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
@spec update_tag(String.t(), map()) :: {:ok, Tag.t()} | {:error, :not_found} | ||
def update_tag(id, attrs) do | ||
query = from(t in Tag, where: t.id == ^id, select: t) | ||
|
||
attrs_with_updated_date = Map.put(attrs, :updated_at, NaiveDateTime.utc_now()) | ||
|
||
query | ||
|> Repo.update_all(set: Map.to_list(attrs_with_updated_date)) | ||
|> case do | ||
{1, [updated_tag]} -> {:ok, updated_tag} | ||
{_, _} -> {:error, :not_found} | ||
end | ||
end | ||
|
||
@spec delete_tag(String.t()) :: :ok | {:error, :not_found} | ||
def delete_tag(id) do | ||
query = from(t in Tag, where: t.id == ^id) | ||
|
||
query | ||
|> Repo.delete_all() | ||
|> case do | ||
{1, _} -> :ok | ||
{_, _} -> {:error, :not_found} | ||
end | ||
end | ||
end |
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,92 @@ | ||
defmodule Pescarte.Blog.Post do | ||
@moduledoc """ | ||
Módulo que define o schema e o changeset para os posts. | ||
""" | ||
alias Pescarte.Database | ||
alias Pescarte.Database.Repo | ||
alias Pescarte.Database.Types.PublicId | ||
alias Pescarte.Identidades.Models.Usuario | ||
use Pescarte, :model | ||
|
||
@type t :: %Post{ | ||
id: String.t(), | ||
titulo: String.t(), | ||
conteudo: String.t(), | ||
link_imagem_capa: String.t(), | ||
published_at: NaiveDateTime.t(), | ||
inserted_at: NaiveDateTime.t(), | ||
updated_at: NaiveDateTime.t(), | ||
usuario: Usuario.t(), | ||
usuario_id: String.t() | ||
} | ||
|
||
@required_params [:titulo, :conteudo, :link_imagem_capa, :published_at] | ||
|
||
@primary_key {:id, PublicId, autogenerate: true} | ||
schema "posts" do | ||
field :titulo, :string | ||
field :conteudo, :binary | ||
field :link_imagem_capa, :string | ||
field :published_at, :naive_datetime | ||
|
||
belongs_to :usuario, Usuario | ||
|
||
# comentado enquanto o PR das tags não é aprovado | ||
# many_to_many :tags, Tag, through: [:post_tags, :tag] | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(post \\ %Post{}, params) do | ||
post | ||
|> cast(params, @required_params) | ||
|> validate_required(@required_params) | ||
|> unique_constraint(:titulo) | ||
end | ||
|
||
@spec get_posts :: list(Post.t()) | Ecto.QueryError | ||
def get_posts do | ||
Repo.Replica.all(Post) | ||
end | ||
|
||
@spec get_post(String.t()) :: {:ok, Post.t()} | {:error, :not_found} | ||
def get_post(id) do | ||
Database.fetch(Post, id) | ||
end | ||
|
||
@spec create_post(Post.t()) :: {:ok, Post.t()} | {:error, Ecto.Changeset.t()} | ||
def create_post(params) do | ||
%Post{} | ||
|> Post.changeset(params) | ||
|> Repo.insert() | ||
end | ||
|
||
@spec delete_post(String.t()) :: {:ok, Post.t()} | {:error, :not_found} | ||
def delete_post(id) do | ||
query = from(p in Post, where: p.id == ^id, select: p) | ||
|
||
query | ||
|> Repo.delete_all() | ||
|> case do | ||
{1, [deleted_post]} -> {:ok, deleted_post} | ||
{0, nil} -> {:error, :not_found} | ||
end | ||
end | ||
|
||
@spec update_post(String.t(), Post.t()) :: {:ok, Post.t()} | {:error, :not_found} | ||
def update_post(id, params) do | ||
query = from(p in Post, where: p.id == ^id, select: p) | ||
|
||
params_with_updated_at = | ||
params | ||
|> Map.put(:updated_at, NaiveDateTime.utc_now()) | ||
|> Map.to_list() | ||
|
||
query | ||
|> Repo.update_all(set: params_with_updated_at) | ||
|> case do | ||
{1, [updated_post]} -> {:ok, updated_post} | ||
{0, _} -> {:error, :not_found} | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
<PescarteWeb.DesignSystem.Navbar.render current_path={@current_path} /> | ||
|
||
<main class="w-full h-full"> | ||
<.flash_group flash={@flash} /> | ||
<%= @inner_content %> | ||
<PescarteWeb.DesignSystem.Navbar.render current_path="{@current_path}" /> | ||
<main class="w-full h-full z-0"> | ||
<.flash_group flash={@flash} /> <%= @inner_content %> | ||
</main> | ||
|
||
<.footer /> |
Oops, something went wrong.