Skip to content

Commit

Permalink
fix: format and dev settings
Browse files Browse the repository at this point in the history
  • Loading branch information
juanzeen committed Nov 24, 2024
1 parent af65ef3 commit 0d2ad10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Config
# -------- #
# Database #
# -------- #
db_name = "peapescarte"
db_user = "postgres"
db_pass = "postgres"
db_port = "5432"
db_host = "localhost"
db_name = System.get_env("DATABASE_NAME", "peapescarte")
db_user = System.get_env("DATABASE_USER", "peapescarte")
db_pass = System.get_env("DATABASE_PASS", "peapescarte")
db_port = System.get_env("DATABASE_PORT", "5432")
db_host = System.get_env("DATABASE_HOST", "localhost")

database_opts = [
username: db_user,
Expand Down
5 changes: 2 additions & 3 deletions lib/pescarte/blog/entity/tag.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ defmodule Pescarte.Blog.Entity.Tag do
end

@spec to_changesets(list(Map.t()), list()) :: {:ok, list(Tag.t())}
def to_changesets(list, acc\\[])
def to_changesets(list, acc \\ [])
def to_changesets([], acc), do: {:ok, acc}
def to_changesets([tag | rest], acc), do: to_changesets(rest,[changeset(%Tag{}, tag) | acc])

def to_changesets([tag | rest], acc), do: to_changesets(rest, [changeset(%Tag{}, tag) | acc])

@spec create_tag(map()) :: {:ok, Tag.t()} | {:error, changeset}
def create_tag(attrs) do
Expand Down
16 changes: 10 additions & 6 deletions lib/pescarte/blog/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Pescarte.Blog.Post do
alias Pescarte.Database
alias Pescarte.Database.Repo
alias Pescarte.Database.Types.PublicId
#alias Pescarte.Identidades.Models.Usuario
alias Pescarte.Identidades.Models.Usuario
use Pescarte, :model

@type t :: %Post{
Expand All @@ -18,10 +18,11 @@ defmodule Pescarte.Blog.Post do
published_at: NaiveDateTime.t(),
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t(),
# usuario_id: PublicId
usuario_id: String.t(),
usuario: Usuario.t()
}

@required_params [:titulo, :conteudo, :link_imagem_capa, :published_at] #, :usuario_id]
@required_params [:titulo, :conteudo, :link_imagem_capa, :published_at, :usuario_id]

@primary_key {:id, PublicId, autogenerate: true}
schema "blog_post" do
Expand All @@ -30,7 +31,7 @@ defmodule Pescarte.Blog.Post do
field :link_imagem_capa, :string
field :published_at, :naive_datetime

#belongs_to :usuario, Usuario
belongs_to :usuario, Usuario, foreign_key: :usuario_id
many_to_many :blog_tags, Tag, join_through: "posts_tags"

timestamps()
Expand All @@ -39,7 +40,7 @@ defmodule Pescarte.Blog.Post do
@spec changeset(Post.t(), map) :: changeset
def changeset(post \\ %Post{}, params) do
post
|>Map.put(:published_at, NaiveDateTime.local_now())
|> Map.put(:published_at, NaiveDateTime.local_now())
|> cast(params, @required_params)
|> validate_required(@required_params)
|> unique_constraint(:titulo)
Expand All @@ -66,7 +67,10 @@ defmodule Pescarte.Blog.Post do
@spec create_post(Map) :: {:ok, Post.t()} | {:error, Ecto.Changeset.t()}
def create_post(%{blog_tags: tags} = params) do
Multi.new()
|> Multi.insert_all(:update_tags, Tag, tags, on_conflict: :replace_all, conflict_target: :nome)
|> Multi.insert_all(:update_tags, Tag, tags,
on_conflict: :replace_all,
conflict_target: :nome
)
|> Multi.insert(:blog_post, Post.changeset(%Post{}, params))
|> Repo.transaction()
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pescarte/identidades/models/usuario.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Pescarte.Identidades.Models.Usuario do

import Brcpfcnpj.Changeset, only: [validate_cpf: 3]

alias Pescarte.Blog.Post
# alias Pescarte.Blog.Post
alias Pescarte.Database.Types.PublicId
alias Pescarte.Identidades.Models.Contato
alias Pescarte.ModuloPesquisa.Models.Pesquisador
Expand Down Expand Up @@ -45,7 +45,7 @@ defmodule Pescarte.Identidades.Models.Usuario do

belongs_to :contato, Contato, type: :string

has_many :posts, Post
has_many :blog_post, Post

timestamps()
end
Expand Down

0 comments on commit 0d2ad10

Please sign in to comment.