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.

Commite6fc4b5

Browse files
committed
chore: wip
1 parent726919c commite6fc4b5

File tree

6 files changed

+95
-67
lines changed

6 files changed

+95
-67
lines changed

‎lib/groupher_server/cms/delegates/Seeds/communities.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,6 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Communities do
123123
end
124124

125125
defget(:devops)do
126-
["git","feedback","docker","kubernetes","shell"]
126+
["git","docker","kubernetes","shell"]
127127
end
128128
end

‎lib/groupher_server/cms/delegates/Seeds/seeds.ex‎

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,19 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
2121
aliasCMS.Delegate.SeedsConfig
2222
aliasCMS.Delegate.Seeds
2323

24-
# threads
25-
@lang_threadsSeeds.Threads.get(:lang)
26-
2724
@pl_communitiesSeeds.Communities.get(:pl)
2825
@framework_communitiesSeeds.Communities.get(:framework)
2926
@editor_communitiesSeeds.Communities.get(:editor)
3027
@database_communitiesSeeds.Communities.get(:database)
3128
@devops_communitiesSeeds.Communities.get(:devops)
32-
@city_communitiesSeeds.Communities.get(:city)
3329
# categories
3430
@default_categoriesSeeds.Categories.get(:default)
3531

3632
@doc"""
3733
seed communities pragraming languages
3834
"""
3935
defseed_communities(:pl)do
40-
with{:ok,threads}<-seed_threads(:lang),
36+
with{:ok,threads}<-seed_threads(:pl),
4137
{:ok,bot}<-seed_bot(),
4238
{:ok,categories}<-seed_categories(bot,:default),
4339
{:ok,communities}<-seed_for_communities(bot,:pl)do
@@ -51,7 +47,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
5147
seed communities for frameworks
5248
"""
5349
defseed_communities(:framework)do
54-
with{:ok,threads}<-seed_threads(:lang),
50+
with{:ok,threads}<-seed_threads(:framework),
5551
{:ok,bot}<-seed_bot(),
5652
{:ok,_categories}<-seed_categories(bot,:default),
5753
{:ok,communities}<-seed_for_communities(bot,:framework)do
@@ -66,7 +62,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
6662
seed communities for editors
6763
"""
6864
defseed_communities(:editor)do
69-
with{:ok,threads}<-seed_threads(:lang),
65+
with{:ok,threads}<-seed_threads(:editor),
7066
{:ok,bot}<-seed_bot(),
7167
{:ok,categories}<-seed_categories(bot,:default),
7268
{:ok,communities}<-seed_for_communities(bot,:editor)do
@@ -81,7 +77,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
8177
seed communities for database
8278
"""
8379
defseed_communities(:database)do
84-
with{:ok,threads}<-seed_threads(:lang),
80+
with{:ok,threads}<-seed_threads(:database),
8581
{:ok,bot}<-seed_bot(),
8682
{:ok,_categories}<-seed_categories(bot,:default),
8783
{:ok,communities}<-seed_for_communities(bot,:database)do
@@ -96,7 +92,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
9692
seed communities for database
9793
"""
9894
defseed_communities(:devops)do
99-
with{:ok,threads}<-seed_threads(:lang),
95+
with{:ok,threads}<-seed_threads(:devops),
10096
{:ok,bot}<-seed_bot(),
10197
{:ok,categories}<-seed_categories(bot,:default),
10298
{:ok,communities}<-seed_for_communities(bot,:devops)do
@@ -111,10 +107,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
111107
seed communities for cities
112108
"""
113109
defseed_communities(:city)do
114-
Seeds.Communities.get(:city)
115-
|>Enum.each(&seed_community(&1,:city))
116-
117-
{:ok,:pass}
110+
Seeds.Communities.get(:city)|>Enum.each(&seed_community(&1,:city))|>done
118111
end
119112

120113
@doc"""
@@ -155,36 +148,17 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
155148
end
156149
end
157150

158-
@doc"""
159-
seed default threads like: post, user, wiki, cheetsheet, job ..
160-
"""
161-
defseed_threads(:default)do
162-
caseORM.find_by(Thread,%{raw:"post"})do
163-
{:ok,_}->
164-
{:ok,:pass}
165-
166-
{:error,_}->
167-
@lang_threads
168-
|>Enum.each(fnthread->
169-
{:ok,_thread}=CMS.create_thread(thread)
170-
end)
171-
end
172-
173-
thread_titles=
174-
@lang_threads
175-
|>Enum.reduce([],fnx,acc->acc++[x.title]end)
176-
177-
Thread
178-
|>where([t],t.rawin^thread_titles)
179-
|>ORM.paginator(page:1,size:30)
180-
|>done()
181-
end
182-
183151
defseed_threads(:city),do:do_seed_threads(:city)
184152
defseed_threads(:home),do:do_seed_threads(:home)
185153

