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(radar-thread): basic workflow#415
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
842d36d
chore(radar): add migration tables
mydearxymb0fc9c1
chore(radar): setup basic model & test react macros
mydearxym93e9db8
chore(radar): fix used value
mydearxym744a481
chore(radar): fix macro
mydearxym1df4ba4
chore(radar): use article_react_mutations
mydearxym733170e
chore(radar): use article_react_mutations
mydearxymc6f3ac8
chore(radar): add tests
mydearxyma587596
chore(radar): missing radar model
mydearxym17d65ae
chore(radar): fix test
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
48 changes: 48 additions & 0 deletionslib/groupher_server/cms/models/radar.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.Radar 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 :: %Radar{} | ||
schema "cms_radars" do | ||
article_tags_field(:radar) | ||
article_communities_field(:radar) | ||
general_article_fields(:radar) | ||
end | ||
@doc false | ||
def changeset(%Radar{} = radar, attrs) do | ||
radar | ||
|> 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(%Radar{} = radar, attrs) do | ||
radar | ||
|> 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/radar_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.RadarDocument 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.Radar | ||
@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 radar_id)a | ||
@optional_fields [] | ||
@type t :: %RadarDocument{} | ||
schema "radar_documents" do | ||
belongs_to(:radar, Radar, foreign_key: :radar_id) | ||
field(:body, :string) | ||
field(:body_html, :string) | ||
field(:toc, :map) | ||
end | ||
@doc false | ||
def changeset(%RadarDocument{} = radar, attrs) do | ||
radar | ||
|> 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(%RadarDocument{} = radar, attrs) do | ||
radar | ||
|> cast(attrs, @optional_fields ++ @required_fields) | ||
|> validate_length(:body, min: @min_body_length, max: @max_body_length) | ||
end | ||
end |
32 changes: 26 additions & 6 deletionslib/groupher_server_web/schema/Helper/mutations.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
12 changes: 12 additions & 0 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
20 changes: 10 additions & 10 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
20 changes: 10 additions & 10 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
20 changes: 10 additions & 10 deletionslib/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
52 changes: 52 additions & 0 deletionslib/groupher_server_web/schema/cms/mutations/radar.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.Radar do | ||
@moduledoc """ | ||
CMS mutations for radar | ||
""" | ||
use Helper.GqlSchemaSuite | ||
import GroupherServerWeb.Schema.Helper.Mutations | ||
object :cms_radar_mutations do | ||
@desc "create a radar" | ||
field :create_radar, :radar 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: :radar) | ||
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/radar" | ||
field :update_radar, :radar 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: :radar) | ||
middleware(M.Passport, claim: "owner;cms->c?->radar.edit") | ||
resolve(&R.CMS.update_article/3) | ||
end | ||
article_react_mutations(:radar, [ | ||
:upvote, | ||
:pin, | ||
:mark_delete, | ||
:delete, | ||
:emotion, | ||
:report, | ||
:sink, | ||
:lock_comment | ||
]) | ||
end | ||
end |
18 changes: 9 additions & 9 deletionslib/groupher_server_web/schema/cms/mutations/repo.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
20 changes: 10 additions & 10 deletionslib/groupher_server_web/schema/cms/mutations/works.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
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.