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.

Commit746e073

Browse files
committed
add raw logo etc .. to Community / thread
1 parent772af10 commit746e073

File tree

10 files changed

+64
-32
lines changed

10 files changed

+64
-32
lines changed

‎lib/mastani_server/cms/community.ex‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ defmodule MastaniServer.CMS.Community do
44
aliasMastaniServer.CMS.{Post,Community,CommunityThread,CommunitySubscriber,CommunityEditor}
55
aliasMastaniServer.Accounts
66

7-
@required_fields~w(title desc user_id)a
8-
@optional_fields~w(category)a
7+
@required_fields~w(title desc user_id logo raw category)a
8+
# @required_fields ~w(title desc user_id)a
9+
@optional_fields~w(label)a
910

1011
schema"communities"do
1112
field(:title,:string)
1213
field(:desc,:string)
14+
field(:logo,:string)
1315
field(:category,:string)
16+
field(:label,:string)
17+
field(:raw,:string)
1418

1519
belongs_to(:author,Accounts.User,foreign_key::user_id)
1620

‎lib/mastani_server/cms/thread.ex‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ defmodule MastaniServer.CMS.Thread do
55

66
schema"community_threads"do
77
field(:title,:string)
8+
field(:raw,:string)
9+
field(:logo,:string)
810

911
timestamps(type::utc_datetime)
1012
end
1113

12-
@required_fields~w(title)a
13-
@optional_fields~w(title)a
14+
# TODO: @required_fields ~w(title raw)a
15+
@required_fields~w(title raw)a
16+
@optional_fields~w(logo)a
1417

1518
@docfalse
1619
defchangeset(%Thread{}=thread,attrs)do

‎lib/mastani_server_web/resolvers/cms_resolver.ex‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ defmodule MastaniServerWeb.Resolvers.CMS do
1414

1515
defcommunities(_root,~m(filter)a,_info),do:CMS.Community|>ORM.find_all(filter)
1616

17-
defcommunity_posts_count(root,_args,_info)do
18-
"communities_posts"
19-
|>where([cp],cp.community_id==^root.id)
20-
|>select([cp],count(cp.post_id))
21-
|>Repo.one()
22-
|>done
23-
end
24-
2517
defcreate_community(_root,args,%{context:%{cur_user:user}})do
26-
CMS.create_community(%{title:args.title,desc:args.desc,user_id:user.id})
18+
args|>Map.merge(%{user_id:user.id})|>CMS.create_community()
2719
end
2820

29-
defcreate_thread(_root,~m(title)a,_info)do
30-
CMS.create_thread(~m(title)a)
21+
defcreate_thread(_root,~m(title raw)a,_info)do
22+
CMS.create_thread(~m(title raw)a)
3123
end
3224

3325
defadd_thread_to_community(_root,~m(community_id thread_id)a,_info)do

‎lib/mastani_server_web/schema/cms/cms_mutations.ex‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ defmodule MastaniServerWeb.Schema.CMS.Mutations do
1111
field:create_community,:communitydo
1212
arg(:title,non_null(:string))
1313
arg(:desc,non_null(:string))
14-
# TODO
15-
# arg(:category, non_null(:string))
14+
arg(:raw,non_null(:string))
15+
arg(:logo,non_null(:string))
16+
arg(:category,non_null(:string))
1617

1718
middleware(M.Authorize,:login)
1819
middleware(M.Passport,claim:"cms->community.create")
@@ -35,6 +36,7 @@ defmodule MastaniServerWeb.Schema.CMS.Mutations do
3536
@desc"create independent thread"
3637
field:create_thread,:threaddo
3738
arg(:title,non_null(:string))
39+
arg(:raw,non_null(:string))
3840

3941
middleware(M.Authorize,:login)
4042
middleware(M.Passport,claim:"cms->thread.create")

‎lib/mastani_server_web/schema/cms/cms_types.ex‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ defmodule MastaniServerWeb.Schema.CMS.Types do
2828
object:threaddo
2929
field(:id,:id)
3030
field(:title,:string)
31+
field(:raw,:string)
3132
end
3233

3334
object:postdo
@@ -130,10 +131,6 @@ defmodule MastaniServerWeb.Schema.CMS.Types do
130131
field(:author,:user,resolve:dataloader(CMS,:author))
131132
field(:threads,list_of(:thread),resolve:dataloader(CMS,:threads))
132133

133-
# field :posts_count, :integer do
134-
# resolve(&Resolvers.CMS.community_posts_count/3)
135-
# end
136-
137134
# Big thanks: https://elixirforum.com/t/grouping-error-in-absinthe-dadaloader/13671/2
138135
# see also: https://github.com/absinthe-graphql/dataloader/issues/25
139136
field:posts_count,:integerdo
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defmoduleMastaniServer.Repo.Migrations.AddInfoToCommunitydo
2+
useEcto.Migration
3+
4+
defchangedo
5+
altertable(:communities)do
6+
add(:raw,:string)
7+
add(:label,:string)
8+
add(:logo,:text)
9+
end
10+
end
11+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmoduleMastaniServer.Repo.Migrations.AddRawToThreaddo
2+
useEcto.Migration
3+
4+
defchangedo
5+
altertable(:community_threads)do
6+
add(:raw,:string)
7+
add(:logo,:text)
8+
end
9+
end
10+
end