186-
defpdo_seed_threads(community)do
187-
threads=Seeds.Threads.get(community)
154+
# def seed_threads(:feedback), do: do_seed_threads(:home)
155+
# def seed_threads(:adwall), do: do_seed_threads(:home)
156+
# def seed_threads(:blackhole), do: do_seed_threads(:home)
157+
158+
defseed_threads(_),do:do_seed_threads(:lang)
159+
160+
defpdo_seed_threads(type)do
161+
threads=Seeds.Threads.get(type)
188162
threads_list=threads|>Enum.map(&&1.raw)
189163

190164
with{:error,_}<-ORM.find_by(Thread,%{raw:"post"})do
@@ -263,17 +237,11 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
263237
end
264238

265239
defpseed_for_communities(bot,:devops)do
266-
with{:error,_}<-ORM.find_by(Community,%{raw:"cps-support"})do
240+
with{:error,_}<-ORM.find_by(Community,%{raw:"shell"})do
267241
{:ok,_communities}=insert_multi_communities(bot,@devops_communities,:devops)
268242
end
269243
end
270244

271-
defpseed_for_communities(bot,:city)do
272-
with{:error,_}<-ORM.find_by(Community,%{raw:"chengdu"})do
273-
{:ok,_communities}=insert_multi_communities(bot,@city_communities,:city)
274-
end
275-
end
276-
277245
defpinsert_multi_communities(bot,communities,type)do
278246
type=Atom.to_string(type)
279247

@@ -319,14 +287,22 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
319287
end
320288

321289
defptagfy_threads(communities,_threads,bot,:city)whenis_list(communities)do
290+
Enum.each(communities,fncommunity->
291+
# IO.inspect(community.title, label: "create tags for")
292+
# IO.inspect(community.id, label: "id")
293+
create_tags(community,:post,bot,:city)
294+
end)
295+
end
296+
297+
defptagfy_threads(communities,_threads,bot,:pl)whenis_list(communities)do
298+
# TODO: tags for all threads
322299
Enum.each(communities,fncommunity->
323300
create_tags(community,:post,bot,:city)
324301
end)
325302
end
326303

327304
defptagfy_threads(community,threads,bot,:home)do
328-
threads
329-
|>Enum.each(&create_tags(community,&1,bot,:home))
305+
threads|>Enum.each(&create_tags(community,&1,bot,:home))
330306
end
331307

332308
defptagfy_threads(communities,threads,bot)whenis_list(communities)do
@@ -345,9 +321,15 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
345321
end)
346322
end
347323

