Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: redirectUrl 추상화 #679

Merged
merged 9 commits into from
Dec 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.zzang.chongdae.offering.repository.entity.OfferingEntity;
import com.zzang.chongdae.offeringmember.repository.entity.OfferingMemberEntity;
import java.util.Arrays;
import org.springframework.web.util.UriComponentsBuilder;

public record CommentRoomInfoResponse(CommentRoomStatus status,
String imageUrl,
Expand Down Expand Up @@ -42,11 +41,11 @@ public CommentRoomInfoResponse(OfferingMemberEntity offeringMember, String resou

private enum ViewMapper {

DELETED_VIEW(DELETED, imageUrl("DELETED"), "삭제된 공고", "삭제된 공동구매입니다."),
GROUPING_VIEW(GROUPING, imageUrl("GROUPING"), "인원확정", "공동구매에 참여할 인원이\n모이면 인원을 확정하세요."),
BUYING_VIEW(BUYING, imageUrl("BUYING"), "구매확정", "총대가 물품 구매를 완료하면 확정하세요."),
TRADING_VIEW(TRADING, imageUrl("TRADING"), "거래확정", "총대가 참여자들과\n거래를 완료하면 확정하세요."),
DONE_VIEW(DONE, imageUrl("DONE"), "거래완료", "거래가 완료되었어요.");
DELETED_VIEW(DELETED, "DELETED", "삭제된 공고", "삭제된 공동구매입니다."),
GROUPING_VIEW(GROUPING, "GROUPING", "인원확정", "공동구매에 참여할 인원이\n모이면 인원을 확정하세요."),
BUYING_VIEW(BUYING, "BUYING", "구매확정", "총대가 물품 구매를 완료하면 확정하세요."),
TRADING_VIEW(TRADING, "TRADING", "거래확정", "총대가 참여자들과\n거래를 완료하면 확정하세요."),
DONE_VIEW(DONE, "DONE", "거래완료", "거래가 완료되었어요.");

private final CommentRoomStatus roomStatus;
private final String image;
Expand All @@ -61,12 +60,7 @@ private enum ViewMapper {
}

private static String toImage(CommentRoomStatus status, String resourceHost) {
return UriComponentsBuilder.newInstance()
.scheme("https")
.host(resourceHost)
.path(findViewMapper(status).image)
.build(false)
.toString();
return "https://%s/common/%s.png".formatted(resourceHost, findViewMapper(status).image);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 커밋에서 작업하신 개선 사항을 이전 커밋에서 필요해보여 길게 조심스럽게 제안해두었는데, 역시 포케도 저와 뜻이 같았군요 ㅎㅎ 훨씬 깔끔하고 좋네요! 이런 리팩터링 너무 좋습니다 👏

}

private static String toButton(CommentRoomStatus status) {
Expand All @@ -83,10 +77,5 @@ private static ViewMapper findViewMapper(CommentRoomStatus status) {
.findFirst()
.orElseThrow(() -> new MarketException(OfferingErrorCode.INVALID_CONDITION));
}

private static String imageUrl(String status) {
String imageUrlFormat = "/common/%s.png";
return String.format(imageUrlFormat, status);
}
}
}