-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Rate accommodation): Rate accommodation
- Add rating model - Add rating migration - Add rating services - Add search Functionality - Add trip search controller - Add trip search query validation [Finishes #167727339]
- Loading branch information
Showing
23 changed files
with
716 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { postAccommodationRating, getAccommodationRatings } from '../services/ratingServices'; | ||
import { respondWithSuccess, respondWithWarning } from '../helpers/responseHandler'; | ||
import statusCode from '../helpers/statusCode'; | ||
|
||
export const createAccommodationRating = async (req, res) => { | ||
const payload = { accommodationId: req.params.accommodationId, rating: req.body.rating }; | ||
try { | ||
const rating = await postAccommodationRating(payload); | ||
return respondWithSuccess(res, statusCode.created, 'Accommodation has been rated successfuly', rating.toJSON()); | ||
} catch (error) { | ||
return respondWithWarning(res, statusCode.internalServerError, 'Oops, something bad happened'); | ||
} | ||
}; | ||
|
||
export const getSingleAccommodationRatings = async (req, res) => { | ||
try { | ||
const accommodationRatings = await getAccommodationRatings(req.params.accommodationId); | ||
return !accommodationRatings.length ? respondWithWarning(res, statusCode.resourceNotFound, 'No ratings for this accommodation') : respondWithSuccess(res, statusCode.success, 'Accommodation ratings has been retrieved', accommodationRatings); | ||
} catch (error) { | ||
return respondWithWarning(res, statusCode.internalServerError, 'Oops, something bad happened'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export default { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Ratings', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
accommodationId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
}, | ||
rating: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: new Date(), | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: new Date(), | ||
} | ||
}), | ||
down: (queryInterface) => queryInterface.dropTable('Ratings') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const accommodationRatingSchema = { | ||
type: 'object', | ||
properties: { | ||
rating: { | ||
type: 'integer', | ||
format: 'int32', | ||
example: 1, | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
export const accommodationRating = { | ||
post: { | ||
tags: [ | ||
'accommodations' | ||
], | ||
security: [ | ||
{ | ||
BearerToken: [] | ||
} | ||
], | ||
summary: 'Post ratings for a particular accommodation', | ||
description: 'Post ratings for a particular accommodation', | ||
parameters: [ | ||
{ | ||
name: 'accommodationId', | ||
in: 'path', | ||
description: 'path parameter takes the accommodation id', | ||
required: true, | ||
type: 'integer', | ||
format: 'int32' | ||
}, | ||
{ | ||
name: 'body', | ||
in: 'body', | ||
required: false, | ||
schema: { | ||
$ref: '#definitions/accommodationRatingSchema' | ||
} | ||
} | ||
], | ||
responses: { | ||
201: { | ||
description: 'Room successfully created', | ||
schema: { | ||
$ref: '#/definitions/createRoomRes' | ||
} | ||
}, | ||
400: { | ||
description: 'Bad input data', | ||
schema: { | ||
$ref: '#/definitions/badRequest' | ||
} | ||
}, | ||
401: { | ||
description: 'Incorrect login details', | ||
schema: { | ||
$ref: '#/definitions/notAuthorized' | ||
} | ||
}, | ||
403: { | ||
description: 'Forbidden access', | ||
schema: { | ||
$ref: '#/definitions/accessForbidden' | ||
} | ||
}, | ||
404: { | ||
description: 'Accommodation not found', | ||
schema: { | ||
$ref: '#/definitions/notFound' | ||
} | ||
}, | ||
500: { | ||
description: 'Server error', | ||
schema: { | ||
$ref: '#/definitions/serverError' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export const getAccommodationRatings = { | ||
get: { | ||
tags: [ | ||
'accommodations' | ||
], | ||
security: [ | ||
{ | ||
BearerToken: [] | ||
} | ||
], | ||
summary: 'Post ratings for a particular accommodation', | ||
description: 'Post ratings for a particular accommodation', | ||
parameters: [ | ||
{ | ||
name: 'accommodationId', | ||
in: 'path', | ||
description: 'path parameter takes the accommodation id', | ||
required: true, | ||
type: 'integer', | ||
format: 'int32' | ||
} | ||
], | ||
responses: { | ||
200: { | ||
description: 'Ratings have been retrieved successfully', | ||
schema: { | ||
$ref: '#/definitions/success' | ||
} | ||
}, | ||
400: { | ||
description: 'Bad input data', | ||
schema: { | ||
$ref: '#/definitions/badRequest' | ||
} | ||
}, | ||
401: { | ||
description: 'Incorrect login details', | ||
schema: { | ||
$ref: '#/definitions/notAuthorized' | ||
} | ||
}, | ||
403: { | ||
description: 'Forbidden access', | ||
schema: { | ||
$ref: '#/definitions/accessForbidden' | ||
} | ||
}, | ||
404: { | ||
description: 'Accommodation not found', | ||
schema: { | ||
$ref: '#/definitions/notFound' | ||
} | ||
}, | ||
500: { | ||
description: 'Server error', | ||
schema: { | ||
$ref: '#/definitions/serverError' | ||
} | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.