348-
defpcreate_tags(%Community{}=community,:post,bot,:city)do
349-
Enum.each(Seeds.Tags.get(community,:post,:city),fnattr->
350-
CMS.create_article_tag(community,:post,attr,bot)
324+
defpcreate_tags(%Community{}=community,thread,bot,:pl)do
325+
Enum.each(Seeds.Tags.get(community,thread,:pl),fnattr->
326+
CMS.create_article_tag(community,thread,attr,bot)
327+
end)
328+
end
329+
330+
defpcreate_tags(%Community{}=community,thread,bot,:city)do
331+
Enum.each(Seeds.Tags.get(community,thread,:city),fnattr->
332+
CMS.create_article_tag(community,thread,attr,bot)
351333
end)
352334
end
353335

‎lib/groupher_server/cms/delegates/Seeds/seeds_config.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule GroupherServer.CMS.Delegate.SeedsConfig do
44
"""
55
defsvg_iconsdo
66
[
7-
"cps-support",
7+
"feedback",
88
"beijing",
99
"shanghai",
1010
"shenzhen",

‎lib/groupher_server/cms/delegates/Seeds/threads.ex‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,32 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Threads do
5555
%{
5656
title:"101",
5757
raw:"tut",
58-
index:20
58+
index:4
5959
},
6060
%{
6161
title:"awesome",
6262
raw:"awesome",
63-
index:20
63+
index:5
6464
},
6565
%{
6666
title:"作品",
6767
raw:"works",
68-
index:25
68+
index:6
6969
},
7070
%{
7171
title:"工作",
7272
raw:"job",
73-
index:30
73+
index:7
7474
},
7575
%{
76-
title:"users",
76+
title:"分布",
7777
raw:"users",
78-
index:30
78+
index:8
79+
},
80+
%{
81+
title:"设置",
82+
raw:"setting",
83+
index:8
7984
}
8085
]
8186
end

‎lib/helper/utils/utils.ex‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ defmodule Helper.Utils do
6767
defdone(false),do:{:error,false}
6868
defdone(true),do:{:ok,true}
6969
defdone(nil),do:{:error,"record not found."}
70+
defdone(:ok),do:{:ok,:pass}
7071
defdone(nil,:boolean),do:{:ok,false}
7172
defdone(_,:boolean),do:{:ok,true}
7273
defdone(nil,err_msg),do:{:error,err_msg}

‎test/groupher_server/seeds/community_seed_test.exs‎

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
defmoduleGroupherServer.Test.Seeds.CommunitySeeddo
2+
@moduledocfalse
3+
24
useGroupherServer.TestTools
35

46
# alias GroupherServer.Accounts.Model.User
57
aliasGroupherServer.CMS
68

7-
aliasCMS.Model.{Community}
8-
aliasCMS.Delegate.SeedsConfig
9+
aliasCMS.Model.{Community,ArticleTag}
10+
#alias CMS.Delegate.SeedsConfig
911

1012
aliasHelper.ORM
1113

@@ -16,7 +18,7 @@ defmodule GroupherServer.Test.Seeds.CommunitySeed do
1618
# end
1719

1820
describe"[cms communities seeds]"do
19-
@tag:wip
21+
@tag:wip2
2022
test"seed home community should works"do
2123
{:ok,community}=CMS.seed_community(:home)
2224
{:ok,found}=ORM.find(Community,community.id,preload:[threads::thread])
@@ -30,19 +32,57 @@ defmodule GroupherServer.Test.Seeds.CommunitySeed do
3032
# IO.inspect(found, label: "found --> ")
3133
end
3234

33-
#@tag :wip
35+
@tag:wip2
3436
test"can seed a city community"do
3537
{:ok,community}=CMS.seed_community("chengdu",:city)
3638
{:ok,found}=ORM.find(Community,community.id,preload:[threads::thread])
3739

40+
filter=%{community_id:community.id,thread:"POST"}
41+
{:ok,tags}=CMS.paged_article_tags(filter)
42+
tags_titles=tags|>Enum.map(&&1.title)
43+
44+
asserttags_titles==["打听","讨论","下班后","推荐","二手","小聚","吐槽","求/转/合租","奇奇怪怪"]
45+
3846
assertcommunity.title=="成都"
3947
assertcommunity.raw=="chengdu"
4048

4149
threads=found.threads|>Enum.map(&&1.thread.title)
4250
assertthreads==["帖子","团队","工作"]
4351
end
4452

45-
# @tag :wip
53+
@tag:wip
54+
test"can seed multi city communities"do
55+
{:ok,_}=CMS.seed_communities(:city)
56+
57+
{:ok,communities}=ORM.find_all(Community,%{page:1,size:20})
58+
59+
assertcommunities.total_count==9
60+
radom_community=communities.entries|>Enum.random()
61+
{:ok,found}=ORM.find(Community,radom_community.id,preload:[threads::thread])
62+
assertlength(found.threads)==3
63+
64+
filter=%{community_id:radom_community.id,thread:"POST"}
65+
{:ok,tags}=CMS.paged_article_tags(filter)
66+
tags_titles=tags|>Enum.map(&&1.title)
67+
asserttags_titles==["打听","讨论","下班后","推荐","二手","小聚","吐槽","求/转/合租","奇奇怪怪"]
68+
69+
threads=found.threads|>Enum.map(&&1.thread.title)
70+
assertthreads==["帖子","团队","工作"]
71+
end
72+
73+
@tag:wip2
74+
test"can seed a general lang community"do
75+
{:ok,community}=CMS.seed_community("elixir",:pl)
76+
{:ok,found}=ORM.find(Community,community.id,preload:[threads::thread])
77+
78+
assertcommunity.title=="elixir"
79+
assertcommunity.raw=="elixir"
80+
81+
threads=found.threads|>Enum.map(&&1.thread.title)
82+
assertthreads==["帖子","雷达","博客","101","awesome","作品","工作","分布","设置"]
83+
end
84+
85+
# @tag :wip2
4686
test"can seed multi cities community"do
4787
{:ok,_}=CMS.seed_communities(:city)
4888
{:ok,communities}=ORM.find_all(Community,%{page:1,size:20})
@@ -54,12 +94,12 @@ defmodule GroupherServer.Test.Seeds.CommunitySeed do
5494
assertthreads==["帖子","团队","工作"]
5595
end
5696

57-
# @tag :wip
97+
# @tag :wip2
5898
test"seed pl & framework community should works"do
5999
#
60100
end
61101

62-
# @tag :wip
102+
# @tag :wip2
63103
test"seed city community should works"do
64104
#
65105
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp