Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Feedback for Events (#115)
Browse files Browse the repository at this point in the history
* Feedback for Events

* Fix Bugs

* Fixing naming Issue

* final fixes for feedback api
  • Loading branch information
joern-vh authored Apr 23, 2017
1 parent 5562609 commit 98d3f7c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
27 changes: 27 additions & 0 deletions api/controllers/feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

var context = require('../../database.js').getContext();
var feedbacks = require('../dsap/feedbacks.js')(context);

module.exports = {
getAllFeedbacks: getAllFeedbacks,
addFeedback: addFeedback,
};

function getAllFeedbacks(req, res) {
feedbacks.findAllFeedbacks().then(function(list) {
res.status(200).json(list)
}).catch(function(error) {
res.status(500).send(error);
});
}


function addFeedback(req, res) {
var feedbackObj = req.body;
feedbacks.addFeedback(feedbackObj).then(function() {
res.status(200).json();
}).catch(function(error) {
res.status(500).send(error);
});
}
17 changes: 17 additions & 0 deletions api/dsap/feedbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';
module.exports = function(context) {
var feedbacks = context.models.feedbacks;

return {
findAllFeedbacks: function() {
return feedbacks.findAll({
attributes: [
'id', 'feedback', 'entityId'
]
});
},
addFeedback: function(data) {
return feedbacks.create(data);
}
}
};
1 change: 1 addition & 0 deletions api/models/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = function(sequelize, DataTypes) {
this.hasMany(models.relationshipEntities);

this.hasMany(models.events);
this.hasMany(models.feedbacks);
}
}

Expand Down
19 changes: 19 additions & 0 deletions api/models/feedbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = function(sequelize, DataTypes) {
return sequelize.define('feedbacks', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
feedback:{
type: DataTypes.BOOLEAN //TRUE - Like, FALSE - Wrong Data
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
classMethods: {
associate: function(models) {
this.belongsTo(models.entities);
}
}
});
};
17 changes: 17 additions & 0 deletions api/swagger/src/definitions/definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,20 @@ SearchResult:
$ref: '#/definitions/Release'
work:
$ref: '#/definitions/Work'

Feedback:
properties:
entityId:
type: string
id:
type: string
feedback:
type: boolean

UpdateFeedback:
required: [entityId, feedback]
properties:
entityId:
type: string
feedback:
type: boolean
35 changes: 35 additions & 0 deletions api/swagger/src/paths/feedback/feedback.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
x-swagger-router-controller: feedback
get:
description: Returns list of all feedbacks
operationId: getAllFeedbacks
responses:
"200":
description: Success
schema:
type: array
items:
$ref: '#/definitions/Feedback'
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"

post:
description: Add a new Feedback to DB
operationId: addFeedback
security:
- DefaultSecurity: []
parameters:
- name: body
in: body
description: Feedback data
required: true
schema:
$ref: '#/definitions/UpdateFeedback'
responses:
"200":
description: Success
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
3 changes: 3 additions & 0 deletions api/swagger/src/paths/paths.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
/events:
$ref: ./events/events.yaml

/feedback:
$ref: ./feedback/feedback.yaml

/events/{id}:
$ref: ./events/events-id.yaml

Expand Down

0 comments on commit 98d3f7c

Please sign in to comment.