Skip to content

Commit

Permalink
Add category to item
Browse files Browse the repository at this point in the history
  • Loading branch information
yuneg11 committed Dec 8, 2019
1 parent 83676f8 commit 2d473e5
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jspm_packages
.build
serverless_sdk
s_*
_warmup

# Credentials
utils/credential.js
15 changes: 9 additions & 6 deletions src/backend/handlers/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

const parser = require("../utils/parser");
const database = require("../utils/database");
const authenticator = require("../utils/authenticator");
const responseTemplate = require("../responses/template");

const registration = async (event) => {
const userId = parser.getUserId(event);
const parameters = parser.getParameters(event);
const item_category = parameters["item_category"].value;
const item_name = parameters["item_name"].origin;
const item_price_raw = parameters["item_price"].value;
const item_price = parser.getPrice(parameters["item_price"].value);
const item_detail = parameters["item_detail"].origin;
const item_image = parameters["item_image"].origin;
const item_image = parser.getImageUrls(parameters["item_image"].origin);

// Todo: Regist item to database

return responseTemplate.itemRegistrationSuccess(item_name);
const result = await database.registNewItem(userId, item_category, item_name, item_price, item_detail, item_image);
if (result.success == true) {
return responseTemplate.itemRegistrationSuccess(item_name, item_detail, item_price, item_image[0]);
} else {
return responseTemplate.itemRegistrationFail("");
}
}

