From 40cc59a03ff3b3efb96b69f02bf75f2b109cb9f0 Mon Sep 17 00:00:00 2001 From: binchoo <079111w@gmail.com> Date: Thu, 22 Sep 2022 21:01:15 +0900 Subject: [PATCH] #29 Change UidListView to support traveler removal loop --- ...fig.java => ErrorContextBinderConfig.java} | 15 +++-- .../chatbot/configs/view/ViewConfig.java | 5 +- .../controllers/HoyopassController.java | 36 ++++++++--- .../chatbot/resources/FallbackMethods.java | 2 + .../chatbot/views/uid/UidListView.java | 60 ++++++++++++------- .../src/main/resources/blocks.yaml | 7 +++ 6 files changed, 89 insertions(+), 36 deletions(-) rename PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/error/{ErrorExplainConfig.java => ErrorContextBinderConfig.java} (87%) diff --git a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/error/ErrorExplainConfig.java b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/error/ErrorContextBinderConfig.java similarity index 87% rename from PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/error/ErrorExplainConfig.java rename to PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/error/ErrorContextBinderConfig.java index b1cb0279..a6ded5c7 100644 --- a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/error/ErrorExplainConfig.java +++ b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/error/ErrorContextBinderConfig.java @@ -6,10 +6,7 @@ import org.binchoo.paimonganyu.chatbot.resources.FallbackMethods; import org.binchoo.paimonganyu.dailycheck.exception.NoUserDailyCheckException; import org.binchoo.paimonganyu.hoyopass.UserHoyopass; -import org.binchoo.paimonganyu.hoyopass.exception.DuplicationException; -import org.binchoo.paimonganyu.hoyopass.exception.InactiveStateException; -import org.binchoo.paimonganyu.hoyopass.exception.QuantityExceedException; -import org.binchoo.paimonganyu.hoyopass.exception.QuantityZeroException; +import org.binchoo.paimonganyu.hoyopass.exception.*; import org.binchoo.paimonganyu.redeem.exception.NoUserRedeemException; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -19,7 +16,7 @@ * @since : 2022-06-12 */ @Configuration -public class ErrorExplainConfig { +public class ErrorContextBinderConfig { @Bean public ErrorContextBinders errorContextBinders() { @@ -49,6 +46,12 @@ public ErrorContextBinders errorContextBinders() { .fallbacks(FallbackMethods.Home, FallbackMethods.ScanHoyopassGuide) .build()); + binders.add(HoyopassExceptionBinder.builder() + .error(ImmortalUidException.class) + .title("지울 수 없는 UID입니다. 통행증은 최소 하나의 UID를 지녀야합니다.") + .fallbacks(FallbackMethods.Home) + .build()); + binders.add(HoyopassExceptionBinder.builder() .error(NoUserDailyCheckException.class) .title("일일 출석을 수행한 이력이 없습니다.") @@ -62,7 +65,7 @@ public ErrorContextBinders errorContextBinders() { .build()); binders.add(CryptoExceptionBinder.builder() - .text("옳지 않은 방법으로 만들어진 QR 코드인 것 같습니다.") + .text("옳지 않은 방법으로 만들어진 QR 코드 같습니다.") .fallbacks(FallbackMethods.Home, FallbackMethods.ScanHoyopass, FallbackMethods.CommonCs) .build()); diff --git a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/view/ViewConfig.java b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/view/ViewConfig.java index 5c096e3b..d08916a0 100644 --- a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/view/ViewConfig.java +++ b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/configs/view/ViewConfig.java @@ -31,8 +31,9 @@ public ViewResolver viewResolver() { @Lazy @Bean public UidListView uidListView(@Autowired Images images, - @Autowired QuickReplies quickReplies) { - return new UidListView(images, quickReplies); + @Autowired QuickReplies quickReplies, + @Autowired Blocks blocks) { + return new UidListView(images, quickReplies, blocks); } @Lazy diff --git a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/controllers/HoyopassController.java b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/controllers/HoyopassController.java index 3b03041e..c95c8d08 100644 --- a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/controllers/HoyopassController.java +++ b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/controllers/HoyopassController.java @@ -22,23 +22,42 @@ @Controller public class HoyopassController { - private final SecureHoyopassRegisterPort secureHoyopassRegister; + private static final String CONTENT_KEY = SkillResponseView.CONTENT_KEY; + private final SecureHoyopassRegisterPort hoyopassRegister; @RequestMapping(value = "/post", method = RequestMethod.POST) public String addHoyopass(@UserId String botUserId, @ActionParam("secure_hoyopass") BarcodeData barcodeData, Model model) { + String secureHoyopass = barcodeData.getBarcodeData(); - UserHoyopass user = secureHoyopassRegister.registerHoyopass(botUserId, secureHoyopass); - model.addAttribute(SkillResponseView.CONTENT_KEY, user.listUids()); + UserHoyopass user = hoyopassRegister.registerHoyopass(botUserId, secureHoyopass); + model.addAttribute(CONTENT_KEY, user.listHoyopasses()); + + return "uidListView"; + } + + @RequestMapping(value = "/uid/list", method = RequestMethod.POST) + public String listUids(@UserId String botUserId, Model model) { + model.addAttribute(CONTENT_KEY, hoyopassRegister.listHoyopasses(botUserId)); return "uidListView"; } + @RequestMapping(value = "/uid/delete", method = RequestMethod.POST) + public String deleteUid(@UserId String botUserId, + @ClientExtra("uid") String uid, Model model) { + + hoyopassRegister.deleteUid(botUserId, uid); + + return listUids(botUserId, model); + } + @RequestMapping(value = "/list", method = RequestMethod.POST) public String listHoyopasses(@UserId String botUserId, Model model) { - List hoyopasses = secureHoyopassRegister.listHoyopasses(botUserId); - model.addAttribute(SkillResponseView.CONTENT_KEY, hoyopasses); + List hoyopasses = hoyopassRegister.listHoyopasses(botUserId); + + model.addAttribute(CONTENT_KEY, hoyopasses); return "hoyopassListView"; } @@ -46,10 +65,11 @@ public String listHoyopasses(@UserId String botUserId, Model model) { @RequestMapping(value = "/delete", method = RequestMethod.POST) public String deleteHoyopass(@UserId String botUserId, @ClientExtra("index") int index, Model model) { - secureHoyopassRegister.deleteHoyopass(botUserId, index); - List hoyopasses = secureHoyopassRegister.listHoyopasses(botUserId); - model.addAttribute(SkillResponseView.CONTENT_KEY, hoyopasses); + hoyopassRegister.deleteHoyopass(botUserId, index); + + List hoyopasses = hoyopassRegister.listHoyopasses(botUserId); + model.addAttribute(CONTENT_KEY, hoyopasses); return "hoyopassListView"; } diff --git a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/resources/FallbackMethods.java b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/resources/FallbackMethods.java index 87050ba3..40fae39f 100644 --- a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/resources/FallbackMethods.java +++ b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/resources/FallbackMethods.java @@ -28,6 +28,8 @@ public final class FallbackMethods { public static FallbackMethod DeleteHoyopass; public static FallbackMethod ListHoyopass; public static FallbackMethod ListHoyopassAliasDeleteHoyopass; + public static FallbackMethod HomeAliasStopTravelerRemovalLoop; + public static FallbackMethod DeleteUid; public static FallbackMethod ListTravelerStatus; diff --git a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/views/uid/UidListView.java b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/views/uid/UidListView.java index 8d4d5eac..bfa85de6 100644 --- a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/views/uid/UidListView.java +++ b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/java/org/binchoo/paimonganyu/chatbot/views/uid/UidListView.java @@ -1,10 +1,12 @@ package org.binchoo.paimonganyu.chatbot.views.uid; -import org.binchoo.paimonganyu.chatbot.views.SkillResponseView; +import org.binchoo.paimonganyu.chatbot.resources.Blocks; import org.binchoo.paimonganyu.chatbot.resources.FallbackMethods; import org.binchoo.paimonganyu.chatbot.resources.Images; import org.binchoo.paimonganyu.chatbot.resources.QuickReplies; +import org.binchoo.paimonganyu.chatbot.views.SkillResponseView; import org.binchoo.paimonganyu.error.FallbackMethod; +import org.binchoo.paimonganyu.hoyopass.Hoyopass; import org.binchoo.paimonganyu.hoyopass.Uid; import org.binchoo.paimonganyu.ikakao.SkillResponse; import org.binchoo.paimonganyu.ikakao.component.CarouselView; @@ -12,10 +14,13 @@ import org.binchoo.paimonganyu.ikakao.component.componentType.BasicCard; import org.binchoo.paimonganyu.ikakao.component.componentType.Carousel; import org.binchoo.paimonganyu.ikakao.component.componentType.SimpleText; +import org.binchoo.paimonganyu.ikakao.type.Button; import org.binchoo.paimonganyu.ikakao.type.SkillTemplate; import org.binchoo.paimonganyu.ikakao.type.Thumbnail; +import org.binchoo.paimonganyu.ikakao.type.buttons.BlockButton; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -27,20 +32,22 @@ public class UidListView extends SkillResponseView { private static final String IMAGEKEY_AETHER = "aether_banner"; private static final String IMAGEKEY_LUMINE = "lumine_banner"; - public UidListView(Images images, QuickReplies quickReplies) { - super(images, quickReplies, null); + public UidListView(Images images, QuickReplies quickReplies, Blocks blocks) { + super(images, quickReplies, blocks); } - private final class UidValue { + private final class UidDto { private final String server, uid, name; + private final boolean isSingleUid; private final int level; private final boolean isLumine; - public UidValue(Uid uid) { + public UidDto(Uid uid, boolean isSingleUid) { this.server = uid.getRegion().suffixLargeCase(); this.uid = uid.getUidString(); this.name = uid.getCharacterName(); + this.isSingleUid = isSingleUid; this.level = uid.getCharacterLevel(); this.isLumine = uid.getIsLumine(); } @@ -59,57 +66,70 @@ private String getImageUrl() { else return images().findByName(IMAGEKEY_AETHER); } + + public Button getButton() { + if (isSingleUid) return null; + return BlockButton.builder() + .label("얘는 빼줘") + .messageText(String.format("%s의 %s⋯ %s는 이미 여행을 다녀왔어", server, name, isLumine? "그녀" : "그")) + .blockId(blocks().findByFallbackMethod(FallbackMethods.DeleteUid)) + .extra(Map.of("uid", uid)) + .build(); + } } @Override protected SkillResponse render(Object modelContent) { - return renderSkillResponse((List) modelContent); + return renderSkillResponse((List) modelContent); } - private SkillResponse renderSkillResponse(List uids) { - List modelValues = uids.stream().map(UidValue::new) - .collect(Collectors.toList()); + private SkillResponse renderSkillResponse(List passes) { + List uids = passes.stream().flatMap(pass-> { + boolean isSingleUid = pass.size() == 1; + return pass.getUids().stream().map(uid-> new UidDto(uid, isSingleUid)); + }).collect(Collectors.toList()); return SkillResponse.builder() - .template(templateOf(modelValues)) + .template(templateOf(uids)) .build(); } - private SkillTemplate templateOf(List modelValues) { + private SkillTemplate templateOf(List uids) { return SkillTemplate.builder() .addOutput(SimpleTextView.builder() - .simpleText(new SimpleText("이제 " + modelValues.size() + "명의 여행자들을 관리할게!")) + .simpleText(new SimpleText(String.format("이제 %s명의 여행자들을 관리할게~%n버튼이 있는 여행자는 지우는 게 가능해!", uids.size()))) .build()) .addOutput(CarouselView.builder() - .carousel(carouselOf(modelValues)) + .carousel(carouselOf(uids)) .build()) .quickReplies(quickReplies().findByFallbackMethod(getFallbacks())) .build(); } private FallbackMethod[] getFallbacks() { - return new FallbackMethod[] {FallbackMethods.Home, FallbackMethods.ListHoyopass}; + return new FallbackMethod[] {FallbackMethods.HomeAliasStopTravelerRemovalLoop, FallbackMethods.ListHoyopass}; } - private Carousel carouselOf(List modelValues) { + private Carousel carouselOf(List uids) { var carouselBuilder = Carousel.builder() .type("basicCard"); - for (UidValue item : modelValues) + for (UidDto item : uids) carouselBuilder.addItem(basicCardOf(item)); return carouselBuilder.build(); } - private BasicCard basicCardOf(UidValue value) { + private BasicCard basicCardOf(UidDto uid) { return BasicCard.builder() .thumbnail(Thumbnail.builder() - .imageUrl(value.getImageUrl()) + .imageUrl(uid.getImageUrl()) .fixedRatio(false) .width(800).height(400) .build()) - .title(value.getTitle()) - .description(value.getDescription()) + .title(uid.getTitle()) + .description(uid.getDescription()) + .addButton(uid.getButton()) .build(); } } diff --git a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/resources/blocks.yaml b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/resources/blocks.yaml index 5f35002f..811236b2 100644 --- a/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/resources/blocks.yaml +++ b/PaimonGanyu/paimonganyu-app/paimonganyu-skill/src/main/resources/blocks.yaml @@ -29,6 +29,12 @@ blocks: ListHoyopassAliasDeleteHoyopass: id: 62a59a68678c9b1480a53389 label: '통행증 삭제' + HomeAliasStopTravelerRemovalLoop: + id: 62a33634d3ab72600628e825 + label: '좋아' + DeleteUid: + id: 632c4b71716ee4246f3f693c + label: '캐릭터 삭제' ListTravelerStatus: @@ -43,6 +49,7 @@ blocks: id: 62a6f1a9c9058012cdfadb82 label: '출첵 로그' + ListUserRedeem: id: 6325c4039a89c94b38666e4f label: '여행자 별 로그'