Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Functional Programming
Diskuy-Backend
Commits
720becab
Commit
720becab
authored
Feb 19, 2021
by
Muhammad Rafif Elfazri
Browse files
Create restriction 'admin' to create topic
parent
90cfd5fb
Changes
1
Show whitespace changes
Inline
Side-by-side
lib/diskuy_web/controllers/topic_controller.ex
View file @
720becab
...
...
@@ -4,6 +4,7 @@ defmodule DiskuyWeb.TopicController do
alias
Diskuy
.
Forum
alias
Diskuy
.
Forum
.
Topic
alias
Diskuy
.
Utility
.
Utility
alias
DiskuyWeb
.
Auth
.
Guardian
action_fallback
DiskuyWeb
.
FallbackController
...
...
@@ -13,7 +14,9 @@ defmodule DiskuyWeb.TopicController do
end
def
create
(
conn
,
%{
"topic"
=>
topic_params
})
do
with
{
:ok
,
%
Topic
{}
=
topic
}
<-
Forum
.
create_topic
(
topic_params
)
do
current_user
=
Guardian
.
Plug
.
current_resource
(
conn
)
with
{
:ok
,
:authorized
}
<-
Guardian
.
check_admin
(
current_user
),
{
:ok
,
%
Topic
{}
=
topic
}
<-
Forum
.
create_topic
(
topic_params
)
do
conn
|>
put_status
(
:created
)
|>
put_resp_header
(
"location"
,
Routes
.
topic_path
(
conn
,
:show
,
topic
))
...
...
@@ -28,8 +31,9 @@ defmodule DiskuyWeb.TopicController do
def
update
(
conn
,
%{
"id"
=>
id
,
"topic"
=>
topic_params
})
do
topic
=
Forum
.
get_topic_by_name!
(
id
)
with
{
:ok
,
%
Topic
{}
=
topic
}
<-
Forum
.
update_topic
(
topic
,
topic_params
)
do
current_user
=
Guardian
.
Plug
.
current_resource
(
conn
)
with
{
:ok
,
:authorized
}
<-
Guardian
.
check_admin
(
current_user
),
{
:ok
,
%
Topic
{}
=
topic
}
<-
Forum
.
update_topic
(
topic
,
topic_params
)
do
render
(
conn
,
"show.json"
,
topic:
topic
)
end
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment