File tree Expand file tree Collapse file tree 1 file changed +28
-9
lines changed Expand file tree Collapse file tree 1 file changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -57,28 +57,47 @@ server.put('/items/{id:[0-9]+}') do |req, res|
57
57
if params.nil? || params[:title].nil?
58
58
res.status = 400
59
59
else
60
- title = params[:title]
61
- ListItem.find(req.params[:id]).update_title(title)
62
- res.status = 200
60
+ record = ListItem.find(req.params[:id])
61
+ if record
62
+ record.update_title(params[:title])
63
+ res.status = 200
64
+ else
65
+ res.status = 404
66
+ end
63
67
end
64
68
end
65
69
66
70
# PUT Check Action
67
71
server.put('/items/{id:[0-9]+}/check') do |req, res|
68
- ListItem.find(req.params[:id]).check
69
- res.status = 200
72
+ record = ListItem.find(req.params["id"])
73
+ if record
74
+ record.check
75
+ res.status = 200
76
+ else
77
+ res.status = 404
78
+ end
70
79
end
71
80
72
81
# PUT Check Action
73
82
server.put('/items/{id:[0-9]+}/uncheck') do |req, res|
74
- ListItem.find(req.params[:id]).uncheck
75
- res.status = 200
83
+ record = ListItem.find(req.params["id"])
84
+ if record
85
+ record.uncheck
86
+ res.status = 200
87
+ else
88
+ res.status = 404
89
+ end
76
90
end
77
91
78
92
# DELETE Delete Action
79
93
server.delete('/items/{id:[0-9]+}') do |req, res|
80
- ListItem.find(req.params["id"]).destroy
81
- res.status = 200
94
+ record = ListItem.find(req.params["id"])
95
+ if record
96
+ record.destroy
97
+ res.status = 200
98
+ else
99
+ res.status = 404
100
+ end
82
101
end
83
102
84
103
server.start
You can’t perform that action at this time.
0 commit comments