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.

Commit8cead59

Browse files
committed
make community query support title && cleanup
1 parent74a7cda commit8cead59

File tree

6 files changed

+41
-33
lines changed

6 files changed

+41
-33
lines changed

‎lib/mastani_server/cms/post.ex‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ defmodule MastaniServer.CMS.Post do
1313
field(:views,:integer,default:0)
1414
belongs_to(:author,Author)
1515

16+
# TODO
17+
# 相关文章
18+
# has_may(:related_post, ...)
19+
1620
has_many(:comments,{"posts_comments",PostComment})
1721
has_many(:favorites,{"posts_favorites",PostFavorite})
1822
has_many(:stars,{"posts_stars",PostStar})
@@ -36,21 +40,6 @@ defmodule MastaniServer.CMS.Post do
3640
timestamps(type::utc_datetime)
3741
end
3842

39-
# create table(:cms_posts_comments) do
40-
# add(:comment_id, references(:cms_comments))
41-
# add(:post_id, references(:cms_posts))
42-
# end
43-
# end
44-
45-
# create(index(:cms_posts_comments, [:post_id]))
46-
47-
# create(unique_index(:cms_posts_comments, [:user_id]))
48-
49-
# alter table(:cms_posts) do
50-
# add(:author_id, references(:cms_authors, on_delete: :delete_all), null: false)
51-
# end
52-
# create(index(:cms_posts, [:author_id]))
53-
5443
@required_fields~w(title body digest length)a
5544
@optional_fields~w(link_addr)a
5645

‎lib/mastani_server_web/resolvers/accounts_resolver.ex‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ defmodule MastaniServerWeb.Resolvers.Accounts do
1010
do:Accounts.User|>ORM.find(cur_user.id)
1111

1212
defupdate_profile(_root,%{profile:profile},%{context:%{cur_user:cur_user}})do
13-
IO.inspect(profile,label:"update_profile")
1413
Accounts.update_profile(%Accounts.User{id:cur_user.id},profile)
1514
end
1615

‎lib/mastani_server_web/resolvers/cms_resolver.ex‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ defmodule MastaniServerWeb.Resolvers.CMS do
1010
defposts(_root,~m(filter)a,_info),do:CMS.Post|>ORM.find_all(filter)
1111

1212
defcommunity(_root,%{id:id},_info),do:CMS.Community|>ORM.find(id)
13+
defcommunity(_root,%{title:title},_info),do:CMS.Community|>ORM.find_by(title:title)
14+
defcommunity(_root,_args,_info),do:{:error,"please provide community id or title"}
1315

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ defmodule MastaniServerWeb.Schema.CMS.Queries do
77

88
object:cms_queriesdo
99
field:community,:communitydo
10-
arg(:id,non_null(:id))
10+
# arg(:id, non_null(:id))
11+
arg(:id,:id)
12+
arg(:title,:string)
1113
resolve(&Resolvers.CMS.community/3)
1214
end
1315

‎test/mastani_server/accounts/accounts_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule MastaniServer.Test.AccountsTest do
1414
describe"[update user]"do
1515
test"update user with valid attrs"do
1616
{:ok,user}=db_insert(:user)
17-
# IO.inspect user, label: "update user"
17+
1818
attrs=%{
1919
nickname:"new nickname",
2020
sex:"dude",

‎test/mastani_server_web/query/cms_test.exs‎

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,38 @@ defmodule MastaniServer.Test.Query.CMSTest do
1616
{:ok,~m(guest_conn community)a}
1717
end
1818

19-
@query"""
20-
query community($id: ID!) {
21-
community(id: $id) {
22-
id
23-
title
24-
desc
19+
describe"[cms query community]"do
20+
@query"""
21+
query community($id: ID, $title: String) {
22+
community(id: $id, title: $title) {
23+
id
24+
title
25+
desc
26+
}
2527
}
26-
}
27-
"""
28-
test"guest user can get badic info a community",~m(guest_conn community)ado
29-
variables=%{id:community.id}
30-
results=guest_conn|>query_result(@query,variables,"community")
31-
32-
assertresults["id"]==to_string(community.id)
33-
assertresults["title"]==community.title
34-
assertresults["desc"]==community.desc
28+
"""
29+
test"guest user can get badic info of a community by id",~m(guest_conn community)ado
30+
variables=%{id:community.id}
31+
results=guest_conn|>query_result(@query,variables,"community")
32+
33+
assertresults["id"]==to_string(community.id)
34+
assertresults["title"]==community.title
35+
assertresults["desc"]==community.desc
36+
end
37+
38+
test"guest user can get badic info of a community by title",~m(guest_conn community)ado
39+
variables=%{title:community.title}
40+
results=guest_conn|>query_result(@query,variables,"community")
41+
42+
assertresults["id"]==to_string(community.id)
43+
assertresults["title"]==community.title
44+
assertresults["desc"]==community.desc
45+
end
46+
47+
test"guest user can get community info without args fails",~m(guest_conn)ado
48+
variables=%{}
49+
assertguest_conn|>query_get_error?(@query,variables)
50+
end
3551
end
3652

3753
describe"[cms community editors]"do

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp