Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
class NotesController < ApplicationController
def create

if params[:service_id]
note = service.notes.build
note.note = params[:note][:note]
service.save!
elsif params[:resource_id]
note = resource.notes.build
note.note = params[:note][:note]
resource.save!
note = nil
note_json = params[:note]
if note_json[:service_id]
note = Note.create!(service_id: note_json[:service_id], note: note_json[:note])
elsif note_json[:resource_id]
note = Note.create!(resource_id: note_json[:resource_id], note: note_json[:note])
else
render plain: "Improper Note Data", status: 400
return
end

render status: :created, json: note
end

def update

note = Note.find(params[:id])
note.note = params[:note][:note]
note.save!

render status: :ok, json: note

end

def destroy
note = Note.find params[:id]
note.delete
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/phones_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# frozen_string_literal: true

class PhonesController < ApplicationController
def create
phone_json = params[:phone]

phone = Phone.create!(resource_id: phone_json[:resource_id], number: phone_json[:number],
service_type: phone_json[:service_type], description: phone_json[:description])

render status: :created, json: phone
end

def destroy
phone = Phone.find params[:id]
phone.delete
Expand Down
201 changes: 201 additions & 0 deletions postman/AskDarcel%20API.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"info": {

"_postman_id": "76cd3595-feb0-4ae6-afb6-12041928c88e",
"name": "AskDarcel API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
Expand Down Expand Up @@ -1627,6 +1628,49 @@
},
"response": []
},
{
"name": "Add Phone",
"event": [
{
"listen": "test",
"script": {
"exec": [
"tests[\"Response time is less than 1000ms\"] = responseTime < 1000;",
"",
"tests[\"Status code is 201\"] = responseCode.code === 201;"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{ \n\t\"phone\" : {\n\t\t\"number\" : \"4155555267\",\n \"service_type\" : \"O\",\n \"resource_id\" : \"1\",\n \"description\" : \"a phone\"\n\t}\n}"
},
"url": {
"raw": "{{base_url}}/phones",
"host": [
"{{base_url}}"
],
"path": [
"phones"
]
}
},
"response": []
},
{
"name": "Submit New Service",
"event": [
Expand Down Expand Up @@ -1983,6 +2027,163 @@
},
"response": []
},
{
"name": "Add Note for Service",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Adding instruction\", function () {",
" pm.response.to.have.status(201);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"note\": {\n \"instruction\": \"test note\",\n \"service_id\": 1\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/notes",
"host": [
"{{base_url}}"
],
"path": [
"notes"
]
}
},
"response": []
},
{
"name": "Add Note for Resource",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Adding instruction\", function () {",
" pm.response.to.have.status(201);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"note\": {\n \"instruction\": \"test note\",\n \"resource_id\": 1\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/notes",
"host": [
"{{base_url}}"
],
"path": [
"notes"
]
}
},
"response": []
},
{
"name": "Add Orphaned Note",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Adding instruction\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"note\": {\n \"note\": \"test note\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/notes",
"host": [
"{{base_url}}"
],
"path": [
"notes"
]
}
},
"response": []
},
{
"name": "Update Note",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Adding instruction\", function () {",
" pm.response.to.have.status(201);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"note\": {\n \"note\": \"updated note\",\n \"resource_id\": 2\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/notes/2",
"host": [
"{{base_url}}"
],
"path": [
"notes",
"2"
]
}
},
"response": []
},
{
"name": "Delete Note",
"event": [
Expand Down