Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mydearxym committed Aug 8, 2019
1 parent 8ff259d commit 9e05206
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/groupher_server/cms/delegates/article_curd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
end
end

@spec ensure_author_exists(User.t()) :: {:ok, User.t()}
def ensure_author_exists(%User{} = user) do
# unique_constraint: avoid race conditions, make sure user_id unique
# foreign_key_constraint: check foreign key: user_id exsit or not
Expand Down
12 changes: 12 additions & 0 deletions lib/groupher_server/cms/delegates/community_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
"""
import Ecto.Query, warn: false
import Helper.ErrorCode
import Helper.CommonTypes
# import ShortMaps

alias Helper.ORM
Expand All @@ -17,6 +18,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
@doc """
get wiki
"""
@spec get_wiki(Community.t()) :: {:ok, CommunityWiki.t()}
def get_wiki(%Community{raw: raw}) do
with {:ok, community} <- ORM.find_by(Community, raw: raw),
{:ok, wiki} <- ORM.find_by(CommunityWiki, community_id: community.id) do
Expand All @@ -30,6 +32,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
@doc """
get cheatsheet
"""
@spec get_cheatsheet(Community.t()) :: {:ok, CommunityCheatsheet.t()}
def get_cheatsheet(%Community{raw: raw}) do
with {:ok, community} <- ORM.find_by(Community, raw: raw),
{:ok, wiki} <- ORM.find_by(CommunityCheatsheet, community_id: community.id) do
Expand All @@ -43,6 +46,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
@doc """
sync wiki
"""
@spec sync_github_content(Community.t(), atom) :: {:ok, CommunityWiki.t()}
def sync_github_content(%Community{id: id}, :wiki, attrs) do
with {:ok, community} <- ORM.find(Community, id) do
attrs = Map.merge(attrs, %{community_id: community.id})
Expand All @@ -54,6 +58,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
@doc """
sync cheatsheet
"""
@spec sync_github_content(Community.t(), atom()) :: {:ok, CommunityCheatsheet.t()}
def sync_github_content(%Community{id: id}, :cheatsheet, attrs) do
with {:ok, community} <- ORM.find(Community, id) do
attrs = Map.merge(attrs, %{community_id: community.id})
Expand All @@ -65,10 +70,17 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
@doc """
add contributor to exsit wiki contributors list
"""
@spec add_contributor(Community.t(), github_contributor()) ::
{:ok, CommunityWiki} | custom_error()
def add_contributor(%CommunityWiki{id: id}, contributor_attrs) do
do_add_contributor(CommunityWiki, id, contributor_attrs)
end

@doc """
add contributor to exsit cheatsheet contributors list
"""
@spec add_contributor(Community.t(), github_contributor()) ::
{:ok, CommunityCheatsheet} | custom_error()
def add_contributor(%CommunityCheatsheet{id: id}, contributor_attrs) do
do_add_contributor(CommunityCheatsheet, id, contributor_attrs)
end
Expand Down
17 changes: 17 additions & 0 deletions lib/helper/common_types.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Helper.CommonTypes do
@moduledoc """
common types for lint
"""

@type github_contributor :: %{
github_id: String.t(),
avatar: String.t(),
html_url: String.t(),
nickname: String.t(),
bio: nil | String.t(),
location: nil | String.t(),
company: nil | String.t()
}

@type custom_error :: {:error, [message: String.t(), code: Number.t()]}
end

0 comments on commit 9e05206

Please sign in to comment.