Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 193 #210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
10 changes: 5 additions & 5 deletions api/controllers/breweriesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ module.exports.create = [
twitter: req.body.twitter,
instagram: req.body.instagram,
othersns: req.body.othersns,
visit: req.body.hasVisit ? req.body.visit : null,
tasting: req.body.hasTasting ? req.body.tasting : null,
cafe: req.body.hasCafe ? req.body.cafe : null,
shop: req.body.hasShop ? req.body.shop : null,
otherBrewing: req.body.hasOtherBrewing ? req.body.otherBrewing : null,
visit: request.body.hasVisit ? req.body.visit : null,
tasting: request.body.hasTasting ? req.body.tasting : null,
cafe: request.body.hasCafe ? req.body.cafe : null,
shop: request.body.hasShop ? req.body.shop : null,
otherBrewing: request.body.hasOtherBrewing ? req.body.otherBrewing : null,
startYear: req.body.startYear,
endYear: req.body.endYear,
userId: req.user._id,
Expand Down
5 changes: 4 additions & 1 deletion api/controllers/commentsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module.exports.all = function (req, res, next) {
var brand = req.query.brand;
var sake = req.query.sake;
var userId = req.query.userId;
var sortField = req.query.sortField;
var sortOrder = req.query.sortOrder;
var search = {};

if (brewery) {
Expand All @@ -34,9 +36,10 @@ module.exports.all = function (req, res, next) {
{ comment: new RegExp(japanese.kanaToHira(keyword), 'i') },
];
}

Comment.paginate(
search,
{ page: req.query.page, limit: req.query.limit },
{ page: req.query.page, limit: req.query.limit, sort: {[sortField]: sortOrder} },
function (err, result) {
if (err) {
return res.status(500).json({
Expand Down
10 changes: 10 additions & 0 deletions api/swagger_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,16 @@
"name": "limit",
"in": "query",
"type": "string"
},
{
"name": "sortField",
"in": "query",
"type": "string"
},
{
"name": "sortOrder",
"in": "query",
"type": "string"
}
],
"responses": {
Expand Down
14 changes: 13 additions & 1 deletion pages/comments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export default {
const sake = context.query.sake != null ? context.query.sake : '';
const limit = context.query.limit != null ? context.query.limit : 10;
const page = context.query.page != null ? context.query.page : 1;
const sortField = context.query.sortField != null ? context.query.sortField : 'createdAt';
const sortOrder = context.query.sortOrder != null ? context.query.sortOrder : 'desc';
const { list, currentPage, count } = await getList(
'comments',
{
Expand All @@ -83,6 +85,8 @@ export default {
sake: sake,
page: page,
limit: limit,
sortField: sortField,
sortOrder: sortOrder,
},
context
);
Expand All @@ -94,6 +98,8 @@ export default {
comments: list,
page: currentPage,
count: count,
sortField: sortField,
sortOrder: sortOrder,
};
},
data() {
Expand All @@ -106,6 +112,8 @@ export default {
page: 1,
count: 0,
limit: 10,
sortField: 'createdAt',
sortOrder: 'desc',
};
},
mounted() {
Expand All @@ -120,6 +128,8 @@ export default {
this.limit =
this.$route.query.limit != null ? this.$route.query.limit : 10;
this.page = this.$route.query.page != null ? this.$route.query.page : 1;
this.sortField = this.$route.query.sortField != null ? this.$route.query.sortField : 'createdAt';
this.sortOrder = this.$route.query.sortOrder != null ? this.$route.query.sortOrder : 'desc';
this.retrieves();
});
},
Expand All @@ -132,6 +142,8 @@ export default {
brewery: this.brewery,
page: this.page,
limit: this.limit,
sortField: this.sortField,
sortOrder: this.sortOrder,
});
this.comments = list;
this.page = currentPage;
Expand All @@ -144,7 +156,7 @@ export default {
},
setHistories() {
const url = window.location.href.replace(/\?.*$/, '');
const queries = `?keyword=${this.keyword}&page=${this.page}&limit=${this.limit}&brewery=${this.brewery}&brand=${this.brand}&sake=${this.sake}`;
const queries = `?sortField=${this.sortField}&sortOrder=${this.sortOrder}&keyword=${this.keyword}&page=${this.page}&limit=${this.limit}&brewery=${this.brewery}&brand=${this.brand}&sake=${this.sake}`;
window.history.pushState(null, null, `${url}${queries}`);
},
},
Expand Down