diff --git a/src/backend/handler.js b/src/backend/handler.js index 177deb8..2731741 100644 --- a/src/backend/handler.js +++ b/src/backend/handler.js @@ -30,8 +30,9 @@ module.exports.verifyEmail = async (event) => { // Skill module.exports.welcome = async (event) => { - if (await checkAuth(event) != null) { - const response = responseTemplate.welcome(); + const auth = await checkAuth(event); + if (auth != null) { + const response = responseTemplate.welcome(auth); console.log(response); return response; } else { diff --git a/src/backend/handlers/user.js b/src/backend/handlers/user.js index 4bc92a8..c1dbf8c 100644 --- a/src/backend/handlers/user.js +++ b/src/backend/handlers/user.js @@ -56,16 +56,16 @@ const information = async (event) => { } }; -// Todo const openprofile = async (event) => { const userId = parser.getUserId(event); + const parameters = parser.getParameters(event); + const user_openprofile = parameters["user_openprofile"].origin; - const user = await database.getUser(userId); - if (user == null) { - return responseTemplate.userRegistration(); + const result = await database.setOpenprofile(userId, user_openprofile); + if (result.success == true) { + return responseTemplate.userOpenprofileSuccess(user_openprofile); } else { - const openprofile = (user.openprofile == null ? "-" : user.openprofile); - return responseTemplate.userInformation(user.nickname, user.school_name, user.school_mail, openprofile, user.reliability_score); + return responseTemplate.processFail("오픈프로필 등록 실패", "오픈프로필 등록에 실패하였습니다."); } }; diff --git a/src/backend/responses/common.js b/src/backend/responses/common.js index 5e5e0ef..f908f60 100644 --- a/src/backend/responses/common.js +++ b/src/backend/responses/common.js @@ -3,7 +3,7 @@ const builder = require("../utils/builder"); const resource = require("../utils/resource"); -module.exports.welcome = () => { +module.exports.welcome = (user) => { // Construct buyer card const buyerThumbnail = builder.getThumbnail(resource.buyerThumbnailUrl); const buyerSearchTextButton = builder.getButton("상품 카테고리 검색", "block", "상품 카테고리 검색", resource.buyerSearchCategoryBlockId); @@ -13,7 +13,8 @@ module.exports.welcome = () => { // Construct seller card const sellerThumbnail = builder.getThumbnail(resource.sellerThumbnailUrl); - const sellerItemRegistButton = builder.getButton("상품 등록", "block", "상품 등록", resource.sellerItemRegistBlockId); + const registLink = (user.openprofile ? resource.sellerItemRegistBlockId : resource.userInfoOpenProfileBlockId); + const sellerItemRegistButton = builder.getButton("상품 등록", "block", "상품 등록", registLink); const sellerItemListButton = builder.getButton("상품 목록", "block", "상품 목록", resource.sellerItemListBlockId, {mode: "list"}); const sellerContractButton = builder.getButton("판매자 거래 체결", "block", "판매자 거래 체결", resource.sellerItemListBlockId, {mode: "contract"}); const sellerCardBody = builder.getBasicCardBody("판매", "상품을 판매합니다.", sellerThumbnail, [sellerItemRegistButton, sellerItemListButton, sellerContractButton]); diff --git a/src/backend/responses/item.js b/src/backend/responses/item.js index 5f69a83..d08f33a 100644 --- a/src/backend/responses/item.js +++ b/src/backend/responses/item.js @@ -49,7 +49,7 @@ module.exports.itemListSuccess = (itemList, mode="search") => { buttons.push(builder.getButton("상세정보", "block", "상세정보", resource.itemDetailBlockId, {itemId: resultItemId, mode: "list"})); buttons.push(builder.getButton("삭제", "block", "삭제", resource.itemDeleteWarningBlockId, {itemId: resultItemId, item_image: item.item_image[0]})); } else if (mode == "search") { - buttons.push(builder.getButton("구매", "block", "구매", resource.itemBuyBlockId, {userId: resultUserId, itemId: resultItemId})); + buttons.push(builder.getButton("판매자 연결", "webLink", (item.openprofile == null ? "" : item.openprofile))); buttons.push(builder.getButton("상세정보", "block", "상세정보", resource.itemDetailBlockId, {userId: resultUserId, itemId: resultItemId, mode: "search"})); } else if (mode == "contract") { buttons.push(builder.getButton("판매", "block", "판매", resource.sellerContractBlockId, {itemId: resultItemId})); @@ -83,7 +83,7 @@ module.exports.itemDetail = (item, mode="list", user=null) => { const resultTitle = item.item_name + "(" + item.item_price + "원)"; const resultDescription = item.item_detail + "\n"+ item.item_date; const resultMainMenuButton = (mode == "list" ? builder.getButton("삭제", "block", "삭제", resource.itemDeleteWarningBlockId, {itemId: item.itemId, item_image: item.item_image[0]}) - : builder.getButton("구매", "block", "구매", resource.itemBuyBlockId, {userId: resultUserId, itemId: resultItemId})); + : builder.getButton("판매자 연결", "webLink", item.openprofile)); const resultCard1 = builder.getBasicCardBody(resultTitle, resultDescription, "", [resultMainMenuButton, resultMainMenuButton]); const resultCard2 = builder.getBasicCardBody("", "", resultThumbnail); diff --git a/src/backend/responses/template.js b/src/backend/responses/template.js index 80c09fe..63aebcd 100644 --- a/src/backend/responses/template.js +++ b/src/backend/responses/template.js @@ -22,5 +22,6 @@ module.exports = { itemBuyerContractSuccess: itemResponse.itemBuyerContractSuccess, itemDeleteWarning: itemResponse.itemDeleteWarning, itemDeleteOk: itemResponse.itemDeleteOk, - itemDeleteCancel: itemResponse.itemDeleteCancel + itemDeleteCancel: itemResponse.itemDeleteCancel, + userOpenprofileSuccess: userResponse.userOpenprofileSuccess }; diff --git a/src/backend/responses/user.js b/src/backend/responses/user.js index b682194..33b5e09 100644 --- a/src/backend/responses/user.js +++ b/src/backend/responses/user.js @@ -63,3 +63,9 @@ module.exports.userAuthenticationSuccess = () => { module.exports.userAuthenticationFail = () => { return builder.buildAWSResponse("Mail authentication fail!"); }; + +module.exports.userOpenprofileSuccess = (openprofile) => { + const listItem = builder.getListItem(openprofile, "오픈프로필 링크"); + const listCard = builder.getListCard("오픈프로필 등록 성공", "", [listItem]); + return builder.buildResponse([listCard]); +}; diff --git a/src/backend/utils/database.js b/src/backend/utils/database.js index caf02d7..d524c2a 100644 --- a/src/backend/utils/database.js +++ b/src/backend/utils/database.js @@ -501,5 +501,6 @@ module.exports = { registNewDeal, deleteItem, deleteUser, - getTransaction + getTransaction, + setOpenprofile }