forked from pokers/backend_template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathonelinerController.js
More file actions
112 lines (91 loc) · 2.05 KB
/
onelinerController.js
File metadata and controls
112 lines (91 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const { OnelinerService } = require('../services')
const { MissingRequestParameter } = require('../services/errorService')
const getOneliner = async (ctx) => {
const { sortType = 'latest', perPage = 5, continuousToken = 0 } = ctx.query; // 첫 페이지를 0으로 함
const userId = ctx.request.headers.user_id;
const onelinerService = new OnelinerService();
const result = await onelinerService.getOneliner(userId, sortType, perPage, continuousToken);
const { totalCount, currentPage} = result.meta;
const data = {
oneliner:
result.data
}
const meta = {
sortType,
continuousToken,
currentPage,
totalCount,
requestId: ctx.state.requestId,
now: +new Date(),
};
ctx.body = {
data: data,
meta
};
};
const postOneliner = async (ctx) => {
const userId = ctx.request.headers.user_id;
const {
book_id,
title,
authors,
oneliner,
color,
top,
left,
font,
font_size,
bg_image_url
} = ctx.request.body;
const onelinerService = new OnelinerService();
const result = await onelinerService.postOneliner({
userId: userId,
book_id: book_id,
title: title,
authors: authors,
oneliner: oneliner,
color: color,
top: top,
left: left,
font: font,
font_size: font_size,
bg_image_url: bg_image_url
});
const data = {
oneliner:
result.data
}
const meta = {
sortType: "latest",
continuousToken: "0",
currentPage: "0",
requestId: ctx.state.requestId,
now: +new Date(),
};
ctx.body = {
data: data,
meta
};
};
const deleteOneliner = async (ctx)=>{
const {
params: {
onelinerId
}
} = ctx
if (!onelinerId){
throw new MissingRequestParameter('bookId')
}
const onelinerService = new OnelinerService();
const result = await onelinerService.deleteOneliner(onelinerId);
ctx.body = result;
ctx.body.meta = {
requestId: ctx.state.requestId,
now: +new Date(),
};
};
module.exports = {
getOneliner,
postOneliner,
deleteOneliner
}