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
1179de49
Commit
1179de49
authored
Feb 19, 2021
by
Muhammad Rafif Elfazri
Browse files
Unallowed update API to update points
parent
2863f601
Changes
2
Show whitespace changes
Inline
Side-by-side
lib/diskuy_web/controllers/post_controller.ex
View file @
1179de49
...
...
@@ -32,8 +32,9 @@ defmodule DiskuyWeb.PostController do
def
update
(
conn
,
%{
"id"
=>
id
,
"post"
=>
post_params
})
do
current_user
=
Guardian
.
Plug
.
current_resource
(
conn
)
post
=
Forum
.
get_post!
(
id
)
new_post_params
=
post_params
|>
Map
.
drop
([
"id"
,
"points"
,
"user_id"
,
"thread_id"
])
with
{
:ok
,
:authorized
}
<-
Guardian
.
check_authorized
(
current_user
,
post
.
user_id
),
{
:ok
,
%
Post
{}
=
post
}
<-
Forum
.
update_post
(
post
,
post_params
)
do
{
:ok
,
%
Post
{}
=
post
}
<-
Forum
.
update_post
(
post
,
new_
post_params
)
do
render
(
conn
,
"show.json"
,
post:
post
)
end
end
...
...
lib/diskuy_web/controllers/thread_controller.ex
View file @
1179de49
...
...
@@ -32,8 +32,9 @@ defmodule DiskuyWeb.ThreadController do
def
update
(
conn
,
%{
"id"
=>
id
,
"thread"
=>
thread_params
})
do
current_user
=
Guardian
.
Plug
.
current_resource
(
conn
)
thread
=
Forum
.
get_thread!
(
id
)
new_thread_params
=
thread_params
|>
Map
.
drop
([
"id"
,
"points"
,
"user_id"
,
"topic_id"
])
with
{
:ok
,
:authorized
}
<-
Guardian
.
check_authorized
(
current_user
,
thread
.
user_id
),
{
:ok
,
%
Thread
{}
=
thread
}
<-
Forum
.
update_thread
(
thread
,
thread_params
)
do
{
:ok
,
%
Thread
{}
=
thread
}
<-
Forum
.
update_thread
(
thread
,
new_
thread_params
)
do
render
(
conn
,
"show.json"
,
thread:
thread
)
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