‎test/mastani_server/cms/cms_test.exs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,22 @@ defmodule MastaniServer.Test.CMSTest do
111111
describe"[cms community thread]"do
112112
test"can create thread"do
113113
title="post"
114-
{:ok,thread}=CMS.create_thread(~m(title)a)
114+
raw=title
115+
{:ok,thread}=CMS.create_thread(~m(title raw)a)
115116
assertthread.title==title
116117
end
117118

118119
test"create thread with exsit title fails"do
119120
title="post"
120-
{:ok,_}=CMS.create_thread(~m(title)a)
121-
assert{:error,_error}=CMS.create_thread(~m(title)a)
121+
raw=title
122+
{:ok,_}=CMS.create_thread(~m(title raw)a)
123+
assert{:error,_error}=CMS.create_thread(~m(title raw)a)
122124
end
123125

124126
test"can add a thread to community",~m(community)ado
125127
title="post"
126-
{:ok,thread}=CMS.create_thread(~m(title)a)
128+
raw=title
129+
{:ok,thread}=CMS.create_thread(~m(title raw)a)
127130
thread_id=thread.id
128131
community_id=community.id
129132
{:ok,ret_community}=CMS.add_thread_to_community(~m(thread_id community_id)a)

‎test/mastani_server_web/mutaion/cms_test.exs‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ defmodule MastaniServer.Test.Mutation.CMSTest do
9191

9292
describe"[mutation cms community]"do
9393
@create_community_query"""
94-
mutation($title: String!, $desc: String!) {
95-
createCommunity(title: $title, desc: $desc) {
94+
mutation($title: String!, $desc: String!, $logo: String!, $raw: String!, $category: String!) {
95+
createCommunity(title: $title, desc: $desc, logo: $logo, raw: $raw, category: $category) {
9696
id
9797
title
9898
desc
@@ -122,13 +122,17 @@ defmodule MastaniServer.Test.Mutation.CMSTest do
122122
assertrule_conn|>mutation_get_error?(@create_community_query,variables)
123123
end
124124

125+
@tag:wip
125126
test"creator of community should be add to userContributes and communityContributes"do
126127
variables=mock_attrs(:community)
127128
rule_conn=simu_conn(:user,cms:%{"community.create"=>true})
128129

130+
IO.inspect(variables,label:"hello variables")
131+
129132
created_community=
130133
rule_conn|>mutation_result(@create_community_query,variables,"createCommunity")
131134

135+
IO.inspect(created_community,label:"hello")
132136
author=created_community["author"]
133137

134138
{:ok,found_community}=CMS.Community|>ORM.find(created_community["id"])
@@ -189,15 +193,16 @@ defmodule MastaniServer.Test.Mutation.CMSTest do
189193

190194
describe"[mutation cms thread]"do
191195
@query"""
192-
mutation($title: String!){
193-
createThread(title: $title) {
196+
mutation($title: String!, $raw: String!){
197+
createThread(title: $title, raw: $raw) {
194198
title
195199
}
196200
}
197201
"""
198202
test"auth user can create thread",~m(user)ado
199203
title="psot"
200-
variables=~m(title)a
204+
raw=title
205+
variables=~m(title raw)a
201206

202207
passport_rules=%{"thread.create"=>true}
203208
rule_conn=simu_conn(:user,user,cms:passport_rules)
@@ -209,7 +214,8 @@ defmodule MastaniServer.Test.Mutation.CMSTest do
209214

210215
test"unauth user create thread fails",~m(user_conn guest_conn)ado
211216
title="psot"
212-
variables=~m(title)a
217+
raw=title
218+
variables=~m(title raw)a
213219
rule_conn=simu_conn(:user,cms:%{"what.ever"=>true})
214220

215221
assertuser_conn|>mutation_get_error?(@query,variables)
@@ -229,7 +235,8 @@ defmodule MastaniServer.Test.Mutation.CMSTest do
229235
"""
230236
test"auth user can add thread to community",~m(user community)ado
231237
title="psot"
232-
{:ok,thread}=CMS.create_thread(~m(title)a)
238+
raw=title
239+
{:ok,thread}=CMS.create_thread(~m(title raw)a)
233240
variables=%{threadId:thread.id,communityId:community.id}
234241

235242
passport_rules=%{community.title=>%{"thread.add"=>true}}

‎test/support/factory.ex‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ defmodule MastaniServer.Factory do
4242
%{
4343
title:"community#{name}#{unique_num}",
4444
desc:"community desc",
45+
raw:"community#{name}#{unique_num}",
46+
logo:"http://fake.jpg",
47+
category:"category#{unique_num}",
4548
author:mock(:user)
4649
}
4750
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp