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

Commit

Permalink
refactor: add more spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mydearxym committed Aug 11, 2019
1 parent 9e05206 commit 6f0ee76
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
18 changes: 10 additions & 8 deletions lib/groupher_server/cms/delegates/community_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
"""
import Ecto.Query, warn: false
import Helper.ErrorCode
import Helper.CommonTypes
# import ShortMaps

alias GroupherServer.CMS

alias Helper.ORM
alias Helper.SpecType, as: T

alias GroupherServer.CMS.{
alias CMS.{
Community,
CommunityWiki,
CommunityCheatsheet
Expand Down Expand Up @@ -46,7 +48,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
@doc """
sync wiki
"""
@spec sync_github_content(Community.t(), atom) :: {:ok, CommunityWiki.t()}
@spec sync_github_content(Community.t(), atom(), any()) :: {: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 @@ -58,7 +60,7 @@ defmodule GroupherServer.CMS.Delegate.CommunitySync do
@doc """
sync cheatsheet
"""
@spec sync_github_content(Community.t(), atom()) :: {:ok, CommunityCheatsheet.t()}
@spec sync_github_content(Community.t(), atom(), any()) :: {: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 @@ -70,17 +72,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()
@spec add_contributor(Community.t(), T.github_contributor()) ::
{:ok, CommunityWiki} | T.gq_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()
@spec add_contributor(Community.t(), T.github_contributor()) ::
{:ok, CommunityCheatsheet} | T.gq_error()
def add_contributor(%CommunityCheatsheet{id: id}, contributor_attrs) do
do_add_contributor(CommunityCheatsheet, id, contributor_attrs)
end
Expand Down
17 changes: 0 additions & 17 deletions lib/helper/common_types.ex

This file was deleted.

13 changes: 13 additions & 0 deletions lib/helper/spec_type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ defmodule Helper.SpecType do
@type done :: {:ok, map} | {:error, map}

@type id :: non_neg_integer() | String.t()

@typedoc """
general contribute type for wiki and cheatshet
"""
@type github_contributor2 :: %{
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()
}
end

0 comments on commit 6f0ee76

Please sign in to comment.