This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork20
feat(drink-thread): basic workflow#418
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
1dd0bac
chore: remove length arg when create article
mydearxymf2dd9e4
chore: setup schema
mydearxymb771a0d
chore: tests
mydearxym39b6260
chore: fix test
mydearxym478ec10
chore: fix mock
mydearxymc110e31
chore: fix migration
mydearxym89b830a
chore: length issue
mydearxym92b1f43
chore: length issue
mydearxymFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 3 additions & 2 deletionsconfig/config.exs
This file contains hidden or 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
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/article_curd.ex
This file contains hidden or 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
3 changes: 1 addition & 2 deletionslib/groupher_server/cms/models/blog.ex
This file contains hidden or 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
48 changes: 48 additions & 0 deletionslib/groupher_server/cms/models/drink.ex
This file contains hidden or 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,48 @@ | ||
defmodule GroupherServer.CMS.Model.Drink do | ||
@moduledoc false | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
use Accessible | ||
import Ecto.Changeset | ||
import GroupherServer.CMS.Helper.Macros | ||
alias GroupherServer.CMS | ||
alias CMS.Model.Embeds | ||
@timestamps_opts [type: :utc_datetime_usec] | ||
@required_fields ~w(title digest)a | ||
@article_cast_fields general_article_cast_fields() | ||
@optional_fields @article_cast_fields | ||
@type t :: %Drink{} | ||
schema "cms_drinks" do | ||
article_tags_field(:drink) | ||
article_communities_field(:drink) | ||
general_article_fields(:drink) | ||
end | ||
@doc false | ||
def changeset(%Drink{} = drink, attrs) do | ||
drink | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> validate_required(@required_fields) | ||
|> cast_embed(:meta, required: false, with: &Embeds.ArticleMeta.changeset/2) | ||
|> generl_changeset | ||
end | ||
@doc false | ||
def update_changeset(%Drink{} = drink, attrs) do | ||
drink | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> generl_changeset | ||
end | ||
defp generl_changeset(changeset) do | ||
changeset | ||
|> validate_length(:title, min: 3, max: 50) | ||
|> cast_embed(:emotions, with: &Embeds.ArticleEmotion.changeset/2) | ||
end | ||
end |
47 changes: 47 additions & 0 deletionslib/groupher_server/cms/models/drink_document.ex
This file contains hidden or 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,47 @@ | ||
defmodule GroupherServer.CMS.Model.DrinkDocument do | ||
@moduledoc """ | ||
mainly for full-text search | ||
""" | ||
alias __MODULE__ | ||
use Ecto.Schema | ||
use Accessible | ||
import Ecto.Changeset | ||
import Helper.Utils, only: [get_config: 2] | ||
alias GroupherServer.CMS | ||
alias CMS.Model.Drink | ||
@timestamps_opts [type: :utc_datetime_usec] | ||
@max_body_length get_config(:article, :max_length) | ||
@min_body_length get_config(:article, :min_length) | ||
@required_fields ~w(body body_html drink_id)a | ||
@optional_fields [] | ||
@type t :: %DrinkDocument{} | ||
schema "drink_documents" do | ||
belongs_to(:drink, Drink, foreign_key: :drink_id) | ||
field(:body, :string) | ||
field(:body_html, :string) | ||
field(:toc, :map) | ||
end | ||
@doc false | ||
def changeset(%DrinkDocument{} = drink, attrs) do | ||
drink | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> validate_required(@required_fields) | ||
|> validate_length(:body, min: @min_body_length, max: @max_body_length) | ||
end | ||
@doc false | ||
def update_changeset(%DrinkDocument{} = drink, attrs) do | ||
drink | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> validate_length(:body, min: @min_body_length, max: @max_body_length) | ||
end | ||
end |
3 changes: 1 addition & 2 deletionslib/groupher_server/cms/models/job.ex
This file contains hidden or 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
3 changes: 1 addition & 2 deletionslib/groupher_server/cms/models/post.ex
This file contains hidden or 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
1 change: 0 additions & 1 deletionlib/groupher_server_web/schema/Helper/fields.ex
This file contains hidden or 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
8 changes: 7 additions & 1 deletionlib/groupher_server_web/schema/cms/cms_metrics.ex
This file contains hidden or 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
16 changes: 8 additions & 8 deletionslib/groupher_server_web/schema/cms/cms_types.ex
This file contains hidden or 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
2 changes: 0 additions & 2 deletionslib/groupher_server_web/schema/cms/mutations/blog.ex
This file contains hidden or 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
52 changes: 52 additions & 0 deletionslib/groupher_server_web/schema/cms/mutations/drink.ex
This file contains hidden or 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,52 @@ | ||
defmodule GroupherServerWeb.Schema.CMS.Mutations.Drink do | ||
@moduledoc """ | ||
CMS mutations for drink | ||
""" | ||
use Helper.GqlSchemaSuite | ||
import GroupherServerWeb.Schema.Helper.Mutations | ||
object :cms_drink_mutations do | ||
@desc "create a drink" | ||
field :create_drink, :drink do | ||
arg(:title, non_null(:string)) | ||
arg(:body, non_null(:string)) | ||
arg(:digest, non_null(:string)) | ||
arg(:community_id, non_null(:id)) | ||
arg(:thread, :thread, default_value: :drink) | ||
arg(:article_tags, list_of(:id)) | ||
middleware(M.Authorize, :login) | ||
middleware(M.PublishThrottle) | ||
resolve(&R.CMS.create_article/3) | ||
middleware(M.Statistics.MakeContribute, for: [:user, :community]) | ||
end | ||
@desc "update a cms/drink" | ||
field :update_drink, :drink do | ||
arg(:id, non_null(:id)) | ||
arg(:title, :string) | ||
arg(:body, :string) | ||
arg(:digest, :string) | ||
arg(:article_tags, list_of(:id)) | ||
# ... | ||
middleware(M.Authorize, :login) | ||
middleware(M.PassportLoader, source: :drink) | ||
middleware(M.Passport, claim: "owner;cms->c?->drink.edit") | ||
resolve(&R.CMS.update_article/3) | ||
end | ||
article_react_mutations(:drink, [ | ||
:upvote, | ||
:pin, | ||
:mark_delete, | ||
:delete, | ||
:emotion, | ||
:report, | ||
:sink, | ||
:lock_comment | ||
]) | ||
end | ||
end |
2 changes: 0 additions & 2 deletionslib/groupher_server_web/schema/cms/mutations/job.ex
This file contains hidden or 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
1 change: 0 additions & 1 deletionlib/groupher_server_web/schema/cms/mutations/post.ex
This file contains hidden or 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
32 changes: 32 additions & 0 deletionspriv/repo/migrations/20210626100316_create_drink.exs
This file contains hidden or 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,32 @@ | ||
defmodule GroupherServer.Repo.Migrations.CreateDrink do | ||
use Ecto.Migration | ||
def change do | ||
create table(:cms_drinks) do | ||
add(:thread, :string) | ||
add(:title, :string) | ||
add(:digest, :string) | ||
add(:views, :integer, default: 0) | ||
add(:mark_delete, :boolean, default: false) | ||
add(:meta, :map) | ||
add(:emotions, :map) | ||
add(:original_community_id, references(:communities, on_delete: :delete_all)) | ||
add(:author_id, references(:cms_authors, on_delete: :delete_all), null: false) | ||
add(:active_at, :utc_datetime) | ||
# reaction | ||
add(:upvotes_count, :integer, default: 0) | ||
add(:collects_count, :integer, default: 0) | ||
# comments | ||
add(:comments_participants_count, :integer, default: 0) | ||
add(:comments_count, :integer, default: 0) | ||
add(:comments_participants, :map) | ||
timestamps() | ||
end | ||
create(index(:cms_drinks, [:author_id])) | ||
end | ||
end |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.