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

Commit 3b43815

Browse files
committed
chore: merge branch 'improve-spec' into dev
2 parents 8ff259d + 6f0ee76 commit 3b43815

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
66
import Helper.ErrorCode
77
# import ShortMaps
88

9+
alias GroupherServer.CMS
10+
911
alias Helper.ORM
12+
alias Helper.SpecType, as: T
1013

11-
alias GroupherServer.CMS.{
14+
alias CMS.{
1215
Community,
1316
CommunityWiki,
1417
CommunityCheatsheet
@@ -17,6 +20,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
1720
@doc """
1821
get wiki
1922
"""
23+
@spec get_wiki(Community.t()) :: {:ok, CommunityWiki.t()}
2024
def get_wiki(%Community{raw: raw}) do
2125
with {:ok, community} <- ORM.find_by(Community, raw: raw),
2226
{:ok, wiki} <- ORM.find_by(CommunityWiki, community_id: community.id) do
@@ -30,6 +34,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
3034
@doc """
3135
get cheatsheet
3236
"""
37+
@spec get_cheatsheet(Community.t()) :: {:ok, CommunityCheatsheet.t()}
3338
def get_cheatsheet(%Community{raw: raw}) do
3439
with {:ok, community} <- ORM.find_by(Community, raw: raw),
3540
{:ok, wiki} <- ORM.find_by(CommunityCheatsheet, community_id: community.id) do
@@ -43,6 +48,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
4348
@doc """
4449
sync wiki
4550
"""
51+
@spec sync_github_content(Community.t(), atom(), any()) :: {:ok, CommunityWiki.t()}
4652
def sync_github_content(%Community{id: id}, :wiki, attrs) do
4753
with {:ok, community} <- ORM.find(Community, id) do
4854
attrs = Map.merge(attrs, %{community_id: community.id})
@@ -54,6 +60,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
5460
@doc """
5561
sync cheatsheet
5662
"""
63+
@spec sync_github_content(Community.t(), atom(), any()) :: {:ok, CommunityCheatsheet.t()}
5764
def sync_github_content(%Community{id: id}, :cheatsheet, attrs) do
5865
with {:ok, community} <- ORM.find(Community, id) do
5966
attrs = Map.merge(attrs, %{community_id: community.id})
@@ -65,10 +72,17 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
6572
@doc """
6673
add contributor to exsit wiki contributors list
6774
"""
75+
@spec add_contributor(Community.t(), T.github_contributor()) ::
76+
{:ok, CommunityWiki} | T.gq_error()
6877
def add_contributor(%CommunityWiki{id: id}, contributor_attrs) do
6978
do_add_contributor(CommunityWiki, id, contributor_attrs)
7079
end
7180

81+
@doc """
82+
add contributor to exsit cheatsheet contributors list
83+
"""
84+
@spec add_contributor(Community.t(), T.github_contributor()) ::
85+
{:ok, CommunityCheatsheet} | T.gq_error()
7286
def add_contributor(%CommunityCheatsheet{id: id}, contributor_attrs) do
7387
do_add_contributor(CommunityCheatsheet, id, contributor_attrs)
7488
end

lib/helper/spec_type.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,17 @@ defmodule Helper.SpecType do
1414
@type done :: {:ok, map} | {:error, map}
1515

1616
@type id :: non_neg_integer() | String.t()
17+
18+
@typedoc """
19+
general contribute type for wiki and cheatshet
20+
"""
21+
@type github_contributor2 :: %{
22+
github_id: String.t(),
23+
avatar: String.t(),
24+
html_url: String.t(),
25+
nickname: String.t(),
26+
bio: nil | String.t(),
27+
location: nil | String.t(),
28+
company: nil | String.t()
29+
}
1730
end

0 commit comments

Comments
 (0)