module.exports = {
Expand Down
12 changes: 7 additions & 5 deletions src/backend/responses/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
const builder = require("../utils/builder");
const resource = require("../utils/resource");

module.exports.itemRegistrationSuccess = (itemName) => {
module.exports.itemRegistrationSuccess = (itemName, itemDetail, itemPrice, imageUrl, nickname) => {
// Construct registration guide
const resultThumbnail = builder.getThumbnail(resource.itemRegistrationSuccessThumbnailUrl);
const resultTitle = "상품 등록 성공";
const resultDescription = itemName + " 등록에 성공하였습니다.";
const resultThumbnail = builder.getThumbnail(imageUrl);
const resultTitle = itemName;
const resultDescription = itemDetail;
const resultPrice = itemPrice;
const resultNickname = nickname;
const resultMainMenuButton = builder.getButton("처음으로", "block", "처음으로", resource.welcomeBlockId);
const resultCard = builder.getBasicCard(resultTitle, resultDescription, resultThumbnail, [resultMainMenuButton]);
const resultCard = builder.getCommerceCard(resultTitle, resultDescription, resultPrice, resultThumbnail, result, [resultMainMenuButton]);

// Build response
return builder.buildResponse([resultCard]);
Expand Down
14 changes: 7 additions & 7 deletions src/backend/tests/item_registration.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"id": "5dda19bf8192ac00011a2918",
"detailParams": {
"item_name": {
"origin": "어어",
"value": "어어",
"origin": "상품의 이름",
"value": "상품의 이름",
"groupName": ""
},
"item_price": {
Expand All @@ -58,13 +58,13 @@
"groupName": ""
},
"item_detail": {
"origin": "처음으로",
"value": "처음으로",
"origin": "상세한 설명",
"value": "상세한 설명",
"groupName": ""
},
"$item_image": {
"origin": "List(http://secure.kakaocdn.net/dna/biS7Z3/K6avpFEudv/XXX/img_org.jpg?credential=Kq0eSbCrZgKIq51jh41Uf1jLsUh7VWcz&expires=1575476312&allow_ip=&allow_referer=&signature=gAuRfga0QSVLQTu%2Fto7KhmgKyGI%3D, http://secure.kakaocdn.net/dna/cjvCoE/K6aAZNxD00/XXX/img_org.jpg?credential=Kq0eSbCrZgKIq51jh41Uf1jLsUh7VWcz&expires=1575476312&allow_ip=&allow_referer=&signature=JZ61bx1qvBaR6RHGo352yak7fHA%3D, http://secure.kakaocdn.net/dna/bPthHV/K6aA1q3sS8/XXX/img_org.jpg?credential=Kq0eSbCrZgKIq51jh41Uf1jLsUh7VWcz&expires=1575476312&allow_ip=&allow_referer=&signature=9rz9GHZDcgjnucALZpUjFe71QAY%3D)",
"value": "{\"privacyAgreement\":\"Y\",\"imageQuantity\":\"3\",\"secureUrls\":\"List(http://secure.kakaocdn.net/dna/biS7Z3/K6avpFEudv/XXX/img_org.jpg?credential=Kq0eSbCrZgKIq51jh41Uf1jLsUh7VWcz&expires=1575476312&allow_ip=&allow_referer=&signature=gAuRfga0QSVLQTu%2Fto7KhmgKyGI%3D, http://secure.kakaocdn.net/dna/cjvCoE/K6aAZNxD00/XXX/img_org.jpg?credential=Kq0eSbCrZgKIq51jh41Uf1jLsUh7VWcz&expires=1575476312&allow_ip=&allow_referer=&signature=JZ61bx1qvBaR6RHGo352yak7fHA%3D, http://secure.kakaocdn.net/dna/bPthHV/K6aA1q3sS8/XXX/img_org.jpg?credential=Kq0eSbCrZgKIq51jh41Uf1jLsUh7VWcz&expires=1575476312&allow_ip=&allow_referer=&signature=9rz9GHZDcgjnucALZpUjFe71QAY%3D)\",\"expire\":\"1970-01-19T14:37:56+0900\"}",
"item_image": {
"origin": "List(http://k.kakaocdn.net/dn/xsBdT/btqqIzbK4Hc/F39JI8XNVDMP9jPvoVdxl1/2x1.jpg, https://i.ibb.co/0f5zh6N/Kakao-Talk-Photo-2019-12-06-16-36-17.jpg)",
"value": "{\"privacyAgreement\":\"Y\",\"imageQuantity\":\"3\",\"secureUrls\":\"List(http://k.kakaocdn.net/dn/xsBdT/btqqIzbK4Hc/F39JI8XNVDMP9jPvoVdxl1/2x1.jpg, https://i.ibb.co/0f5zh6N/Kakao-Talk-Photo-2019-12-06-16-36-17.jpg)\"}",
"groupName": ""
}
}
Expand Down
18 changes: 17 additions & 1 deletion src/backend/utils/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ const getCarousel = (type, cards) => {
}
}

const getCommerceCard = (title, description, price, thumbnail, nickname, buttons=[]) => {
return {
commerceCard: {
description: title + "\n" + description,
price: price,
currency: "won",
thumbnails: [ thumbnail ],
profile: {
nickname: nickname
},
buttons: buttons
}
};
}

module.exports = {
buildResponse,
buildAWSResponse,
Expand All @@ -129,5 +144,6 @@ module.exports = {
getBasicCardBody,
getBasicCard,
getListCard,
getCarousel
getCarousel,
getCommerceCard
}
9 changes: 5 additions & 4 deletions src/backend/utils/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const query = async (sql, params) => {
});
};


const uploadImages = async (directory, locations) => {
const results = [];
for (var key in locations) {
Expand Down Expand Up @@ -206,7 +205,8 @@ const registNewItem = async (userId, item_name, item_price, item_detail, item_im
const itemId = await generateToken();
const imageurls = JSON.stringify(await uploadImages(itemId + '/', item_image));
var sql = 'INSERT INTO item(userId, itemId, item_name, item_price, item_detail, item_image, item_date)VALUES(?,?,?,?,?,?,?)';
var params = [userId, 'itemid', item_name, item_price, item_detail, imageurls, NOW()];
var params = [userId, itemId, item_name, item_price, item_detail, imageurls, new Date().toISOString().slice(0, 19).replace('T', ' ')];
console.log(Date.now());
// userId: string, item_name: string, item_price: number, item_detail: string, item_image: JSON array
// Todo: Create new item with scheme { userId: string,
// itemId: number (auto increment),
Expand All @@ -223,6 +223,7 @@ const registNewItem = async (userId, item_name, item_price, item_detail, item_im
message: ""
};
}catch(err){
console.log(err);
return{
success: false,
message:"fail"
Expand Down Expand Up @@ -257,7 +258,7 @@ const getItem = async (itemId) => {
}
};

const getuserItem = async (userId) => {
const getUserItem = async (userId) => {
const results = [];
var sql = 'SELECT * FROM item WHERE userId = ?';
try{
Expand Down Expand Up @@ -325,5 +326,5 @@ module.exports = {
getUser,
registNewItem,
getItem,
getuserItem
getUserItem
}
12 changes: 11 additions & 1 deletion src/backend/utils/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ const getKeys = (event) => {
return event.queryStringParameters;
}

const getPrice = (price_string) => {
return JSON.parse(price_string).amount
};

const getImageUrls = (image_list) => {
return image_list.substring(5, image_list.length - 1).split(", ");
};

module.exports = {
getBody,
getUserId,
getMessage,
getParameters,
getBlockId,
getKeys
getKeys,
getPrice,
getImageUrls
}

0 comments on commit 2d473e5

Please sign in to comment.