Thanks to visit codestin.com
Credit goes to github.com

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

Commit 9e05206

Browse files
author
mydearxym
committed
chore: wip
1 parent 8ff259d commit 9e05206

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

lib/groupher_server/cms/delegates/article_curd.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
130130
end
131131
end
132132

133+
@spec ensure_author_exists(User.t()) :: {:ok, User.t()}
133134
def ensure_author_exists(%User{} = user) do
134135
# unique_constraint: avoid race conditions, make sure user_id unique
135136
# foreign_key_constraint: check foreign key: user_id exsit or not

lib/groupher_server/cms/delegates/community_sync.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
44
"""
55
import Ecto.Query, warn: false
66
import Helper.ErrorCode
7+
import Helper.CommonTypes
78
# import ShortMaps
89

910
alias Helper.ORM
@@ -17,6 +18,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
1718
@doc """
1819
get wiki
1920
"""
21+
@spec get_wiki(Community.t()) :: {:ok, CommunityWiki.t()}
2022
def get_wiki(%Community{raw: raw}) do
2123
with {:ok, community} <- ORM.find_by(Community, raw: raw),
2224
{:ok, wiki} <- ORM.find_by(CommunityWiki, community_id: community.id) do
@@ -30,6 +32,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
3032
@doc """
3133
get cheatsheet
3234
"""
35+
@spec get_cheatsheet(Community.t()) :: {:ok, CommunityCheatsheet.t()}
3336
def get_cheatsheet(%Community{raw: raw}) do
3437
with {:ok, community} <- ORM.find_by(Community, raw: raw),
3538
{:ok, wiki} <- ORM.find_by(CommunityCheatsheet, community_id: community.id) do
@@ -43,6 +46,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
4346
@doc """
4447
sync wiki
4548
"""
49+
@spec sync_github_content(Community.t(), atom) :: {:ok, CommunityWiki.t()}
4650
def sync_github_content(%Community{id: id}, :wiki, attrs) do
4751
with {:ok, community} <- ORM.find(Community, id) do
4852
attrs = Map.merge(attrs, %{community_id: community.id})
@@ -54,6 +58,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
5458
@doc """
5559
sync cheatsheet
5660
"""
61+
@spec sync_github_content(Community.t(), atom()) :: {:ok, CommunityCheatsheet.t()}
5762
def sync_github_content(%Community{id: id}, :cheatsheet, attrs) do
5863
with {:ok, community} <- ORM.find(Community, id) do
5964
attrs = Map.merge(attrs, %{community_id: community.id})
@@ -65,10 +70,17 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
6570
@doc """
6671
add contributor to exsit wiki contributors list
6772
"""
73+
@spec add_contributor(Community.t(), github_contributor()) ::
74+
{:ok, CommunityWiki} | custom_error()
6875
def add_contributor(%CommunityWiki{id: id}, contributor_attrs) do
6976
do_add_contributor(CommunityWiki, id, contributor_attrs)
7077
end
7178

79+
@doc """
80+
add contributor to exsit cheatsheet contributors list
81+
"""
82+
@spec add_contributor(Community.t(), github_contributor()) ::
83+
{:ok, CommunityCheatsheet} | custom_error()
7284
def add_contributor(%CommunityCheatsheet{id: id}, contributor_attrs) do
7385
do_add_contributor(CommunityCheatsheet, id, contributor_attrs)
7486
end

lib/helper/common_types.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Helper.CommonTypes do
2+
@moduledoc """
3+
common types for lint
4+
"""
5+
6+
@type github_contributor :: %{
7+
github_id: String.t(),
8+
avatar: String.t(),
9+
html_url: String.t(),
10+
nickname: String.t(),
11+
bio: nil | String.t(),
12+
location: nil | String.t(),
13+
company: nil | String.t()
14+
}
15+
16+
@type custom_error :: {:error, [message: String.t(), code: Number.t()]}
17+
end

0 commit comments

Comments
 (0)