Skip to content

Commit

Permalink
#29 Change UidListView to support traveler removal loop
Browse files Browse the repository at this point in the history
  • Loading branch information
binchoo committed Sep 22, 2022
1 parent fdaf20a commit 40cc59a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +16,7 @@
* @since : 2022-06-12
*/
@Configuration
public class ErrorExplainConfig {
public class ErrorContextBinderConfig {

@Bean
public ErrorContextBinders errorContextBinders() {
Expand Down Expand Up @@ -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("일일 출석을 수행한 이력이 없습니다.")
Expand All @@ -62,7 +65,7 @@ public ErrorContextBinders errorContextBinders() {
.build());

binders.add(CryptoExceptionBinder.builder()
.text("옳지 않은 방법으로 만들어진 QR 코드인 것 같습니다.")
.text("옳지 않은 방법으로 만들어진 QR 코드 같습니다.")
.fallbacks(FallbackMethods.Home, FallbackMethods.ScanHoyopass, FallbackMethods.CommonCs)
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,54 @@
@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<Hoyopass> hoyopasses = secureHoyopassRegister.listHoyopasses(botUserId);
model.addAttribute(SkillResponseView.CONTENT_KEY, hoyopasses);
List<Hoyopass> hoyopasses = hoyopassRegister.listHoyopasses(botUserId);

model.addAttribute(CONTENT_KEY, hoyopasses);

return "hoyopassListView";
}

@RequestMapping(value = "/delete", method = RequestMethod.POST)
public String deleteHoyopass(@UserId String botUserId,
@ClientExtra("index") int index, Model model) {
secureHoyopassRegister.deleteHoyopass(botUserId, index);

List<Hoyopass> hoyopasses = secureHoyopassRegister.listHoyopasses(botUserId);
model.addAttribute(SkillResponseView.CONTENT_KEY, hoyopasses);
hoyopassRegister.deleteHoyopass(botUserId, index);

List<Hoyopass> hoyopasses = hoyopassRegister.listHoyopasses(botUserId);
model.addAttribute(CONTENT_KEY, hoyopasses);

return "hoyopassListView";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
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;
import org.binchoo.paimonganyu.ikakao.component.SimpleTextView;
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;

/**
Expand All @@ -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();
}
Expand All @@ -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<Uid>) modelContent);
return renderSkillResponse((List<Hoyopass>) modelContent);
}

private SkillResponse renderSkillResponse(List<Uid> uids) {
List<UidValue> modelValues = uids.stream().map(UidValue::new)
.collect(Collectors.toList());
private SkillResponse renderSkillResponse(List<Hoyopass> passes) {
List<UidDto> 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<UidValue> modelValues) {
private SkillTemplate templateOf(List<UidDto> 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<UidValue> modelValues) {
private Carousel carouselOf(List<UidDto> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ blocks:
ListHoyopassAliasDeleteHoyopass:
id: 62a59a68678c9b1480a53389
label: '통행증 삭제'
HomeAliasStopTravelerRemovalLoop:
id: 62a33634d3ab72600628e825
label: '좋아'
DeleteUid:
id: 632c4b71716ee4246f3f693c
label: '캐릭터 삭제'


ListTravelerStatus:
Expand All @@ -43,6 +49,7 @@ blocks:
id: 62a6f1a9c9058012cdfadb82
label: '출첵 로그'


ListUserRedeem:
id: 6325c4039a89c94b38666e4f
label: '여행자 별 로그'
Expand Down

0 comments on commit 40cc59a

Please sign in to comment.