Module: JPie::Controller::RelationshipActions
- Extended by:
- ActiveSupport::Concern
- Includes:
- RelationshipValidation
- Included in:
- JPie::Controller
- Defined in:
- lib/jpie/controller/relationship_actions.rb
Instance Method Summary collapse
-
#relationship_create ⇒ Object
POST /resources/:id/relationships/:relationship_name Adds to relationship linkage (for to-many relationships).
-
#relationship_destroy ⇒ Object
DELETE /resources/:id/relationships/:relationship_name Removes from relationship linkage (for to-many relationships).
-
#relationship_show ⇒ Object
GET /resources/:id/relationships/:relationship_name Returns relationship linkage data.
-
#relationship_update ⇒ Object
PATCH /resources/:id/relationships/:relationship_name Updates relationship linkage (replaces all relationships).
Instance Method Details
#relationship_create ⇒ Object
POST /resources/:id/relationships/:relationship_name Adds to relationship linkage (for to-many relationships)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jpie/controller/relationship_actions.rb', line 33 def relationship_create validate_relationship_exists validate_relationship_update_request resource = find_resource unless relationship_is_to_many? raise JPie::Errors::BadRequestError.new( detail: 'POST is only supported for to-many relationships' ) end relationship_data = parse_relationship_data unless relationship_data.is_a?(Array) raise JPie::Errors::BadRequestError.new( detail: 'Adding to relationships requires an array of resource identifier objects' ) end add_to_relationship(resource, relationship_data) render_relationship_data(get_relationship_data(resource)) end |
#relationship_destroy ⇒ Object
DELETE /resources/:id/relationships/:relationship_name Removes from relationship linkage (for to-many relationships)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/jpie/controller/relationship_actions.rb', line 58 def relationship_destroy validate_relationship_exists validate_relationship_update_request resource = find_resource unless relationship_is_to_many? raise JPie::Errors::BadRequestError.new( detail: 'DELETE is only supported for to-many relationships' ) end relationship_data = parse_relationship_data unless relationship_data.is_a?(Array) raise JPie::Errors::BadRequestError.new( detail: 'Removing from relationships requires an array of resource identifier objects' ) end remove_from_relationship(resource, relationship_data) render_relationship_data(get_relationship_data(resource)) end |
#relationship_show ⇒ Object
GET /resources/:id/relationships/:relationship_name Returns relationship linkage data
13 14 15 16 17 18 |
# File 'lib/jpie/controller/relationship_actions.rb', line 13 def relationship_show validate_relationship_exists resource = find_resource relationship_data = get_relationship_data(resource) render_relationship_data(relationship_data) end |
#relationship_update ⇒ Object
PATCH /resources/:id/relationships/:relationship_name Updates relationship linkage (replaces all relationships)
22 23 24 25 26 27 28 29 |
# File 'lib/jpie/controller/relationship_actions.rb', line 22 def relationship_update validate_relationship_exists validate_relationship_update_request resource = find_resource relationship_data = parse_relationship_data update_relationship_data(resource, relationship_data) render_relationship_data(get_relationship_data(resource)) end |