Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit5549752

Browse files
committed
refactor(orm): use ! after-fix to make API clear
1 parent0023c38 commit5549752

File tree

9 files changed

+24
-19
lines changed

9 files changed

+24
-19
lines changed

‎cover/excoveralls.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎lib/groupher_server/accounts/delegates/fans.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ defmodule GroupherServer.Accounts.Delegate.Fans do
7575
{:ok,_follow_user}<-ORM.find(User,follower_id)do
7676
Multi.new()
7777
|>Multi.run(:delete_follower,fn_,_->
78-
ORM.findby_delete(UserFollower,%{user_id:follower_id,follower_id:user_id})
78+
ORM.findby_delete!(UserFollower,%{user_id:follower_id,follower_id:user_id})
7979
end)
8080
|>Multi.run(:delete_following,fn_,_->
81-
ORM.findby_delete(UserFollowing,%{user_id:user_id,following_id:follower_id})
81+
ORM.findby_delete!(UserFollowing,%{user_id:user_id,following_id:follower_id})
8282
end)
8383
|>Multi.run(:minus_achievement,fn_,_->
8484
Accounts.achieve(%User{id:follower_id},:minus,:follow)

‎lib/groupher_server/cms/delegates/article_comment.ex‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
351351
article_comment_id:comment.id,
352352
user_id:user_id
353353
})
354-
355-
{:ok,:pass}
356354
end)
357355
|>Multi.run(:desc_upvotes_count,fn_,_->
358356
count_query=from(cinArticleCommentUpvote,where:c.article_comment_id==^comment_id)

‎lib/groupher_server/cms/delegates/comment_reaction.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defmodule GroupherServer.CMS.Delegate.CommentReaction do
3737
with{:ok,action}<-match_action(thread,feeling)do
3838
clause=Map.merge(%{user_id:user_id},merge_thread_comment_id(thread,comment_id))
3939
# clause = %{post_comment_id: comment_id, user_id: user_id}
40-
ORM.findby_delete(action.reactor,clause)
40+
ORM.findby_delete!(action.reactor,clause)
4141
ORM.find(action.target,comment_id)
4242
end
4343
end

‎lib/groupher_server/cms/delegates/community_operation.ex‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do
3535
"""
3636
defunset_category(%Community{id:community_id},%Category{id:category_id})do
3737
with{:ok,community_category}<-
38-
CommunityCategory|>ORM.findby_delete(~m(community_id category_id)a)do
38+
CommunityCategory|>ORM.findby_delete!(~m(community_id category_id)a)do
3939
Community|>ORM.find(community_category.community_id)
4040
end
4141
end
@@ -54,7 +54,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do
5454
"""
5555
defunset_thread(%Community{id:community_id},%Thread{id:thread_id})do
5656
with{:ok,community_thread}<-
57-
CommunityThread|>ORM.findby_delete(~m(community_id thread_id)a)do
57+
CommunityThread|>ORM.findby_delete!(~m(community_id thread_id)a)do
5858
Community|>ORM.find(community_thread.community_id)
5959
end
6060
end
@@ -80,7 +80,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do
8080
unset a community editor
8181
"""
8282
defunset_editor(%Community{id:community_id},%User{id:user_id})do
83-
with{:ok,_}<-ORM.findby_delete(CommunityEditor,~m(user_id community_id)a),
83+
with{:ok,_}<-ORM.findby_delete!(CommunityEditor,~m(user_id community_id)a),
8484
{:ok,_}<-PassportCURD.delete_passport(%User{id:user_id})do
8585
User|>ORM.find(user_id)
8686
end
@@ -132,7 +132,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do
132132
with{:ok,community}<-ORM.find(Community,community_id),
133133
true<-community.raw!=="home",
134134
{:ok,record}<-
135-
ORM.findby_delete(CommunitySubscriber,community_id:community.id,user_id:user_id)do
135+
ORM.findby_delete!(CommunitySubscriber,community_id:community.id,user_id:user_id)do
136136
Community|>ORM.find(record.community_id)
137137
else
138138
false->
@@ -151,7 +151,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do
151151
with{:ok,community}<-ORM.find(Community,community_id),
152152
true<-community.raw!=="home",
153153
{:ok,record}<-
154-
CommunitySubscriber|>ORM.findby_delete(community_id:community.id,user_id:user_id)do
154+
CommunitySubscriber|>ORM.findby_delete!(community_id:community.id,user_id:user_id)do
155155
update_community_geo(community_id,user_id,remote_ip,:dec)
156156
Community|>ORM.find(record.community_id)
157157
else
@@ -171,7 +171,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do
171171
with{:ok,community}<-ORM.find(Community,community_id),
172172
true<-community.raw!=="home",
173173
{:ok,record}<-
174-
CommunitySubscriber|>ORM.findby_delete(community_id:community.id,user_id:user_id)do
174+
CommunitySubscriber|>ORM.findby_delete!(community_id:community.id,user_id:user_id)do
175175
update_community_geo_map(community.id,city,:dec)
176176
Community|>ORM.find(record.community_id)
177177
else

‎lib/groupher_server/cms/delegates/passport_curd.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ defmodule GroupherServer.CMS.Delegate.PassportCURD do
6565
end
6666

6767
defdelete_passport(%Accounts.User{id:user_id})do
68-
ORM.findby_delete(UserPasport,~m(user_id)a)
68+
ORM.findby_delete!(UserPasport,~m(user_id)a)
6969
end
7070

7171
defpreject_invalid_rules(rules)whenis_map(rules)do

‎lib/groupher_server_web/resolvers/cms_resolver.ex‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule GroupherServerWeb.Resolvers.CMS do
4141

4242
defupdate_community(_root,args,_info),do:Community|>ORM.find_update(args)
4343

44-
defdelete_community(_root,%{id:id},_info),do:Community|>ORM.find_delete(id)
44+
defdelete_community(_root,%{id:id},_info),do:Community|>ORM.find_delete!(id)
4545

4646
# #######################
4747
# community thread (post, job), login user should be logged
@@ -178,7 +178,7 @@ defmodule GroupherServerWeb.Resolvers.CMS do
178178
CMS.create_category(%{title:title,raw:raw},user)
179179
end
180180

181-
defdelete_category(_root,%{id:id},_info),do:Category|>ORM.find_delete(id)
181+
defdelete_category(_root,%{id:id},_info),do:Category|>ORM.find_delete!(id)
182182

183183
defupdate_category(_root,~m(id title)a,%{context:%{cur_user:_}})do
184184
CMS.update_category(~m(%Category id title)a)
@@ -243,7 +243,7 @@ defmodule GroupherServerWeb.Resolvers.CMS do
243243
CMS.create_tag(%Community{id:community_id},thread,args,user)
244244
end
245245

246-
defdelete_tag(_root,%{id:id},_info),do:Tag|>ORM.find_delete(id)
246+
defdelete_tag(_root,%{id:id},_info),do:Tag|>ORM.find_delete!(id)
247247

248248
defupdate_tag(_root,args,_info),do:CMS.update_tag(args)
249249

‎lib/helper/orm.ex‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,25 @@ defmodule Helper.ORM do
121121
"""
122122
defdelete(content),do:Repo.delete(content)
123123

124-
deffind_delete(queryable,id)do
124+
deffind_delete!(queryable,id)do
125125
with{:ok,content}<-find(queryable,id)do
126126
delete(content)
127127
end
128128
end
129129

130-
deffindby_delete(queryable,clauses)do
130+
deffindby_delete!(queryable,clauses)do
131131
with{:ok,content}<-find_by(queryable,clauses)do
132132
delete(content)
133133
end
134134
end
135135

136+
deffindby_delete(queryable,clauses)do
137+
casefind_by(queryable,clauses)do
138+
{:ok,content}->delete(content)
139+
_->{:ok,:pass}
140+
end
141+
end
142+
136143
deffindby_or_insert(queryable,clauses,attrs)do
137144
casequeryable|>find_by(clauses)do
138145
{:ok,content}->

‎test/groupher_server/cms/post_comment_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ defmodule GroupherServer.Test.PostComment do
124124
{:ok,reply}=
125125
CMS.reply_comment(:post,comment.id,%{community:community.raw,body:reply_body},user)
126126

127-
PostComment|>ORM.find_delete(comment.id)
127+
PostComment|>ORM.find_delete!(comment.id)
128128

129129
{:error,_}=ORM.find(PostComment,comment.id)
130130
{:error,_}=ORM.find(PostComment,reply.id)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp