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.

Commite1bb1b8

Browse files
authored
refactor(cms): remove post topic concept (#326)
* refactor(drop-topic): remove from table* refactor(drop-topic): wip* refactor(drop-topic): wip* chore: wip* chore: wip
1 parent1de1a89 commite1bb1b8

File tree

35 files changed

+118
-671
lines changed

35 files changed

+118
-671
lines changed

‎lib/groupher_server/cms/cms.ex‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ defmodule GroupherServer.CMS do
4444
defdelegatecreate_tag(community,thread,attrs,user),to:CommunityCURD
4545
defdelegateupdate_tag(attrs),to:CommunityCURD
4646
defdelegateget_tags(community,thread),to:CommunityCURD
47-
defdelegateget_tags(community,thread,topic),to:CommunityCURD
4847
defdelegateget_tags(filter),to:CommunityCURD
4948
# >> wiki & cheatsheet (sync with github)
5049
defdelegateget_wiki(community),to:CommunitySync
@@ -87,22 +86,15 @@ defmodule GroupherServer.CMS do
8786
# ArticleOperation
8887
# >> set flag on article, like: pin / unpin article
8988
defdelegateset_community_flags(community_info,queryable,attrs),to:ArticleOperation
90-
defdelegatepin_content(queryable,community_id,topic),to:ArticleOperation
91-
defdelegateundo_pin_content(queryable,community_id,topic),to:ArticleOperation
9289
defdelegatepin_content(queryable,community_id),to:ArticleOperation
9390
defdelegateundo_pin_content(queryable,community_id),to:ArticleOperation
9491

9592
defdelegatelock_article_comment(content),to:ArticleOperation
96-
# defdelegate pin_content(queryable, community_id, thread), to: ArticleOperation
97-
# defdelegate undo_pin_content(queryable, community_id, thread, topic), to: ArticleOperation
98-
# defdelegate undo_pin_content(queryable, community_id, thread), to: ArticleOperation
9993

10094
# >> tag: set / unset
10195
defdelegateset_tag(thread,tag,content_id),to:ArticleOperation
10296
defdelegateunset_tag(thread,tag,content_id),to:ArticleOperation
103-
defdelegateset_refined_tag(community,thread,topic,content_id),to:ArticleOperation
10497
defdelegateset_refined_tag(community,thread,content_id),to:ArticleOperation
105-
defdelegateunset_refined_tag(community,thread,topic,content_id),to:ArticleOperation
10698
defdelegateunset_refined_tag(community,thread,content_id),to:ArticleOperation
10799
# >> community: set / unset
108100
defdelegateset_community(community,thread,content_id),to:ArticleOperation

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
1111
aliasGroupherServer.{Accounts,CMS,Delivery,Email,Repo,Statistics}
1212

1313
aliasAccounts.User
14-
aliasCMS.{Author,Community,Embeds,Delegate,Tag,Topic}
14+
aliasCMS.{Author,Community,Embeds,Delegate,Tag}
1515

1616
aliasDelegate.ArticleOperation
1717
aliasHelper.{Later,ORM,QueryBuilder}
@@ -76,9 +76,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
7676
|>Multi.run(:set_community,fn_,%{create_content:content}->
7777
ArticleOperation.set_community(community,thread,content.id)
7878
end)
79-
|>Multi.run(:set_topic,fn_,%{create_content:content}->
80-
exec_set_topic(thread,content.id,attrs)
81-
end)
8279
|>Multi.run(:set_community_flag,fn_,%{create_content:content}->
8380
exec_set_community_flag(community,content,action)
8481
end)
@@ -294,13 +291,9 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
294291
{:ok,pined_content}=
295292
CMS.PinedPost
296293
|>join(:inner,[p],cinassoc(p,:community))
297-
|>join(:inner,[p],tinassoc(p,:topic))
298294
|>join(:inner,[p],contentinassoc(p,:post))
299-
|>where(
300-
[p,c,t,content],
301-
c.raw==^communityandt.raw==^Map.get(filter,:topic,"posts")
302-
)
303-
|>select([p,c,t,content],content)
295+
|>where([p,c,content],c.raw==^community)
296+
|>select([p,c,content],content)
304297
# 10 pined contents per community/thread, at most
305298
|>ORM.paginater(%{page:1,size:10})
306299
|>done()
@@ -348,7 +341,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
348341
defpshould_add_pin?(%{page:1,tag::all,sort::desc_inserted,read::all}=filter)do
349342
filter
350343
|>Map.keys()
351-
|>Enum.reject(fnx->xin[:community,:tag,:sort,:read,:topic,:page,:size]end)
344+
|>Enum.reject(fnx->xin[:community,:tag,:sort,:read,:page,:size]end)
352345
|>casedo
353346
[]->{:ok,:pass}
354347
_->{:error,:pass}
@@ -403,10 +396,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
403396
{:error,[message:"set community flag",code:ecode(:create_fails)]}
404397
end
405398

406-
defpcreate_content_result({:error,:set_topic,_result,_steps})do
407-
{:error,[message:"set topic",code:ecode(:create_fails)]}
408-
end
409-
410399
defpcreate_content_result({:error,:set_tag,result,_steps})do
411400
{:error,result}
412401
end
@@ -434,15 +423,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
434423
|>Repo.insert()
435424
end
436425

437-
defpexec_set_topic(thread,id,%{topic:topic})do
438-
ArticleOperation.set_topic(%Topic{title:topic},thread,id)
439-
end
440-
441-
# if topic is not provide, use posts as default
442-
defpexec_set_topic(thread,id,_attrs)do
443-
ArticleOperation.set_topic(%Topic{title:"posts"},thread,id)
444-
end
445-
446426
defpexec_set_tag(thread,id,%{tags:tags})do
447427
trydo
448428
Enum.each(tags,fntag->

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

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
1818
JobCommunityFlag,
1919
RepoCommunityFlag,
2020
Tag,
21-
Topic,
2221
PinedPost,
2322
PinedJob,
2423
PinedRepo
@@ -27,13 +26,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
2726
aliasGroupherServer.CMS.Repo,as:CMSRepo
2827
aliasGroupherServer.Repo
2928

30-
defpin_content(%Post{id:post_id},%Community{id:community_id},topic)do
31-
with{:ok,%{id:topic_id}}<-ORM.find_by(Topic,%{raw:topic}),
32-
{:ok,pined}<-
29+
defpin_content(%Post{id:post_id},%Community{id:community_id})do
30+
with{:ok,pined}<-
3331
ORM.findby_or_insert(
3432
PinedPost,
35-
~m(post_id community_id topic_id)a,
36-
~m(post_id community_id topic_id)a
33+
~m(post_id community_id)a,
34+
~m(post_id community_id)a
3735
)do
3836
Post|>ORM.find(pined.post_id)
3937
end
@@ -55,9 +53,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
5553
end
5654
end
5755

58-
defundo_pin_content(%Post{id:post_id},%Community{id:community_id},topic)do
59-
with{:ok,%{id:topic_id}}<-ORM.find_by(Topic,%{raw:topic}),
60-
{:ok,pined}<-ORM.find_by(PinedPost,~m(post_id community_id topic_id)a),
56+
defundo_pin_content(%Post{id:post_id},%Community{id:community_id})do
57+
with{:ok,pined}<-ORM.find_by(PinedPost,~m(post_id community_id)a),
6158
{:ok,deleted}<-ORM.delete(pined)do
6259
Post|>ORM.find(deleted.post_id)
6360
end
@@ -177,55 +174,33 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
177174
@doc"""
178175
set refined_tag to common content
179176
"""
180-
defset_refined_tag(%Community{id:community_id},thread,topic_raw,content_id)do
177+
defset_refined_tag(%Community{id:community_id},thread,content_id)do
181178
with{:ok,action}<-match_action(thread,:tag),
182179
{:ok,content}<-ORM.find(action.target,content_id,preload::tags),
183-
{:ok,topic}<-ORM.find_by(Topic,%{raw:topic_raw}),
184180
{:ok,tag}<-
185181
ORM.find_by(action.reactor,%{
186182
title:"refined",
187-
community_id:community_id,
188-
topic_id:topic.id
183+
community_id:community_id
189184
})do
190185
update_content_tag(content,tag)
191186
end
192187
end
193188

194-
defset_refined_tag(%Community{id:community_id},thread,content_id)do
195-
with{:ok,action}<-match_action(thread,:tag),
196-
{:ok,content}<-ORM.find(action.target,content_id,preload::tags),
197-
{:ok,tag}<-
198-
ORM.find_by(action.reactor,%{title:"refined",community_id:community_id})do
199-
update_content_tag(content,tag)
200-
end
201-
end
202-
203189
@doc"""
204190
unset refined_tag to common content
205191
"""
206-
defunset_refined_tag(%Community{id:community_id},thread,topic_raw,content_id)do
192+
defunset_refined_tag(%Community{id:community_id},thread,content_id)do
207193
with{:ok,action}<-match_action(thread,:tag),
208194
{:ok,content}<-ORM.find(action.target,content_id,preload::tags),
209-
{:ok,topic}<-ORM.find_by(Topic,%{raw:topic_raw}),
210195
{:ok,tag}<-
211196
ORM.find_by(action.reactor,%{
212197
title:"refined",
213-
community_id:community_id,
214-
topic_id:topic.id
198+
community_id:community_id
215199
})do
216200
update_content_tag(content,tag,:drop)
217201
end
218202
end
219203

220-
defunset_refined_tag(%Community{id:community_id},thread,content_id)do
221-
with{:ok,action}<-match_action(thread,:tag),
222-
{:ok,content}<-ORM.find(action.target,content_id,preload::tags),
223-
{:ok,tag}<-
224-
ORM.find_by(action.reactor,%{title:"refined",community_id:community_id})do
225-
update_content_tag(content,tag,:drop)
226-
end
227-
end
228-
229204
defpupdate_content_tag(content,%Tag{}=tag,opt\\:add)do
230205
new_tags=ifopt==:add,do:content.tags++[tag],else:content.tags--[tag]
231206

@@ -235,26 +210,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleOperation do
235210
|>Repo.update()
236211
end
237212

238-
@doc"""
239-
set topic only for post
240-
"""
241-
defset_topic(%Topic{title:title},:post,content_id)do
242-
with{:ok,content}<-ORM.find(Post,content_id,preload::topics),
243-
{:ok,topic}<-
244-
ORM.findby_or_insert(Topic,%{title:title},%{
245-
title:title,
246-
thread:"post",
247-
raw:title
248-
})do
249-
content
250-
|>Ecto.Changeset.change()
251-
|>Ecto.Changeset.put_assoc(:topics,content.topics++[topic])
252-
|>Repo.update()
253-
end
254-
end
255-
256-
defset_topic(_topic,_thread,_content_id),do:{:ok,:pass}
257-
258213
@doc"update isEdited meta label if needed"
259214
# TODO: diff history
260215
defupdate_edit_status(%{meta:%Embeds.ArticleMeta{is_edited:false}=meta}=content)do

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

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ defmodule GroupherServer.CMS.Delegate.CommunityCURD do
1818
CommunityEditor,
1919
CommunitySubscriber,
2020
Tag,
21-
Topic,
2221
Thread
2322
}
2423

@@ -59,15 +58,13 @@ defmodule GroupherServer.CMS.Delegate.CommunityCURD do
5958
@doc"""
6059
create a Tag base on type: post / tuts ...
6160
"""
62-
# TODO: change to create_tag(community, thread, attrs, ....)
6361
defcreate_tag(%Community{id:community_id},thread,attrs,%Accounts.User{id:user_id})do
6462
with{:ok,action}<-match_action(thread,:tag),
6563
{:ok,author}<-ensure_author_exists(%Accounts.User{id:user_id}),
66-
{:ok,_community}<-ORM.find(Community,community_id),
67-
{:ok,topic}=find_or_insert_topic(attrs)do
64+
{:ok,_community}<-ORM.find(Community,community_id)do
6865
attrs=
6966
attrs
70-
|>Map.merge(%{author_id:author.id,topic_id:topic.id,community_id:community_id})
67+
|>Map.merge(%{author_id:author.id,community_id:community_id})
7168
|>map_atom_value(:string)
7269
|>Map.merge(%{thread:thread|>to_string|>String.downcase()})
7370

@@ -78,10 +75,8 @@ defmodule GroupherServer.CMS.Delegate.CommunityCURD do
7875
defupdate_tag(%{id:_id}=attrs)do
7976
~m(id title color)a=attrs|>map_atom_value(:string)
8077

81-
with{:ok,%{id:topic_id}}=find_or_insert_topic(attrs)do
82-
Tag
83-
|>ORM.find_update(~m(id title color topic_id)a)
84-
end
78+
Tag
79+
|>ORM.find_update(~m(id title color)a)
8580
end
8681

8782
@doc"""
@@ -116,31 +111,12 @@ defmodule GroupherServer.CMS.Delegate.CommunityCURD do
116111
@doc"""
117112
get tags belongs to a community / thread
118113
"""
119-
defget_tags(%Community{id:community_id},thread,topic)whennotis_nil(community_id)do
120-
# thread = thread |> to_string |> String.upcase()
121-
# topic = topic |> to_string |> String.upcase()
114+
defget_tags(%Community{raw:community_raw},thread)whennotis_nil(community_raw)do
122115
thread=thread|>to_string|>String.downcase()
123-
topic=topic|>to_string|>String.downcase()
124116

125117
Tag
126118
|>join(:inner,[t],cinassoc(t,:community))
127-
|>join(:inner,[t],cpinassoc(t,:topic))
128-
|>where([t,c,cp],c.id==^community_idandt.thread==^threadandcp.title==^topic)
129-
|>distinct([t],t.title)
130-
|>Repo.all()
131-
|>done()
132-
end
133-
134-
defget_tags(%Community{raw:community_raw},thread,topic)whennotis_nil(community_raw)do
135-
# thread = thread |> to_string |> String.upcase()
136-
# topic = topic |> to_string |> String.upcase()
137-
thread=thread|>to_string|>String.downcase()
138-
topic=topic|>to_string|>String.downcase()
139-
140-
Tag
141-
|>join(:inner,[t],cinassoc(t,:community))
142-
|>join(:inner,[t],cpinassoc(t,:topic))
143-
|>where([t,c,cp],c.raw==^community_rawandt.thread==^threadandcp.title==^topic)
119+
|>where([t,c],c.raw==^community_rawandt.thread==^thread)
144120
|>distinct([t],t.title)
145121
|>Repo.all()
146122
|>done()
@@ -248,25 +224,6 @@ defmodule GroupherServer.CMS.Delegate.CommunityCURD do
248224
end
249225
end
250226

251-
defpfind_or_insert_topic(%{topic:title}=attrs)whenis_binary(title)do
252-
title=title|>to_string()|>String.downcase()
253-
thread=attrs.thread|>to_string()|>String.downcase()
254-
255-
ORM.findby_or_insert(Topic,%{title:title},%{
256-
title:title,
257-
thread:thread,
258-
raw:title
259-
})
260-
end
261-
262-
defpfind_or_insert_topic(%{thread:thread})do
263-
find_or_insert_topic(%{topic:"posts",thread:thread})
264-
end
265-
266-
defpfind_or_insert_topic(_attrs)do
267-
find_or_insert_topic(%{topic:"posts",thread::post})
268-
end
269-
270227
defpload_community_members(%Community{id:id},queryable,%{page:page,size:size}=filters)
271228
whennotis_nil(id)do
272229
queryable

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp