code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -0,0 +1,56 @@ +import { print, priceToString } from "../commons/utils.js"; +import { MESSAGE, ARRAY, BENEFIT_AMOUNT } from "../commons/constants.js"; + +const OutputView = { + printStart() { + print(MESSAGE.START); + }, + + printOrderInformation(date, menu) { + print(MESSAGE.MONTH + date + MESSAGE.SHOW_BENEFIT); + print(MESSAGE.MENU); + menu[ARRAY.MENU].forEach((menuName, index) => { + print(menuName + MESSAGE.BLANK + menu[ARRAY.COUNT][index] + MESSAGE.EA); + }); + }, + + printAllAmount(amount) { + print(MESSAGE.TOTAL_AMOUNT); + print(priceToString(amount) + MESSAGE.WON); + }, + + printGiveaway(benefitResult) { + print(MESSAGE.GIVEAWAY); + if (benefitResult[ARRAY.GIVEAWAY] !== 0) print(MESSAGE.GIVEAWAY_ITEM); + else print(MESSAGE.NOTHING); + }, + + printBenefitDetail(benefitResult) { + print(MESSAGE.BENEFIT_DETAILS); + if (JSON.stringify(benefitResult) === "[0,0,0,0,0]") { + print(MESSAGE.NOTHING); + } else { + benefitResult.forEach((benefit, index) => { + if (benefit !== 0) print(MESSAGE.BENEFIT_DETAILS_TITLE[index] + priceToString(benefit) + MESSAGE.WON); + }); + } + }, + + printTotalBenefit(totalBenefit) { + print(MESSAGE.TOTAL_BENEFIT); + if (totalBenefit > 0) print(MESSAGE.HYPEN + priceToString(totalBenefit) + MESSAGE.WON); + else print(priceToString(totalBenefit) + MESSAGE.WON); + }, + + printExpectedAmount(expectedAmount) { + print(MESSAGE.EXPECTED_AMOUNT); + print(priceToString(expectedAmount) + MESSAGE.WON); + }, + + printEventBadge(eventBadge) { + print(MESSAGE.EVENT_BADGE); + print(eventBadge); + }, +}; + +export default OutputView;
JavaScript
else ๋ฅผ ์ง€์–‘ํ•˜๋ผ๋Š” ์š”๊ตฌ์‚ฌํ•ญ์ด ์žˆ์–ด์„œ, ์œ„์— if๋ฌธ์— return ํ•ด์ฃผ๋Š” ๋ฐฉ์‹์„ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,135 @@ +package christmas.validator; + +import christmas.constant.Constants; +import christmas.constant.ErrorMessage; +import christmas.constant.Menu; +import christmas.util.Utils; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class OrderValidator implements Validator { + @Override + public void check(String input) { + chechDefaultTemplate(input); + checkValidatedForm(input); + checkIfStringMenu(input); + checkQuantityRange(input); + checkIfMenuExists(input); + checkForDuplicateMenu(input); + checkTotalMenuCount(input); + checkBeverageOnly(input); + } + + private void chechDefaultTemplate(final String input) { + List<String> orderItems = Arrays.asList(input.split(",")); + + orderItems.stream() + .map(item -> item.split("-")) + .forEach(parts -> { + try { + if (parts.length != 2 || !parts[1].matches("\\d+")) { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + } + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + } + }); + } + + private void checkValidatedForm(final String input) { // ์œ ํšจํ•˜์ง€์•Š์€ ์ž…๋ ฅ (๊ธฐ๋ณธ ํ…œํ”Œ๋ฆฟ ์ž…๋ ฅ์ด ์•„๋‹Œ ๊ฒฝ์šฐ) [์š”์ฒญ ์‚ฌํ•ญ ์กด์žฌ] + try { + Map<String, Integer> resultMap = Stream.of(input.split(",")) + .map(s -> s.split("-")).collect(Collectors.toMap( + arr -> arr[0], + arr -> Integer.parseInt(arr[1]), + (existing, replacement) -> existing, + HashMap::new + )); + // {"ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€": 2, "๋ ˆ๋“œ์™€์ธ": 1, ...} + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + } + } + + private void checkIfStringMenu(final String input) { // ๋ฉ”๋‰ด(key) ๋ถ€๋ถ„์ด String, ์ฆ‰ ๋ฌธ์ž์—ด(ํ•œ๊ธ€,์˜์–ด)์ด ์•„๋‹ˆ๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ [์š”์ฒญ ํ…œํ”Œ๋ฆฟ] + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + menu.keySet().stream() + .filter(key -> !key.matches("[a-zA-Z๊ฐ€-ํžฃ]+")) + .findAny() + .ifPresent(invalidKey -> { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + }); + } + + private void checkQuantityRange(final String input) { // ์ˆ˜๋Ÿ‰์ด ๊ฐ๊ฐ 1์ด์ƒ 20์ดํ•˜ ๊ฐ€ ์•„๋‹ˆ๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ [์š”์ฒญ ์‚ฌํ•ญ ์กด์žฌ] + try { + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + menu.entrySet().stream() + .filter(entry -> entry.getValue() < 1 || entry.getValue() > 20) + .findAny() + .ifPresent(entry -> { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + }); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + } + } + + private void checkIfMenuExists(final String input) { // ์—†๋Š” ๋ฉ”๋‰ด์ผ์ง€ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ( ex) T๋ณธ์Šคํ…Œ์ดํฌ ) [์š”์ฒญ ์‚ฌํ•ญ ์กด์žฌ] + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + + Set<String> availableMenuItems = Arrays.stream(Menu.values()) + .map(menuEnum -> menuEnum.getName()) + .collect(Collectors.toSet()); + + menu.keySet().stream() + .filter(inputMenu -> !availableMenuItems.contains(inputMenu)) + .findAny() + .ifPresent(invalidKey -> { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + }); + } + + private void checkForDuplicateMenu(final String input) { + Map<String, Integer> resultMap = Stream.of(input.split(",")) + .map(s -> s.split("-")) + .collect(Collectors.toMap( + arr -> arr[0], + arr -> Integer.parseInt(arr[1]), + (existing, replacement) -> { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + }, + HashMap::new + )); + } + + private void checkTotalMenuCount(final String input) { + // ๋ฉ”๋‰ด ๊ฐœ์ˆ˜์˜ ํ•ฉ์ด 20๊ฐœ๊ฐ€ ์ดˆ๊ณผํ• ์‹œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + int total = menu.values().stream().mapToInt(Integer::intValue).sum(); + + if (total > Constants.MENU_LIMIT.getConstants()) { + throw new IllegalArgumentException(ErrorMessage.TOTAL_MENU_COUNT_IS_OVER.getMessage()); + } + } + + private void checkBeverageOnly(final String input) { + // ๊ฐ ๋ฉ”๋‰ด์— ์Œ๋ฃŒ ํด๋ž˜์Šค๋งŒ ์žˆ์œผ๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ + + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + List<String> onlyBeverage = Menu.BEVERAGE_MENU; + + List<String> matchCount = menu.keySet().stream() + .filter(onlyBeverage::contains) + .toList(); + + if (menu.size() == matchCount.size()) { + throw new IllegalArgumentException(ErrorMessage.ORDER_ONLY_BEVERAGE.getMessage()); + } + } +}
Java
https://www.inflearn.com/questions/819415/verify-validate-check-is verify, validate, check, is ์˜ ๋„ค์ด๋ฐ ์ฐจ์ด์— ๋Œ€ํ•ด์„œ ์„ค๋ช…ํ•˜๋Š” ๊ธ€์ธ๋ฐ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,25 @@ +package christmas.validator; + +import christmas.constant.ErrorMessage; + +public class DateValidator implements Validator{ + @Override + public void check(final String input) { + checkInteger(input); + checkOutOfRange(input); + } + + private void checkInteger(final String input) { + try { + Integer.parseInt(input); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(ErrorMessage.DATE_OUT_OF_RANGE.getMessage()); + } + } + private void checkOutOfRange(final String input) { + int date = Integer.parseInt(input); + if (date < 1 || date > 31) { + throw new IllegalArgumentException(ErrorMessage.DATE_OUT_OF_RANGE.getMessage()); + } + } +}
Java
1๊ณผ 31์ด ๋งค์ง๋„˜๋ฒ„๋ผ๊ณ  ์ƒ๊ฐํ•ด์š”! ์ƒ์ˆ˜๋กœ ๋นผ์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,28 @@ +package christmas.domain; + +import christmas.util.Utils; +import christmas.view.OutputView; + +public class OrderPrice { + // ๊ธˆ์•ก๊ณผ ๊ด€๋ จ๋œ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค. + // ํ• ์ธ ์ „ ์ด ์ฃผ๋ฌธ๊ธˆ์•ก, ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก ๋“ฑ์„ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค ์ž…๋‹ˆ๋‹ค. + private static final String UNIT = "์›"; + private OrderRepository orders; + private int totalAmount; + + public OrderPrice(final OrderRepository orders) { + this.orders = orders; + } + + public void printBeforeDiscountInfo() { + this.totalAmount = orders.calculateTotalAmount(); + + OutputView.printBeforeDiscount(); + String result = Utils.makeFormattedNumberWithComma(this.totalAmount); + OutputView.printMessage(result + UNIT); + } + + public int getTotalAmount() { + return totalAmount; + } +}
Java
'์›' ๊ฐ™์€ ๋‹จ์œ„๋Š” ์ถœ๋ ฅ ๋ฐ ํฌ๋งคํŒ…๊ณผ ๊ด€๊ณ„์žˆ์œผ๋ฏ€๋กœ OutputView์— ์žˆ๋Š” ๊ฒƒ์ด ์ข€ ๋” ์ ์ ˆํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”??ใ…Žใ…Ž
@@ -0,0 +1,40 @@ +package christmas.domain; + +import christmas.view.OutputView; + +public class EventBadge { + // ์ด๋ฒคํŠธ ๋ฑƒ์ง€๋ฅผ ๊ด€๋ฆฌ ํ•˜๋Š” ํด๋ž˜์Šค ์ž…๋‹ˆ๋‹ค. + private static final int SANTA_MINIMUM_LIMIT = 20000; + private static final int TREE_MINIMUM_LIMIT = 20000; + private static final int STAR_MINIMUM_LIMIT = 20000; + private static final String SANTA = "์‚ฐํƒ€"; + private static final String TREE = "ํŠธ๋ฆฌ"; + private static final String STAR = "๋ณ„"; + + private static final String NOTHING = "์—†์Œ"; + + private int discountAmount; + + public EventBadge(final int discountAmount) { + this.discountAmount = discountAmount; + } + + public void printEventBadge() { + OutputView.printEventBadge(); + String badge = determineBadge(discountAmount); + OutputView.printMessage(badge); + } + + private String determineBadge(final int discountAmount) { + if (-discountAmount >= SANTA_MINIMUM_LIMIT) { + return SANTA; + } + if (-discountAmount >= TREE_MINIMUM_LIMIT) { + return TREE; + } + if (-discountAmount >= STAR_MINIMUM_LIMIT) { + return STAR; + } + return NOTHING; + } +}
Java
์ฒ˜์Œ๋ณด๋Š” ์‚ฌ๋žŒ์€ discountAmount์— -๋ฅผ ์™œ ๋ถ™์ด์ง€? ๋ผ๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค! ์ €๋„ ๋น„์Šทํ•˜๊ฒŒ ๊ตฌํ˜„ํ•˜๊ณ  ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์•˜๋Š”๋ฐ ๋ณ€์ˆ˜์ด๋ฆ„๊ณผ final์„ ์ด์šฉํ•ด -๋ฅผ ๋ถ™์ธ ๋ณ€์ˆ˜๊ฐ€ ๋ฌด์—‡์„ ๋œปํ•˜๋Š”์ง€ ํ•œ๋ฒˆ ๋” ์ •์˜ํ•ด์ฃผ๋Š” ๊ฒƒ๋„ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•ด์š”!
@@ -0,0 +1,178 @@ +package christmas.domain; + +import christmas.constant.Constants; +import christmas.constant.Menu; +import christmas.constant.MenuType; +import christmas.util.Utils; +import christmas.view.OutputView; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class BenefitInformation { + // ๋ชจ๋“  ํ˜œํƒ๊ณผ ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค ์ž…๋‹ˆ๋‹ค. + private static final String UNIT = "์›"; + private static final int CHAMPAGNE_PRICE = 25000; + private Date date; + private OrderRepository orderRepository; + + public BenefitInformation(final Date date, final OrderRepository orderRepository) { + this.date = date; + this.orderRepository = orderRepository; + } + + public void printDiscountInfo() { + OutputView.printBenefit(); + int totalAmount = orderRepository.calculateTotalAmount(); + + if (totalAmount < Constants.MINIMUM_DISCOUNT_ABLE_AMOUNT.getConstants()) { + OutputView.printNothing(); + return; + } + List<String> discounts = calculateDiscounts(date, totalAmount); + + if (discounts.isEmpty()) { + OutputView.printNothing(); + return; + } + printDiscountMessages(discounts); + } + + public void printTotalDiscount(final int Amount) { + OutputView.printTotalBenefit(); + + int totalAmount = Amount; + + if (totalAmount < Constants.MINIMUM_DISCOUNT_ABLE_AMOUNT.getConstants()) { + OutputView.printMessage("0" + UNIT); + return; + } + + int result = calculateTotalDiscount(totalAmount); + OutputView.printMessage(Utils.makeFormattedNumberWithComma(result) + UNIT); + } + + public void printPaymentAmountAfterDiscount(final int totalAmount) { + OutputView.printAfterDiscount(); + + int result = calculateAfterDiscount(totalAmount); + OutputView.printMessage(Utils.makeFormattedNumberWithComma(result) + UNIT); + } + + public int calculateTotalDiscount(final int totalAmount) { + int totalDiscount = 0; + + if (totalAmount > 10000) { + totalDiscount += calculateChristmasDiscount(date); + totalDiscount += calculateWeekdayWeekendDiscount(date); + totalDiscount += calculateSpecialDiscount(date); + } + + if (totalAmount > Constants.CHAMPAGNE_LIMIT.getConstants()) { + totalDiscount -= CHAMPAGNE_PRICE; + } + + return totalDiscount; + } + + private int calculateAfterDiscount(int totalAmount) { + if (totalAmount > Constants.CHAMPAGNE_LIMIT.getConstants()) { + totalAmount += CHAMPAGNE_PRICE; + } + int totalDiscount = calculateTotalDiscount(totalAmount); + return totalAmount + totalDiscount; + } + + private List<String> calculateDiscounts(final Date date, final int totalAmount) { + List<String> discounts = new ArrayList<>(); + + addDiscountInfo(discounts, "ํฌ๋ฆฌ์Šค๋งˆ์Šค ๋””๋ฐ์ด ํ• ์ธ", calculateChristmasDiscount(date)); + if (isWeekend(date)) { + addDiscountInfo(discounts, "์ฃผ๋ง ํ• ์ธ", calculateWeekdayWeekendDiscount(date)); + } + if (!isWeekend(date)) { + addDiscountInfo(discounts, "ํ‰์ผ ํ• ์ธ", calculateWeekdayWeekendDiscount(date)); + } + addDiscountInfo(discounts, "ํŠน๋ณ„ ํ• ์ธ", calculateSpecialDiscount(date)); + + if (totalAmount > Constants.CHAMPAGNE_LIMIT.getConstants()) { + addDiscountInfo(discounts, "์ฆ์ • ์ด๋ฒคํŠธ", -CHAMPAGNE_PRICE); + } + return discounts; + } + + private boolean isWeekend(Date date) { + LocalDate localDate = LocalDate.of(Constants.THIS_YEAR.getConstants(), Constants.EVENT_MONTH.getConstants(), + date.getDate()); + DayOfWeek dayOfWeek = localDate.getDayOfWeek(); + return dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY; + } + + private void printDiscountMessages(final List<String> discounts) { + discounts.forEach(OutputView::printMessage); + } + + private void addDiscountInfo(final List<String> discounts, final String discountName, final int discountAmount) { + if (discountAmount != 0) { + discounts.add(discountName + ": " + Utils.makeFormattedNumberWithComma(discountAmount) + UNIT); + } + } + + private int calculateChristmasDiscount(Date date) { + int christmasDiscount = 0; + int dayOfMonth = date.getDate(); + + if (dayOfMonth >= Constants.EVENT_START_DATE.getConstants() + && dayOfMonth <= Constants.EVENT_END_DATE.getConstants()) { + int discountPerDay = 1000 + (dayOfMonth - 1) * 100; // ์ผ์ผ ํ• ์ธ์•ก ๊ณ„์‚ฐ + christmasDiscount += discountPerDay; + } + + return -christmasDiscount; + } + + + private int calculateWeekdayWeekendDiscount(final Date date) { + int weekdayWeekendDiscount = 0; + + LocalDate localDate = LocalDate.of(Constants.THIS_YEAR.getConstants(), Constants.EVENT_MONTH.getConstants(), + date.getDate()); + DayOfWeek dayOfWeek = localDate.getDayOfWeek(); + + if (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY) { + weekdayWeekendDiscount = -calculateMainDiscount(); + return weekdayWeekendDiscount; + } + + weekdayWeekendDiscount = -calculateDessertDiscount(); + return weekdayWeekendDiscount; + } + + + private int calculateDessertDiscount() { + List<Order> orders = orderRepository.getOrderList(); + + return orders.stream().filter(order -> Menu.getMenuName(order.retrieveMenuName()).getType() == MenuType.DESSERT) + .mapToInt(order -> Constants.THIS_YEAR.getConstants() * order.retrieveMenuQuantity()).sum(); + } + + private int calculateMainDiscount() { + List<Order> orders = orderRepository.getOrderList(); + + return orders.stream().filter(order -> Menu.getMenuName(order.retrieveMenuName()).getType() == MenuType.MAIN) + .mapToInt(order -> Constants.THIS_YEAR.getConstants() * order.retrieveMenuQuantity()).sum(); + } + + private int calculateSpecialDiscount(final Date date) { + int specialDiscount = 0; + + int day = date.getDate(); + + if (day == 3 || day == 10 || day == 17 || day == 24 || day == 25 || day == 31) { + specialDiscount = -1000; + } + + return specialDiscount; + } +}
Java
๋งค์ง๋„˜๋ฒ„๊ฐ€ ๋งŽ์ด ์“ฐ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์œ„์—์„œ ์ƒ์ˆ˜๋กœ ์„ ์–ธํ•ด์ฃผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~!!
@@ -0,0 +1,105 @@ +package christmas.controller; + +import christmas.domain.BenefitInformation; +import christmas.domain.Date; +import christmas.domain.EventBadge; +import christmas.domain.GiftMenu; +import christmas.domain.Order; +import christmas.domain.OrderManager; +import christmas.domain.OrderPrice; +import christmas.domain.OrderRepository; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; + +public class EventPlannerController { + private final InputView inputView; + private final OrderRepository orderRepository; + private Date date; + private int Amount; + + public EventPlannerController(final InputView inputView, final OrderRepository orderRepository) { + this.inputView = inputView; + this.orderRepository = orderRepository; + } + + public void run() { + initialize(); + printResult(); + + } + + private void initialize() { + OutputView.printWelcome(); + int dateInput = readDateUntilSuccess(); + date = new Date(dateInput); + Map<String, Integer> menuOrder = readMenuAndQuantityForOrderUntilSuccess(); + + menuOrder.entrySet().stream() + .map(menu -> new Order(menu.getKey(), menu.getValue())) + .forEach(orderRepository::addOrder); + OutputView.printBenefit(date.getDate()); + } + + private void printResult() { + printOrderMenu(); + printTotalOrderAmountBeforeDiscount(); + printGiftMenu(); + BenefitInformation benefitInformation = printBenefitDetail(); + printEventBadge(benefitInformation); + } + + private void printEventBadge(final BenefitInformation benefitInformation) { + int result = benefitInformation.calculateTotalDiscount(Amount); + EventBadge eventBadge = new EventBadge(result); + eventBadge.printEventBadge(); + } + + private BenefitInformation printBenefitDetail() { + BenefitInformation benefitInformation = new BenefitInformation(date, orderRepository); + benefitInformation.printDiscountInfo(); + + benefitInformation.printTotalDiscount(Amount); + benefitInformation.printPaymentAmountAfterDiscount(Amount); + return benefitInformation; + } + + private void printGiftMenu() { + GiftMenu giftMenu = new GiftMenu(Amount); + giftMenu.printGiftInfo(); + } + + private void printTotalOrderAmountBeforeDiscount() { + OrderPrice orderPriceInfo = new OrderPrice(orderRepository); + orderPriceInfo.printBeforeDiscountInfo(); + Amount = orderPriceInfo.getTotalAmount(); + } + + private void printOrderMenu() { + OrderManager orderInfo = new OrderManager(orderRepository); + orderInfo.printAllDetail(); + } + + private int readDateUntilSuccess() { + while (true) { + try { + int dateInput = inputView.readDate(); + return dateInput; + } catch (IllegalArgumentException exception) { + OutputView.printMessage(exception.getMessage()); + } + } + } + + private Map<String, Integer> readMenuAndQuantityForOrderUntilSuccess() { + while (true) { + try { + Map<String, Integer> menuAndQuantityForOrder = inputView.readMenuAndQuantityForOrder(); + return menuAndQuantityForOrder; + } catch (IllegalArgumentException exception) { + OutputView.printMessage(exception.getMessage()); + } + } + } +} +
Java
๋„๋ฉ”์ธ๋ณด๋‹ค๋Š” controller์—์„œ outputView๋ฅผ ํ˜ธ์ถœํ•ด์ฃผ๋Š” ๊ตฌ์กฐ๊ฐ€ ๋˜์–ด์•ผํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค ใ…Žใ…Ž ๋งŒ์•ฝ mvc ๊ตฌ์กฐ๋ผ๋ฉด์š”!!
@@ -0,0 +1,21 @@ +package christmas.constant; + +public enum Constants { + EVENT_START_DATE(1), + EVENT_END_DATE(25), + MENU_LIMIT(20), + CHAMPAGNE_LIMIT(120000), + MINIMUM_DISCOUNT_ABLE_AMOUNT(10000), + THIS_YEAR(2023), + EVENT_MONTH(12); + + public int constants; + + Constants(final int constants) { + this.constants = constants; + } + + public int getConstants() { + return constants; + } +}
Java
ํ•ด๋‹น ์ƒ์ˆ˜ ๊ฐ’๋“ค์„ ํ•„์š”ํ•œ ๊ฐ ๋„๋ฉ”์ธ์ด ๋“ค๊ณ  ์žˆ๋Š” ๊ฒƒ์€ ์–ด๋–ค๊ฐ€์š”~~?? ๊ทธ๋ ‡๊ฒŒ ํ•˜๋ฉด ํด๋ž˜์Šค์˜ ์‘์ง‘๋„๋ฅผ ์กฐ๊ธˆ ๋” ๋†’์ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,13 @@ +package christmas.domain; + +public class Date { + private int date; + + public Date(final int date) { + this.date = date; + } + + public int getDate() { + return this.date; + } +} \ No newline at end of file
Java
ํ•ด๋‹น ํด๋ž˜์Šค๊ฐ€ ์กด์žฌํ•˜๋Š” ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?!! ํด๋ž˜์Šค๋กœ์„œ ์™„์ „ํ•˜๋ ค๋ฉด Date์™€ ๊ด€๋ จ๋œ validate ์ฝ”๋“œ๊ฐ€ ์ƒ์„ฑ์ž ์•ˆ์— ์žˆ์–ด์•ผํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค..!!!
@@ -0,0 +1,13 @@ +package christmas.domain; + +public class Date { + private int date; + + public Date(final int date) { + this.date = date; + } + + public int getDate() { + return this.date; + } +} \ No newline at end of file
Java
๋˜ํ•œ record๋กœ ๋ฐ”๊ฟ”๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š” ใ…Žใ…Ž
@@ -0,0 +1,21 @@ +package christmas.constant; + +public enum Constants { + EVENT_START_DATE(1), + EVENT_END_DATE(25), + MENU_LIMIT(20), + CHAMPAGNE_LIMIT(120000), + MINIMUM_DISCOUNT_ABLE_AMOUNT(10000), + THIS_YEAR(2023), + EVENT_MONTH(12); + + public int constants; + + Constants(final int constants) { + this.constants = constants; + } + + public int getConstants() { + return constants; + } +}
Java
๊ฐ ๋„๋ฉ”์ธ์ด ๋“ค๋ฉฐ ์‘์ง‘๋„๋ฅผ ๋†’ํžˆ๋Š” ๋ฐฉ๋ฒ•๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ๐Ÿซ 
@@ -0,0 +1,105 @@ +package christmas.controller; + +import christmas.domain.BenefitInformation; +import christmas.domain.Date; +import christmas.domain.EventBadge; +import christmas.domain.GiftMenu; +import christmas.domain.Order; +import christmas.domain.OrderManager; +import christmas.domain.OrderPrice; +import christmas.domain.OrderRepository; +import christmas.view.InputView; +import christmas.view.OutputView; +import java.util.Map; + +public class EventPlannerController { + private final InputView inputView; + private final OrderRepository orderRepository; + private Date date; + private int Amount; + + public EventPlannerController(final InputView inputView, final OrderRepository orderRepository) { + this.inputView = inputView; + this.orderRepository = orderRepository; + } + + public void run() { + initialize(); + printResult(); + + } + + private void initialize() { + OutputView.printWelcome(); + int dateInput = readDateUntilSuccess(); + date = new Date(dateInput); + Map<String, Integer> menuOrder = readMenuAndQuantityForOrderUntilSuccess(); + + menuOrder.entrySet().stream() + .map(menu -> new Order(menu.getKey(), menu.getValue())) + .forEach(orderRepository::addOrder); + OutputView.printBenefit(date.getDate()); + } + + private void printResult() { + printOrderMenu(); + printTotalOrderAmountBeforeDiscount(); + printGiftMenu(); + BenefitInformation benefitInformation = printBenefitDetail(); + printEventBadge(benefitInformation); + } + + private void printEventBadge(final BenefitInformation benefitInformation) { + int result = benefitInformation.calculateTotalDiscount(Amount); + EventBadge eventBadge = new EventBadge(result); + eventBadge.printEventBadge(); + } + + private BenefitInformation printBenefitDetail() { + BenefitInformation benefitInformation = new BenefitInformation(date, orderRepository); + benefitInformation.printDiscountInfo(); + + benefitInformation.printTotalDiscount(Amount); + benefitInformation.printPaymentAmountAfterDiscount(Amount); + return benefitInformation; + } + + private void printGiftMenu() { + GiftMenu giftMenu = new GiftMenu(Amount); + giftMenu.printGiftInfo(); + } + + private void printTotalOrderAmountBeforeDiscount() { + OrderPrice orderPriceInfo = new OrderPrice(orderRepository); + orderPriceInfo.printBeforeDiscountInfo(); + Amount = orderPriceInfo.getTotalAmount(); + } + + private void printOrderMenu() { + OrderManager orderInfo = new OrderManager(orderRepository); + orderInfo.printAllDetail(); + } + + private int readDateUntilSuccess() { + while (true) { + try { + int dateInput = inputView.readDate(); + return dateInput; + } catch (IllegalArgumentException exception) { + OutputView.printMessage(exception.getMessage()); + } + } + } + + private Map<String, Integer> readMenuAndQuantityForOrderUntilSuccess() { + while (true) { + try { + Map<String, Integer> menuAndQuantityForOrder = inputView.readMenuAndQuantityForOrder(); + return menuAndQuantityForOrder; + } catch (IllegalArgumentException exception) { + OutputView.printMessage(exception.getMessage()); + } + } + } +} +
Java
MVC ๋งŽ์ด ๊ณต๋ถ€ํ•ด์•ผ ๊ฒ ๋„ค์š” ใ… ใ… 
@@ -0,0 +1,13 @@ +package christmas.domain; + +public class Date { + private int date; + + public Date(final int date) { + this.date = date; + } + + public int getDate() { + return this.date; + } +} \ No newline at end of file
Java
recordํ˜•์€ ์„œ์šฐ๋‹˜ ์ฝ”๋“œ ๋ณด๋ฉด์„œ ์ฒ˜์Œ ๋ฐฐ์› ๋Š”๋ฐ ์œ ์šฉํ•˜๊ฒŒ ์ž˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ! `date`์— `validate`๊ฐ€ ์—†๋Š” ์ด์ƒ์€ ์‚ฌ์‹ค ์˜๋ฏธ๊ฐ€ ์—†๋Š”๊ฑฐ ๊ฐ™๋„ค์š”,,ใ…Žใ…Ž
@@ -0,0 +1,40 @@ +package christmas.domain; + +import christmas.view.OutputView; + +public class EventBadge { + // ์ด๋ฒคํŠธ ๋ฑƒ์ง€๋ฅผ ๊ด€๋ฆฌ ํ•˜๋Š” ํด๋ž˜์Šค ์ž…๋‹ˆ๋‹ค. + private static final int SANTA_MINIMUM_LIMIT = 20000; + private static final int TREE_MINIMUM_LIMIT = 20000; + private static final int STAR_MINIMUM_LIMIT = 20000; + private static final String SANTA = "์‚ฐํƒ€"; + private static final String TREE = "ํŠธ๋ฆฌ"; + private static final String STAR = "๋ณ„"; + + private static final String NOTHING = "์—†์Œ"; + + private int discountAmount; + + public EventBadge(final int discountAmount) { + this.discountAmount = discountAmount; + } + + public void printEventBadge() { + OutputView.printEventBadge(); + String badge = determineBadge(discountAmount); + OutputView.printMessage(badge); + } + + private String determineBadge(final int discountAmount) { + if (-discountAmount >= SANTA_MINIMUM_LIMIT) { + return SANTA; + } + if (-discountAmount >= TREE_MINIMUM_LIMIT) { + return TREE; + } + if (-discountAmount >= STAR_MINIMUM_LIMIT) { + return STAR; + } + return NOTHING; + } +}
Java
๋ชจ๋ฅด๋Š” ์‚ฌ๋žŒ์ด ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ์™œ ์žˆ์ง€? ์ƒ๊ฐํ•  ์ˆ˜๋Š” ์žˆ๊ฒ ๋„ค์š”! ๋ณ€์ˆ˜๋ช…๊ณผ, ์ฃผ์„์„ ํ†ตํ•ด ์˜๋ฏธ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ธ ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿซ 
@@ -0,0 +1,28 @@ +package christmas.domain; + +import christmas.util.Utils; +import christmas.view.OutputView; + +public class OrderPrice { + // ๊ธˆ์•ก๊ณผ ๊ด€๋ จ๋œ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค. + // ํ• ์ธ ์ „ ์ด ์ฃผ๋ฌธ๊ธˆ์•ก, ํ• ์ธ ํ›„ ์˜ˆ์ƒ ๊ฒฐ์ œ ๊ธˆ์•ก ๋“ฑ์„ ๊ด€๋ฆฌํ•˜๋Š” ํด๋ž˜์Šค ์ž…๋‹ˆ๋‹ค. + private static final String UNIT = "์›"; + private OrderRepository orders; + private int totalAmount; + + public OrderPrice(final OrderRepository orders) { + this.orders = orders; + } + + public void printBeforeDiscountInfo() { + this.totalAmount = orders.calculateTotalAmount(); + + OutputView.printBeforeDiscount(); + String result = Utils.makeFormattedNumberWithComma(this.totalAmount); + OutputView.printMessage(result + UNIT); + } + + public int getTotalAmount() { + return totalAmount; + } +}
Java
๋”ฐ๋กœ OutputView ํด๋ž˜์Šค์— ์„ ์–ธํ•˜๋Š”๊ฒŒ ์ข€ ๋” ์ ์ ˆํ•ด ๋ณด์ด๋„ค์š” ใ…Žใ…Ž
@@ -0,0 +1,135 @@ +package christmas.validator; + +import christmas.constant.Constants; +import christmas.constant.ErrorMessage; +import christmas.constant.Menu; +import christmas.util.Utils; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class OrderValidator implements Validator { + @Override + public void check(String input) { + chechDefaultTemplate(input); + checkValidatedForm(input); + checkIfStringMenu(input); + checkQuantityRange(input); + checkIfMenuExists(input); + checkForDuplicateMenu(input); + checkTotalMenuCount(input); + checkBeverageOnly(input); + } + + private void chechDefaultTemplate(final String input) { + List<String> orderItems = Arrays.asList(input.split(",")); + + orderItems.stream() + .map(item -> item.split("-")) + .forEach(parts -> { + try { + if (parts.length != 2 || !parts[1].matches("\\d+")) { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + } + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + } + }); + } + + private void checkValidatedForm(final String input) { // ์œ ํšจํ•˜์ง€์•Š์€ ์ž…๋ ฅ (๊ธฐ๋ณธ ํ…œํ”Œ๋ฆฟ ์ž…๋ ฅ์ด ์•„๋‹Œ ๊ฒฝ์šฐ) [์š”์ฒญ ์‚ฌํ•ญ ์กด์žฌ] + try { + Map<String, Integer> resultMap = Stream.of(input.split(",")) + .map(s -> s.split("-")).collect(Collectors.toMap( + arr -> arr[0], + arr -> Integer.parseInt(arr[1]), + (existing, replacement) -> existing, + HashMap::new + )); + // {"ํ•ด์‚ฐ๋ฌผํŒŒ์Šคํƒ€": 2, "๋ ˆ๋“œ์™€์ธ": 1, ...} + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + } + } + + private void checkIfStringMenu(final String input) { // ๋ฉ”๋‰ด(key) ๋ถ€๋ถ„์ด String, ์ฆ‰ ๋ฌธ์ž์—ด(ํ•œ๊ธ€,์˜์–ด)์ด ์•„๋‹ˆ๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ [์š”์ฒญ ํ…œํ”Œ๋ฆฟ] + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + menu.keySet().stream() + .filter(key -> !key.matches("[a-zA-Z๊ฐ€-ํžฃ]+")) + .findAny() + .ifPresent(invalidKey -> { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + }); + } + + private void checkQuantityRange(final String input) { // ์ˆ˜๋Ÿ‰์ด ๊ฐ๊ฐ 1์ด์ƒ 20์ดํ•˜ ๊ฐ€ ์•„๋‹ˆ๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ [์š”์ฒญ ์‚ฌํ•ญ ์กด์žฌ] + try { + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + menu.entrySet().stream() + .filter(entry -> entry.getValue() < 1 || entry.getValue() > 20) + .findAny() + .ifPresent(entry -> { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + }); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + } + } + + private void checkIfMenuExists(final String input) { // ์—†๋Š” ๋ฉ”๋‰ด์ผ์ง€ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ( ex) T๋ณธ์Šคํ…Œ์ดํฌ ) [์š”์ฒญ ์‚ฌํ•ญ ์กด์žฌ] + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + + Set<String> availableMenuItems = Arrays.stream(Menu.values()) + .map(menuEnum -> menuEnum.getName()) + .collect(Collectors.toSet()); + + menu.keySet().stream() + .filter(inputMenu -> !availableMenuItems.contains(inputMenu)) + .findAny() + .ifPresent(invalidKey -> { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + }); + } + + private void checkForDuplicateMenu(final String input) { + Map<String, Integer> resultMap = Stream.of(input.split(",")) + .map(s -> s.split("-")) + .collect(Collectors.toMap( + arr -> arr[0], + arr -> Integer.parseInt(arr[1]), + (existing, replacement) -> { + throw new IllegalArgumentException(ErrorMessage.NOT_VALIDATED_ORDER.getMessage()); + }, + HashMap::new + )); + } + + private void checkTotalMenuCount(final String input) { + // ๋ฉ”๋‰ด ๊ฐœ์ˆ˜์˜ ํ•ฉ์ด 20๊ฐœ๊ฐ€ ์ดˆ๊ณผํ• ์‹œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + int total = menu.values().stream().mapToInt(Integer::intValue).sum(); + + if (total > Constants.MENU_LIMIT.getConstants()) { + throw new IllegalArgumentException(ErrorMessage.TOTAL_MENU_COUNT_IS_OVER.getMessage()); + } + } + + private void checkBeverageOnly(final String input) { + // ๊ฐ ๋ฉ”๋‰ด์— ์Œ๋ฃŒ ํด๋ž˜์Šค๋งŒ ์žˆ์œผ๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ + + Map<String, Integer> menu = Utils.makeStringToHashMap(input); + List<String> onlyBeverage = Menu.BEVERAGE_MENU; + + List<String> matchCount = menu.keySet().stream() + .filter(onlyBeverage::contains) + .toList(); + + if (menu.size() == matchCount.size()) { + throw new IllegalArgumentException(ErrorMessage.ORDER_ONLY_BEVERAGE.getMessage()); + } + } +}
Java
์ข‹์€ ์ •๋ณด ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ”ฅ๐Ÿ”ฅ
@@ -1,25 +1,13 @@ -import logo from './logo.svg'; -import './App.css'; +import ReviewForm from "./Components/DetailPage/ReviewForm"; function App() { return ( <div className="App"> <header className="App-header"> - <img src={logo} className="App-logo" alt="logo" /> - <p> - Edit <code>src/App.js</code> and save to reload. - </p> - <a - className="App-link" - href="https://reactjs.org" - target="_blank" - rel="noopener noreferrer" - > - Learn React - </a> </header> + <ReviewForm /> </div> ); } -export default App; +export default App; \ No newline at end of file
JavaScript
๊ฒฝ๋กœ ./Components/DetailPage/ReviewForm ์š”๊ฑฐ ์•„๋‹Œ๊ฐ€์š” ?!
@@ -0,0 +1,57 @@ +import { ReviewSectionName, Button, ReviewFormArea, Conditions, IfReward, Checkbox, Number, DropDown, ReviewContent } from "./ReviewForm.style"; +import { useState } from "react"; + +const ReviewForm = () => { + const [received, setReceived] = useState(false); + const [year, setYear] = useState(""); + const [semester, setSemester] = useState(""); + const [review, setReview] = useState(""); + + const Submission = () => { + console.log({ received, year, semester, review }); + }; + + return ( + <div> + <ReviewSectionName>๋ฆฌ๋ทฐ์“ฐ๊ธฐ</ReviewSectionName> + <ReviewFormArea> + <Conditions> + <IfReward> + <Checkbox + type="checkbox" + checked={received} + onChange={() => setReceived(!received)} + /> + ์ˆ˜ํ˜œ์—ฌ๋ถ€ + </IfReward> + + <Number + type="number" + value={year} + onChange={(e) => setYear(e.target.value)} + placeholder="์‹ ์ฒญ ์—ฐ๋„" + /> + + <DropDown value={semester} onChange={(e) => setSemester(e.target.value)}> + <option value="">์‹ ์ฒญ ํ•™๊ธฐ</option> + <option value="1ํ•™๊ธฐ">1ํ•™๊ธฐ</option> + <option value="2ํ•™๊ธฐ">2ํ•™๊ธฐ</option> + </DropDown> + </Conditions> + + <ReviewContent> + <textarea + value={review} + onChange={(e) => setReview(e.target.value)} + placeHolder="์žฅํ•™๊ธˆ ์‹ ์ฒญ ๊ณผ์ •์ด ์–ด๋– ํ–ˆ๋‚˜์š”? &#13;&#10;์ž…๊ธˆ ๊ธˆ์•ก ๋ฐ ์‹œ๊ธฐ, ์„ ๋ฐœ ๊ธฐ์ค€, ํŒ ๋“ฑ ์žฅํ•™๊ธˆ์— ๊ด€ํ•œ ์ •๋ณด์™€ ๊ฒฝํ—˜์„ ์ž์œ ๋กญ๊ฒŒ ๋‚จ๊ฒจ์ฃผ์„ธ์š”." + /> + </ReviewContent> + + <Button onClick={Submission}>๋ฆฌ๋ทฐ ์ž‘์„ฑํ•˜๊ธฐ</Button> + + </ReviewFormArea> + </div> + ); +}; + +export default ReviewForm; \ No newline at end of file
Unknown
ํ•จ์ˆ˜ ์ด๋ฆ„ ํŒŒ์Šค์นผ์ผ€์ด์Šค๋กœ ํ†ต์ผํ•˜์…จ๋‚˜์š”? ๐Ÿ™‚ (just ๊ถ๊ธˆ)
@@ -0,0 +1,57 @@ +import { ReviewSectionName, Button, ReviewFormArea, Conditions, IfReward, Checkbox, Number, DropDown, ReviewContent } from "./ReviewForm.style"; +import { useState } from "react"; + +const ReviewForm = () => { + const [received, setReceived] = useState(false); + const [year, setYear] = useState(""); + const [semester, setSemester] = useState(""); + const [review, setReview] = useState(""); + + const Submission = () => { + console.log({ received, year, semester, review }); + }; + + return ( + <div> + <ReviewSectionName>๋ฆฌ๋ทฐ์“ฐ๊ธฐ</ReviewSectionName> + <ReviewFormArea> + <Conditions> + <IfReward> + <Checkbox + type="checkbox" + checked={received} + onChange={() => setReceived(!received)} + /> + ์ˆ˜ํ˜œ์—ฌ๋ถ€ + </IfReward> + + <Number + type="number" + value={year} + onChange={(e) => setYear(e.target.value)} + placeholder="์‹ ์ฒญ ์—ฐ๋„" + /> + + <DropDown value={semester} onChange={(e) => setSemester(e.target.value)}> + <option value="">์‹ ์ฒญ ํ•™๊ธฐ</option> + <option value="1ํ•™๊ธฐ">1ํ•™๊ธฐ</option> + <option value="2ํ•™๊ธฐ">2ํ•™๊ธฐ</option> + </DropDown> + </Conditions> + + <ReviewContent> + <textarea + value={review} + onChange={(e) => setReview(e.target.value)} + placeHolder="์žฅํ•™๊ธˆ ์‹ ์ฒญ ๊ณผ์ •์ด ์–ด๋– ํ–ˆ๋‚˜์š”? &#13;&#10;์ž…๊ธˆ ๊ธˆ์•ก ๋ฐ ์‹œ๊ธฐ, ์„ ๋ฐœ ๊ธฐ์ค€, ํŒ ๋“ฑ ์žฅํ•™๊ธˆ์— ๊ด€ํ•œ ์ •๋ณด์™€ ๊ฒฝํ—˜์„ ์ž์œ ๋กญ๊ฒŒ ๋‚จ๊ฒจ์ฃผ์„ธ์š”." + /> + </ReviewContent> + + <Button onClick={Submission}>๋ฆฌ๋ทฐ ์ž‘์„ฑํ•˜๊ธฐ</Button> + + </ReviewFormArea> + </div> + ); +}; + +export default ReviewForm; \ No newline at end of file
Unknown
ํ•จ์ˆ˜๋ช…์€ ๋ณดํŽธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์นด๋ฉœ์ผ€์ด์Šค๋กœ ์‚ฌ์šฉํ•ด๋ณด๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์š”~?<br/> ์ถ”๊ฐ€๋กœ `handleSubmit`๊ณผ ๊ฐ™์ด handle prefix๋กœ ์ˆ˜์ •ํ•ด๋ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~ cf. [๋ฆฌ์•กํŠธ ๊ณต์‹๋ฌธ์„œ](https://ko.react.dev/learn/adding-interactivity) <img width="396" alt="image" src="https://github.com/user-attachments/assets/efda3a60-12ff-4957-9e17-32377de6ce05" />
@@ -1,25 +1,13 @@ -import logo from './logo.svg'; -import './App.css'; +import ReviewForm from "./Components/DetailPage/ReviewForm"; function App() { return ( <div className="App"> <header className="App-header"> - <img src={logo} className="App-logo" alt="logo" /> - <p> - Edit <code>src/App.js</code> and save to reload. - </p> - <a - className="App-link" - href="https://reactjs.org" - target="_blank" - rel="noopener noreferrer" - > - Learn React - </a> </header> + <ReviewForm /> </div> ); } -export default App; +export default App; \ No newline at end of file
JavaScript
๋งž์•„์š”! ์ €๋Ÿฐ ์˜ค๋ฅ˜๊ฐ€ ์žˆ์—ˆ๋„ค์š”.. ๋‚˜์ค‘์— DetailPage ํด๋”๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์ € ๋ถ€๋ถ„์„ ์ˆ˜์ • ์•ˆ ํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๋•๋ถ„์— ์•Œ๊ฒŒ ๋์–ด์š” ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!
@@ -0,0 +1,57 @@ +import { ReviewSectionName, Button, ReviewFormArea, Conditions, IfReward, Checkbox, Number, DropDown, ReviewContent } from "./ReviewForm.style"; +import { useState } from "react"; + +const ReviewForm = () => { + const [received, setReceived] = useState(false); + const [year, setYear] = useState(""); + const [semester, setSemester] = useState(""); + const [review, setReview] = useState(""); + + const Submission = () => { + console.log({ received, year, semester, review }); + }; + + return ( + <div> + <ReviewSectionName>๋ฆฌ๋ทฐ์“ฐ๊ธฐ</ReviewSectionName> + <ReviewFormArea> + <Conditions> + <IfReward> + <Checkbox + type="checkbox" + checked={received} + onChange={() => setReceived(!received)} + /> + ์ˆ˜ํ˜œ์—ฌ๋ถ€ + </IfReward> + + <Number + type="number" + value={year} + onChange={(e) => setYear(e.target.value)} + placeholder="์‹ ์ฒญ ์—ฐ๋„" + /> + + <DropDown value={semester} onChange={(e) => setSemester(e.target.value)}> + <option value="">์‹ ์ฒญ ํ•™๊ธฐ</option> + <option value="1ํ•™๊ธฐ">1ํ•™๊ธฐ</option> + <option value="2ํ•™๊ธฐ">2ํ•™๊ธฐ</option> + </DropDown> + </Conditions> + + <ReviewContent> + <textarea + value={review} + onChange={(e) => setReview(e.target.value)} + placeHolder="์žฅํ•™๊ธˆ ์‹ ์ฒญ ๊ณผ์ •์ด ์–ด๋– ํ–ˆ๋‚˜์š”? &#13;&#10;์ž…๊ธˆ ๊ธˆ์•ก ๋ฐ ์‹œ๊ธฐ, ์„ ๋ฐœ ๊ธฐ์ค€, ํŒ ๋“ฑ ์žฅํ•™๊ธˆ์— ๊ด€ํ•œ ์ •๋ณด์™€ ๊ฒฝํ—˜์„ ์ž์œ ๋กญ๊ฒŒ ๋‚จ๊ฒจ์ฃผ์„ธ์š”." + /> + </ReviewContent> + + <Button onClick={Submission}>๋ฆฌ๋ทฐ ์ž‘์„ฑํ•˜๊ธฐ</Button> + + </ReviewFormArea> + </div> + ); +}; + +export default ReviewForm; \ No newline at end of file
Unknown
์•ˆ๊ทธ๋ž˜๋„ ๋„ค์ด๋ฐ์ปจ๋ฒค์…˜์„ ์ž˜ ๋ชฐ๋ผ์„œ ์ด๋ฒˆ์ฃผ์— ๊ณต๋ถ€ํ•ด์˜ค๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค...ใ…Žใ…Ž ๊ณต๋ถ€ํ•˜๊ณ  ์ฝ”๋“œ ์ˆ˜์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ๋‘ ๋ถ„ ๋‹ค ๋ฆฌ๋ทฐํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค:)
@@ -0,0 +1,88 @@ +import { createGlobalStyle } from 'styled-components' +import reset from 'styled-reset' + +const MainStyles = createGlobalStyle` + .relative{position:relative} + .absolute{position:absolute} + .fixed{position:fixed} + + .flex-center-between { + display: flex; + align-items: center; + justify-content: space-between; + } + .flex-center-center { + display: flex; + align-items: center; + justify-content: center; + } + .flex-center-start { + display: flex; + align-items: center; + justify-content: flex-start; + } + .gap-8{gap:8px} + .gap-9{gap:9px} + .gap-10{gap:10px} + .gap-20{gap:20px} + .gap-21{gap:21px} + .gap-22{gap:22px} + .gap-23{gap:23px} + .gap-24{gap:24px} + .gap-25{gap:25px} + .gap-26{gap:26px} + .gap-27{gap:27px} + .gap-28{gap:28px} + .gap-29{gap:29px} + .gap-30{gap:30px} + .gap-40{gap:40px} + .gap-50{gap:50px} + .gap-60{gap:60px} + .gap-70{gap:70px} + .gap-80{gap:80px} + .gap-90{gap:90px} + .width-100{width:100%} + .max-width{width:max-content} + .over-hidden{overflow: scroll} + + .margint-tb-10{margin:10px 0} + .margint-tb-11{margin:11px 0} + .margint-tb-12{margin:12px 0} + .margint-tb-13{margin:13px 0} + .margint-tb-14{margin:14px 0} + .margint-tb-15{margin:15px 0} + .margint-tb-16{margin:16px 0} + .margint-tb-17{margin:17px 0} + .margint-tb-18{margin:18px 0} + .margint-tb-19{margin:19px 0} + .margint-tb-20{margin:10px 0} + + .margin-b-10{margin-bottom:10px} + .margin-b-11{margin-bottom:11px} + .margin-b-12{margin-bottom:12px} + .margin-b-13{margin-bottom:13px} + .margin-b-14{margin-bottom:14px} + .margin-b-15{margin-bottom:15px} + .margin-b-16{margin-bottom:16px} + .margin-b-17{margin-bottom:17px} + .margin-b-18{margin-bottom:18px} + .margin-b-19{margin-bottom:19px} + .margin-b-20{margin-bottom:20px} + + .padding-lr-10{padding:0 10px} + .padding-lr-11{padding:0 11px} + .padding-lr-12{padding:0 12px} + .padding-lr-13{padding:0 13px} + .padding-lr-14{padding:0 14px} + .padding-lr-15{padding:0 15px} + .padding-lr-16{padding:0 16px} + .padding-lr-17{padding:0 17px} + .padding-lr-18{padding:0 18px} + .padding-lr-19{padding:0 19px} + .padding-lr-20{padding:0 20px} + + .bottom-0{bottom:0} + +` + +export default MainStyles
TypeScript
์ด๋ ‡๊ฒŒ ์“ฐ๊ณ  ์‹ถ๋‹ค๋ฉด, ๊ด€๋ จ `styles/mixin.ts`์— mixin ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. // flex๊ด€๋ จ mixin ```suggestion interface FlexMixin={ justifyContent?:'center' | 'flex-end' | 'flex-start' | 'space-evenly' alignItems? :'center' | 'flex-end' } export const MixinFlex({ alignItems,justifyContent } : FlexMixin) { return css` display:flex; ${justifyContent && css` justify-content : ${justifyContent}`} ${alignItems && css`align-Items : ${alignItems}`} ` } ``` ์ด๋Ÿฐ์‹์œผ๋กœ ํ™•์žฅ์„ฑ์žˆ๊ฒŒ ๊ฐœ๋ฐœ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค! cc. @eunbae11
@@ -1 +1,5 @@ -export interface IReviewController {} +import { Review, ReviewInputDTO } from '#reviews/review.types.js'; + +export interface IReviewController { + postReview: (driverId: string, body: ReviewInputDTO) => Promise<Review>; +}
TypeScript
ํ”„๋กœ์ ํŠธ ํƒ€์ž…์œผ๋กœ
@@ -1 +1,5 @@ -export interface IReviewService {} +import { Review, ReviewInputDTO } from '#reviews/review.types.js'; + +export interface IReviewService { + postReview: (driverId: string, body: ReviewInputDTO) => Promise<Review>; +}
TypeScript
๋งˆ์ฐฌ๊ฐ€์ง€
@@ -0,0 +1,35 @@ +package db; + +import db.HttpSessions; +import model.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import webserver.domain.Session; + +import static org.assertj.core.api.Assertions.assertThat; + +public class HttpSessionsTest { + + @Test + @DisplayName("์„ธ์…˜ ์ผ์น˜ ํ…Œ์ŠคํŠธ") + void matchTest() { + User user = new User("dino", "dino", "dino", "dino.bin@kakaocorp.com"); + String id = HttpSessions.getId(); + Session session = new Session(); + session.addAttribute("user", user); + HttpSessions.addSession(id, session); + assertThat(HttpSessions.getSession(id).getAttribute("user")).isEqualTo(user); + } + + @Test + @DisplayName("์„ธ์…˜ ๋ถˆ์ผ์น˜ ํ…Œ์ŠคํŠธ") + void unMatchTest() { + User user = new User("dino", "dino", "dino", "dino.bin@kakaocorp.com"); + String id = HttpSessions.getId(); + Session session = new Session(); + session.addAttribute("user", user); + HttpSessions.addSession(id, session); + String id2 = HttpSessions.getId(); + assertThat(HttpSessions.getSession(id2)).isNotEqualTo(HttpSessions.getSession(id)); + } +}
Java
ํ…Œ์ŠคํŠธ๋„ Session ์ถ”๊ฐ€์‹œ์— ๊ฐ™์ด ํ•ด์ฃผ์…จ๋„ค์š”. ๐Ÿ‘
@@ -0,0 +1,35 @@ +package db; + +import db.HttpSessions; +import model.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import webserver.domain.Session; + +import static org.assertj.core.api.Assertions.assertThat; + +public class HttpSessionsTest { + + @Test + @DisplayName("์„ธ์…˜ ์ผ์น˜ ํ…Œ์ŠคํŠธ") + void matchTest() { + User user = new User("dino", "dino", "dino", "dino.bin@kakaocorp.com"); + String id = HttpSessions.getId(); + Session session = new Session(); + session.addAttribute("user", user); + HttpSessions.addSession(id, session); + assertThat(HttpSessions.getSession(id).getAttribute("user")).isEqualTo(user); + } + + @Test + @DisplayName("์„ธ์…˜ ๋ถˆ์ผ์น˜ ํ…Œ์ŠคํŠธ") + void unMatchTest() { + User user = new User("dino", "dino", "dino", "dino.bin@kakaocorp.com"); + String id = HttpSessions.getId(); + Session session = new Session(); + session.addAttribute("user", user); + HttpSessions.addSession(id, session); + String id2 = HttpSessions.getId(); + assertThat(HttpSessions.getSession(id2)).isNotEqualTo(HttpSessions.getSession(id)); + } +}
Java
๋ถˆ์ผ์น˜๊นŒ์ง€ ๐Ÿ‘
@@ -0,0 +1,35 @@ +package db; + +import db.HttpSessions; +import model.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import webserver.domain.Session; + +import static org.assertj.core.api.Assertions.assertThat; + +public class HttpSessionsTest { + + @Test + @DisplayName("์„ธ์…˜ ์ผ์น˜ ํ…Œ์ŠคํŠธ") + void matchTest() { + User user = new User("dino", "dino", "dino", "dino.bin@kakaocorp.com"); + String id = HttpSessions.getId(); + Session session = new Session(); + session.addAttribute("user", user); + HttpSessions.addSession(id, session); + assertThat(HttpSessions.getSession(id).getAttribute("user")).isEqualTo(user); + } + + @Test + @DisplayName("์„ธ์…˜ ๋ถˆ์ผ์น˜ ํ…Œ์ŠคํŠธ") + void unMatchTest() { + User user = new User("dino", "dino", "dino", "dino.bin@kakaocorp.com"); + String id = HttpSessions.getId(); + Session session = new Session(); + session.addAttribute("user", user); + HttpSessions.addSession(id, session); + String id2 = HttpSessions.getId(); + assertThat(HttpSessions.getSession(id2)).isNotEqualTo(HttpSessions.getSession(id)); + } +}
Java
์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” import๋Š” ์ œ๊ฑฐํ•˜์ฃ  ๐Ÿ˜‰
@@ -16,10 +16,10 @@ public class HttpResponse { private HttpStatusCode httpStatusCode; private Map<String, String> headers; - private List<Cookie> cookies; + private Cookies cookies; private byte[] body; - public HttpResponse(HttpStatusCode httpStatusCode, Map<String, String> headers, List<Cookie> cookies, byte[] body) { + public HttpResponse(HttpStatusCode httpStatusCode, Map<String, String> headers, Cookies cookies, byte[] body) { this.httpStatusCode = httpStatusCode; this.headers = headers; this.cookies = cookies; @@ -43,18 +43,15 @@ private String headersList() { .append(": ") .append(headers.get(key)) .append("\r\n")); + sb.append(cookies.toString()); - cookies.forEach(cookie -> sb.append(HttpHeader.SET_COOKIE) - .append(": ") - .append(cookie.toString()) - .append("\r\n")); return sb.toString(); } public static class Builder { private HttpStatusCode httpStatusCode; private Map<String, String> headers = new HashMap<>(); - private List<Cookie> cookies = new ArrayList<>(); + private Cookies cookies = new Cookies(); private byte[] body; public Builder status(HttpStatusCode httpStatusCode) { @@ -71,13 +68,12 @@ public Builder body(String path) throws IOException, URISyntaxException { public Builder body(String path, Map<String, Object> parameter) throws IOException { this.body = TemplateUtils.getTemplatePage(path, parameter); - logger.debug(new String(body)); headers.put(HttpHeader.CONTENT_LENGTH, String.valueOf(this.body.length)); return this; } public Builder cookie(Cookie cookie) { - this.cookies.add(cookie); + this.cookies.addCookie(cookie); return this; }
Java
์ง€๊ธˆ์€ ์ œ๊ฑฐํ•˜์…จ์ง€๋งŒ ๋””๋ฒ„๊น… ๋ชฉ์ ์œผ๋กœ System.out.println์ด ์•„๋‹ˆ๋ผ logger.debug๋ฅผ ์‚ฌ์šฉํ•ด์ฃผ์…จ์—ˆ๋„ค์š”. ๐Ÿ’ฏ
@@ -105,9 +105,15 @@ public String getBody() { } public boolean containsCookie(String cookie) { - return this.headers - .get(HttpHeader.COOKIE) - .contains(cookie); + String requestCookie = this.headers.get(HttpHeader.COOKIE); + if (requestCookie != null) { + return requestCookie.contains(cookie); + } + return false; + } + + public Cookies getCookies() { + return new Cookies(headers.get(HttpHeader.COOKIE)); } public boolean isTemplate() {
Java
์•ฝ๊ฐ„์˜ ๊ฐœ์ธ์ ์ธ ์„ ํ˜ธ์ธ๋ฐ ์ง€๊ธˆ์€ ๋ณต์žกํ•˜์ง€ ์•Š์•„์„œ ์ฐจ์ด๊ฐ€ ํฌ์ง€ ์•Š์ง€๋งŒ ์‚ฌ๋žŒ์€ ๋ถ€์ •๋ณด๋‹ค๋Š” ๊ธ์ •์„ ๋” ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ฝ๋Š” ๊ฒฝํ–ฅ์ด ์žˆ์–ด์„œ ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ๊ธ์ •์˜ ์กฐ๊ฑด์„ ์„ ํƒํ•˜๋Š” ํŽธ์ž…๋‹ˆ๋‹ค. ```java if (StringUtils.hasText(requestCookie)) { return requestCookie.contains(cookie); } return false; ``` ๋นˆ ๋ฌธ์ž์—ด์ผ ๋•Œ๋Š” ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ์ง€๋Š” ์‚ด์ง ๊ณ ๋ฏผ๋˜๋„ค์š”.
@@ -0,0 +1,31 @@ +package db; + +import webserver.domain.Session; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class HttpSessions { + private static final Map<String, Session> sessions = new HashMap<>(); + + public static String getId() { + return UUID.randomUUID().toString(); + } + + public static void addSession(String name, Session session) { + sessions.put(name, session); + } + + public static Session getSession(String name) { + return sessions.get(name); + } + + public static void removeSession(String name) { + sessions.remove(name); + } + + public static void invalidate() { + sessions.clear(); + } +}
Java
์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ณตํ†ต์ ์œผ๋กœ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๊ฒŒ DB๋กœ ์‚ฌ์šฉํ•ด ์ฃผ์…จ๋„ค์š” ๐Ÿ‘
@@ -0,0 +1,31 @@ +package db; + +import webserver.domain.Session; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class HttpSessions { + private static final Map<String, Session> sessions = new HashMap<>(); + + public static String getId() { + return UUID.randomUUID().toString(); + } + + public static void addSession(String name, Session session) { + sessions.put(name, session); + } + + public static Session getSession(String name) { + return sessions.get(name); + } + + public static void removeSession(String name) { + sessions.remove(name); + } + + public static void invalidate() { + sessions.clear(); + } +}
Java
ํ‚ค ์ƒ์„ฑ์„ ์–ด๋–ป๊ฒŒ ํ• ๊นŒ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ DB๊ฐ€ ํ‚ค์ƒ์„ฑ์„ ํ•˜๋Š”๊ฑธ ๊ณ ๋ คํ•˜์—ฌ ์—ฌ๊ธฐ ๋„ฃ์–ด ์ฃผ์‹  ๊ฒƒ ๊ฐ™๋„ค์š”. DB์—์„œ ๋ณดํ†ต ์ด์™€ ๊ฐ™์€ ๋‚œ์ˆ˜๋กœ ํ‚ค๋ฅผ ๋งŒ๋“ค์ง€๋„ ์•Š๊ณ , HttpSessions๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ DB, ์˜ˆ๋ฅผ ๋“ค๋ฉด Redis๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‹จ์ˆœํžˆ DB๋ฅผ ๋ฐ”๊พธ๋Š” ๊ฑธ๋กœ ์ž‘์—…์ด ๋๋‚˜์ง€ ์•Š๊ณ  ๋‚œ์ˆ˜ ์ƒ์„ฑ์— ๋Œ€ํ•œ ๊ณ ๋ฏผ์„ ํ•˜์…”์•ผ ํ• ํ…๋ฐ ์ด์— ๋Œ€ํ•œ ์—ญํ• ์„ DB๊ฐ€ ์•„๋‹Œ ๊ณณ์œผ๋กœ ๋„˜๊ฒจ๋ณด์ฃ . ์ด๊ฑด ์•„๋ž˜ Request๊ด€๋ จ ๋‚ด์šฉ์— ๋‚จ๊ธธ๊ฒŒ์š”!
@@ -1,24 +1,43 @@ package webserver.controller; import db.DataBase; +import db.HttpSessions; import model.User; +import org.checkerframework.checker.units.qual.C; import webserver.domain.*; +import java.util.UUID; + public class LoginController extends AbstractController { @Override public HttpResponse doPost(HttpRequest httpRequest) throws Exception { User findUser = DataBase.findUserById(httpRequest.getParameter("userId")); - if (findUser == null || !findUser.isValidPassword(httpRequest.getParameter("password"))) { + if (wrongUser(httpRequest, findUser)) { + Cookie cookie = new Cookie("logined=false"); + cookie.setPath("/"); return new HttpResponse.Builder() .status(HttpStatusCode.FOUND) .redirect("/user/login_failed.html") - .cookie(new Cookie("logined", "false", "Path", "/")) + .cookie(cookie) .build(); } + Cookie cookie = new Cookie("logined=true"); + cookie.setPath("/"); + Session session = new Session(); + session.addAttribute("user", findUser); + String uuid = HttpSessions.getId(); + HttpSessions.addSession(uuid, session); + Cookie sessionCookie = new Cookie("Session=" + uuid); + sessionCookie.setPath("/"); return new HttpResponse.Builder() .status(HttpStatusCode.FOUND) .redirect("/index.html") - .cookie(new Cookie("logined", "true", "Path", "/")) + .cookie(cookie) + .cookie(sessionCookie) .build(); } + + private boolean wrongUser(HttpRequest httpRequest, User findUser) { + return findUser == null || !findUser.isValidPassword(httpRequest.getParameter("password")); + } }
Java
Session์— ๋Œ€ํ•œ ์ถ”๊ฐ€๋กœ ์ƒ๋‹นํžˆ ๋ณต์žกํ•ด์กŒ๋„ค์š”. Controller์˜ ๋Œ€๋ถ€๋ถ„์˜ ์ฝ”๋“œ๊ฐ€ Http์— ๋Œ€ํ•œ ์ž‘์—…์ธ๋ฐ Session๋„ ๊ฒฐ๊ตญ Http์˜ ์ŠคํŽ™์ธ๊ฑธ ๊ณ ๋ คํ•ด์„œ Request, Response๋ฅผ ํ†ตํ•ด ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ์š”? (์œ„์— ๋ง์”€๋“œ๋ฆฐ session id์˜ ์ถ”๊ฐ€ ๋˜ํ•œ ๋ง์ด์ฃ .) ๊ทธ๋Ÿฌ๋ฉด Controller๋Š” Session์„ ๊ฐ€์ ธ์˜ค๊ณ , ์ถ”๊ฐ€ ์š”์ฒญ๋งŒ ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ๋งŒ ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”.
@@ -1,21 +1,27 @@ package webserver.domain; + +import java.util.Objects; + public class Cookie { + public static final String PATH = "Path"; private String name; private String value; - private String pathName; - private String pathValue; + private String path; public Cookie(String name, String value) { this.name = name; this.value = value; } - public Cookie(String name, String value, String pathName, String pathValue) { - this.name = name; - this.value = value; - this.pathName = pathName; - this.pathValue = pathValue; + public Cookie(String cookieString) { + String[] splitData = cookieString.split("="); + this.name = splitData[0]; + this.value = splitData[1]; + } + + public void setPath(String path) { + this.path = path; } public String getName() { @@ -26,16 +32,33 @@ public String getValue() { return value; } - public String getPathName() { - return pathName; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Cookie cookie = (Cookie) o; + return Objects.equals(name, cookie.name) && Objects.equals(value, cookie.value); } - public String getPathValue() { - return pathValue; + @Override + public int hashCode() { + return Objects.hash(name, value); } @Override public String toString() { - return name + "=" + value + "; " + pathName + "=" + pathValue; + StringBuilder sb = new StringBuilder(); + sb.append(HttpHeader.SET_COOKIE) + .append(": ") + .append(name) + .append("=") + .append(value) + .append("; "); + if (path != null) { + sb.append(PATH) + .append("=") + .append(path); + } + return sb.toString(); } }
Java
`cookieString` ํƒ€์ž…์„ ๋ณ€์ˆ˜๋ช…์— ์จ์ค„ ํ•„์š”๋Š” ์—†์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,42 @@ +package webserver.domain; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class Cookies { + private static final Logger logger = LoggerFactory.getLogger(Cookies.class); + + private Map<String, Cookie> cookies; + + public Cookies() { + cookies = new HashMap<>(); + } + + public Cookies(String cookiesString) { + cookies = new HashMap<>(); + Arrays.stream(cookiesString.trim().split(";")).forEach(str -> { + String[] keyValue = str.split("="); + cookies.put(keyValue[0].trim(), new Cookie(keyValue[0].trim(), keyValue[1].trim())); + }); + } + + public Cookie getCookie(String name) { + return cookies.get(name); + } + + public void addCookie(Cookie cookie) { + cookies.put(cookie.getName(), cookie); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + cookies.forEach((key, value) -> sb.append(cookies.get(key)).append("\r\n")); + return sb.toString(); + } +}
Java
[Java8 Stream์€ loop๊ฐ€ ์•„๋‹ˆ๋‹ค.](https://www.popit.kr/java8-stream%EC%9D%80-loop%EA%B0%80-%EC%95%84%EB%8B%88%EB%8B%A4/) ```java for (String str : cookiesString.trim().split(";")) { String[] keyValue = str.split("="); cookies.put(keyValue[0].trim(), new Cookie(keyValue[0].trim(), keyValue[1].trim())); } ``` ๋ฐ˜๋ณต๋ฌธ๋„ ํฐ ์ฐจ์ด๊ฐ€ ์—†๊ธดํ•˜์ง€๋งŒ stream.forEach๋งŒ ํ• ๊ฑฐ๋ผ๋ฉด ๋ง๊ทธ๋Œ€๋กœ ๋ฐ˜๋ณต๋ฌธ๊ณผ ํฌ๊ฒŒ ๋‹ค๋ฅผ๊ฒŒ ์—†๋‹ต๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ์ผ๋ฐ˜์ ์œผ๋กœ ๋” ์นœ์ˆ™ํ•œ ๋ฐ˜๋ณต๋ฌธ์ด ๋” ์ข‹๋‹ค๊ณ  ์ƒ๊ฐ๋“ค์–ด์š”. ๊ฐœ์ธ์ ์œผ๋กœ๋Š” ํŠน์ • ์—ฐ์‚ฐ์„ ์—ฐ๊ฒฐํ•ด์„œ ์‚ฌ์šฉํ•  ํ•„์š”๊ฐ€ ์žˆ๊ฑฐ๋‚˜, ๊ฐ€๋…์„ฑ ์ธก๋ฉด์—์„œ ์ด์ ์ด ์žˆ์„ ๋•Œ ์œ„์ฃผ๋กœ ์ŠคํŠธ๋ฆผ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,29 @@ +package webserver.domain; + + +import java.util.HashMap; +import java.util.Map; + +public class Session { + private Map<String, Object> attribute; + + public Session() { + this.attribute = new HashMap<>(); + } + + public Object getAttribute(String name) { + return attribute.get(name); + } + + public void addAttribute(String name, Object value) { + attribute.put(name, value); + } + + public void removeAttribute(String name) { + attribute.remove(name); + } + + public void invalidate() { + attribute.clear(); + } +}
Java
๊ตฐ๋”๋”๊ธฐ ์—†์ด ์ž˜ ๊ตฌํ˜„ํ–ˆ๋„ค์š”. ๐Ÿ‘
@@ -0,0 +1,79 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); + +* { + box-sizing: border-box; +} +body{ + background-color:#fafafa; +} + +.login-wrap{ + width:30%; + height:550px; + background-color:#fff; + border:3px solid rgba(221, 221, 221, 0.3); + margin:130px auto 0 auto; + + h1{ + width:80%; + height:50px; + font-size:55px; + font-family: 'Lobster', cursive; + padding-top:50px; + margin:0 auto 120px auto; + text-align: center; + } + + .inner-wrap { + width:80%; + margin:auto; + height:300px; + + input { + width:100%; + height:60px; + border-radius: 5px; + border:2px solid rgba(221, 221, 221, 0.2); + margin-bottom:10px; + padding:30px 10px; + font-size:18px; + color:#000; + cursor: pointer; + outline:none; + line-height: 30px; + } + + .on { + background-color:#0094f6; + } + + .off { + background-color:#0094f64b; + } + + button { + width:100%; + height:50px; + margin-top:15px; + border:none; + background-color:#0094f64b; + border-radius: 8px; + color:#fff; + font-size:20px; + font-weight:600; + outline:none; + cursor:pointer; + } + + p{ + text-align:center; + margin-top:110px; + + a{ + color:#00376b; + font-size:16px; + text-decoration: none; + } + } + } +}
Unknown
CSS ์†์„ฑ ์ˆœ์„œ๋Œ€๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด ๋” ์ข‹์„๊ฒƒ ๊ฐ™์•„์š” margin, padding ๋‹ค์Œ font-size ์ˆœ์ด๋„ค์š” ;)
@@ -0,0 +1,32 @@ +import React from "react"; +import "./Footer.scss"; + +class Footer extends React.Component { + render() { + return ( + <footer> + <ul> + {RIGHT_FOOTER.map((element, index) => { + return <li key={index}>{element}</li>; + })} + </ul> + <p className="made">ยฉ 2021 INSTAGRAM FROM doheekim</p> + </footer> + ); + } +} + +export default Footer; + +const RIGHT_FOOTER = [ + "์†Œ๊ฐœ", + "๋„์›€๋ง", + "ํ™๋ณด ์„ผํ„ฐ", + "API", + "์ฑ„์šฉ์ •๋ณด", + "๊ฐœ์ธ์ •๋ณด์ฒ˜๋ผ๋ฐฉ์นจ", + "์•ฝ๊ด€", + "์œ„์น˜", + "์ธ๊ธฐ ๊ณ„์ •", + "ํ•ด์‰ฌํƒœ๊ทธ", +];
JavaScript
footer ๋‚ด์šฉ ์ž˜ ๋งŒ๋“œ์…จ๋„ค์š” bb
@@ -0,0 +1,79 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); + +* { + box-sizing: border-box; +} +body{ + background-color:#fafafa; +} + +.login-wrap{ + width:30%; + height:550px; + background-color:#fff; + border:3px solid rgba(221, 221, 221, 0.3); + margin:130px auto 0 auto; + + h1{ + width:80%; + height:50px; + font-size:55px; + font-family: 'Lobster', cursive; + padding-top:50px; + margin:0 auto 120px auto; + text-align: center; + } + + .inner-wrap { + width:80%; + margin:auto; + height:300px; + + input { + width:100%; + height:60px; + border-radius: 5px; + border:2px solid rgba(221, 221, 221, 0.2); + margin-bottom:10px; + padding:30px 10px; + font-size:18px; + color:#000; + cursor: pointer; + outline:none; + line-height: 30px; + } + + .on { + background-color:#0094f6; + } + + .off { + background-color:#0094f64b; + } + + button { + width:100%; + height:50px; + margin-top:15px; + border:none; + background-color:#0094f64b; + border-radius: 8px; + color:#fff; + font-size:20px; + font-weight:600; + outline:none; + cursor:pointer; + } + + p{ + text-align:center; + margin-top:110px; + + a{ + color:#00376b; + font-size:16px; + text-decoration: none; + } + } + } +}
Unknown
๋„ต ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,98 @@ +import { Component } from "react"; +import { Link, withRouter } from "react-router-dom"; +import "./Login.scss"; + +class Login extends Component { + constructor() { + super(); + this.state = { + id: "", + pw: "", + }; + } + + // localStorage.clear(); + // localStorage.removeItem('key'); + // localStorage.getItem('key'); + + //์ €์žฅ + + //์กฐํšŒ + // let getValue = localStorage.getItem('Token'); + // console.log(getValue); + // localStorage + + goToMain = () => { + fetch("http://10.58.2.229:8000/users/login", { + method: "POST", + body: JSON.stringify({ + account: this.state.id, + password: this.state.pw, + // phone_number: "01034358181", + // name: "๊น€๋„ํžˆ", + }), + }) + .then((res) => res.json()) + .then((result) => { + console.log(result); + if (result.MESSAGE === "SUCCESS") { + localStorage.setItem("Token", result.Token); + alert("๋กœ๊ทธ์ธ์„ฑ๊ณต!"); + this.props.history.push("/maindh"); + } else { + alert("๐ŸคฌIT'S YOUR FAULT!๐Ÿคฌ"); + } + }); + }; + + handleInput = (event) => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + render() { + const { id, pw } = this.state; + return ( + <> + <div className="login-wrap"> + <h1 className="title">Westagram</h1> + <div className="inner-wrap"> + <input + className="id" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={this.handleInput} + value={id} + name="id" + /> + <input + className="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={this.handleInput} + value={pw} + name="pw" + /> + <button + className={id.includes("@") && pw.length >= 5 ? "on" : "off"} + onClick={this.goToMain} + > + ๋กœ๊ทธ์ธ + </button> + <p> + <Link to="/Main">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</Link> + </p> + </div> + </div> + </> + ); + } +} + +export default withRouter(Login); + +//๊ฐ์ฒด ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น + +//const { fontState} = this.state
JavaScript
this.state ๋Š” ๊ตฌ์กฐ๋ถ„ํ•ดํ• ๋‹น์„ ์‚ฌ์šฉํ•ด์„œ ์ •๋ฆฌํ•ด์ฃผ์‹œ๋ฉด ๋” ๊น”๋”ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,98 @@ +import { Component } from "react"; +import { Link, withRouter } from "react-router-dom"; +import "./Login.scss"; + +class Login extends Component { + constructor() { + super(); + this.state = { + id: "", + pw: "", + }; + } + + // localStorage.clear(); + // localStorage.removeItem('key'); + // localStorage.getItem('key'); + + //์ €์žฅ + + //์กฐํšŒ + // let getValue = localStorage.getItem('Token'); + // console.log(getValue); + // localStorage + + goToMain = () => { + fetch("http://10.58.2.229:8000/users/login", { + method: "POST", + body: JSON.stringify({ + account: this.state.id, + password: this.state.pw, + // phone_number: "01034358181", + // name: "๊น€๋„ํžˆ", + }), + }) + .then((res) => res.json()) + .then((result) => { + console.log(result); + if (result.MESSAGE === "SUCCESS") { + localStorage.setItem("Token", result.Token); + alert("๋กœ๊ทธ์ธ์„ฑ๊ณต!"); + this.props.history.push("/maindh"); + } else { + alert("๐ŸคฌIT'S YOUR FAULT!๐Ÿคฌ"); + } + }); + }; + + handleInput = (event) => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + render() { + const { id, pw } = this.state; + return ( + <> + <div className="login-wrap"> + <h1 className="title">Westagram</h1> + <div className="inner-wrap"> + <input + className="id" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={this.handleInput} + value={id} + name="id" + /> + <input + className="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={this.handleInput} + value={pw} + name="pw" + /> + <button + className={id.includes("@") && pw.length >= 5 ? "on" : "off"} + onClick={this.goToMain} + > + ๋กœ๊ทธ์ธ + </button> + <p> + <Link to="/Main">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</Link> + </p> + </div> + </div> + </> + ); + } +} + +export default withRouter(Login); + +//๊ฐ์ฒด ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น + +//const { fontState} = this.state
JavaScript
์š” ๋ถ€๋ถ„ ๋…ธ์…˜์—์„œ ๋ดค๋Š”๋ฐ handleId๋ž‘ handlePw๊ฐ™์ด ๋˜‘๊ฐ™์€ ํ˜•์‹์˜ event handler๋ผ์„œ ํ•ฉ์น ์ˆ˜ ์žˆ๋”๋ผ๊ตฌ์š”! ์ €๋„ ์•„์ง์•ˆํ–ˆ์ง€๋งŒ...^^ ๊ฐ™์ด ํ•ด๋ณด์•„์š” ใ…‹ใ…‹ใ…‹
@@ -0,0 +1,79 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); + +* { + box-sizing: border-box; +} +body{ + background-color:#fafafa; +} + +.login-wrap{ + width:30%; + height:550px; + background-color:#fff; + border:3px solid rgba(221, 221, 221, 0.3); + margin:130px auto 0 auto; + + h1{ + width:80%; + height:50px; + font-size:55px; + font-family: 'Lobster', cursive; + padding-top:50px; + margin:0 auto 120px auto; + text-align: center; + } + + .inner-wrap { + width:80%; + margin:auto; + height:300px; + + input { + width:100%; + height:60px; + border-radius: 5px; + border:2px solid rgba(221, 221, 221, 0.2); + margin-bottom:10px; + padding:30px 10px; + font-size:18px; + color:#000; + cursor: pointer; + outline:none; + line-height: 30px; + } + + .on { + background-color:#0094f6; + } + + .off { + background-color:#0094f64b; + } + + button { + width:100%; + height:50px; + margin-top:15px; + border:none; + background-color:#0094f64b; + border-radius: 8px; + color:#fff; + font-size:20px; + font-weight:600; + outline:none; + cursor:pointer; + } + + p{ + text-align:center; + margin-top:110px; + + a{ + color:#00376b; + font-size:16px; + text-decoration: none; + } + } + } +}
Unknown
์ž์ฃผ์“ฐ๋Š” border variable ์—๋‹ค๊ฐ€ ์ €์žฅํ•ด๋†“๊ณ  ์“ฐ๋‹ˆ๊นŒ ํŽธํ•˜๊ณ  ์ข‹๋”๋ผ๊ตฌ์š”!
@@ -0,0 +1,21 @@ +import React from "react"; +import "./MainRight.scss"; +import RecommendHeader from "./MainRight/RecommendHeader"; +import RecommendTitle from "./MainRight/RecommendTitle"; +import RecommendFriends from "./MainRight/RecommendFriends"; +import Footer from "./MainRight/Footer"; + +class MainRight extends React.Component { + render() { + return ( + <div className="main-right"> + <RecommendHeader></RecommendHeader> + <RecommendTitle></RecommendTitle> + <RecommendFriends></RecommendFriends> + <Footer></Footer> + </div> + ); + } +} + +export default MainRight;
JavaScript
์˜ค ๋ฒŒ์จ ๋‹ค ๋‚˜๋ˆ„์…จ๋‹ค๋‹ ๐Ÿ‘
@@ -0,0 +1,21 @@ +import React from "react"; +import "./MainRight.scss"; +import RecommendHeader from "./MainRight/RecommendHeader"; +import RecommendTitle from "./MainRight/RecommendTitle"; +import RecommendFriends from "./MainRight/RecommendFriends"; +import Footer from "./MainRight/Footer"; + +class MainRight extends React.Component { + render() { + return ( + <div className="main-right"> + <RecommendHeader></RecommendHeader> + <RecommendTitle></RecommendTitle> + <RecommendFriends></RecommendFriends> + <Footer></Footer> + </div> + ); + } +} + +export default MainRight;
JavaScript
๊น”๋”....๐Ÿคญ
@@ -0,0 +1,98 @@ +import { Component } from "react"; +import { Link, withRouter } from "react-router-dom"; +import "./Login.scss"; + +class Login extends Component { + constructor() { + super(); + this.state = { + id: "", + pw: "", + }; + } + + // localStorage.clear(); + // localStorage.removeItem('key'); + // localStorage.getItem('key'); + + //์ €์žฅ + + //์กฐํšŒ + // let getValue = localStorage.getItem('Token'); + // console.log(getValue); + // localStorage + + goToMain = () => { + fetch("http://10.58.2.229:8000/users/login", { + method: "POST", + body: JSON.stringify({ + account: this.state.id, + password: this.state.pw, + // phone_number: "01034358181", + // name: "๊น€๋„ํžˆ", + }), + }) + .then((res) => res.json()) + .then((result) => { + console.log(result); + if (result.MESSAGE === "SUCCESS") { + localStorage.setItem("Token", result.Token); + alert("๋กœ๊ทธ์ธ์„ฑ๊ณต!"); + this.props.history.push("/maindh"); + } else { + alert("๐ŸคฌIT'S YOUR FAULT!๐Ÿคฌ"); + } + }); + }; + + handleInput = (event) => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + render() { + const { id, pw } = this.state; + return ( + <> + <div className="login-wrap"> + <h1 className="title">Westagram</h1> + <div className="inner-wrap"> + <input + className="id" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={this.handleInput} + value={id} + name="id" + /> + <input + className="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={this.handleInput} + value={pw} + name="pw" + /> + <button + className={id.includes("@") && pw.length >= 5 ? "on" : "off"} + onClick={this.goToMain} + > + ๋กœ๊ทธ์ธ + </button> + <p> + <Link to="/Main">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</Link> + </p> + </div> + </div> + </> + ); + } +} + +export default withRouter(Login); + +//๊ฐ์ฒด ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น + +//const { fontState} = this.state
JavaScript
์˜ค์˜ท ํ•œ๋ฒˆ ์‹œ๋„ํ•ด๋ด์•ผ๊ฒ ์–ด์š”!
@@ -0,0 +1,21 @@ +import React from "react"; +import "./MainRight.scss"; +import RecommendHeader from "./MainRight/RecommendHeader"; +import RecommendTitle from "./MainRight/RecommendTitle"; +import RecommendFriends from "./MainRight/RecommendFriends"; +import Footer from "./MainRight/Footer"; + +class MainRight extends React.Component { + render() { + return ( + <div className="main-right"> + <RecommendHeader></RecommendHeader> + <RecommendTitle></RecommendTitle> + <RecommendFriends></RecommendFriends> + <Footer></Footer> + </div> + ); + } +} + +export default MainRight;
JavaScript
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋Œฏ๐Ÿคญ
@@ -0,0 +1,79 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); + +* { + box-sizing: border-box; +} +body{ + background-color:#fafafa; +} + +.login-wrap{ + width:30%; + height:550px; + background-color:#fff; + border:3px solid rgba(221, 221, 221, 0.3); + margin:130px auto 0 auto; + + h1{ + width:80%; + height:50px; + font-size:55px; + font-family: 'Lobster', cursive; + padding-top:50px; + margin:0 auto 120px auto; + text-align: center; + } + + .inner-wrap { + width:80%; + margin:auto; + height:300px; + + input { + width:100%; + height:60px; + border-radius: 5px; + border:2px solid rgba(221, 221, 221, 0.2); + margin-bottom:10px; + padding:30px 10px; + font-size:18px; + color:#000; + cursor: pointer; + outline:none; + line-height: 30px; + } + + .on { + background-color:#0094f6; + } + + .off { + background-color:#0094f64b; + } + + button { + width:100%; + height:50px; + margin-top:15px; + border:none; + background-color:#0094f64b; + border-radius: 8px; + color:#fff; + font-size:20px; + font-weight:600; + outline:none; + cursor:pointer; + } + + p{ + text-align:center; + margin-top:110px; + + a{ + color:#00376b; + font-size:16px; + text-decoration: none; + } + } + } +}
Unknown
๊ณตํ†ต scss๋ฅผ ์ž˜ ํ™œ์šฉํ•ด๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,18 @@ +.recommend-title { + width:100%; + height:40px; + margin-bottom:5px; + + .recommend-title-left { + float:left; + font-size:14px; + color:#888; + font-weight:700; + } + + .recommend-title-right { + float:right; + font-size:12px; + font-weight:600; + } +} \ No newline at end of file
Unknown
์ œ๋ชฉ ๊น”๋”ํ•˜๊ณ  ์•Œ์•„๋“ฃ๊ธฐ ์‰ฌ์›Œ์„œ ์ข‹์€๊ฑฐ๊ฐ™์•„์š”!
@@ -0,0 +1,98 @@ +import { Component } from "react"; +import { Link, withRouter } from "react-router-dom"; +import "./Login.scss"; + +class Login extends Component { + constructor() { + super(); + this.state = { + id: "", + pw: "", + }; + } + + // localStorage.clear(); + // localStorage.removeItem('key'); + // localStorage.getItem('key'); + + //์ €์žฅ + + //์กฐํšŒ + // let getValue = localStorage.getItem('Token'); + // console.log(getValue); + // localStorage + + goToMain = () => { + fetch("http://10.58.2.229:8000/users/login", { + method: "POST", + body: JSON.stringify({ + account: this.state.id, + password: this.state.pw, + // phone_number: "01034358181", + // name: "๊น€๋„ํžˆ", + }), + }) + .then((res) => res.json()) + .then((result) => { + console.log(result); + if (result.MESSAGE === "SUCCESS") { + localStorage.setItem("Token", result.Token); + alert("๋กœ๊ทธ์ธ์„ฑ๊ณต!"); + this.props.history.push("/maindh"); + } else { + alert("๐ŸคฌIT'S YOUR FAULT!๐Ÿคฌ"); + } + }); + }; + + handleInput = (event) => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + render() { + const { id, pw } = this.state; + return ( + <> + <div className="login-wrap"> + <h1 className="title">Westagram</h1> + <div className="inner-wrap"> + <input + className="id" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={this.handleInput} + value={id} + name="id" + /> + <input + className="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={this.handleInput} + value={pw} + name="pw" + /> + <button + className={id.includes("@") && pw.length >= 5 ? "on" : "off"} + onClick={this.goToMain} + > + ๋กœ๊ทธ์ธ + </button> + <p> + <Link to="/Main">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</Link> + </p> + </div> + </div> + </> + ); + } +} + +export default withRouter(Login); + +//๊ฐ์ฒด ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น + +//const { fontState} = this.state
JavaScript
import { Link, withRouter } from "react-router-dom"; ํ•œ์ค„๋กœ ๋งŒ๋“ค์–ด๋„ ์ข‹์„๊ฑฐ๊ฐ™์•„์š”!
@@ -0,0 +1,98 @@ +import { Component } from "react"; +import { Link, withRouter } from "react-router-dom"; +import "./Login.scss"; + +class Login extends Component { + constructor() { + super(); + this.state = { + id: "", + pw: "", + }; + } + + // localStorage.clear(); + // localStorage.removeItem('key'); + // localStorage.getItem('key'); + + //์ €์žฅ + + //์กฐํšŒ + // let getValue = localStorage.getItem('Token'); + // console.log(getValue); + // localStorage + + goToMain = () => { + fetch("http://10.58.2.229:8000/users/login", { + method: "POST", + body: JSON.stringify({ + account: this.state.id, + password: this.state.pw, + // phone_number: "01034358181", + // name: "๊น€๋„ํžˆ", + }), + }) + .then((res) => res.json()) + .then((result) => { + console.log(result); + if (result.MESSAGE === "SUCCESS") { + localStorage.setItem("Token", result.Token); + alert("๋กœ๊ทธ์ธ์„ฑ๊ณต!"); + this.props.history.push("/maindh"); + } else { + alert("๐ŸคฌIT'S YOUR FAULT!๐Ÿคฌ"); + } + }); + }; + + handleInput = (event) => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + render() { + const { id, pw } = this.state; + return ( + <> + <div className="login-wrap"> + <h1 className="title">Westagram</h1> + <div className="inner-wrap"> + <input + className="id" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={this.handleInput} + value={id} + name="id" + /> + <input + className="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={this.handleInput} + value={pw} + name="pw" + /> + <button + className={id.includes("@") && pw.length >= 5 ? "on" : "off"} + onClick={this.goToMain} + > + ๋กœ๊ทธ์ธ + </button> + <p> + <Link to="/Main">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</Link> + </p> + </div> + </div> + </> + ); + } +} + +export default withRouter(Login); + +//๊ฐ์ฒด ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น + +//const { fontState} = this.state
JavaScript
๋„ต! ๋ฆฌํŒฉํ† ๋ง ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค๐Ÿ˜„
@@ -0,0 +1,63 @@ +import React from "react"; +import Story from "./Mainleft/Story"; +import Feed from "./Mainleft/Feed"; +import "./MainLeft.scss"; +// import { FaRedditAlien } from "react-icons/fa"; + +class MainLeft extends React.Component { + state = { + feedList: [], + }; + + componentDidMount() { + fetch("/data/FeedData.json", { + method: "GET", + }) + .then((res) => res.json()) + .then((data) => { + this.setState({ + feedList: data, + }); + }); + } + + aaa = () => { + // console.log("aaa ํ•จ์ˆ˜ํ˜ธ์ถœ"); + fetch("http://10.58.2.229:8000/posts/post", { + method: "GET", + headers: { + Authorization: localStorage.getItem("Token"), + }, + }) + .then((res) => res.json()) + .then((res) => { + this.setState({ + feedList: res.RESULT, + }); + console.log(res.RESULT); + }); + }; + + render() { + const { feedList } = this.state; + return ( + <div className="main-left"> + {/* <button onClick={this.aaa}>click</button> */} + <Story /> + {feedList.map((element) => { + return ( + <Feed + id={element.id} + name={element.userId} + count={element.count} + img={element.img} + title={element.title} + /> + ); + })} + </div> + ); + } +} + +export default MainLeft;
JavaScript
ํƒœ๊ทธ๋ช…์ด ํ•œ๋ˆˆ์— ๋“ค์–ด์™€์š”๐Ÿ‘
@@ -0,0 +1,50 @@ +@import "../../common.scss"; + +.recommend-header { + width:100%; + height:100px; + @extend %flexbetween; + margin-top:5px; + + li { + position:relative; + &:first-child { + &:after { + width:64px; + height:64px; + border:1px solid #ddd; + border-radius: 50%; + content:""; + position:absolute; + top:-3px; left:-3px; + } + } + + .recommend-header-flex { + display:flex; + justify-content: flex-start; + align-items: center; + + li { + + img { + width:100%; + width:60px; + height:60px; + border-radius:50%; + margin-bottom:5px; + } + + .recommend-header-id { + font-weight:700; + margin-left:10px; + } + } + } + } + + .log-out { + float:right; + } +} +
Unknown
tirm ํ•จ์ˆ˜? ์ด์šฉํ•ด์„œ ๋นˆ์นธ enter๋ฐฉ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด์žˆ๋”๋ผ๊ตฌ์š” ๊ฐ™์ด ์‚ฌ์šฉํ•ด๋ด์š”๐Ÿ–
@@ -0,0 +1,181 @@ +import React from "react"; +import Comments from "./Comments"; +import COMMENT from "./CommentData"; +import "./Feed.scss"; +import { FaEllipsisH } from "react-icons/fa"; +import { FaRegHeart } from "react-icons/fa"; +import { FaRegComment } from "react-icons/fa"; +import { FaRegShareSquare } from "react-icons/fa"; +import { FaRegBookmark } from "react-icons/fa"; +import { FaRegSmile } from "react-icons/fa"; + +class Feed extends React.Component { + constructor() { + super(); + this.state = { + color: "#0094f64b", + newComment: "", + comments: [[{ id: 0, userId: "", comment: "" }]], + }; + } + + commentValue = (e) => { + this.setState({ + newComment: e.target.value, + }); + }; + + addComment = () => { + console.log("ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰๋œ๊ฑฐ์ž„"); + const { comments, newComment } = this.state; + const token = localStorage.getItem("Token"); + fetch("http://10.58.2.229:8000/comment", { + method: "POST", + headers: { + Authorization: token, //Authorization : ์ธ์ฆํ† ํฐ์„ ์„œ๋ฒ„๋กœ ๋ณด๋‚ผ๋•Œ + }, + body: JSON.stringify({ + newComment: newComment, + //๊ฒฝ์žฌ๋‹˜์ด ๋งํ•ด์ค„ ์ด๋ฆ„ + }), + }) + .then((res) => res.json()) + .then((res) => { + this.setState({ comments: res.message }); + this.setState({ newComment: "" }); + }); + + this.setState({ + comments: [ + ...comments, + { + userId: "_ggul_dodo", + comment: newComment, + key: comments.length, + }, + ], + newComment: "", + }); + }; + + componentDidMount() { + this.setState({ + comments: COMMENT, + }); + } + + pressEnter = (e) => { + if (e.key === "Enter" && this.state.newComment) { + this.addComment(); + e.target.value = ""; + } + }; + + render() { + console.log(this.props); //๋ฐ์ดํ„ฐ ํ”„๋กญ์Šค ๋ฐ›์•„์˜ค๋Š”์ง€ + return ( + <div className="feeds"> + <article> + <ul className="feeds-header"> + <li className="feeds-idwrap"> + <ul> + <li className="mini-profile"> + <img + src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/154058443_217688870078059_3669752827847367841_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=ceRMdT1axXoAX_Lpuxn&edm=AABBvjUAAAAA&ccb=7-4&oh=92252211fe0704195cbc8ded03d8a95b&oe=608AF997&_nc_sid=83d603" + alt="๋„ํฌ๋ฏธ๋‹ˆํ”„๋กœํ•„" + /> + </li> + <li className="mini-id">{this.props.name}</li> + </ul> + </li> + <li className="more"> + <FaEllipsisH /> + </li> + </ul> + <img src={this.props.img} alt="ํ”ผ๋“œ์‚ฌ์ง„" /> + <div className="feeds-bottom"> + <ul className="feeds-bottom-flex"> + <li className="feeds-icon"> + <ul className="feeds-iconbox"> + <li className="heart-btn"> + <button> + <FaRegHeart /> + </button> + </li> + <li className="comment-btn"> + <button> + <FaRegComment /> + </button> + </li> + <li className="share-btn"> + <button> + <FaRegShareSquare /> + </button> + </li> + </ul> + </li> + <li className="bookmark"> + <button> + <FaRegBookmark /> + </button> + </li> + </ul> + <div className="heart-count"> + <img + src="https://scontent-ssn1-1.cdninstagram.com/v/t51.2885-19/s150x150/155180730_424134145319091_2244618473151617561_n.jpg?tp=1&_nc_ht=scontent-ssn1-1.cdninstagram.com&_nc_ohc=jkEKojtr85AAX-RveBi&edm=AOG-cTkAAAAA&ccb=7-4&oh=7f7b1c626d17579c1586680935296ee6&oe=608C1C0B&_nc_sid=282b66" + alt="์ข‹์•„์š”๋ˆ„๋ฅธ์‚ฌ๋žŒ์‚ฌ์ง„" + /> + <p> + <span className="bold">j_vely_s2</span>๋‹˜{" "} + <span>์™ธ {this.props.count}๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </p> + </div> + <ul className="content-write"> + <li> + <span className="chat-id">{this.props.name}</span> + <span className="chat-content">{this.props.title}</span> + </li> + {this.state.comments.map((item) => ( + <Comments + key={item.length} + userId={item.userId} + comment={item.comment} + ></Comments> + ))} + </ul> + <p className="time">7์‹œ๊ฐ„ ์ „</p> + </div> + <ul className="comment-write"> + <li>{FaRegSmile}</li> + <li> + <input + className="comment-inner" + onChange={this.commentValue} + onKeyPress={this.pressEnter} + value={this.state.newComment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + </li> + <li> + <button + className="submit" + onClick={this.addComment} + style={{ + color: + this.state.newComment.length > 0 + ? "#0094f6" + : this.state.color, + }} + > + ๊ฒŒ์‹œ + </button> + </li> + </ul> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
๋™์‹œ์— ์ด๋ฒคํŠธ๊ฐ€ ์‹คํ–‰๋ ์ˆ˜์žˆ๊ฒŒ ์ €๋„ ์—ฐ์‚ฐ์ž๋กœ ์‚ฌ์šฉํ•ด๋ด์•ผ๊ฒ ์–ด์š”!!
@@ -0,0 +1,88 @@ +@import "../../../../styles/common.scss"; + + +%flexbetween { + display: flex; + align-items: center; + justify-content: space-between; +} + +nav { + width:100%; + height:55px; + background-color:#fff; + border-bottom :1px solid #ddd; + position:fixed; + top:0; + z-index:10; + + ul{ + margin:auto; + height:inherit; + width:60%; + display:flex; + justify-content:space-between; + align-items: center; + + li{ + .logo { + font-family: 'Lobster', cursive; + font-size:25px; + margin-top:-5px; + } + } + + .search-wrap { + position:relative; + + input { + width:200px; + height:30px; + border:1px solid #ddd; + background-color:#fafafa; + outline:none; + border-radius: 5px; + &::placeholder { + text-align:center; + } + } + + svg { + color:#888; + font-size:12px; + position:absolute; + left:60px; top:9px; + } + } + } +} + +.icon { + @extend %flexbetween; + margin-left:-30px; + + li { + position:relative; + margin-left:15px; + &:nth-child(2):after { + width:4px; + height:4px; + border-radius:50%; + content:""; + background-color:red; + position:absolute; + top:30px; + right:10px; + } + &:last-child { + img { + border-radius: 50%; + } + } + img { + border-radius: 50%; + width:25px; + height:25px; + } + } +} \ No newline at end of file
Unknown
placeholder ์Šคํƒ€์ผ ๊ฐ’์ฃผ๋Š” ๋ฒ• ์ €๋„ ์จ๋ด์•ผ๊ฒ ์–ด์š”!
@@ -0,0 +1,46 @@ +footer { + width:100%; + height:70px; + + ul { + width:90%; + margin-top:20px; + + li { + font-size:12px; + color:#888; + margin-bottom:10px; + position:relative; + padding-left:5px; + padding-right:10px; + display:inline-block; + + &::after { + width:3px; + height:3px; + border-radius: 50%; + position:absolute; + top:25%; left:95%; + content:""; + background-color:#888; + } + + &:nth-child(6) { + &::after { + display:none; + } + } + + &:last-child { + &::after { + display:none; + } + } + } + } + + .made { + font-size:12px; + color:#888; + } +} \ No newline at end of file
Unknown
css์„ ํƒ์ž์™€ ๊ฐ€์ƒ์š”์†Œ์„ ํƒ์ž๋ฅผ ์ž˜ ์ด์šฉํ•˜์…จ๋„ค์š”..! ์ •ํ™•ํ•œ ์ด์šฉ๋ฒ•์„ ๋ชฐ๋ž๋Š”๋ฐ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค ๐Ÿ”ฅ๐Ÿ‘๐Ÿป
@@ -0,0 +1,50 @@ +@import "../../common.scss"; + +.recommend-header { + width:100%; + height:100px; + @extend %flexbetween; + margin-top:5px; + + li { + position:relative; + &:first-child { + &:after { + width:64px; + height:64px; + border:1px solid #ddd; + border-radius: 50%; + content:""; + position:absolute; + top:-3px; left:-3px; + } + } + + .recommend-header-flex { + display:flex; + justify-content: flex-start; + align-items: center; + + li { + + img { + width:100%; + width:60px; + height:60px; + border-radius:50%; + margin-bottom:5px; + } + + .recommend-header-id { + font-weight:700; + margin-left:10px; + } + } + } + } + + .log-out { + float:right; + } +} +
Unknown
afterํ™œ์šฉ ๐Ÿ‘๐Ÿป
@@ -0,0 +1,98 @@ +import { Component } from "react"; +import { Link, withRouter } from "react-router-dom"; +import "./Login.scss"; + +class Login extends Component { + constructor() { + super(); + this.state = { + id: "", + pw: "", + }; + } + + // localStorage.clear(); + // localStorage.removeItem('key'); + // localStorage.getItem('key'); + + //์ €์žฅ + + //์กฐํšŒ + // let getValue = localStorage.getItem('Token'); + // console.log(getValue); + // localStorage + + goToMain = () => { + fetch("http://10.58.2.229:8000/users/login", { + method: "POST", + body: JSON.stringify({ + account: this.state.id, + password: this.state.pw, + // phone_number: "01034358181", + // name: "๊น€๋„ํžˆ", + }), + }) + .then((res) => res.json()) + .then((result) => { + console.log(result); + if (result.MESSAGE === "SUCCESS") { + localStorage.setItem("Token", result.Token); + alert("๋กœ๊ทธ์ธ์„ฑ๊ณต!"); + this.props.history.push("/maindh"); + } else { + alert("๐ŸคฌIT'S YOUR FAULT!๐Ÿคฌ"); + } + }); + }; + + handleInput = (event) => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + render() { + const { id, pw } = this.state; + return ( + <> + <div className="login-wrap"> + <h1 className="title">Westagram</h1> + <div className="inner-wrap"> + <input + className="id" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={this.handleInput} + value={id} + name="id" + /> + <input + className="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={this.handleInput} + value={pw} + name="pw" + /> + <button + className={id.includes("@") && pw.length >= 5 ? "on" : "off"} + onClick={this.goToMain} + > + ๋กœ๊ทธ์ธ + </button> + <p> + <Link to="/Main">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</Link> + </p> + </div> + </div> + </> + ); + } +} + +export default withRouter(Login); + +//๊ฐ์ฒด ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น + +//const { fontState} = this.state
JavaScript
ํ•˜๋‚˜์˜ ํ•จ์ˆ˜๋กœ ํ•ฉ์ณ์ฃผ์‹ค์ˆ˜ ์žˆ๊ฒ ๋„ค์š”-! ๐Ÿ‘
@@ -0,0 +1,79 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); + +* { + box-sizing: border-box; +} +body{ + background-color:#fafafa; +} + +.login-wrap{ + width:30%; + height:550px; + background-color:#fff; + border:3px solid rgba(221, 221, 221, 0.3); + margin:130px auto 0 auto; + + h1{ + width:80%; + height:50px; + font-size:55px; + font-family: 'Lobster', cursive; + padding-top:50px; + margin:0 auto 120px auto; + text-align: center; + } + + .inner-wrap { + width:80%; + margin:auto; + height:300px; + + input { + width:100%; + height:60px; + border-radius: 5px; + border:2px solid rgba(221, 221, 221, 0.2); + margin-bottom:10px; + padding:30px 10px; + font-size:18px; + color:#000; + cursor: pointer; + outline:none; + line-height: 30px; + } + + .on { + background-color:#0094f6; + } + + .off { + background-color:#0094f64b; + } + + button { + width:100%; + height:50px; + margin-top:15px; + border:none; + background-color:#0094f64b; + border-radius: 8px; + color:#fff; + font-size:20px; + font-weight:600; + outline:none; + cursor:pointer; + } + + p{ + text-align:center; + margin-top:110px; + + a{ + color:#00376b; + font-size:16px; + text-decoration: none; + } + } + } +}
Unknown
ํ•œ์ค„ margin ์†์„ฑ์œผ๋กœ ์ค„์—ฌ๋ณผ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”-! ๐Ÿ‘
@@ -0,0 +1,98 @@ +import { Component } from "react"; +import { Link, withRouter } from "react-router-dom"; +import "./Login.scss"; + +class Login extends Component { + constructor() { + super(); + this.state = { + id: "", + pw: "", + }; + } + + // localStorage.clear(); + // localStorage.removeItem('key'); + // localStorage.getItem('key'); + + //์ €์žฅ + + //์กฐํšŒ + // let getValue = localStorage.getItem('Token'); + // console.log(getValue); + // localStorage + + goToMain = () => { + fetch("http://10.58.2.229:8000/users/login", { + method: "POST", + body: JSON.stringify({ + account: this.state.id, + password: this.state.pw, + // phone_number: "01034358181", + // name: "๊น€๋„ํžˆ", + }), + }) + .then((res) => res.json()) + .then((result) => { + console.log(result); + if (result.MESSAGE === "SUCCESS") { + localStorage.setItem("Token", result.Token); + alert("๋กœ๊ทธ์ธ์„ฑ๊ณต!"); + this.props.history.push("/maindh"); + } else { + alert("๐ŸคฌIT'S YOUR FAULT!๐Ÿคฌ"); + } + }); + }; + + handleInput = (event) => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + render() { + const { id, pw } = this.state; + return ( + <> + <div className="login-wrap"> + <h1 className="title">Westagram</h1> + <div className="inner-wrap"> + <input + className="id" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={this.handleInput} + value={id} + name="id" + /> + <input + className="password" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={this.handleInput} + value={pw} + name="pw" + /> + <button + className={id.includes("@") && pw.length >= 5 ? "on" : "off"} + onClick={this.goToMain} + > + ๋กœ๊ทธ์ธ + </button> + <p> + <Link to="/Main">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</Link> + </p> + </div> + </div> + </> + ); + } +} + +export default withRouter(Login); + +//๊ฐ์ฒด ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น + +//const { fontState} = this.state
JavaScript
๋”ฐ๋กœ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์ฃผ์‹œ์ง€ ์•Š์•„๋„ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค-! ```js const { id, pw } = this.state; <button className={id.includes('@') && pw.length >= 5 ? 'on' : 'off'} onClick={this.goToMain}> ```
@@ -0,0 +1,79 @@ +@import url('https://fonts.googleapis.com/css2?family=Lobster&display=swap'); + +* { + box-sizing: border-box; +} +body{ + background-color:#fafafa; +} + +.login-wrap{ + width:30%; + height:550px; + background-color:#fff; + border:3px solid rgba(221, 221, 221, 0.3); + margin:130px auto 0 auto; + + h1{ + width:80%; + height:50px; + font-size:55px; + font-family: 'Lobster', cursive; + padding-top:50px; + margin:0 auto 120px auto; + text-align: center; + } + + .inner-wrap { + width:80%; + margin:auto; + height:300px; + + input { + width:100%; + height:60px; + border-radius: 5px; + border:2px solid rgba(221, 221, 221, 0.2); + margin-bottom:10px; + padding:30px 10px; + font-size:18px; + color:#000; + cursor: pointer; + outline:none; + line-height: 30px; + } + + .on { + background-color:#0094f6; + } + + .off { + background-color:#0094f64b; + } + + button { + width:100%; + height:50px; + margin-top:15px; + border:none; + background-color:#0094f64b; + border-radius: 8px; + color:#fff; + font-size:20px; + font-weight:600; + outline:none; + cursor:pointer; + } + + p{ + text-align:center; + margin-top:110px; + + a{ + color:#00376b; + font-size:16px; + text-decoration: none; + } + } + } +}
Unknown
์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ์Šคํƒ€์ผ ๊ฐ™์€๋ฐ, scss ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ด์„œ ์‚ฌ์šฉํ•ด์ฃผ์‹œ๋ฉด ์ข‹์„ ๋“ฏ ํ•˜๋„ค์š”-! ๐Ÿ‘
@@ -0,0 +1,63 @@ +import React from "react"; +import Story from "./Mainleft/Story"; +import Feed from "./Mainleft/Feed"; +import "./MainLeft.scss"; +// import { FaRedditAlien } from "react-icons/fa"; + +class MainLeft extends React.Component { + state = { + feedList: [], + }; + + componentDidMount() { + fetch("/data/FeedData.json", { + method: "GET", + }) + .then((res) => res.json()) + .then((data) => { + this.setState({ + feedList: data, + }); + }); + } + + aaa = () => { + // console.log("aaa ํ•จ์ˆ˜ํ˜ธ์ถœ"); + fetch("http://10.58.2.229:8000/posts/post", { + method: "GET", + headers: { + Authorization: localStorage.getItem("Token"), + }, + }) + .then((res) => res.json()) + .then((res) => { + this.setState({ + feedList: res.RESULT, + }); + console.log(res.RESULT); + }); + }; + + render() { + const { feedList } = this.state; + return ( + <div className="main-left"> + {/* <button onClick={this.aaa}>click</button> */} + <Story /> + {feedList.map((element) => { + return ( + <Feed + id={element.id} + name={element.userId} + count={element.count} + img={element.img} + title={element.title} + /> + ); + })} + </div> + ); + } +} + +export default MainLeft;
JavaScript
import ์ˆœ์„œ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š” ๐Ÿ‘ ์ผ๋ฐ˜์ ์ธ convention์„ ๋”ฐ๋ฅด๋Š” ์ด์œ ๋„ ์žˆ์ง€๋งŒ ์ˆœ์„œ๋งŒ ์ž˜ ์ง€์ผœ์ฃผ์…”๋„ ๊ฐ€๋…์„ฑ์ด ์ข‹์•„์ง‘๋‹ˆ๋‹ค. ์•„๋ž˜ ์ˆœ์„œ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”. - React โ†’ Library(Package) โ†’ Component โ†’ ๋ณ€์ˆ˜ / ์ด๋ฏธ์ง€ โ†’ css ํŒŒ์ผ(scss ํŒŒ์ผ)
@@ -0,0 +1,63 @@ +import React from "react"; +import Story from "./Mainleft/Story"; +import Feed from "./Mainleft/Feed"; +import "./MainLeft.scss"; +// import { FaRedditAlien } from "react-icons/fa"; + +class MainLeft extends React.Component { + state = { + feedList: [], + }; + + componentDidMount() { + fetch("/data/FeedData.json", { + method: "GET", + }) + .then((res) => res.json()) + .then((data) => { + this.setState({ + feedList: data, + }); + }); + } + + aaa = () => { + // console.log("aaa ํ•จ์ˆ˜ํ˜ธ์ถœ"); + fetch("http://10.58.2.229:8000/posts/post", { + method: "GET", + headers: { + Authorization: localStorage.getItem("Token"), + }, + }) + .then((res) => res.json()) + .then((res) => { + this.setState({ + feedList: res.RESULT, + }); + console.log(res.RESULT); + }); + }; + + render() { + const { feedList } = this.state; + return ( + <div className="main-left"> + {/* <button onClick={this.aaa}>click</button> */} + <Story /> + {feedList.map((element) => { + return ( + <Feed + id={element.id} + name={element.userId} + count={element.count} + img={element.img} + title={element.title} + /> + ); + })} + </div> + ); + } +} + +export default MainLeft;
JavaScript
1. ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ์˜ ๊ฒฝ์šฐ ๋”ฐ๋กœ ์ž…๋ ฅ์„ ํ•ด์ฃผ์ง€ ์•Š์œผ์…”๋„ ์ž๋™์œผ๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์ƒ๋žตํ•ด์„œ ์ž‘์„ฑ์„ ํ•ด์ฃผ์‹œ๋Š” ๊ฒŒ ๋” ์ข‹์Šต๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด, ํฌํŠธ ๋ฒˆํ˜ธ๊ฐ€ ๋ณ€๊ฒฝ๋˜๋Š” ๋•Œ๊ฐ€ ์ƒ๊ฐ๋ณด๋‹ค ๋งŽ์€๋ฐ, ์ด๋ ‡๊ฒŒ ์ง์ ‘ ์ž‘์„ฑ์„ ํ•ด์ฃผ์‹  ๊ฒฝ์šฐ ํฌํŠธ ๋ฒˆํ˜ธ๋ฅผ ์ผ์ผ์ด ์ˆ˜์ •ํ•ด์ฃผ์‹œ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ƒ๋žต์„ ํ•ด์„œ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•  ๊ฒฝ์šฐ, ์ž๋™์œผ๋กœ ๋ณ€๊ฒฝ๋œ ํฌํŠธ๋ฒˆํ˜ธ๊ฐ€ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค ๐Ÿ™Œ ```js fetch(`/data/Story.json`) .then(res => res.json()) .then( ... ) ``` 2. fetch ์˜ ๊ธฐ๋ณธ ๋ฉ”์„œ๋“œ๋Š” GET ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ { method: 'GET' } ๋ถ€๋ถ„๋„ ์ƒ๋žตํ•ด ์ฃผ์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
@@ -30,15 +30,17 @@ const OrderItem = () => { </div> </div> </div> - <div className="flex flex-row justify-center gap-3"> - <Link className="w-1/2" href={ROUTE_PATHS.ORDER_DETAIL}> + <div className="flex flex-row gap-3"> + <Link className="w-full" href={`${ROUTE_PATHS.ORDERS_DETAIL}/1`}> <Button size="s" className="h-10"> ์ฃผ๋ฌธ ์ƒ์„ธ </Button> </Link> - <Button variant="grayFit" size="s" className="h-10 w-1/2"> - ๋ฆฌ๋ทฐ ๋‹ฌ๊ธฐ - </Button> + <Link className="w-full" href={ROUTE_PATHS.REVIEW}> + <Button variant="grayFit" size="s" className="h-10"> + ๋ฆฌ๋ทฐ ๋‹ฌ๊ธฐ + </Button> + </Link> </div> </div> )
Unknown
href={`${ROUTE_PATHS.ORDER_DETAIL}/1`} ๋กœ ๋ณ€๊ฒฝํ•ด์ค€๋‹ค๋ฉด ์ถ”ํ›„์— route๊ฐ€ ๋ณ€๊ฒฝ๋์„ ๋•Œ ํ•˜๋‚˜ํ•˜๋‚˜ ์ฐพ์•„์„œ ๋ณ€๊ฒฝํ•ด์ฃผ์ง€ ์•Š์•„๋„ ๋  ๊ฑฐ ๊ฐ™์•„์š”~ ๋‚˜์ค‘์—๋Š” 1 ๋Œ€์‹  ${id} ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์‹œ๊ตฌ์š”!
@@ -7,8 +7,8 @@ const buttonVariants = cva('inline-flex items-center justify-center gap-2 whites variants: { variant: { default: 'bg-primary text-white hover:bg-primary/90 w-full px-4', - primaryFit: 'w-fit px-4 text-primary border-solid border border-primary', - grayFit: 'w-fit px-4 text-gray-400 border-solid border border-gray-400', + primaryFit: 'w-full px-4 text-primary border-solid border border-primary', + grayFit: 'w-full px-4 text-gray-400 border-solid border border-gray-400', }, size: { @@ -34,7 +34,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( return ( <button className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} /> ) - }, + } ) Button.displayName = 'Button'
Unknown
๊ณตํ†ต ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋ณ€๊ฒฝํ•  ๋•Œ๋Š” ๊ผญ ํŒ€์›๋“ค์—๊ฒŒ ๋ณ€๊ฒฝํ•ด๋„ ๋ ์ง€ ๋ฌผ์–ด๋ด์ฃผ์‹œ๋Š”๊ฒŒ ์ข‹์•„์š”! ๋ˆ„๊ตฐ๊ฐ€๋Š” w-fit์— ๋งž์ถฐ์„œ ๊ฐœ๋ฐœํ•ด๋†จ๋Š”๋ฐ ๋‚˜์ค‘์— ๋“ค์–ด๊ฐ€๋ณด๋‹ˆ ui๊ฐ€ ๊นจ์ ธ์žˆ์„ ์ˆ˜๋„ ์žˆ๊ฑฐ๋“ ์š” ใ… 
@@ -7,8 +7,8 @@ const buttonVariants = cva('inline-flex items-center justify-center gap-2 whites variants: { variant: { default: 'bg-primary text-white hover:bg-primary/90 w-full px-4', - primaryFit: 'w-fit px-4 text-primary border-solid border border-primary', - grayFit: 'w-fit px-4 text-gray-400 border-solid border border-gray-400', + primaryFit: 'w-full px-4 text-primary border-solid border border-primary', + grayFit: 'w-full px-4 text-gray-400 border-solid border border-gray-400', }, size: { @@ -34,7 +34,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( return ( <button className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} /> ) - }, + } ) Button.displayName = 'Button'
Unknown
๋„ต ๋‹ค์Œ์—๋Š” ๊ณต์ง€ ํ›„์— ๋ณ€๊ฒฝํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,65 @@ +import History from "@models/History"; +import { + getHistoryItemTemplate, + NO_HISTORY_TEMPLATE, +} from "@templates/history"; + +export default class HistoryController { + constructor(historyContainer) { + this.historyContainer = historyContainer; + this.numberOfHistory = 0; + this._init(); + } + _init() { + this._initEvent(); + this._initHistory(); + } + _initEvent() { + this.historyContainer.addEventListener("click", (event) => { + if (event.target.classList.contains("button__delete")) { + const toDeleteEl = event.target.parentElement; + this.deleteHistory(toDeleteEl); + } + }); + } + _initHistory() { + const history = History.getAll(); + this.numberOfHistory = history.length; + + if (this.numberOfHistory === 0) { + this.historyContainer.innerHTML = NO_HISTORY_TEMPLATE; + return; + } + + const historyTemplates = history + .map(({ value, id }) => getHistoryItemTemplate(value, id)) + .join(""); + this.historyContainer.innerHTML = historyTemplates; + } + addHistory(searchValue) { + const historyId = History.add(searchValue); + if (!historyId) { + return; + } + + const listItemEl = getHistoryItemTemplate(searchValue, historyId); + + this.numberOfHistory++; + if (this.numberOfHistory === 1) { + this.historyContainer.innerHTML = listItemEl; + return; + } + + this.historyContainer.insertAdjacentHTML("beforeend", listItemEl); + } + deleteHistory(historyEl) { + const id = historyEl.id; + this.historyContainer.removeChild(historyEl); + History.delete(id); + this.numberOfHistory--; + + if (this.numberOfHistory === 0) { + this.historyContainer.innerHTML = NO_HISTORY_TEMPLATE; + } + } +}
JavaScript
๐Ÿ‘ ๐Ÿ‘ ๋ฆฌ๋ทฐ๋“œ๋ฆฐ ๋ถ€๋ถ„ ๋ฐ˜์˜ํ•ด์ฃผ์…จ๋„ค์š”~! ํ™•์‹คํžˆ ํ…œํ”Œ๋ฆฟ์„ ์ƒ์ˆ˜๋กœ ๋ถ„๋ฆฌํ•˜๋‹ˆ๊นŒ ๊ฐ€๋…์„ฑ์ด ์ข‹์•„์กŒ๋„ค์š” :)
@@ -19,41 +19,56 @@ export default class Repo { }) { this.id = id; this.name = name; - this.full_name = full_name; + this.fullName = full_name; this.owner = owner; - this.html_url = html_url; + this.htmlUrl = html_url; this.description = description; - this.stargazers_count = stargazers_count; - this.watchers_count = watchers_count; - this.forks_count = forks_count; + this.stargazersCount = stargazers_count; + this.watchersCount = watchers_count; + this.forksCount = forks_count; this.forks = forks; - this.created_at = created_at; - this.updated_at = updated_at; - this.clone_url = clone_url; + this.createdAt = created_at; + this.updatedAt = updated_at; + this.cloneUrl = clone_url; this.language = language; this.watchers = watchers; this.visibility = visibility; } render() { return ` - <div class="col-12 col-sm-6 mb-4" id="repo-${this.id}"> + <div class="col-12 col-sm-6 mb-4 px-2" id="repo-${this.id}"> <div class="card border-secondary h-100" > - <div class="card-body"> - <div class="d-flex align-items-center flex-wrap"> - <h5 class="mb-2 mr-2"> - ${this.name} - </h5> - <span class="mb-2 badge bg-light"> + <div class="card-body d-flex flex-column justify-content-between"> + <div class="d-flex align-items-center flex-wrap" > + <a class="text-info d-flex align-items-center flex-wrap mb-2 mr-2" href="${ + this.htmlUrl + }" target="_blank"> + <h5> + ${this.name} + </h5> + </a> + <span class="mb-2 badge bg-light mr-2"> ${this.visibility} </span> + <span class="mb-2 d-flex align-items-center"> + <img alt="๋ ˆํฌ์ง€ํ† ๋ฆฌ ์Šคํƒ€ ์•„์ด์ฝ˜" src="${ + this.stargazersCount > 0 ? "star_filled.svg" : "star.svg" + }" height="16"/> + ${this.stargazersCount} + </span> </div> <p class="card-text">${this.description ?? ""}</p> <div> - <span class="text-secondary"> + <span class="text-secondary mr-2"> ${this.language ?? ""} </span> + <span class="text-secondary mr-2"> + <img src="fork.svg" alt="ํฌํฌ ์•„์ด์ฝ˜" height="18"/> + ${this.forks} + </span> <span class="text-secondary"> - ${this.forks > 0 ? this.forks : ""} + <img src="watch.svg" alt="์›Œ์น˜ ์•„์ด์ฝ˜" height="18"/> + ${this.watchersCount} </span> </div> </div>
JavaScript
`models/User.js` ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์ด๋ฏธ์ง€์—๋Š” alt๊ฐ€ ํ•œ๊ธ€๋กœ ๋˜์–ด์žˆ๋Š”๋ฐ ์ด๋ถ€๋ถ„์€ ์˜์–ด๋กœ ๋˜์–ด์žˆ๋„ค์š”! ํ†ต์ผ์‹œ์ผœ์ฃผ๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~
@@ -1,83 +1,112 @@ import GithubApiController from "@controllers/githubController"; import User from "@models/User"; +import { + NO_SEARCH_RESULT_TEMPLATE, + SEARCH_LOADING_TEMPLATE, + getReposTemplate, + NO_REPOS_TEMPLATE, +} from "@templates/search"; +import { SPINNER_TEMPLATE } from "@templates/spinner"; +import { NUMBER_OF_REPOS } from "@constants/search"; const searchResultContainer = document.body.querySelector(".search-result"); export default class SearchController { - constructor(inputEl, submitEl) { + constructor(inputEl, submitEl, historyController) { this.inputEl = inputEl; this.submitEl = submitEl; this.fetcher = new GithubApiController(); + this.historyController = historyController; this.init(); } init() { this.inputEl.addEventListener("keypress", (event) => { - if (event.code === 'Enter') { + if (event.code === "Enter") { this.search(this.inputEl.value); } }); this.submitEl.addEventListener("click", () => { this.search(this.inputEl.value); }); + + this.historyController.historyContainer.addEventListener( + "click", + (event) => { + if ( + event.target.classList.contains("list-group-item") && + !event.target.classList.contains("button__delete") + ) { + const [searchValue] = event.target.textContent.trim().split("\n"); + this.search(searchValue); + } + } + ); } async search(searchValue) { const renderUser = (user) => { const userResult = searchResultContainer.querySelector("#user-result"); userResult.id = user.id; - userResult.innerHTML = user.render(); + user.render(userResult); }; - - const renderRepos = (repos) => { + const renderNoUserInfo = () => { + const userResult = searchResultContainer.querySelector("#user-result"); + userResult.innerHTML = NO_SEARCH_RESULT_TEMPLATE; + }; + const createRepoResultContainerEl = () => { const repoResult = document.createElement("div"); - repoResult.id = "#repos-result"; + repoResult.id = "repo-result"; repoResult.className = "bs-component"; + return repoResult; + }; + const renderRepos = (repos, numberOfRepos) => { + const repoResult = createRepoResultContainerEl(); + repoResult.innerHTML = getReposTemplate(repos, numberOfRepos); - repoResult.innerHTML = ` - <div class="container"> - <div class="row"> - ${repos - .slice(0, 5) - .map((repo) => repo.render()) - .join("\n")} - </div> - </div> - `; searchResultContainer.appendChild(repoResult); }; + const renderNoRepos = () => { + const repoResult = createRepoResultContainerEl(); + repoResult.innerHTML = NO_REPOS_TEMPLATE; + + searchResultContainer.appendChild(repoResult); + }; + const createLoadingElement = () => { + const element = document.createElement("div"); + element.className = "card-body d-flex align-items-center"; + element.innerHTML = SPINNER_TEMPLATE; + return element; + }; const trimmedValue = searchValue.trim(); if (!trimmedValue) { alert("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”"); return; } - - searchResultContainer.innerHTML = ` - <div class="card my-3"> - <h4 class="card-header">๊ฒ€์ƒ‰๊ฒฐ๊ณผ</h4> - <div id="user-result" class="card-body d-flex align-items-center"> - <p class="text-center container-fluid"> - ๊ฒ€์ƒ‰์ค‘ - </p> - </div> - </div> - `; + this.historyController.addHistory(trimmedValue); + searchResultContainer.innerHTML = SEARCH_LOADING_TEMPLATE; const userInfo = await this.fetcher.getUser(trimmedValue); if (!userInfo) { - const userResult = searchResultContainer.querySelector("#user-result"); - userResult.innerHTML = ` - <p class="text-center container-fluid"> - ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. - </p> - `; + renderNoUserInfo(); return; } const user = new User(userInfo); renderUser(user); - user.setRepos(await this.fetcher.getRepos(user)); - renderRepos(user.repos); + const loadingEl = createLoadingElement(); + + searchResultContainer.appendChild(loadingEl); + const repos = await this.fetcher.getRepos(user); + searchResultContainer.removeChild(loadingEl); + + if (repos.length === 0) { + renderNoRepos(); + return; + } + + user.setRepos(repos); + renderRepos(user.repos, NUMBER_OF_REPOS); } }
JavaScript
๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์œผ๋ก  ํ•จ์ˆ˜๋ช…์ด `getXXXEl`๋กœ ๋˜์–ด์žˆ์–ด์„œ ๊ธฐ์กด์— ์กด์žฌํ•˜๋Š” ์—˜๋ ˆ๋จผํŠธ๋ฅผ ์ฟผ๋ฆฌ์…€๋ ‰ํŠธ๋กœ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ ๊ฐ™์€ ๋А๋‚Œ์ด ์žˆ๋Š”๋ฐ์š”, ์ƒˆ๋กœ์šด ์—˜๋ ˆ๋จผํŠธ๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋ฐ˜ํ™˜ํ•˜๋Š” ์—ญํ• ์„ ํ•ด์ฃผ๊ณ  ์žˆ์œผ๋‹ˆ `get` ๋Œ€์‹  `create`๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋„ค์ด๋ฐํ•ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š” :)
@@ -1,83 +1,112 @@ import GithubApiController from "@controllers/githubController"; import User from "@models/User"; +import { + NO_SEARCH_RESULT_TEMPLATE, + SEARCH_LOADING_TEMPLATE, + getReposTemplate, + NO_REPOS_TEMPLATE, +} from "@templates/search"; +import { SPINNER_TEMPLATE } from "@templates/spinner"; +import { NUMBER_OF_REPOS } from "@constants/search"; const searchResultContainer = document.body.querySelector(".search-result"); export default class SearchController { - constructor(inputEl, submitEl) { + constructor(inputEl, submitEl, historyController) { this.inputEl = inputEl; this.submitEl = submitEl; this.fetcher = new GithubApiController(); + this.historyController = historyController; this.init(); } init() { this.inputEl.addEventListener("keypress", (event) => { - if (event.code === 'Enter') { + if (event.code === "Enter") { this.search(this.inputEl.value); } }); this.submitEl.addEventListener("click", () => { this.search(this.inputEl.value); }); + + this.historyController.historyContainer.addEventListener( + "click", + (event) => { + if ( + event.target.classList.contains("list-group-item") && + !event.target.classList.contains("button__delete") + ) { + const [searchValue] = event.target.textContent.trim().split("\n"); + this.search(searchValue); + } + } + ); } async search(searchValue) { const renderUser = (user) => { const userResult = searchResultContainer.querySelector("#user-result"); userResult.id = user.id; - userResult.innerHTML = user.render(); + user.render(userResult); }; - - const renderRepos = (repos) => { + const renderNoUserInfo = () => { + const userResult = searchResultContainer.querySelector("#user-result"); + userResult.innerHTML = NO_SEARCH_RESULT_TEMPLATE; + }; + const createRepoResultContainerEl = () => { const repoResult = document.createElement("div"); - repoResult.id = "#repos-result"; + repoResult.id = "repo-result"; repoResult.className = "bs-component"; + return repoResult; + }; + const renderRepos = (repos, numberOfRepos) => { + const repoResult = createRepoResultContainerEl(); + repoResult.innerHTML = getReposTemplate(repos, numberOfRepos); - repoResult.innerHTML = ` - <div class="container"> - <div class="row"> - ${repos - .slice(0, 5) - .map((repo) => repo.render()) - .join("\n")} - </div> - </div> - `; searchResultContainer.appendChild(repoResult); }; + const renderNoRepos = () => { + const repoResult = createRepoResultContainerEl(); + repoResult.innerHTML = NO_REPOS_TEMPLATE; + + searchResultContainer.appendChild(repoResult); + }; + const createLoadingElement = () => { + const element = document.createElement("div"); + element.className = "card-body d-flex align-items-center"; + element.innerHTML = SPINNER_TEMPLATE; + return element; + }; const trimmedValue = searchValue.trim(); if (!trimmedValue) { alert("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”"); return; } - - searchResultContainer.innerHTML = ` - <div class="card my-3"> - <h4 class="card-header">๊ฒ€์ƒ‰๊ฒฐ๊ณผ</h4> - <div id="user-result" class="card-body d-flex align-items-center"> - <p class="text-center container-fluid"> - ๊ฒ€์ƒ‰์ค‘ - </p> - </div> - </div> - `; + this.historyController.addHistory(trimmedValue); + searchResultContainer.innerHTML = SEARCH_LOADING_TEMPLATE; const userInfo = await this.fetcher.getUser(trimmedValue); if (!userInfo) { - const userResult = searchResultContainer.querySelector("#user-result"); - userResult.innerHTML = ` - <p class="text-center container-fluid"> - ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. - </p> - `; + renderNoUserInfo(); return; } const user = new User(userInfo); renderUser(user); - user.setRepos(await this.fetcher.getRepos(user)); - renderRepos(user.repos); + const loadingEl = createLoadingElement(); + + searchResultContainer.appendChild(loadingEl); + const repos = await this.fetcher.getRepos(user); + searchResultContainer.removeChild(loadingEl); + + if (repos.length === 0) { + renderNoRepos(); + return; + } + + user.setRepos(repos); + renderRepos(user.repos, NUMBER_OF_REPOS); } }
JavaScript
์ง€๋‚œ๋ฒˆ์— `keyCode`๋กœ ์ฒ˜๋ฆฌํ–ˆ์„ ๋•Œ ๋ณด๋‹ค ์–ด๋–ค ํ‚ค๋ฅผ ๋ˆŒ๋ €์„ ๋•Œ ๋™์ž‘ํ•˜๋Š” ๋กœ์ง์ธ์ง€ ํŒŒ์•…ํ•˜๊ธฐ๊ฐ€ ์‰ฌ์›Œ์กŒ๋„ค์š” ๐Ÿ‘
@@ -0,0 +1,65 @@ +import History from "@models/History"; +import { + getHistoryItemTemplate, + NO_HISTORY_TEMPLATE, +} from "@templates/history"; + +export default class HistoryController { + constructor(historyContainer) { + this.historyContainer = historyContainer; + this.numberOfHistory = 0; + this._init(); + } + _init() { + this._initEvent(); + this._initHistory(); + } + _initEvent() { + this.historyContainer.addEventListener("click", (event) => { + if (event.target.classList.contains("button__delete")) { + const toDeleteEl = event.target.parentElement; + this.deleteHistory(toDeleteEl); + } + }); + } + _initHistory() { + const history = History.getAll(); + this.numberOfHistory = history.length; + + if (this.numberOfHistory === 0) { + this.historyContainer.innerHTML = NO_HISTORY_TEMPLATE; + return; + } + + const historyTemplates = history + .map(({ value, id }) => getHistoryItemTemplate(value, id)) + .join(""); + this.historyContainer.innerHTML = historyTemplates; + } + addHistory(searchValue) { + const historyId = History.add(searchValue); + if (!historyId) { + return; + } + + const listItemEl = getHistoryItemTemplate(searchValue, historyId); + + this.numberOfHistory++; + if (this.numberOfHistory === 1) { + this.historyContainer.innerHTML = listItemEl; + return; + } + + this.historyContainer.insertAdjacentHTML("beforeend", listItemEl); + } + deleteHistory(historyEl) { + const id = historyEl.id; + this.historyContainer.removeChild(historyEl); + History.delete(id); + this.numberOfHistory--; + + if (this.numberOfHistory === 0) { + this.historyContainer.innerHTML = NO_HISTORY_TEMPLATE; + } + } +}
JavaScript
์ง€์–ด์ฃผ์‹  ๋ณ€์ˆ˜๋ช…๋„ ์ถฉ๋ถ„ํžˆ ์˜๋ฏธํŒŒ์•…์ด ์ž˜๋˜๋Š”๋ฐ์š”! ํ˜น์‹œ ์ข€๋” ๊ฐ„๊ฒฐํ•œ ๋ณ€์ˆ˜๋ช…์„ ์›ํ•˜์‹ ๋‹ค๋ฉด `historyCount` ๋กœ ๋„ค์ด๋ฐํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž
@@ -1,11 +1,13 @@ import Repo from "@models/Repo"; +import { getDateDiff } from "@utils/dateUtils"; export default class User { constructor({ id, avatar_url, created_at, email, + bio, followers, following, login, @@ -22,57 +24,114 @@ export default class User { this.id = id; this.avartar = avatar_url; this.name = name; + this.bio = bio; this.followers = followers; this.following = following; this.loginId = login; this.email = email; - this.public_repos = public_repos; - this.public_gists = public_gists; - this.created_at = created_at; - this.html_url = html_url; + this.publicRepos = public_repos; + this.publicGists = public_gists; + this.createdAt = created_at; + this.htmlUrl = html_url; this.organizations_url = organizations_url; - this.starred_url = starred_url; + this.starredUrl = starred_url; this.subscriptions_url = subscriptions_url; - this.repos_url = repos_url; - this.updated_at = updated_at; + this.reposUrl = repos_url; + this.updatedAt = updated_at; this.repos = []; } - render() { + _getCreatedDateInfo() { + const today = new Date(); + const createdDate = new Date(this.createdAt); + const monthDiff = getDateDiff(today, createdDate, "month"); + + if (monthDiff === 0) { + const dayDiff = getDateDiff(today, createdDate, "day"); + return `${dayDiff}์ผ ์ „`; + } + + const year = Math.floor(monthDiff / 12); + const month = monthDiff % 12; + if (year === 0) { + return `${month}๊ฐœ์›” ์ „`; + } + if (month === 0) { + return `${year}๋…„ ์ „`; + } + + return `${year}๋…„ ${month}๊ฐœ์›” ์ „`; + } + setEvent() { + const activityChart = document.body.querySelector("#activity-chart"); + activityChart.onerror = (event) => { + event.target.style.setProperty("display", "none"); + event.target.parentElement.insertAdjacentHTML( + "beforeend", + '<div class="activity-error ml-4">No Activity Chart</div>' + ); + }; + } + template() { return ` - <div> - <img - src="${this.avartar}" - alt="${this.name} ํ”„๋กœํ•„์‚ฌ์ง„" - width="90" - class="mr-3 rounded-circle" - /> + <div class="w-100 flex-lg-row flex-column d-flex align-items-center justify-content-center"> + <div class="d-flex align-items-center justify-content-center"> + <img + src="${this.avartar}" + alt="${this.name} ํ”„๋กœํ•„์‚ฌ์ง„" + width="200" + class="mr-xl-3 mb-3 mb-xl-0 rounded-circle" + /> + </div> + <div class="w-100 d-flex flex-column align-items-lg-start align-items-center"> + <div class="px-4 text-lg-left text-center"> + <a class="text-primary" href="${this.htmlUrl}" target="_blank"> + <h5 class="card-title">${this.loginId} </h5> + </a> + <div class="d-flex align-items-end"> + <h6 class="card-subtitle m-0">${this.name ?? ""}</h6> + <span class="card-text text-muted ml-2 font-size-xs">${this._getCreatedDateInfo()}</span> </div> - <div> - <h5 class="card-title">${this.name} </h5> - <h6 class="card-subtitle text-muted">${this.loginId}</h6> - <div class="card-body p-0 mt-2"> - <a - href="https://github.com/dmstmdrbs?tab=followers" - target="_blank" - class="card-link badge bg-success text-white" - >Followers ${this.followers}๋ช…</a - > - <a - href="https://github.com/dmstmdrbs?tab=following" - target="_blank" - class="card-link badge bg-success text-white ml-2" - >Following ${this.following}๋ช…</a - > - <a - href="https://github.com/dmstmdrbs?tab=repositories" - target="_blank" - class="card-link badge bg-info text-white ml-2" - >Repos ${this.public_repos}๊ฐœ</a - > - <span class="badge bg-secondary text-white ml-2">Gists ${this.public_gists}๊ฐœ</span> - </div> - </div> - `; + <p class="m-0 mt-2">${this.bio ?? ""}</p> + </div> + <div class="card-body py-1 ml-1 mb-2"> + <a + href="https://github.com/${this.loginId}?tab=followers" + target="_blank" + class="card-link badge bg-success text-white" + >Followers ${this.followers}๋ช…</a + > + <a + href="https://github.com/${this.loginId}?tab=following" + target="_blank" + class="card-link badge bg-success text-white ml-2" + >Following ${this.following}๋ช…</a + > + <a + href="https://github.com/${this.loginId}?tab=repositories" + target="_blank" + class="card-link badge bg-info text-white ml-2" + >Repos ${this.publicRepos}๊ฐœ + </a> + <span class="badge bg-secondary text-white ml-2"> + Gists ${this.publicGists}๊ฐœ + </span> + </div> + <div class="w-100"> + <img + id="activity-chart" + class="w-100" + style="max-width: 663px;" + src="https://ghchart.rshah.org/${this.loginId}" + alt="๊นƒํ—ˆ๋ธŒ ํ™œ๋™ ์ฐจํŠธ" + /> + </div> + </div> + </div> + `; + } + render(container) { + container.innerHTML = this.template(); + this.setEvent(); } setRepos(repos) { this.repos = repos
JavaScript
`loginId` ๋งŒ ์นด๋ฉœ์ผ€์ด์Šค๋กœ ์ •์˜ ๋˜์–ด์žˆ๋„ค์š”! ๋ณ€์ˆ˜๋ช… ํ‘œ๊ธฐ๋ฒ•์„ ํ†ต์ผ์‹œํ‚ค๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”
@@ -19,41 +19,56 @@ export default class Repo { }) { this.id = id; this.name = name; - this.full_name = full_name; + this.fullName = full_name; this.owner = owner; - this.html_url = html_url; + this.htmlUrl = html_url; this.description = description; - this.stargazers_count = stargazers_count; - this.watchers_count = watchers_count; - this.forks_count = forks_count; + this.stargazersCount = stargazers_count; + this.watchersCount = watchers_count; + this.forksCount = forks_count; this.forks = forks; - this.created_at = created_at; - this.updated_at = updated_at; - this.clone_url = clone_url; + this.createdAt = created_at; + this.updatedAt = updated_at; + this.cloneUrl = clone_url; this.language = language; this.watchers = watchers; this.visibility = visibility; } render() { return ` - <div class="col-12 col-sm-6 mb-4" id="repo-${this.id}"> + <div class="col-12 col-sm-6 mb-4 px-2" id="repo-${this.id}"> <div class="card border-secondary h-100" > - <div class="card-body"> - <div class="d-flex align-items-center flex-wrap"> - <h5 class="mb-2 mr-2"> - ${this.name} - </h5> - <span class="mb-2 badge bg-light"> + <div class="card-body d-flex flex-column justify-content-between"> + <div class="d-flex align-items-center flex-wrap" > + <a class="text-info d-flex align-items-center flex-wrap mb-2 mr-2" href="${ + this.htmlUrl + }" target="_blank"> + <h5> + ${this.name} + </h5> + </a> + <span class="mb-2 badge bg-light mr-2"> ${this.visibility} </span> + <span class="mb-2 d-flex align-items-center"> + <img alt="๋ ˆํฌ์ง€ํ† ๋ฆฌ ์Šคํƒ€ ์•„์ด์ฝ˜" src="${ + this.stargazersCount > 0 ? "star_filled.svg" : "star.svg" + }" height="16"/> + ${this.stargazersCount} + </span> </div> <p class="card-text">${this.description ?? ""}</p> <div> - <span class="text-secondary"> + <span class="text-secondary mr-2"> ${this.language ?? ""} </span> + <span class="text-secondary mr-2"> + <img src="fork.svg" alt="ํฌํฌ ์•„์ด์ฝ˜" height="18"/> + ${this.forks} + </span> <span class="text-secondary"> - ${this.forks > 0 ? this.forks : ""} + <img src="watch.svg" alt="์›Œ์น˜ ์•„์ด์ฝ˜" height="18"/> + ${this.watchersCount} </span> </div> </div>
JavaScript
๊ทธ ๋ถ€๋ถ„์€ ์‹ ๊ฒฝ์“ฐ์ง€ ๋ชปํ–ˆ๋„ค์š”! ํ•œ๊ตญ ์„œ๋น„์Šค์—์„œ๋Š” alt๋„ ํ•œ๊ธ€๋กœ ์ ์–ด์ฃผ๋Š”๊ฒŒ ๋” ๋‚˜์„๊นŒ์š”?
@@ -1,83 +1,112 @@ import GithubApiController from "@controllers/githubController"; import User from "@models/User"; +import { + NO_SEARCH_RESULT_TEMPLATE, + SEARCH_LOADING_TEMPLATE, + getReposTemplate, + NO_REPOS_TEMPLATE, +} from "@templates/search"; +import { SPINNER_TEMPLATE } from "@templates/spinner"; +import { NUMBER_OF_REPOS } from "@constants/search"; const searchResultContainer = document.body.querySelector(".search-result"); export default class SearchController { - constructor(inputEl, submitEl) { + constructor(inputEl, submitEl, historyController) { this.inputEl = inputEl; this.submitEl = submitEl; this.fetcher = new GithubApiController(); + this.historyController = historyController; this.init(); } init() { this.inputEl.addEventListener("keypress", (event) => { - if (event.code === 'Enter') { + if (event.code === "Enter") { this.search(this.inputEl.value); } }); this.submitEl.addEventListener("click", () => { this.search(this.inputEl.value); }); + + this.historyController.historyContainer.addEventListener( + "click", + (event) => { + if ( + event.target.classList.contains("list-group-item") && + !event.target.classList.contains("button__delete") + ) { + const [searchValue] = event.target.textContent.trim().split("\n"); + this.search(searchValue); + } + } + ); } async search(searchValue) { const renderUser = (user) => { const userResult = searchResultContainer.querySelector("#user-result"); userResult.id = user.id; - userResult.innerHTML = user.render(); + user.render(userResult); }; - - const renderRepos = (repos) => { + const renderNoUserInfo = () => { + const userResult = searchResultContainer.querySelector("#user-result"); + userResult.innerHTML = NO_SEARCH_RESULT_TEMPLATE; + }; + const createRepoResultContainerEl = () => { const repoResult = document.createElement("div"); - repoResult.id = "#repos-result"; + repoResult.id = "repo-result"; repoResult.className = "bs-component"; + return repoResult; + }; + const renderRepos = (repos, numberOfRepos) => { + const repoResult = createRepoResultContainerEl(); + repoResult.innerHTML = getReposTemplate(repos, numberOfRepos); - repoResult.innerHTML = ` - <div class="container"> - <div class="row"> - ${repos - .slice(0, 5) - .map((repo) => repo.render()) - .join("\n")} - </div> - </div> - `; searchResultContainer.appendChild(repoResult); }; + const renderNoRepos = () => { + const repoResult = createRepoResultContainerEl(); + repoResult.innerHTML = NO_REPOS_TEMPLATE; + + searchResultContainer.appendChild(repoResult); + }; + const createLoadingElement = () => { + const element = document.createElement("div"); + element.className = "card-body d-flex align-items-center"; + element.innerHTML = SPINNER_TEMPLATE; + return element; + }; const trimmedValue = searchValue.trim(); if (!trimmedValue) { alert("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”"); return; } - - searchResultContainer.innerHTML = ` - <div class="card my-3"> - <h4 class="card-header">๊ฒ€์ƒ‰๊ฒฐ๊ณผ</h4> - <div id="user-result" class="card-body d-flex align-items-center"> - <p class="text-center container-fluid"> - ๊ฒ€์ƒ‰์ค‘ - </p> - </div> - </div> - `; + this.historyController.addHistory(trimmedValue); + searchResultContainer.innerHTML = SEARCH_LOADING_TEMPLATE; const userInfo = await this.fetcher.getUser(trimmedValue); if (!userInfo) { - const userResult = searchResultContainer.querySelector("#user-result"); - userResult.innerHTML = ` - <p class="text-center container-fluid"> - ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. - </p> - `; + renderNoUserInfo(); return; } const user = new User(userInfo); renderUser(user); - user.setRepos(await this.fetcher.getRepos(user)); - renderRepos(user.repos); + const loadingEl = createLoadingElement(); + + searchResultContainer.appendChild(loadingEl); + const repos = await this.fetcher.getRepos(user); + searchResultContainer.removeChild(loadingEl); + + if (repos.length === 0) { + renderNoRepos(); + return; + } + + user.setRepos(repos); + renderRepos(user.repos, NUMBER_OF_REPOS); } }
JavaScript
๊ธฐ์กด vs ์ƒˆ๋กœ ์ƒ์„ฑ์€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ๋‹ˆ๊นŒ create๊ฐ€ ๋” ๋ช…ํ™•ํ•˜๊ฒ ๋„ค์š” :)
@@ -0,0 +1,65 @@ +import History from "@models/History"; +import { + getHistoryItemTemplate, + NO_HISTORY_TEMPLATE, +} from "@templates/history"; + +export default class HistoryController { + constructor(historyContainer) { + this.historyContainer = historyContainer; + this.numberOfHistory = 0; + this._init(); + } + _init() { + this._initEvent(); + this._initHistory(); + } + _initEvent() { + this.historyContainer.addEventListener("click", (event) => { + if (event.target.classList.contains("button__delete")) { + const toDeleteEl = event.target.parentElement; + this.deleteHistory(toDeleteEl); + } + }); + } + _initHistory() { + const history = History.getAll(); + this.numberOfHistory = history.length; + + if (this.numberOfHistory === 0) { + this.historyContainer.innerHTML = NO_HISTORY_TEMPLATE; + return; + } + + const historyTemplates = history + .map(({ value, id }) => getHistoryItemTemplate(value, id)) + .join(""); + this.historyContainer.innerHTML = historyTemplates; + } + addHistory(searchValue) { + const historyId = History.add(searchValue); + if (!historyId) { + return; + } + + const listItemEl = getHistoryItemTemplate(searchValue, historyId); + + this.numberOfHistory++; + if (this.numberOfHistory === 1) { + this.historyContainer.innerHTML = listItemEl; + return; + } + + this.historyContainer.insertAdjacentHTML("beforeend", listItemEl); + } + deleteHistory(historyEl) { + const id = historyEl.id; + this.historyContainer.removeChild(historyEl); + History.delete(id); + this.numberOfHistory--; + + if (this.numberOfHistory === 0) { + this.historyContainer.innerHTML = NO_HISTORY_TEMPLATE; + } + } +}
JavaScript
๊ฐ„๊ฒฐํ•œ ๋ฒ„์ „๋„ ๊ดœ์ฐฎ๊ตฐ์š” ใ…Žใ…Ž
@@ -1,11 +1,13 @@ import Repo from "@models/Repo"; +import { getDateDiff } from "@utils/dateUtils"; export default class User { constructor({ id, avatar_url, created_at, email, + bio, followers, following, login, @@ -22,57 +24,114 @@ export default class User { this.id = id; this.avartar = avatar_url; this.name = name; + this.bio = bio; this.followers = followers; this.following = following; this.loginId = login; this.email = email; - this.public_repos = public_repos; - this.public_gists = public_gists; - this.created_at = created_at; - this.html_url = html_url; + this.publicRepos = public_repos; + this.publicGists = public_gists; + this.createdAt = created_at; + this.htmlUrl = html_url; this.organizations_url = organizations_url; - this.starred_url = starred_url; + this.starredUrl = starred_url; this.subscriptions_url = subscriptions_url; - this.repos_url = repos_url; - this.updated_at = updated_at; + this.reposUrl = repos_url; + this.updatedAt = updated_at; this.repos = []; } - render() { + _getCreatedDateInfo() { + const today = new Date(); + const createdDate = new Date(this.createdAt); + const monthDiff = getDateDiff(today, createdDate, "month"); + + if (monthDiff === 0) { + const dayDiff = getDateDiff(today, createdDate, "day"); + return `${dayDiff}์ผ ์ „`; + } + + const year = Math.floor(monthDiff / 12); + const month = monthDiff % 12; + if (year === 0) { + return `${month}๊ฐœ์›” ์ „`; + } + if (month === 0) { + return `${year}๋…„ ์ „`; + } + + return `${year}๋…„ ${month}๊ฐœ์›” ์ „`; + } + setEvent() { + const activityChart = document.body.querySelector("#activity-chart"); + activityChart.onerror = (event) => { + event.target.style.setProperty("display", "none"); + event.target.parentElement.insertAdjacentHTML( + "beforeend", + '<div class="activity-error ml-4">No Activity Chart</div>' + ); + }; + } + template() { return ` - <div> - <img - src="${this.avartar}" - alt="${this.name} ํ”„๋กœํ•„์‚ฌ์ง„" - width="90" - class="mr-3 rounded-circle" - /> + <div class="w-100 flex-lg-row flex-column d-flex align-items-center justify-content-center"> + <div class="d-flex align-items-center justify-content-center"> + <img + src="${this.avartar}" + alt="${this.name} ํ”„๋กœํ•„์‚ฌ์ง„" + width="200" + class="mr-xl-3 mb-3 mb-xl-0 rounded-circle" + /> + </div> + <div class="w-100 d-flex flex-column align-items-lg-start align-items-center"> + <div class="px-4 text-lg-left text-center"> + <a class="text-primary" href="${this.htmlUrl}" target="_blank"> + <h5 class="card-title">${this.loginId} </h5> + </a> + <div class="d-flex align-items-end"> + <h6 class="card-subtitle m-0">${this.name ?? ""}</h6> + <span class="card-text text-muted ml-2 font-size-xs">${this._getCreatedDateInfo()}</span> </div> - <div> - <h5 class="card-title">${this.name} </h5> - <h6 class="card-subtitle text-muted">${this.loginId}</h6> - <div class="card-body p-0 mt-2"> - <a - href="https://github.com/dmstmdrbs?tab=followers" - target="_blank" - class="card-link badge bg-success text-white" - >Followers ${this.followers}๋ช…</a - > - <a - href="https://github.com/dmstmdrbs?tab=following" - target="_blank" - class="card-link badge bg-success text-white ml-2" - >Following ${this.following}๋ช…</a - > - <a - href="https://github.com/dmstmdrbs?tab=repositories" - target="_blank" - class="card-link badge bg-info text-white ml-2" - >Repos ${this.public_repos}๊ฐœ</a - > - <span class="badge bg-secondary text-white ml-2">Gists ${this.public_gists}๊ฐœ</span> - </div> - </div> - `; + <p class="m-0 mt-2">${this.bio ?? ""}</p> + </div> + <div class="card-body py-1 ml-1 mb-2"> + <a + href="https://github.com/${this.loginId}?tab=followers" + target="_blank" + class="card-link badge bg-success text-white" + >Followers ${this.followers}๋ช…</a + > + <a + href="https://github.com/${this.loginId}?tab=following" + target="_blank" + class="card-link badge bg-success text-white ml-2" + >Following ${this.following}๋ช…</a + > + <a + href="https://github.com/${this.loginId}?tab=repositories" + target="_blank" + class="card-link badge bg-info text-white ml-2" + >Repos ${this.publicRepos}๊ฐœ + </a> + <span class="badge bg-secondary text-white ml-2"> + Gists ${this.publicGists}๊ฐœ + </span> + </div> + <div class="w-100"> + <img + id="activity-chart" + class="w-100" + style="max-width: 663px;" + src="https://ghchart.rshah.org/${this.loginId}" + alt="๊นƒํ—ˆ๋ธŒ ํ™œ๋™ ์ฐจํŠธ" + /> + </div> + </div> + </div> + `; + } + render(container) { + container.innerHTML = this.template(); + this.setEvent(); } setRepos(repos) { this.repos = repos
JavaScript
๊ฐ์ฒด ํ”„๋กœํผํ‹ฐ๋ฅผ ๋ณต์‚ฌํ•ด์˜ค๋Š” ๊ณผ์ •์—์„œ ๋‹ค๋ฅธ ๋ถ€๋ถ„์€ ์‹ ๊ฒฝ์„ ์“ฐ์ง€ ๋ชปํ–ˆ๋„ค์š”...! ํ†ต์ผ ์‹œ์ผœ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -19,41 +19,56 @@ export default class Repo { }) { this.id = id; this.name = name; - this.full_name = full_name; + this.fullName = full_name; this.owner = owner; - this.html_url = html_url; + this.htmlUrl = html_url; this.description = description; - this.stargazers_count = stargazers_count; - this.watchers_count = watchers_count; - this.forks_count = forks_count; + this.stargazersCount = stargazers_count; + this.watchersCount = watchers_count; + this.forksCount = forks_count; this.forks = forks; - this.created_at = created_at; - this.updated_at = updated_at; - this.clone_url = clone_url; + this.createdAt = created_at; + this.updatedAt = updated_at; + this.cloneUrl = clone_url; this.language = language; this.watchers = watchers; this.visibility = visibility; } render() { return ` - <div class="col-12 col-sm-6 mb-4" id="repo-${this.id}"> + <div class="col-12 col-sm-6 mb-4 px-2" id="repo-${this.id}"> <div class="card border-secondary h-100" > - <div class="card-body"> - <div class="d-flex align-items-center flex-wrap"> - <h5 class="mb-2 mr-2"> - ${this.name} - </h5> - <span class="mb-2 badge bg-light"> + <div class="card-body d-flex flex-column justify-content-between"> + <div class="d-flex align-items-center flex-wrap" > + <a class="text-info d-flex align-items-center flex-wrap mb-2 mr-2" href="${ + this.htmlUrl + }" target="_blank"> + <h5> + ${this.name} + </h5> + </a> + <span class="mb-2 badge bg-light mr-2"> ${this.visibility} </span> + <span class="mb-2 d-flex align-items-center"> + <img alt="๋ ˆํฌ์ง€ํ† ๋ฆฌ ์Šคํƒ€ ์•„์ด์ฝ˜" src="${ + this.stargazersCount > 0 ? "star_filled.svg" : "star.svg" + }" height="16"/> + ${this.stargazersCount} + </span> </div> <p class="card-text">${this.description ?? ""}</p> <div> - <span class="text-secondary"> + <span class="text-secondary mr-2"> ${this.language ?? ""} </span> + <span class="text-secondary mr-2"> + <img src="fork.svg" alt="ํฌํฌ ์•„์ด์ฝ˜" height="18"/> + ${this.forks} + </span> <span class="text-secondary"> - ${this.forks > 0 ? this.forks : ""} + <img src="watch.svg" alt="์›Œ์น˜ ์•„์ด์ฝ˜" height="18"/> + ${this.watchersCount} </span> </div> </div>
JavaScript
๋„ต~ ์ œ๊ฐ€ ์ง€๊ธˆ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์˜ ๊ฒฝ์šฐ ๋‹ค ํ•œ๊ธ€๋กœ alt ์ ์–ด์ฃผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค!
@@ -19,41 +19,56 @@ export default class Repo { }) { this.id = id; this.name = name; - this.full_name = full_name; + this.fullName = full_name; this.owner = owner; - this.html_url = html_url; + this.htmlUrl = html_url; this.description = description; - this.stargazers_count = stargazers_count; - this.watchers_count = watchers_count; - this.forks_count = forks_count; + this.stargazersCount = stargazers_count; + this.watchersCount = watchers_count; + this.forksCount = forks_count; this.forks = forks; - this.created_at = created_at; - this.updated_at = updated_at; - this.clone_url = clone_url; + this.createdAt = created_at; + this.updatedAt = updated_at; + this.cloneUrl = clone_url; this.language = language; this.watchers = watchers; this.visibility = visibility; } render() { return ` - <div class="col-12 col-sm-6 mb-4" id="repo-${this.id}"> + <div class="col-12 col-sm-6 mb-4 px-2" id="repo-${this.id}"> <div class="card border-secondary h-100" > - <div class="card-body"> - <div class="d-flex align-items-center flex-wrap"> - <h5 class="mb-2 mr-2"> - ${this.name} - </h5> - <span class="mb-2 badge bg-light"> + <div class="card-body d-flex flex-column justify-content-between"> + <div class="d-flex align-items-center flex-wrap" > + <a class="text-info d-flex align-items-center flex-wrap mb-2 mr-2" href="${ + this.htmlUrl + }" target="_blank"> + <h5> + ${this.name} + </h5> + </a> + <span class="mb-2 badge bg-light mr-2"> ${this.visibility} </span> + <span class="mb-2 d-flex align-items-center"> + <img alt="๋ ˆํฌ์ง€ํ† ๋ฆฌ ์Šคํƒ€ ์•„์ด์ฝ˜" src="${ + this.stargazersCount > 0 ? "star_filled.svg" : "star.svg" + }" height="16"/> + ${this.stargazersCount} + </span> </div> <p class="card-text">${this.description ?? ""}</p> <div> - <span class="text-secondary"> + <span class="text-secondary mr-2"> ${this.language ?? ""} </span> + <span class="text-secondary mr-2"> + <img src="fork.svg" alt="ํฌํฌ ์•„์ด์ฝ˜" height="18"/> + ${this.forks} + </span> <span class="text-secondary"> - ${this.forks > 0 ? this.forks : ""} + <img src="watch.svg" alt="์›Œ์น˜ ์•„์ด์ฝ˜" height="18"/> + ${this.watchersCount} </span> </div> </div>
JavaScript
์•„ํ•˜! ์ฐธ๊ณ ํ•ด์„œ ์ง„ํ–‰ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค~
@@ -0,0 +1,20 @@ +import { IsInt, IsNotEmpty, IsPositive, IsString, IsUUID } from 'class-validator'; + +export class CreateReviewDTO { + @IsUUID() + @IsNotEmpty() + makerId: string; + + @IsInt() + @IsPositive() + @IsNotEmpty() + rating: number; + + @IsString() + @IsNotEmpty() + content: string; + + @IsUUID() + @IsNotEmpty() + planId: string; +}
TypeScript
๋ณ„์ ์— 0.5์ ์€ ์—†๋‚˜์š”?
@@ -0,0 +1,20 @@ +import { IsInt, IsNotEmpty, IsPositive, IsString, IsUUID } from 'class-validator'; + +export class CreateReviewDTO { + @IsUUID() + @IsNotEmpty() + makerId: string; + + @IsInt() + @IsPositive() + @IsNotEmpty() + rating: number; + + @IsString() + @IsNotEmpty() + content: string; + + @IsUUID() + @IsNotEmpty() + planId: string; +}
TypeScript
๋„ค! ๊ฐ’์€ ์ •์ˆ˜(1,2,3,4,5)๋กœ ๋ฐ›๊ธฐ๋กœ ํ•˜๊ณ , ์‘๋‹ต์—๋Š” ์†Œ์ˆ˜์  1์ž๋ฆฌ๊นŒ์ง€ ๋ฐ˜ํ™˜ํ•˜๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,48 @@ +import { PlanReference } from 'src/common/types/plan/plan.type'; +import { ReviewAllProperties, ReviewProperties } from 'src/common/types/review/review.types'; +import { UserReference } from 'src/common/types/user/user.types'; + +export default class Review { + private readonly id?: string; + private writerId: string; + private writer?: UserReference; + private ownerId: string; + private owner?: UserReference; + private rating: number; + private content: string; + private planId: string; + private plan: PlanReference; + private readonly createdAt?: Date; + private readonly updatedAt?: Date; + + constructor(review: ReviewAllProperties) { + this.id = review?.id; + this.writerId = review.writerId; + this.writer = review?.writer; + this.ownerId = review.ownerId; + this.owner = review?.owner; + this.rating = review.rating; + this.content = review.content; + this.planId = review.planId; + this.plan = review?.plan; + this.createdAt = review?.createdAt; + this.updatedAt = review?.updatedAt; + } + + static create(data: ReviewProperties) { + return new Review(data); + } + + toDB() { + return { + id: this.id, + writerId: this.writerId, + ownerId: this.ownerId, + rating: this.rating, + content: this.content, + planId: this.planId, + createdAt: this.createdAt, + updatedAt: this.updatedAt + }; + } +}
TypeScript
get ๋ฉ”์†Œ๋“œ๋กœ DB๋ณด๋‚ด๊ธฐ ๋ณด๋‹ค๋Š” DB์—๋Š” createdAt๊ณผ updatedAt์„ ์“ธ ์ผ์ด ์—†์œผ๋‹ˆ๊นŒ ๋บด๊ณ  toDB ๋ฉ”์†Œ๋“œ ์ด๋ฆ„์ด ์ข‹์•„๋ณด์—ฌ์š”. ๋งŒ์•ฝ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๊ฐ€ ํ•„์š”ํ•œ ๋ถ€๋ถ„์ด ์ƒ๊ธด๋‹ค๋ฉด ๊ทธ ๋•Œ get ๋ฉ”์†Œ๋“œ๋กœ ๋ชจ๋“ ๊ฑธ ๋‚ด๋ณด๋‚ด๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,45 @@ +import { Injectable } from '@nestjs/common'; +import ReviewRepository from './review.repository'; +import PlanService from '../plan/plan.service'; +import { StatusEnum } from 'src/common/constants/status.type'; +import BadRequestError from 'src/common/errors/badRequestError'; +import ErrorMessage from 'src/common/constants/errorMessage.enum'; +import { CreateReviewDTO } from 'src/common/types/review/review.dto'; +import Review from 'src/common/domains/review/review.domain'; +import { InjectQueue } from '@nestjs/bullmq'; +import { Queue } from 'bullmq'; + +@Injectable() +export default class ReviewService { + constructor( + @InjectQueue('stats') private readonly queue: Queue, + private readonly repository: ReviewRepository, + private readonly plan: PlanService + ) {} + + async create(writerId: string, data: CreateReviewDTO) { + const plan = await this.plan.getPlanById(data.planId); + if (plan.status !== StatusEnum.COMPLETED) { + throw new BadRequestError(ErrorMessage.REVIEW_BAD_REQUEST); + } + + const review = Review.create({ + writerId, + ownerId: data.makerId, + rating: data.rating, + content: data.content, + planId: data.planId + }); + await this.repository.create(review); + + // ๋ฉ”์ด์ปค์˜ UserStats(๋ฆฌ๋ทฐ ์ˆ˜, ํ‰์ ) ์—…๋ฐ์ดํŠธ ์ž‘์—…์„ ํ์— ์ถ”๊ฐ€ + await this.queue.add('stats', { + userId: data.makerId, + event: EventType.REVIEW, + isAdd: true, + rating: data.rating + }); + + return; + } +}
TypeScript
๊ฐ’์„ ๋„ฃ์–ด์ค„ ๋ฟ์ด๋”๋ผ๋„ ์œ ์ง€๋ณด์ˆ˜ ์ธก๋ฉด์—์„œ static create ๋ฉ”์†Œ๋“œ๋กœ ๋งŒ๋“œ์‹œ๋ ค๋Š”๊ฑฐ ์•„๋‹ˆ์˜€๋‚˜์š”?
@@ -0,0 +1,45 @@ +import { Injectable } from '@nestjs/common'; +import ReviewRepository from './review.repository'; +import PlanService from '../plan/plan.service'; +import { StatusEnum } from 'src/common/constants/status.type'; +import BadRequestError from 'src/common/errors/badRequestError'; +import ErrorMessage from 'src/common/constants/errorMessage.enum'; +import { CreateReviewDTO } from 'src/common/types/review/review.dto'; +import Review from 'src/common/domains/review/review.domain'; +import { InjectQueue } from '@nestjs/bullmq'; +import { Queue } from 'bullmq'; + +@Injectable() +export default class ReviewService { + constructor( + @InjectQueue('stats') private readonly queue: Queue, + private readonly repository: ReviewRepository, + private readonly plan: PlanService + ) {} + + async create(writerId: string, data: CreateReviewDTO) { + const plan = await this.plan.getPlanById(data.planId); + if (plan.status !== StatusEnum.COMPLETED) { + throw new BadRequestError(ErrorMessage.REVIEW_BAD_REQUEST); + } + + const review = Review.create({ + writerId, + ownerId: data.makerId, + rating: data.rating, + content: data.content, + planId: data.planId + }); + await this.repository.create(review); + + // ๋ฉ”์ด์ปค์˜ UserStats(๋ฆฌ๋ทฐ ์ˆ˜, ํ‰์ ) ์—…๋ฐ์ดํŠธ ์ž‘์—…์„ ํ์— ์ถ”๊ฐ€ + await this.queue.add('stats', { + userId: data.makerId, + event: EventType.REVIEW, + isAdd: true, + rating: data.rating + }); + + return; + } +}
TypeScript
์ €๋ฒˆ์— ๊ทธ๋ ‡๊ฒŒ ๋ง์”€๋“œ๋ ธ์—ˆ์ฃ ..ใ…Žใ…Žใ…Ž ๊ทธ๋Ÿฐ๋ฐ ์˜ค๋Š˜ review ๋„๋ฉ”์ธ์„ ์ƒˆ๋กœ ๋งŒ๋“ค๋‹ค๋ณด๋‹ˆ create ๋ฉ”์†Œ๋“œ์—์„œ return new Revier(data)๋งŒ ํ•˜๊ณ , ํŠน๋ณ„ํžˆ ๊ฒ€์ฆ์ด๋‚˜ ๋‹ค๋ฅธ ์ž‘์—…์ด ์—†์–ด์„œ ๊ตณ์ด ์จ์•ผ ํ• ๊นŒ ์˜๋ฌธ์ด ๋“ค์–ด๊ฐ€์ง€๊ณ ... ๋‹ค๋ฅธ ๋„๋ฉ”์ธ๋„ ๋„๋ฉ”์ธ์„ ๋งŒ๋“ค ๋•Œ ํŠน๋ณ„ํ•œ ์ด์Šˆ๊ฐ€ ์—†๋‹ค๋ฉด ๋ฐ”๊ฟ€๊นŒ ํ•˜๋Š”๋ฐ, ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”?
@@ -0,0 +1,48 @@ +import { PlanReference } from 'src/common/types/plan/plan.type'; +import { ReviewAllProperties, ReviewProperties } from 'src/common/types/review/review.types'; +import { UserReference } from 'src/common/types/user/user.types'; + +export default class Review { + private readonly id?: string; + private writerId: string; + private writer?: UserReference; + private ownerId: string; + private owner?: UserReference; + private rating: number; + private content: string; + private planId: string; + private plan: PlanReference; + private readonly createdAt?: Date; + private readonly updatedAt?: Date; + + constructor(review: ReviewAllProperties) { + this.id = review?.id; + this.writerId = review.writerId; + this.writer = review?.writer; + this.ownerId = review.ownerId; + this.owner = review?.owner; + this.rating = review.rating; + this.content = review.content; + this.planId = review.planId; + this.plan = review?.plan; + this.createdAt = review?.createdAt; + this.updatedAt = review?.updatedAt; + } + + static create(data: ReviewProperties) { + return new Review(data); + } + + toDB() { + return { + id: this.id, + writerId: this.writerId, + ownerId: this.ownerId, + rating: this.rating, + content: this.content, + planId: this.planId, + createdAt: this.createdAt, + updatedAt: this.updatedAt + }; + } +}
TypeScript
๋„ค! ์„œ๋น„์Šค์— get ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€ํ•˜๋ฉด์„œ toDB, toClient ์ด๋Ÿฐ ์‹์œผ๋กœ ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :)
@@ -1,70 +1,10 @@ -# Getting Started with Create React App +# React Westagram 3ํŒ€ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +instagram์„ ๋ชจํ‹ฐ๋ธŒ๋กœ ํ•œ ํด๋ก  ํŒ€ ํ”„๋กœ์ ํŠธ -## Available Scripts +# ํŒ€์› -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in your browser. - -The page will reload when you make changes.\ -You may also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can't go back!** - -If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. - -You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `npm run build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) +- ์ •๋‹ค์ธ +- ๋‹ค๋‚˜ +- ์ด์ง€ํ˜œ +- ํ•œ์ง€์„ 
Unknown
๐Ÿ‘ README.md ํŒŒ์ผ ์ˆ˜์ •ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ^^
@@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import "./Login.scss"; + +const Login = () => { + const navigate = useNavigate(); + const [showErrorMessage, setShowErrorMessage] = useState(false); + + const [userInfo, setUserInfo] = useState({ + userId: "", + userPw: "", + }); + + const isActive = userInfo.userPw.length >= 5 && userInfo.userId.includes("@"); + + useEffect(() => {}, [userInfo, showErrorMessage]); + + const handleInput = (event) => { + const { value, id } = event.target; + setUserInfo({ ...userInfo, [id]: value }); + }; + + const goToMain = () => { + if (isActive) { + navigate("/jisun-main"); + } else { + setShowErrorMessage(true); + } + }; + + return ( + <div className="login"> + <div className="box"> + <h1>Westagram</h1> + <input + type="text" + id="userId" + onChange={handleInput} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input type="password" id="userPw" onChange={handleInput} placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" /> + <button + className="btnLogin" + onClick={goToMain} + style={{ backgroundColor: isActive ? "#2d94ef" : "#67b5fa" }} + > + ๋กœ๊ทธ์ธ + </button> + <span>๋˜๋Š”</span> + <button className="btnFacebook">Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</button> + {showErrorMessage && <p className="err">์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•˜์„ธ์š”.</p>} + <button className="findPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + <div className="box"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? <a href="/signup">๊ฐ€์ž…ํ•˜๊ธฐ</a> + </div> + </div> + ); +}; + +export default Login;
Unknown
๋” ์ด์ƒ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ถˆํ•„์š”ํ•œ ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ฃผ์„์€ ๊ผญ ์‚ญ์ œํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import "./Login.scss"; + +const Login = () => { + const navigate = useNavigate(); + const [showErrorMessage, setShowErrorMessage] = useState(false); + + const [userInfo, setUserInfo] = useState({ + userId: "", + userPw: "", + }); + + const isActive = userInfo.userPw.length >= 5 && userInfo.userId.includes("@"); + + useEffect(() => {}, [userInfo, showErrorMessage]); + + const handleInput = (event) => { + const { value, id } = event.target; + setUserInfo({ ...userInfo, [id]: value }); + }; + + const goToMain = () => { + if (isActive) { + navigate("/jisun-main"); + } else { + setShowErrorMessage(true); + } + }; + + return ( + <div className="login"> + <div className="box"> + <h1>Westagram</h1> + <input + type="text" + id="userId" + onChange={handleInput} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input type="password" id="userPw" onChange={handleInput} placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" /> + <button + className="btnLogin" + onClick={goToMain} + style={{ backgroundColor: isActive ? "#2d94ef" : "#67b5fa" }} + > + ๋กœ๊ทธ์ธ + </button> + <span>๋˜๋Š”</span> + <button className="btnFacebook">Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</button> + {showErrorMessage && <p className="err">์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•˜์„ธ์š”.</p>} + <button className="findPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + <div className="box"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? <a href="/signup">๊ฐ€์ž…ํ•˜๊ธฐ</a> + </div> + </div> + ); +}; + +export default Login;
Unknown
์ฝ˜์†”๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค ํ…Œ์ŠคํŠธ๊ฐ€ ๋๋‚œ ์ฝ”๋“œ๋Š” ํ•ญ์ƒ ์ง€์›Œ์ฃผ์„ธ์š”! ์•„๋ž˜์— ๋‚จ์•„์žˆ๋Š” ๋ชจ๋“  ์ฝ˜์†”์€ ์‚ญ์ œ ํ•ด์ฃผ์„ธ์š”
@@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import "./Login.scss"; + +const Login = () => { + const navigate = useNavigate(); + const [showErrorMessage, setShowErrorMessage] = useState(false); + + const [userInfo, setUserInfo] = useState({ + userId: "", + userPw: "", + }); + + const isActive = userInfo.userPw.length >= 5 && userInfo.userId.includes("@"); + + useEffect(() => {}, [userInfo, showErrorMessage]); + + const handleInput = (event) => { + const { value, id } = event.target; + setUserInfo({ ...userInfo, [id]: value }); + }; + + const goToMain = () => { + if (isActive) { + navigate("/jisun-main"); + } else { + setShowErrorMessage(true); + } + }; + + return ( + <div className="login"> + <div className="box"> + <h1>Westagram</h1> + <input + type="text" + id="userId" + onChange={handleInput} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input type="password" id="userPw" onChange={handleInput} placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" /> + <button + className="btnLogin" + onClick={goToMain} + style={{ backgroundColor: isActive ? "#2d94ef" : "#67b5fa" }} + > + ๋กœ๊ทธ์ธ + </button> + <span>๋˜๋Š”</span> + <button className="btnFacebook">Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</button> + {showErrorMessage && <p className="err">์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•˜์„ธ์š”.</p>} + <button className="findPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + <div className="box"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? <a href="/signup">๊ฐ€์ž…ํ•˜๊ธฐ</a> + </div> + </div> + ); +}; + +export default Login;
Unknown
๐Ÿ‘ useEffect ๊นŒ์ง€ ํ™œ์šฉํ•ด๋ณด์…จ๊ตฐ์š”! condition ๋ณ€์ˆ˜๊ฐ€ userInfo๋ผ๋Š” state๋ฅผ ์ด๋ฏธ ์ฐธ์กฐํ•œ ๊ฐ’์ด๊ธฐ๋•Œ๋ฌธ์— isActive๋ผ๋Š” ๊ฐ’์„ ๋”ฐ๋กœ state๋กœ ๊ด€๋ฆฌํ•˜์ง€์•Š์•„๋„ condition ๋ณ€์ˆ˜๊ฐ€ ์ฐธ์กฐํ•˜๊ณ ์žˆ๋Š” ๊ฐ’์ด ์ด๋ฏธ state๋ผ์„œ state๋ณ€ํ™”์— ๋”ฐ๋ผ ์ฆ‰๊ฐ์ ์œผ๋กœ ๋‹ค๋ฅธ ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. isActive๋ฅผ state๊ฐ€ ์•„๋‹Œ ์ผ๋ฐ˜๋ณ€์ˆ˜๋กœ ๊ด€๋ฆฌํ•ด๋ณด์‹œ๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,61 @@ +import React, { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; +import "./Login.scss"; + +const Login = () => { + const navigate = useNavigate(); + const [showErrorMessage, setShowErrorMessage] = useState(false); + + const [userInfo, setUserInfo] = useState({ + userId: "", + userPw: "", + }); + + const isActive = userInfo.userPw.length >= 5 && userInfo.userId.includes("@"); + + useEffect(() => {}, [userInfo, showErrorMessage]); + + const handleInput = (event) => { + const { value, id } = event.target; + setUserInfo({ ...userInfo, [id]: value }); + }; + + const goToMain = () => { + if (isActive) { + navigate("/jisun-main"); + } else { + setShowErrorMessage(true); + } + }; + + return ( + <div className="login"> + <div className="box"> + <h1>Westagram</h1> + <input + type="text" + id="userId" + onChange={handleInput} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input type="password" id="userPw" onChange={handleInput} placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" /> + <button + className="btnLogin" + onClick={goToMain} + style={{ backgroundColor: isActive ? "#2d94ef" : "#67b5fa" }} + > + ๋กœ๊ทธ์ธ + </button> + <span>๋˜๋Š”</span> + <button className="btnFacebook">Facebook์œผ๋กœ ๋กœ๊ทธ์ธ</button> + {showErrorMessage && <p className="err">์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ํ™•์ธํ•˜์„ธ์š”.</p>} + <button className="findPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</button> + </div> + <div className="box"> + ๊ณ„์ •์ด ์—†์œผ์‹ ๊ฐ€์š”? <a href="/signup">๊ฐ€์ž…ํ•˜๊ธฐ</a> + </div> + </div> + ); +}; + +export default Login;
Unknown
๐Ÿ‘ ์กฐ๊ฑด๋ถ€๋žœ๋”๋ง ํ™œ์šฉํ•ด๋ณด์…จ๊ตฐ์š”!! ์˜คํžˆ๋ ค showErrorMessage๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ useEffectํ•จ์ˆ˜ ๋‚ด์—์„œ ์„ ์–ธํ•œ condition๊ฐ’์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ๊ด€๋ฆฌํ•ด๋ณผ ์ˆ˜ ์žˆ๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,144 @@ +.login { + width: 100%; + height: 100vh; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + + .box { + padding: 25px 40px; + display: flex; + flex-direction: column; + align-items: center; + width: 100%; + max-width: 350px; + box-sizing: border-box; + border: 1px solid #dbdbdb; + + &:first-of-type { + margin-bottom: 12px; + } + + h1 { + margin: 15px 0 40px; + font-family: "Lobster", cursive; + font-weight: 100; + font-size: 42px; + } + + input { + padding: 8px 8px; + width: 100%; + background: #fafafa; + color: #737373; + font-size: 12px; + box-sizing: border-box; + border: 1px solid #dbdbdb; + border-radius: 4px; + + &:first-of-type { + margin-bottom: 7px; + } + + &:last-of-type { + margin-bottom: 14px; + } + } + + span { + margin: 20px 0 30px; + padding: 0 20px; + position: relative; + font-size: 12px; + color: #737373; + + &:before { + content: ""; + position: absolute; + top: 50%; + right: -110px; + width: 110px; + height: 1px; + background: #dbdbdb; + } + + &:after { + content: ""; + position: absolute; + top: 50%; + left: -110px; + width: 110px; + height: 1px; + background: #dbdbdb; + } + } + + .btnLogin { + padding: 10px 0; + width: 100%; + background: #67b5fa; + color: #fff; + font-size: 14px; + font-weight: 500; + border: none; + border-radius: 8px; + + // &:hover { + // background: #2d94ef; + // } + } + + .btnLoginChange { + background: #2d94ef; + } + + .btnFacebook { + padding-left: 24px; + position: relative; + height: 16px; + background: none; + color: #375085; + border: none; + font-size: 14px; + font-weight: 600; + + &:before { + content: ""; + position: absolute; + left: 0; + width: 16px; + height: 16px; + background: url("../../../assets/jisun/Login/icon_facebook.png") no-repeat; + } + } + + .err { + margin: 35px 0 10px; + color: #ed4956; + font-size: 14px; + } + + .findPassword { + margin-top: 25px; + color: #375085; + font-size: 12px; + font-weight: 600; + background: none; + border: none; + } + } + + .box:last-of-type { + flex-direction: row; + justify-content: center; + color: #000; + font-size: 13px; + font-weight: 500; + + &:last-of-type > a { + margin-left: 4px; + color: #0095f6; + } + } +}
Unknown
์›นํฐํŠธ ๊ฐ™์€๊ฒฝ์šฐ๋Š” index.htmlํŒŒ์ผ์—์„œ ์ถ”๊ฐ€ํ•  ์ˆ˜๋„ ์žˆ๊ณ  common.scss์—์„œ ๊ด€๋ฆฌํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,160 @@ +import React from "react"; +import "./Main.scss"; +import { Link, useNavigate } from "react-router-dom"; + +const Main = () => { + const navigate = useNavigate(); + + const goToMain = () => { + navigate("/jisun-main"); + }; + + return ( + <div className="main"> + <nav> + <Link to="/jisun-main" className="goHome"> + <span className="logo"></span> + <p>Westagram</p> + </Link> + <div className="inputWrap"> + <input type="search" placeholder="๊ฒ€์ƒ‰" /> + </div> + <div className="icons"> + <button className="iconCompass"></button> + <button className="iconLike on"></button> + <button className="iconMypage"></button> + </div> + </nav> + <div className="contentsWrap"> + <div className="feeds"> + <article> + <div className="accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> + </a> + <a className="accountName">hanccino</a> + <a className="moreMenu"> + <img alt="๋”๋ณด๊ธฐ ์•„์ด์ฝ˜" src="../../../../images/jisun/icon_more.png" /> + </a> + </div> + <div className="image"> + <img alt="์›ฐ์‹œ์ฝ”๊ธฐ ํ•œ๊ฐ•" src="../../../../images/jisun/img_feed.png" /> + </div> + <div className="text"> + <div className="buttons"> + <span className="like on"></span> + <span className="dm"></span> + <span className="share"></span> + <span className="bookMark"></span> + </div> + <div className="likedStatus"> + <a className="accountPicture"> + <img + alt="์œ„์ฝ”๋“œ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wecode.png" + /> + </a> + <a className="accountName">wecode_life</a>๋‹˜ <a>์™ธ 10๋ช…</a>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </div> + <div className="mention"> + <a className="accountName mr5">hanccino</a> + ์šฐ๋ฆฌ์ง‘ ๊ฐ•์•„์ง€ ์ธ„๋ฅด๋ฅผ ์ข‹์•„ํ•ด... + <span className="viewMore">๋” ๋ณด๊ธฐ</span> + </div> + <div className="currentComments"> + <a className="accountName mr5">wecode_bootcamp</a>์กธ๊ท€ํƒฑ! + </div> + <div className="addComments"> + <textarea aria-label="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..."></textarea> + </div> + </div> + </article> + </div> + <div className="mainRight"> + <div className="myAccount accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="../../../../images/jisun/img_profile.png" /> + </a> + <span> + <a className="accountName">hanccino</a> + Jisun lives with a corgi + </span> + </div> + <div className="recommandList"> + <div> + <strong>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</strong> + <span className="viewAll">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="์œ„์›Œํฌ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wework.jpeg" + /> + </a> + <span> + <a className="accountName">wework</a> + wecode_bootcamp๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋„ทํ”Œ๋ฆญ์Šค ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_netflix.jpeg" + /> + </a> + <span> + <a className="accountName">netflixkr</a> + wecode_premium๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๊ฐฑ๋”์ฝ”๊ธฐ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_corgi.jpeg" + /> + </a> + <span> + <a className="accountName">gang_the_corgi</a> + ํšŒ์›๋‹˜์„ ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋ฐค๋น„ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_bambi.jpeg" + /> + </a> + <span> + <a className="accountName">bambi__jeju</a> + gdragon๋‹˜ ์™ธ 4๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="ํ”ผ์‹๋Œ€ํ•™ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_psickuniv.jpeg" + /> + </a> + <span> + <a className="accountName">psickuniv</a> + dev_gag๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + </div> + </div> + </div> + </div> + ); +}; + +export default Main;
Unknown
reset.scss ํŒŒ์ผ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ „์—ญ์—์„œ ์ ์šฉ๋˜์–ด์•ผ ํ•˜๋Š” ํŒŒ์ผ์ž„์œผ๋กœ index.js์—์„œ importํ•ด ์˜ค๋Š”๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,160 @@ +import React from "react"; +import "./Main.scss"; +import { Link, useNavigate } from "react-router-dom"; + +const Main = () => { + const navigate = useNavigate(); + + const goToMain = () => { + navigate("/jisun-main"); + }; + + return ( + <div className="main"> + <nav> + <Link to="/jisun-main" className="goHome"> + <span className="logo"></span> + <p>Westagram</p> + </Link> + <div className="inputWrap"> + <input type="search" placeholder="๊ฒ€์ƒ‰" /> + </div> + <div className="icons"> + <button className="iconCompass"></button> + <button className="iconLike on"></button> + <button className="iconMypage"></button> + </div> + </nav> + <div className="contentsWrap"> + <div className="feeds"> + <article> + <div className="accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> + </a> + <a className="accountName">hanccino</a> + <a className="moreMenu"> + <img alt="๋”๋ณด๊ธฐ ์•„์ด์ฝ˜" src="../../../../images/jisun/icon_more.png" /> + </a> + </div> + <div className="image"> + <img alt="์›ฐ์‹œ์ฝ”๊ธฐ ํ•œ๊ฐ•" src="../../../../images/jisun/img_feed.png" /> + </div> + <div className="text"> + <div className="buttons"> + <span className="like on"></span> + <span className="dm"></span> + <span className="share"></span> + <span className="bookMark"></span> + </div> + <div className="likedStatus"> + <a className="accountPicture"> + <img + alt="์œ„์ฝ”๋“œ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wecode.png" + /> + </a> + <a className="accountName">wecode_life</a>๋‹˜ <a>์™ธ 10๋ช…</a>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </div> + <div className="mention"> + <a className="accountName mr5">hanccino</a> + ์šฐ๋ฆฌ์ง‘ ๊ฐ•์•„์ง€ ์ธ„๋ฅด๋ฅผ ์ข‹์•„ํ•ด... + <span className="viewMore">๋” ๋ณด๊ธฐ</span> + </div> + <div className="currentComments"> + <a className="accountName mr5">wecode_bootcamp</a>์กธ๊ท€ํƒฑ! + </div> + <div className="addComments"> + <textarea aria-label="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..."></textarea> + </div> + </div> + </article> + </div> + <div className="mainRight"> + <div className="myAccount accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="../../../../images/jisun/img_profile.png" /> + </a> + <span> + <a className="accountName">hanccino</a> + Jisun lives with a corgi + </span> + </div> + <div className="recommandList"> + <div> + <strong>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</strong> + <span className="viewAll">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="์œ„์›Œํฌ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wework.jpeg" + /> + </a> + <span> + <a className="accountName">wework</a> + wecode_bootcamp๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋„ทํ”Œ๋ฆญ์Šค ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_netflix.jpeg" + /> + </a> + <span> + <a className="accountName">netflixkr</a> + wecode_premium๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๊ฐฑ๋”์ฝ”๊ธฐ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_corgi.jpeg" + /> + </a> + <span> + <a className="accountName">gang_the_corgi</a> + ํšŒ์›๋‹˜์„ ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋ฐค๋น„ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_bambi.jpeg" + /> + </a> + <span> + <a className="accountName">bambi__jeju</a> + gdragon๋‹˜ ์™ธ 4๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="ํ”ผ์‹๋Œ€ํ•™ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_psickuniv.jpeg" + /> + </a> + <span> + <a className="accountName">psickuniv</a> + dev_gag๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + </div> + </div> + </div> + </div> + ); +}; + +export default Main;
Unknown
์•„์ด์ฝ˜๋“ค์„ ๋ˆŒ๋ €์„๋•Œ ํŠน์ •ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ด์•ผํ•˜๋Š”๊ฒƒ์ด ์•„๋‹ˆ๋ผ๋ฉด a ํƒœ๊ทธ๋‚˜ Link ํƒœ๊ทธ๊ฐ€ ์•„๋‹Œ ์—ฌํƒ€ ๋‹ค๋ฅธํƒœ๊ทธ๋ฅผ ํ™œ์šฉํ•ด์„œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,160 @@ +import React from "react"; +import "./Main.scss"; +import { Link, useNavigate } from "react-router-dom"; + +const Main = () => { + const navigate = useNavigate(); + + const goToMain = () => { + navigate("/jisun-main"); + }; + + return ( + <div className="main"> + <nav> + <Link to="/jisun-main" className="goHome"> + <span className="logo"></span> + <p>Westagram</p> + </Link> + <div className="inputWrap"> + <input type="search" placeholder="๊ฒ€์ƒ‰" /> + </div> + <div className="icons"> + <button className="iconCompass"></button> + <button className="iconLike on"></button> + <button className="iconMypage"></button> + </div> + </nav> + <div className="contentsWrap"> + <div className="feeds"> + <article> + <div className="accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> + </a> + <a className="accountName">hanccino</a> + <a className="moreMenu"> + <img alt="๋”๋ณด๊ธฐ ์•„์ด์ฝ˜" src="../../../../images/jisun/icon_more.png" /> + </a> + </div> + <div className="image"> + <img alt="์›ฐ์‹œ์ฝ”๊ธฐ ํ•œ๊ฐ•" src="../../../../images/jisun/img_feed.png" /> + </div> + <div className="text"> + <div className="buttons"> + <span className="like on"></span> + <span className="dm"></span> + <span className="share"></span> + <span className="bookMark"></span> + </div> + <div className="likedStatus"> + <a className="accountPicture"> + <img + alt="์œ„์ฝ”๋“œ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wecode.png" + /> + </a> + <a className="accountName">wecode_life</a>๋‹˜ <a>์™ธ 10๋ช…</a>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </div> + <div className="mention"> + <a className="accountName mr5">hanccino</a> + ์šฐ๋ฆฌ์ง‘ ๊ฐ•์•„์ง€ ์ธ„๋ฅด๋ฅผ ์ข‹์•„ํ•ด... + <span className="viewMore">๋” ๋ณด๊ธฐ</span> + </div> + <div className="currentComments"> + <a className="accountName mr5">wecode_bootcamp</a>์กธ๊ท€ํƒฑ! + </div> + <div className="addComments"> + <textarea aria-label="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..."></textarea> + </div> + </div> + </article> + </div> + <div className="mainRight"> + <div className="myAccount accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="../../../../images/jisun/img_profile.png" /> + </a> + <span> + <a className="accountName">hanccino</a> + Jisun lives with a corgi + </span> + </div> + <div className="recommandList"> + <div> + <strong>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</strong> + <span className="viewAll">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="์œ„์›Œํฌ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wework.jpeg" + /> + </a> + <span> + <a className="accountName">wework</a> + wecode_bootcamp๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋„ทํ”Œ๋ฆญ์Šค ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_netflix.jpeg" + /> + </a> + <span> + <a className="accountName">netflixkr</a> + wecode_premium๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๊ฐฑ๋”์ฝ”๊ธฐ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_corgi.jpeg" + /> + </a> + <span> + <a className="accountName">gang_the_corgi</a> + ํšŒ์›๋‹˜์„ ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋ฐค๋น„ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_bambi.jpeg" + /> + </a> + <span> + <a className="accountName">bambi__jeju</a> + gdragon๋‹˜ ์™ธ 4๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="ํ”ผ์‹๋Œ€ํ•™ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_psickuniv.jpeg" + /> + </a> + <span> + <a className="accountName">psickuniv</a> + dev_gag๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + </div> + </div> + </div> + </div> + ); +}; + +export default Main;
Unknown
ํ•ด๋‹น ์ƒ๋Œ€๊ฒฝ๋กœ๊ฐ€ publicํด๋”๋ฅผ ์ฐธ๊ณ ํ•˜๋Š”๊ฑฐ๋ผ๋ฉด ```suggestion <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> ``` ์ด๋ ‡๊ฒŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,160 @@ +import React from "react"; +import "./Main.scss"; +import { Link, useNavigate } from "react-router-dom"; + +const Main = () => { + const navigate = useNavigate(); + + const goToMain = () => { + navigate("/jisun-main"); + }; + + return ( + <div className="main"> + <nav> + <Link to="/jisun-main" className="goHome"> + <span className="logo"></span> + <p>Westagram</p> + </Link> + <div className="inputWrap"> + <input type="search" placeholder="๊ฒ€์ƒ‰" /> + </div> + <div className="icons"> + <button className="iconCompass"></button> + <button className="iconLike on"></button> + <button className="iconMypage"></button> + </div> + </nav> + <div className="contentsWrap"> + <div className="feeds"> + <article> + <div className="accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="/images/jisun/img_profile.png" /> + </a> + <a className="accountName">hanccino</a> + <a className="moreMenu"> + <img alt="๋”๋ณด๊ธฐ ์•„์ด์ฝ˜" src="../../../../images/jisun/icon_more.png" /> + </a> + </div> + <div className="image"> + <img alt="์›ฐ์‹œ์ฝ”๊ธฐ ํ•œ๊ฐ•" src="../../../../images/jisun/img_feed.png" /> + </div> + <div className="text"> + <div className="buttons"> + <span className="like on"></span> + <span className="dm"></span> + <span className="share"></span> + <span className="bookMark"></span> + </div> + <div className="likedStatus"> + <a className="accountPicture"> + <img + alt="์œ„์ฝ”๋“œ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wecode.png" + /> + </a> + <a className="accountName">wecode_life</a>๋‹˜ <a>์™ธ 10๋ช…</a>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </div> + <div className="mention"> + <a className="accountName mr5">hanccino</a> + ์šฐ๋ฆฌ์ง‘ ๊ฐ•์•„์ง€ ์ธ„๋ฅด๋ฅผ ์ข‹์•„ํ•ด... + <span className="viewMore">๋” ๋ณด๊ธฐ</span> + </div> + <div className="currentComments"> + <a className="accountName mr5">wecode_bootcamp</a>์กธ๊ท€ํƒฑ! + </div> + <div className="addComments"> + <textarea aria-label="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..."></textarea> + </div> + </div> + </article> + </div> + <div className="mainRight"> + <div className="myAccount accountWrap"> + <a className="accountPicture"> + <img alt="๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" src="../../../../images/jisun/img_profile.png" /> + </a> + <span> + <a className="accountName">hanccino</a> + Jisun lives with a corgi + </span> + </div> + <div className="recommandList"> + <div> + <strong>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</strong> + <span className="viewAll">๋ชจ๋‘ ๋ณด๊ธฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="์œ„์›Œํฌ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_wework.jpeg" + /> + </a> + <span> + <a className="accountName">wework</a> + wecode_bootcamp๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋„ทํ”Œ๋ฆญ์Šค ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_netflix.jpeg" + /> + </a> + <span> + <a className="accountName">netflixkr</a> + wecode_premium๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๊ฐฑ๋”์ฝ”๊ธฐ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_corgi.jpeg" + /> + </a> + <span> + <a className="accountName">gang_the_corgi</a> + ํšŒ์›๋‹˜์„ ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="๋ฐค๋น„ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_bambi.jpeg" + /> + </a> + <span> + <a className="accountName">bambi__jeju</a> + gdragon๋‹˜ ์™ธ 4๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + <div className="accountWrap"> + <a className="accountPicture"> + <img + alt="ํ”ผ์‹๋Œ€ํ•™ ๊ณ„์ • ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="../../../../images/jisun/img_profile_psickuniv.jpeg" + /> + </a> + <span> + <a className="accountName">psickuniv</a> + dev_gag๋‹˜ ์™ธ 6๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + <span className="follow">ํŒ”๋กœ์šฐ</span> + </div> + </div> + </div> + </div> + </div> + ); +}; + +export default Main;
Unknown
className์ด ๋„ˆ๋ฌด ๋ชจํ˜ธํ•ฉ๋‹ˆ๋‹ค!! ์–ด๋–ค ์•„์ด์ฝ˜์ธ์ง€ ์•Œ๋ ค์ฃผ์„ธ์š”
@@ -78,6 +78,7 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re List<ReviewPhoto> reviewPhotoList = new ArrayList<>(); List<String> photoUrls = new ArrayList<>(); + if(reviewPhotos == null) return reviewPhotoList; reviewPhotos.forEach(multipartFile -> { try { photoUrls.add(s3Util.upload(multipartFile)); @@ -87,7 +88,6 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re }); photoUrls.forEach(photoUrl -> reviewPhotoList.add(reviewPhotoPort.save(new ReviewPhoto(reviewId, photoUrl)))); - return reviewPhotoList; }
Java
์ด ๋ถ€๋ถ„์€ ์–ด๋–ค ์˜๋ฏธ์ธ๊ฐ€์š”?
@@ -78,6 +78,7 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re List<ReviewPhoto> reviewPhotoList = new ArrayList<>(); List<String> photoUrls = new ArrayList<>(); + if(reviewPhotos == null) return reviewPhotoList; reviewPhotos.forEach(multipartFile -> { try { photoUrls.add(s3Util.upload(multipartFile)); @@ -87,7 +88,6 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re }); photoUrls.forEach(photoUrl -> reviewPhotoList.add(reviewPhotoPort.save(new ReviewPhoto(reviewId, photoUrl)))); - return reviewPhotoList; }
Java
์ด ๋ถ€๋ถ„์€ ์–ด๋–ค ์˜๋ฏธ์ธ๊ฐ€์š”?
@@ -0,0 +1,34 @@ +package com.luckytree.shop.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Type; + +@Component +public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { + + /** + * Converter for support http request with header Content-Type: multipart/form-data + */ + public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) { + super(objectMapper, MediaType.APPLICATION_OCTET_STREAM); + } + + @Override + public boolean canWrite(Class<?> clazz, MediaType mediaType) { + return false; + } + + @Override + public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) { + return false; + } + + @Override + protected boolean canWrite(MediaType mediaType) { + return false; + } +}
Java
์ด ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ณณ์ด ์–ด๋”˜๊ฐ€์š”?
@@ -32,12 +32,11 @@ public class ReviewController { private final ReviewUseCase reviewUseCase; @Operation(summary = "๋ฆฌ๋ทฐ ๋“ฑ๋ก") - @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity<CreateReviewResponse> createReview( - @RequestBody @Valid CreateReviewRequest createReviewRequest, - @RequestPart("reviewPhotos") @Valid List<MultipartFile> reviewPhotos) { + @RequestPart("createReviewRequest") @Valid CreateReviewRequest createReviewRequest, + @RequestPart(value = "reviewPhotos", required = false) @Valid List<MultipartFile> reviewPhotos) { Review review = reviewUseCase.create(createReviewRequest.toDomain(Long.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()))); - List<ReviewPhoto> reviewPhotoList = reviewUseCase.createReviewPhoto(review.getId(), reviewPhotos); return ResponseEntity.ok(new CreateReviewResponse(review, reviewPhotoList));
Java
๋ฆฌํ€˜์ŠคํŠธ๋ฐ”๋””๊ฐ€ ์‚ฌ๋ผ์กŒ๋Š”๋ฐ, ์ด ๊ฒฝ์šฐ์—๋„ ํด๋ผ์ด์–ธํŠธ์—์„œ JSON ํ˜•์‹์˜ Body ํƒœ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ค๋Š” ๋ฐ์— ๋ฌธ์ œ๊ฐ€ ์—†๋‚˜์š”?
@@ -78,6 +78,7 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re List<ReviewPhoto> reviewPhotoList = new ArrayList<>(); List<String> photoUrls = new ArrayList<>(); + if(reviewPhotos == null) return reviewPhotoList; reviewPhotos.forEach(multipartFile -> { try { photoUrls.add(s3Util.upload(multipartFile)); @@ -87,7 +88,6 @@ public List<ReviewPhoto> createReviewPhoto(Long reviewId, List<MultipartFile> re }); photoUrls.forEach(photoUrl -> reviewPhotoList.add(reviewPhotoPort.save(new ReviewPhoto(reviewId, photoUrl)))); - return reviewPhotoList; }
Java
๋ฆฌ๋ทฐ ์ƒ์„ฑ ์‹œ ํฌํ† ๋ฅผ ์„ ํƒํ•˜์ง€ ์•Š์•„๋„ ์ด ์„œ๋น„์Šค๊ฐ€ ์‹คํ–‰๋˜์–ด์„œ ์„ ํƒ๋˜์ง€ ์•Š์•˜์„ ๋•Œ ๋ฐ”๋กœ ๋น ์ ธ๋‚˜๊ฐ€๊ฒŒ ํ•œ๊ฒ๋‹ˆ๋‹ค
@@ -0,0 +1,34 @@ +package com.luckytree.shop.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Type; + +@Component +public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { + + /** + * Converter for support http request with header Content-Type: multipart/form-data + */ + public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) { + super(objectMapper, MediaType.APPLICATION_OCTET_STREAM); + } + + @Override + public boolean canWrite(Class<?> clazz, MediaType mediaType) { + return false; + } + + @Override + public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) { + return false; + } + + @Override + protected boolean canWrite(MediaType mediaType) { + return false; + } +}
Java
swagger์—์„œ ๋ฆฌ๋ทฐ ์ƒ์„ฑ API์— multipartfile์„ ์‚ฌ์šฉํ•ด์„œ ๊ทธ๊ฑฐ ์‚ฌ์šฉํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ๋Š” ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค
@@ -32,12 +32,11 @@ public class ReviewController { private final ReviewUseCase reviewUseCase; @Operation(summary = "๋ฆฌ๋ทฐ ๋“ฑ๋ก") - @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity<CreateReviewResponse> createReview( - @RequestBody @Valid CreateReviewRequest createReviewRequest, - @RequestPart("reviewPhotos") @Valid List<MultipartFile> reviewPhotos) { + @RequestPart("createReviewRequest") @Valid CreateReviewRequest createReviewRequest, + @RequestPart(value = "reviewPhotos", required = false) @Valid List<MultipartFile> reviewPhotos) { Review review = reviewUseCase.create(createReviewRequest.toDomain(Long.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()))); - List<ReviewPhoto> reviewPhotoList = reviewUseCase.createReviewPhoto(review.getId(), reviewPhotos); return ResponseEntity.ok(new CreateReviewResponse(review, reviewPhotoList));
Java
swagger๋ž‘ postman์—์„œ ํ™•์ธํ–ˆ๊ณ  ์˜คํžˆ๋ ค ๋ฆฌํ€˜์ŠคํŠธ๋ฐ”๋””๋ฅผ ์ผ์„ ๋•Œ ์•ˆ๋ผ์„œ ๋ฐ”๊ฟจ์Šต๋‹ˆ๋‹ค. ์ด์œ ๋Š” ์ฐพ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -1,26 +1,30 @@ import { CHAT_SORT_OPTIONS } from '@/constants/chat'; +import { User } from './user'; -export type SortType = keyof typeof CHAT_SORT_OPTIONS; - -export interface RoomResponse { +export interface ChatRoom { chatId: string; chattingName: string; + description: string; host: string; + hostProfileImage: string; hasJoined: boolean; + unreadMessageCount: number; lastMessageTime: string; image: string; - unreadMessageCount: number; membersCount: number; totalMembersCount: number; - hostProfileImage: string; - description: string; } -export interface ChattingResponse { +export interface Chat { chatTitle: string; chatMessages: ChatMessage[]; } +export interface ChatOverview { + participants: Participant[]; + album: ImageInfo[]; +} + export interface ChatMessage { chatMessageId: string; images: string[]; @@ -31,20 +35,15 @@ export interface ChatMessage { unreadCount: number; } -export interface ChatOverview { - participants: Participant[]; - album: ImageInfo[]; -} - export interface ImageInfo { images: string[]; uploadDate: string; uploader: string; } -export interface Participant { - user: string; - email: string; - description: string; - profileImage: string; + +export interface Participant + extends Pick<User, 'email' | 'profileImage' | 'nickname' | 'description'> { travelCount: number; } + +export type SortType = keyof typeof CHAT_SORT_OPTIONS;
TypeScript
๊ณต์šฉ ์œ ์ € ํƒ€์ž…๊ณผ ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์ด ๋งŽ์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. User ์ธํ„ฐํŽ˜์ด์Šค ๊ฐ€์ ธ๋‹ค๊ฐ€ ์“ฐ์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”. ์œ ํ‹ธ๋ฆฌํ‹ฐ ํƒ€์ž…๊ณผ ํ™•์žฅ ์ด์šฉํ•˜์‹œ๋ฉด ๋  ๊ฒƒ ๊ฐ™์•„์š”.