code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -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 | ์ข์ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค ๐ฅ๐ฅ |
@@ -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 |
@@ -0,0 +1,106 @@
+package nextstep.security.authorization.hierarchy;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class RoleHierarchyTest {
+
+ private RoleHierarchyImpl roleHierarchy;
+
+ @BeforeEach
+ void setUp() {
+ roleHierarchy = RoleHierarchyImpl.with()
+ .role("ADMIN").implies("USER")
+ .role("USER").implies("GUEST")
+ .build();
+ }
+
+ @Nested
+ @DisplayName("build()")
+ class build {
+ @Test
+ @DisplayName("๊ณ์ธต ์ค์ ์ ์ํ์ฐธ์กฐ๊ฐ ์กด์ฌํ๋ฉด ์์ธ๋ฅผ ๋ฐ์ํ๋ค.")
+ void shouldReturnSameRole_WhenNoHierarchy() {
+ assertThatThrownBy(() ->
+ RoleHierarchyImpl.with()
+ .role("ADMIN").implies("USER")
+ .role("USER").implies("GUEST")
+ .role("GUEST").implies("ADMIN")
+ .build()
+ ).isInstanceOf(CycleInRoleHierarchyException.class);
+ }
+
+ }
+
+ @Nested
+ @DisplayName("getReachableAuthorities()")
+ class GetReachableAuthorities {
+
+ @Test
+ @DisplayName("๊ณ์ธต์ด ์๋ ๊ฒฝ์ฐ, ์
๋ ฅํ ์ญํ ๊ทธ๋๋ก ๋ฐํํ๋ค.")
+ void shouldReturnSameRole_WhenNoHierarchy() {
+ RoleHierarchy singleHierarchy = new NullRoleHierarchy();
+
+ Collection<String> reachableRoles = singleHierarchy.getReachableAuthorities(Set.of("ADMIN"));
+
+ assertThat(reachableRoles).containsExactlyInAnyOrder("ADMIN");
+ }
+
+ @Test
+ @DisplayName("ADMIN์ด ์ฃผ์ด์ง๋ฉด USER, GUEST๊น์ง ํฌํจํ์ฌ ๋ฐํํ๋ค.")
+ void shouldReturnAllReachableRoles_WhenAdminIsGiven() {
+ Collection<String> reachableRoles = roleHierarchy.getReachableAuthorities(Set.of("ADMIN"));
+
+ assertThat(reachableRoles).containsExactlyInAnyOrder("ADMIN", "USER", "GUEST");
+ }
+
+ @Test
+ @DisplayName("USER๊ฐ ์ฃผ์ด์ง๋ฉด GUEST๊น์ง ํฌํจํ์ฌ ๋ฐํํ๋ค.")
+ void shouldReturnReachableRoles_WhenUserIsGiven() {
+ Collection<String> reachableRoles = roleHierarchy.getReachableAuthorities(Set.of("USER"));
+
+ assertThat(reachableRoles).containsExactlyInAnyOrder("USER", "GUEST");
+ }
+
+ @Test
+ @DisplayName("GUEST๊ฐ ์ฃผ์ด์ง๋ฉด ๋ณธ์ธ๋ง ๋ฐํํ๋ค.")
+ void shouldReturnSelf_WhenGuestIsGiven() {
+ Collection<String> reachableRoles = roleHierarchy.getReachableAuthorities(Set.of("GUEST"));
+
+ assertThat(reachableRoles).containsExactlyInAnyOrder("GUEST");
+ }
+
+ @Test
+ @DisplayName("์ฌ๋ฌ ๊ฐ์ ์ญํ ์ด ์ฃผ์ด์ง๋ฉด ๊ณ์ธต์ ํฌํจ๋ ๋ชจ๋ ์ญํ ์ ๋ฐํํ๋ค.")
+ void shouldHandleMultipleRoles() {
+ Collection<String> reachableRoles = roleHierarchy.getReachableAuthorities(Set.of("ADMIN", "GUEST"));
+
+ assertThat(reachableRoles).containsExactlyInAnyOrder("ADMIN", "USER", "GUEST");
+ }
+
+ @Test
+ @DisplayName("๋น ๋ฆฌ์คํธ๋ฅผ ์
๋ ฅํ๋ฉด ๋น ๋ฆฌ์คํธ ๋ฐํ")
+ void shouldReturnEmptyList_WhenNoRolesAreProvided() {
+ Collection<String> reachableRoles = roleHierarchy.getReachableAuthorities(Set.of());
+
+ assertThat(reachableRoles).isEmpty();
+ }
+
+ @Test
+ @DisplayName("NULL ์
๋ ฅ ์ ๋น ๋ฆฌ์คํธ ๋ฐํ")
+ void shouldReturnEmptyList_WhenNullIsProvided() {
+ Collection<String> reachableRoles = roleHierarchy.getReachableAuthorities(null);
+
+ assertThat(reachableRoles).isEmpty();
+ }
+ }
+
+}
\ No newline at end of file | Java | ๊ผผ๊ผผํ ํ
์คํธ ์ฝ๋ ๐ |
@@ -1,20 +1,22 @@
package nextstep.security.authorization;
import nextstep.security.authentication.Authentication;
+import nextstep.security.authorization.hierarchy.RoleHierarchy;
import java.util.Set;
public class AuthorityAuthorizationManager<T> implements AuthorizationManager<T> {
- private final AuthoritiesAuthorizationManager delegate = new AuthoritiesAuthorizationManager();
+ private final AuthoritiesAuthorizationManager delegate;
- private final String authority;
+ private final Set<String> authorities;
- public AuthorityAuthorizationManager(String authority) {
- this.authority = authority;
+ public AuthorityAuthorizationManager(RoleHierarchy roleHierarchy, String ...authorities) {
+ this.delegate = new AuthoritiesAuthorizationManager(roleHierarchy);
+ this.authorities = Set.of(authorities);
}
@Override
public AuthorizationDecision check(final Authentication authentication, final T object) {
- return this.delegate.check(authentication, Set.of(this.authority));
+ return this.delegate.check(authentication, this.authorities);
}
} | Java | Spring Security์ AuthoritiesAuthorizationManager๋ String... authorities๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ค ๊ถํ์ ์ฒ๋ฆฌํ ์ ์๋๋ก ์ค๊ณ๋์์ต๋๋ค.
๊ฐ๋ณ์ธ์ ํ์ฉ์ ํตํด AuthorityAuthorizationManager๊ฐ ๋ ์ ์ฐํ๊ฒ ๋์ํ ์ ์๋๋ก ํด๋ณด๋ฉด ์ด๋จ๊น์? ๐
```suggestion
public AuthorityAuthorizationManager(RoleHierarchy roleHierarchy, String... authorities) {
``` |
@@ -0,0 +1,126 @@
+package nextstep.security.authorization.hierarchy;
+
+import org.springframework.util.Assert;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
+
+public class RoleHierarchyImpl implements RoleHierarchy {
+ private final Map<String, Set<String>> rolesReachableInOneOrMoreStepsMap;
+
+ private RoleHierarchyImpl(final Map<String, Set<String>> rolesReachableInOneOrMoreStepsMap) {
+ this.rolesReachableInOneOrMoreStepsMap = rolesReachableInOneOrMoreStepsMap;
+ }
+
+ public static Builder with() {
+ return new Builder();
+ }
+
+ @Override
+ public Collection<String> getReachableAuthorities(Collection<String> authorities) {
+ if (authorities == null || authorities.isEmpty()) {
+ return new ArrayList<>();
+ }
+
+ Set<String> reachableRoles = new HashSet<>();
+ Set<String> processedRoles = new HashSet<>();
+ Queue<String> queue = new ArrayDeque<>(authorities);
+
+ while (!queue.isEmpty()) {
+ String role = queue.poll();
+ if (!processedRoles.add(role)) {
+ continue;
+ }
+
+ reachableRoles.add(role);
+
+ Set<String> lowerRoles = this.rolesReachableInOneOrMoreStepsMap.get(role);
+ if (lowerRoles != null) {
+ queue.addAll(lowerRoles);
+ }
+ }
+
+ return new ArrayList<>(reachableRoles);
+ }
+
+ public static class Builder {
+ private final Map<String, Set<String>> hierarchy;
+
+ private Builder() {
+ this.hierarchy = new LinkedHashMap<>();
+ }
+
+ public ImpliedRoles role(String role) {
+ Assert.hasText(role, "role must not be empty");
+ return new ImpliedRoles(role);
+ }
+
+ public RoleHierarchyImpl build() {
+ detectCycle();
+ return new RoleHierarchyImpl(this.hierarchy);
+ }
+
+ private void detectCycle() {
+ Set<String> visited = new HashSet<>();
+ Set<String> stack = new HashSet<>();
+
+ for (String role : hierarchy.keySet()) {
+ if (hasCycle(role, visited, stack)) {
+ throw new CycleInRoleHierarchyException();
+ }
+ }
+ }
+
+ private boolean hasCycle(String role, Set<String> visited, Set<String> stack) {
+ if (stack.contains(role)) {
+ return true;
+ }
+ if (visited.contains(role)) {
+ return false;
+ }
+
+ visited.add(role);
+ stack.add(role);
+
+ Set<String> children = hierarchy.get(role);
+ if (children != null) {
+ for (String child : children) {
+ if (hasCycle(child, visited, stack)) {
+ return true;
+ }
+ }
+ }
+
+ stack.remove(role);
+ return false;
+ }
+
+ private Builder addHierarchy(String role, String... impliedRoles) {
+ Set<String> childRoles = Set.of(impliedRoles);
+
+ this.hierarchy.put(role, childRoles);
+ return this;
+ }
+
+ public final class ImpliedRoles {
+
+ private final String role;
+
+ private ImpliedRoles(String role) {
+ this.role = role;
+ }
+
+ public Builder implies(String... impliedRoles) {
+ Assert.notEmpty(impliedRoles, "at least one implied role must be provided");
+ Assert.noNullElements(impliedRoles, "implied role name(s) cannot be empty");
+ return Builder.this.addHierarchy(this.role, impliedRoles);
+ }
+ }
+ }
+} | Java | ๋ค์๊ณผ ๊ฐ์ด ํด๋ณผ ์๋ ์๊ฒ ๋ค์ ๐
```suggestion
Set<String> childRoles = Set.of(impliedRoles);
``` |
@@ -0,0 +1,126 @@
+package nextstep.security.authorization.hierarchy;
+
+import org.springframework.util.Assert;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
+
+public class RoleHierarchyImpl implements RoleHierarchy {
+ private final Map<String, Set<String>> rolesReachableInOneOrMoreStepsMap;
+
+ private RoleHierarchyImpl(final Map<String, Set<String>> rolesReachableInOneOrMoreStepsMap) {
+ this.rolesReachableInOneOrMoreStepsMap = rolesReachableInOneOrMoreStepsMap;
+ }
+
+ public static Builder with() {
+ return new Builder();
+ }
+
+ @Override
+ public Collection<String> getReachableAuthorities(Collection<String> authorities) {
+ if (authorities == null || authorities.isEmpty()) {
+ return new ArrayList<>();
+ }
+
+ Set<String> reachableRoles = new HashSet<>();
+ Set<String> processedRoles = new HashSet<>();
+ Queue<String> queue = new ArrayDeque<>(authorities);
+
+ while (!queue.isEmpty()) {
+ String role = queue.poll();
+ if (!processedRoles.add(role)) {
+ continue;
+ }
+
+ reachableRoles.add(role);
+
+ Set<String> lowerRoles = this.rolesReachableInOneOrMoreStepsMap.get(role);
+ if (lowerRoles != null) {
+ queue.addAll(lowerRoles);
+ }
+ }
+
+ return new ArrayList<>(reachableRoles);
+ }
+
+ public static class Builder {
+ private final Map<String, Set<String>> hierarchy;
+
+ private Builder() {
+ this.hierarchy = new LinkedHashMap<>();
+ }
+
+ public ImpliedRoles role(String role) {
+ Assert.hasText(role, "role must not be empty");
+ return new ImpliedRoles(role);
+ }
+
+ public RoleHierarchyImpl build() {
+ detectCycle();
+ return new RoleHierarchyImpl(this.hierarchy);
+ }
+
+ private void detectCycle() {
+ Set<String> visited = new HashSet<>();
+ Set<String> stack = new HashSet<>();
+
+ for (String role : hierarchy.keySet()) {
+ if (hasCycle(role, visited, stack)) {
+ throw new CycleInRoleHierarchyException();
+ }
+ }
+ }
+
+ private boolean hasCycle(String role, Set<String> visited, Set<String> stack) {
+ if (stack.contains(role)) {
+ return true;
+ }
+ if (visited.contains(role)) {
+ return false;
+ }
+
+ visited.add(role);
+ stack.add(role);
+
+ Set<String> children = hierarchy.get(role);
+ if (children != null) {
+ for (String child : children) {
+ if (hasCycle(child, visited, stack)) {
+ return true;
+ }
+ }
+ }
+
+ stack.remove(role);
+ return false;
+ }
+
+ private Builder addHierarchy(String role, String... impliedRoles) {
+ Set<String> childRoles = Set.of(impliedRoles);
+
+ this.hierarchy.put(role, childRoles);
+ return this;
+ }
+
+ public final class ImpliedRoles {
+
+ private final String role;
+
+ private ImpliedRoles(String role) {
+ this.role = role;
+ }
+
+ public Builder implies(String... impliedRoles) {
+ Assert.notEmpty(impliedRoles, "at least one implied role must be provided");
+ Assert.noNullElements(impliedRoles, "implied role name(s) cannot be empty");
+ return Builder.this.addHierarchy(this.role, impliedRoles);
+ }
+ }
+ }
+} | Java | ์ํ ์ฐธ์กฐ๊ฐ ์ผ์ด๋ ์ ์์ ๊ฒ ๊ฐ์์
์ญํ ๊ณ์ธต์ ์ค์ ํ ๋ ์ํ ์ฐธ์กฐ(์ฌ์ดํด)์ ๋ํ ์์ธ์ฒ๋ฆฌ๋ฅผ ํด๋ณด๋๊ฑด ์ด๋จ๊น์? ๐ |
@@ -0,0 +1,126 @@
+package nextstep.security.authorization.hierarchy;
+
+import org.springframework.util.Assert;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
+
+public class RoleHierarchyImpl implements RoleHierarchy {
+ private final Map<String, Set<String>> rolesReachableInOneOrMoreStepsMap;
+
+ private RoleHierarchyImpl(final Map<String, Set<String>> rolesReachableInOneOrMoreStepsMap) {
+ this.rolesReachableInOneOrMoreStepsMap = rolesReachableInOneOrMoreStepsMap;
+ }
+
+ public static Builder with() {
+ return new Builder();
+ }
+
+ @Override
+ public Collection<String> getReachableAuthorities(Collection<String> authorities) {
+ if (authorities == null || authorities.isEmpty()) {
+ return new ArrayList<>();
+ }
+
+ Set<String> reachableRoles = new HashSet<>();
+ Set<String> processedRoles = new HashSet<>();
+ Queue<String> queue = new ArrayDeque<>(authorities);
+
+ while (!queue.isEmpty()) {
+ String role = queue.poll();
+ if (!processedRoles.add(role)) {
+ continue;
+ }
+
+ reachableRoles.add(role);
+
+ Set<String> lowerRoles = this.rolesReachableInOneOrMoreStepsMap.get(role);
+ if (lowerRoles != null) {
+ queue.addAll(lowerRoles);
+ }
+ }
+
+ return new ArrayList<>(reachableRoles);
+ }
+
+ public static class Builder {
+ private final Map<String, Set<String>> hierarchy;
+
+ private Builder() {
+ this.hierarchy = new LinkedHashMap<>();
+ }
+
+ public ImpliedRoles role(String role) {
+ Assert.hasText(role, "role must not be empty");
+ return new ImpliedRoles(role);
+ }
+
+ public RoleHierarchyImpl build() {
+ detectCycle();
+ return new RoleHierarchyImpl(this.hierarchy);
+ }
+
+ private void detectCycle() {
+ Set<String> visited = new HashSet<>();
+ Set<String> stack = new HashSet<>();
+
+ for (String role : hierarchy.keySet()) {
+ if (hasCycle(role, visited, stack)) {
+ throw new CycleInRoleHierarchyException();
+ }
+ }
+ }
+
+ private boolean hasCycle(String role, Set<String> visited, Set<String> stack) {
+ if (stack.contains(role)) {
+ return true;
+ }
+ if (visited.contains(role)) {
+ return false;
+ }
+
+ visited.add(role);
+ stack.add(role);
+
+ Set<String> children = hierarchy.get(role);
+ if (children != null) {
+ for (String child : children) {
+ if (hasCycle(child, visited, stack)) {
+ return true;
+ }
+ }
+ }
+
+ stack.remove(role);
+ return false;
+ }
+
+ private Builder addHierarchy(String role, String... impliedRoles) {
+ Set<String> childRoles = Set.of(impliedRoles);
+
+ this.hierarchy.put(role, childRoles);
+ return this;
+ }
+
+ public final class ImpliedRoles {
+
+ private final String role;
+
+ private ImpliedRoles(String role) {
+ this.role = role;
+ }
+
+ public Builder implies(String... impliedRoles) {
+ Assert.notEmpty(impliedRoles, "at least one implied role must be provided");
+ Assert.noNullElements(impliedRoles, "implied role name(s) cannot be empty");
+ return Builder.this.addHierarchy(this.role, impliedRoles);
+ }
+ }
+ }
+} | Java | Spring Security๋ ์ฑ๋ฅ ์ต์ ํ๋ฅผ ์ค์ํ๊ฒ ์๊ฐํ๋๋ฐ์,
ArrayDeque ์ฌ์ฉ์ ํตํด ์ฑ๋ฅ์ ํฅ์ ์์ผ๋ด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ๐
```suggestion
Queue<String> queue = new ArrayDeque<>(authorities);
``` |
@@ -1,20 +1,22 @@
package nextstep.security.authorization;
import nextstep.security.authentication.Authentication;
+import nextstep.security.authorization.hierarchy.RoleHierarchy;
import java.util.Set;
public class AuthorityAuthorizationManager<T> implements AuthorizationManager<T> {
- private final AuthoritiesAuthorizationManager delegate = new AuthoritiesAuthorizationManager();
+ private final AuthoritiesAuthorizationManager delegate;
- private final String authority;
+ private final Set<String> authorities;
- public AuthorityAuthorizationManager(String authority) {
- this.authority = authority;
+ public AuthorityAuthorizationManager(RoleHierarchy roleHierarchy, String ...authorities) {
+ this.delegate = new AuthoritiesAuthorizationManager(roleHierarchy);
+ this.authorities = Set.of(authorities);
}
@Override
public AuthorizationDecision check(final Authentication authentication, final T object) {
- return this.delegate.check(authentication, Set.of(this.authority));
+ return this.delegate.check(authentication, this.authorities);
}
} | Java | Set ์ผ๋ก ์ค๋ณต์ ์ ๊ฑฐํด ์ฃผ์
จ๊ตฐ์ ๐ |
@@ -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,33 @@
+package com.hansarangdelivery.config;
+
+import com.hansarangdelivery.entity.PageType;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
+import org.springframework.web.method.support.HandlerMethodArgumentResolver;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import java.util.List;
+
+@Configuration
+public class PageableConfig implements WebMvcConfigurer {
+ @Override
+ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
+ PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
+ resolver.setFallbackPageable(PageRequest.of(0, 10)); // ๊ธฐ๋ณธ๊ฐ ์ค์
+ resolver.setMaxPageSize(50); // ์ต๋ ํ์ด์ง ํฌ๊ธฐ ์ ํ
+ resolvers.add(resolver);
+ }
+
+ public static void validatePageSize(Pageable pageable) {
+ if(pageable.getPageSize() != PageType.TEN.getSize()
+ && pageable.getPageSize() != PageType.THIRTY.getSize()
+ && pageable.getPageSize() != PageType.FIFTY.getSize()
+ ) {
+ throw new IllegalArgumentException("ํ์ด์ง ์ฌ์ด์ฆ๋ 10 / 30 / 50 ์ค์์ ์
๋ ฅ ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+}
+ | Java | ์ด ๋ถ๋ถ์์ size๋ฅผ 10,30,50 ์ ์ฉ์์ผ์ผ ํ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,155 @@
+package com.coffeebean.domain.review.review.service;
+
+import com.coffeebean.domain.order.order.DeliveryStatus;
+import com.coffeebean.domain.order.orderItem.entity.OrderItem;
+import com.coffeebean.domain.order.orderItem.repository.OrderItemRepository;
+import com.coffeebean.domain.review.review.ReviewableOrderItemDto;
+import com.coffeebean.domain.review.review.entity.Review;
+import com.coffeebean.domain.review.review.entity.ReviewDetailDto;
+import com.coffeebean.domain.review.review.respository.ReviewRepository;
+import com.coffeebean.domain.user.user.enitity.User;
+import com.coffeebean.domain.user.user.repository.UserRepository;
+import jakarta.persistence.EntityListeners;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Optional;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+@Transactional
+public class ReviewService {
+
+ private final ReviewRepository reviewRepository;
+ private final OrderItemRepository orderItemRepository;
+ private final UserRepository userRepository;
+
+ /**
+ * ๋ฆฌ๋ทฐ ์์ฑ ๊ธฐ๊ฐ ์ด๊ณผ ์ ์์ฑ ๋ถ๊ฐ (๋ฐฐ์ก ์๋ฃ ํ 7์ผ ์ด๋ด)
+ * ์ํ ์ฃผ๋ฌธ์ ๊ธฐ์ค์ผ๋ก ์ดํ ํ๋ฉด ๋ฌด์กฐ๊ฑด ๋์ฐฉํ๋ค๊ณ ๊ฐ์
+ * ์ํ ์ฃผ๋ฌธ ๋ ์ง + 9 ์ผ -> ๋ฆฌ๋ทฐ ์์ฑ ๊ฐ๋ฅ์ผ
+ */
+ public void writeReivew(Long orderId, String content, int rating) {
+ // ์ฃผ๋ฌธ ์์ดํ
์กฐํ
+ OrderItem orderItem = orderItemRepository.findById(orderId)
+ .orElseThrow(() -> new IllegalArgumentException("์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค."));
+
+ // ๊ฒ์ฆ ๋ก์ง ํธ์ถ
+ if (isReviewable(orderItem)) {
+ // ์ ์ ์ ๋ณด ์กฐํ
+ String email = orderItem.getOrder().getEmail();
+ User user = userRepository.findByEmail(email)
+ .orElseThrow(() -> new IllegalArgumentException("์ ํจํ์ง ์์ ์ฌ์ฉ์์
๋๋ค."));
+
+ // ๋ฆฌ๋ทฐ ์์ฑ ๋ฐ ์ ์ฅ
+ Review review = Review.builder()
+ .user(user)
+ .orderItem(orderItem)
+ .content(content)
+ .rating(rating)
+ .build();
+
+ reviewRepository.save(review);
+
+ // ๊ฒฐ์ ๊ธ์ก์ 10% ํฌ์ธํธ ์ ๋ฆฝ
+ pointAdded(orderItem, user);
+ }
+
+ }
+
+ private void pointAdded(OrderItem orderItem, User user) {
+ int pointsToAdd = (int) (orderItem.getTotalPrice() * 0.1);
+ String description = "๋ฆฌ๋ทฐ ์์ฑ ํฌ์ธํธ ์ ๋ฆฝ - ์ฃผ๋ฌธ ์ํ ๋ฒํธ: " + orderItem.getId();
+ user.addPoints(pointsToAdd, description);
+ }
+
+ // ๋ฆฌ๋ทฐ ์์ฑ ๊ฒ์ฆ ๋ก์ง
+ private boolean isReviewable(OrderItem orderItem) {
+ // ๋ฐฐ์ก ์๋ฃ ์ฌ๋ถ ํ์ธ
+ if (orderItem.getOrder().getDeliveryStatus() != DeliveryStatus.DONE) {
+ throw new IllegalStateException("๋ฐฐ์ก์ด ์๋ฃ๋์ง ์์ ์ฃผ๋ฌธ์ ๋ํด ๋ฆฌ๋ทฐ๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.");
+ }
+
+ // ๋ฆฌ๋ทฐ ์์ฑ ๊ฐ๋ฅ ๊ธฐ๊ฐ ๊ฒ์ฆ (๊ตฌ๋งค์ผ + 9์ผ ์ด๋ด)
+ LocalDateTime orderDate = orderItem.getOrder().getOrderDate();
+ if (orderDate.plusDays(9).isBefore(LocalDateTime.now())) {
+ throw new IllegalStateException("๋ฆฌ๋ทฐ ์์ฑ ๊ฐ๋ฅ ๊ธฐ๊ฐ์ด ์ง๋ฌ์ต๋๋ค.");
+ }
+ return true;
+ }
+
+ @Transactional(readOnly = true)
+ // ์์ฑํ ๋ฆฌ๋ทฐ ๋ด์ญ ์ ์ฒด ์กฐํ (์ญ์ ๋ ๋ฆฌ๋ทฐ ๋นผ๊ณ )
+ public List<ReviewDetailDto> getReviewsByUser(Long userId, int page, int size) {
+ Pageable pageable = PageRequest.of(page, size, Sort.by("createDate").descending());
+
+ // ์ญ์ ๋์ง ์์ ๋ฆฌ๋ทฐ ํ์ด์ง ์กฐํ
+ Page<Review> reviews = reviewRepository.findReviewsByUserId(userId, pageable);
+
+ // Review ์ํฐํฐ๋ฅผ ReviewDetailDto๋ก ๋ณํ
+ return reviews.stream().map(review -> new ReviewDetailDto(
+ review.getId(),
+ review.getContent(),
+ review.getRating(),
+ review.getCreateDate()
+ )).toList();
+ }
+
+ // ์์ฑ ๊ฐ๋ฅํ ๋ฆฌ๋ทฐ๋ง ๋ณด์ฌ ์ฃผ๋ ์ฉ๋
+ @Transactional(readOnly = true)
+ public List<ReviewableOrderItemDto> getReviewableOrderItems(String email) {
+ // ๋ฆฌ๋ทฐ ์์ฑ ๊ฐ๋ฅ ๊ธฐ๊ฐ
+ LocalDateTime cutoffDate = LocalDateTime.now().minusDays(9);
+
+ // ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ํํฐ๋งํ OrderItem ์กฐํ
+ List<OrderItem> orderItems = orderItemRepository.findReviewableOrderItems(email, cutoffDate);
+
+ // DTO ๋ณํ
+ return orderItems.stream()
+ .map(orderItem -> new ReviewableOrderItemDto(
+ orderItem.getId(),
+ orderItem.getItem().getName(),
+ orderItem.getOrder().getOrderDate()
+ )).toList();
+ }
+
+ public void modifyReview(Long reviewId, String content, int rating) {
+
+ Review review = reviewRepository.findById(reviewId).orElseThrow(() -> new IllegalArgumentException("ํด๋น ๋ฆฌ๋ทฐ๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค."));
+
+ Optional<User> _user = userRepository.findById(review.getUser().getId());
+ if (_user.isPresent()) {
+ User user = _user.get();
+
+ if (!review.getUser().getId().equals(user.getId())) {
+ throw new IllegalStateException("๋ณธ์ธ์ ๋ฆฌ๋ทฐ๋ง ์์ ํ ์ ์์ต๋๋ค.");
+ }
+ }
+
+ review.update(content, rating);
+ }
+
+ public void deleteReview(Long reviewId) {
+ Review review = reviewRepository.findById(reviewId).orElseThrow(() -> new IllegalArgumentException("ํด๋น ๋ฆฌ๋ทฐ๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค."));
+
+ Optional<User> _user = userRepository.findById(review.getUser().getId());
+ if (_user.isPresent()) {
+ User user = _user.get();
+
+ if (!review.getUser().getId().equals(user.getId())) {
+ throw new IllegalStateException("๋ณธ์ธ์ ๋ฆฌ๋ทฐ๋ง ์ญ์ ํ ์ ์์ต๋๋ค.");
+ }
+ }
+
+ reviewRepository.delete(review);
+ }
+} | Java | **P4:** Entity๋ฅผ DTO๋ก ๋ง๋๋ DTO ์์ฑ์๋ฅผ ๋ง๋ค์ด ์ฌ์ฉํด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,21 @@
+package com.coffeebean.domain.review.review;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.time.LocalDateTime;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+// ์์ฑ ๊ฐ๋ฅ ๋ฆฌ๋ทฐ
+public class ReviewableOrderItemDto {
+
+ private Long orderItemId; // ์ฃผ๋ฌธ ์์ดํ
ID
+ private String itemName; // ์ํ๋ช
+ private LocalDateTime orderDate; // ์ฃผ๋ฌธ ๋ ์ง
+} | Java | ํ์ฌ ํ์ด์ง์์ ๋ฆฌ๋ทฐ ์์ฑ์ ํ์ ๋์ `์์ฑ ์๋ฃ`๋ก ํ์๋๋๋ฐ, ๋ค์ ์ ์ํ๋ฉด `๋ฆฌ๋ทฐ ์์ฑ`์ผ๋ก ํ์๋ฉ๋๋ค.
์์ฑ ๊ฐ๋ฅ ๋ฆฌ๋ทฐ ์๋ต `ReviewableOrderItemDto`์ ๋ฆฌ๋ทฐ๋์๋์ง ์ฌ๋ถ `isReviewed`๋ `reviewId`๋ฅผ ์ถ๊ฐํด์ ์๋ตํ๋ฉด ํ์ด์ง์ ๋ค์ ์ ์ํ์ ๋ ๋ฆฌ๋ทฐ๊ฐ ์์ฑ๋ ์ฃผ๋ฌธ์ ์์ฑ ์๋ฃ๋ก ํ์ํ๋๋ฐ ํ์ฉํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,21 @@
+package com.coffeebean.domain.review.review;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.time.LocalDateTime;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+// ์์ฑ ๊ฐ๋ฅ ๋ฆฌ๋ทฐ
+public class ReviewableOrderItemDto {
+
+ private Long orderItemId; // ์ฃผ๋ฌธ ์์ดํ
ID
+ private String itemName; // ์ํ๋ช
+ private LocalDateTime orderDate; // ์ฃผ๋ฌธ ๋ ์ง
+} | 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' } ๋ถ๋ถ๋ ์๋ตํด ์ฃผ์ค ์ ์์ต๋๋ค. |
@@ -1,8 +1,8 @@
export type User = {
id: number;
- email: string;
+ email?: string;
name: string;
- companyName: string;
+ companyName?: string;
image: string | null;
};
@@ -13,3 +13,52 @@ export type GatheringParticipant = {
joinedAt: string;
User: User;
};
+
+export type ReviewQuery = {
+ gatheringId?: string;
+ useId?: number;
+ type?: string;
+ location?: string;
+ date?: string;
+ registrationEnd?: string;
+ sortBy?: "createdAt" | "score" | "participantCount";
+ sortOrder?: "asc" | "desc";
+ limit?: number;
+ offset?: number;
+};
+
+type Gathering = {
+ teamId: string;
+ id: number;
+ type: string;
+ name: string;
+ dateTime: string;
+ location: string;
+ image: string;
+};
+
+export type Review = {
+ teamId?: string;
+ id: number;
+ score: number;
+ comment: string;
+ createdAt: string;
+ Gathering?: Gathering;
+ User: User;
+};
+
+// ์ค์ ๋ฐ์ดํฐ ์๋ต๊ฐ
+export type ReviewsResponse = {
+ data: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+};
+
+// ๋ฆฌ๋ทฐ ์ ์ ๋ฐ์ดํฐ
+export type ReviewData = {
+ reviews: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+}; | TypeScript | _:hammer_and_wrench: Refactor suggestion_
**์ค๋ณต๋๋ ํ์
์ ์ ํตํฉ ํ์**
`ReviewsResponse`์ `ReviewData` ํ์
์ด ๋์ผํ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ํ์
์ ํตํฉํ๋ ๊ฒ์ด ์ข๊ฒ ์ต๋๋ค:
```diff
-// ์ค์ ๋ฐ์ดํฐ ์๋ต๊ฐ
-export type ReviewsResponse = {
- data: Review[];
- totalItemCount: number;
- currentPage: number;
- totalPages: number;
-};
-
-// ๋ฆฌ๋ทฐ ์ ์ ๋ฐ์ดํฐ
-export type ReviewData = {
- reviews: Review[];
- totalItemCount: number;
- currentPage: number;
- totalPages: number;
-};
+export type ReviewsResponse = {
+ data: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+};
+
+export type ReviewData = Omit<ReviewsResponse, 'data'> & {
+ reviews: Review[];
+};
```
<!-- suggestion_start -->
<details>
<summary>๐ Committable suggestion</summary>
> โผ๏ธ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
// ์ค์ ๋ฐ์ดํฐ ์๋ต๊ฐ
export type ReviewsResponse = {
data: Review[];
totalItemCount: number;
currentPage: number;
totalPages: number;
};
export type ReviewData = Omit<ReviewsResponse, 'data'> & {
reviews: Review[];
};
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -0,0 +1,54 @@
+import { useMemo } from "react";
+import Arrow from "@/images/arrow.svg";
+import { cn } from "@/utils/classnames";
+
+type PaginationProps = {
+ currentPage: number;
+ totalPages: number;
+ onClick: (page: number) => void;
+ pageLimit?: number;
+};
+
+export default function Pagination({ currentPage, totalPages, onClick, pageLimit = 6 }: PaginationProps) {
+ const currentStartPage = useMemo(() => {
+ return Math.floor((currentPage - 1) / pageLimit) * pageLimit + 1;
+ }, [currentPage, pageLimit]);
+
+ // ํ์ฌ ํ์ด์ง ๊ทธ๋ฃน์์ ๋ณด์ฌ์ค ํ์ด์ง ๋ชฉ๋ก ์์ฑ
+ const pages = useMemo(() => {
+ return Array.from(
+ { length: Math.min(pageLimit, totalPages - currentStartPage + 1) },
+ (_, i) => currentStartPage + i,
+ );
+ }, [currentStartPage, pageLimit, totalPages]);
+
+ return (
+ <div className="mt-6 flex items-center justify-center gap-2 text-gray-200">
+ <button
+ onClick={() => onClick(currentStartPage - pageLimit)}
+ disabled={currentPage <= pageLimit}
+ aria-label="์ด์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
+ >
+ <Arrow className={cn(currentPage > pageLimit && "text-black")} />
+ </button>
+ {pages.map((page) => (
+ <button
+ key={page}
+ onClick={() => onClick(page)}
+ aria-label={`${page}ํ์ด์ง๋ก ์ด๋`}
+ aria-current={currentPage === page && "page"}
+ className={cn("size-12 text-gray-500", currentPage === page && "font-semibold text-black")}
+ >
+ {page}
+ </button>
+ ))}
+ <button
+ onClick={() => onClick(currentStartPage + pageLimit)}
+ disabled={currentStartPage + pageLimit > totalPages}
+ aria-label="๋ค์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
+ >
+ <Arrow className={cn("scale-x-[-1] transform", currentStartPage + pageLimit <= totalPages && "text-black")} />
+ </button>
+ </div>
+ );
+} | Unknown | _:hammer_and_wrench: Refactor suggestion_
**๋ค์ ํ์ด์ง ๊ทธ๋ฃน ๋ฒํผ ์ ๊ทผ์ฑ ๊ฐ์ ํ์**
๋ค์ ํ์ด์ง ๊ทธ๋ฃน ๋ฒํผ์๋ ์ ์ ํ aria ๋ ์ด๋ธ์ด ํ์ํฉ๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ๊ฐ์ ํด๋ณด์ธ์:
```diff
<button
onClick={() => onClick(currentStartPage + pageLimit)}
disabled={currentStartPage + pageLimit > totalPages}
+ aria-label="๋ค์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
>
<Arrow className={cn("scale-x-[-1] transform", currentStartPage + pageLimit <= totalPages && "text-black")} />
</button>
```
<!-- suggestion_start -->
<details>
<summary>๐ Committable suggestion</summary>
> โผ๏ธ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
<button
onClick={() => onClick(currentStartPage + pageLimit)}
disabled={currentStartPage + pageLimit > totalPages}
aria-label="๋ค์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
>
<Arrow className={cn("scale-x-[-1] transform", currentStartPage + pageLimit <= totalPages && "text-black")} />
</button>
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -0,0 +1,54 @@
+import { useMemo } from "react";
+import Arrow from "@/images/arrow.svg";
+import { cn } from "@/utils/classnames";
+
+type PaginationProps = {
+ currentPage: number;
+ totalPages: number;
+ onClick: (page: number) => void;
+ pageLimit?: number;
+};
+
+export default function Pagination({ currentPage, totalPages, onClick, pageLimit = 6 }: PaginationProps) {
+ const currentStartPage = useMemo(() => {
+ return Math.floor((currentPage - 1) / pageLimit) * pageLimit + 1;
+ }, [currentPage, pageLimit]);
+
+ // ํ์ฌ ํ์ด์ง ๊ทธ๋ฃน์์ ๋ณด์ฌ์ค ํ์ด์ง ๋ชฉ๋ก ์์ฑ
+ const pages = useMemo(() => {
+ return Array.from(
+ { length: Math.min(pageLimit, totalPages - currentStartPage + 1) },
+ (_, i) => currentStartPage + i,
+ );
+ }, [currentStartPage, pageLimit, totalPages]);
+
+ return (
+ <div className="mt-6 flex items-center justify-center gap-2 text-gray-200">
+ <button
+ onClick={() => onClick(currentStartPage - pageLimit)}
+ disabled={currentPage <= pageLimit}
+ aria-label="์ด์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
+ >
+ <Arrow className={cn(currentPage > pageLimit && "text-black")} />
+ </button>
+ {pages.map((page) => (
+ <button
+ key={page}
+ onClick={() => onClick(page)}
+ aria-label={`${page}ํ์ด์ง๋ก ์ด๋`}
+ aria-current={currentPage === page && "page"}
+ className={cn("size-12 text-gray-500", currentPage === page && "font-semibold text-black")}
+ >
+ {page}
+ </button>
+ ))}
+ <button
+ onClick={() => onClick(currentStartPage + pageLimit)}
+ disabled={currentStartPage + pageLimit > totalPages}
+ aria-label="๋ค์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
+ >
+ <Arrow className={cn("scale-x-[-1] transform", currentStartPage + pageLimit <= totalPages && "text-black")} />
+ </button>
+ </div>
+ );
+} | Unknown | _:hammer_and_wrench: Refactor suggestion_
**ํ์ด์ง ๋ฒํผ ์ ๊ทผ์ฑ ๋ฐ ํ์ฌ ํ์ด์ง ํ์ ๊ฐ์ ํ์**
ํ์ด์ง ๋ฒํผ์ ํ์ฌ ํ์ด์ง ํ์์ aria ์์ฑ์ด ๋ถ์กฑํฉ๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ๊ฐ์ ํด๋ณด์ธ์:
```diff
{pages.map((page) => (
<button
key={page}
onClick={() => onClick(page)}
+ aria-label={`${page}ํ์ด์ง๋ก ์ด๋`}
+ aria-current={currentPage === page ? 'page' : undefined}
className={cn("size-12 text-gray-500", currentPage === page && "font-semibold text-black")}
>
{page}
</button>
))}
```
<!-- suggestion_start -->
<details>
<summary>๐ Committable suggestion</summary>
> โผ๏ธ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
{pages.map((page) => (
<button
key={page}
onClick={() => onClick(page)}
aria-label={`${page}ํ์ด์ง๋ก ์ด๋`}
aria-current={currentPage === page ? 'page' : undefined}
className={cn("size-12 text-gray-500", currentPage === page && "font-semibold text-black")}
>
{page}
</button>
))}
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -0,0 +1,54 @@
+import { useMemo } from "react";
+import Arrow from "@/images/arrow.svg";
+import { cn } from "@/utils/classnames";
+
+type PaginationProps = {
+ currentPage: number;
+ totalPages: number;
+ onClick: (page: number) => void;
+ pageLimit?: number;
+};
+
+export default function Pagination({ currentPage, totalPages, onClick, pageLimit = 6 }: PaginationProps) {
+ const currentStartPage = useMemo(() => {
+ return Math.floor((currentPage - 1) / pageLimit) * pageLimit + 1;
+ }, [currentPage, pageLimit]);
+
+ // ํ์ฌ ํ์ด์ง ๊ทธ๋ฃน์์ ๋ณด์ฌ์ค ํ์ด์ง ๋ชฉ๋ก ์์ฑ
+ const pages = useMemo(() => {
+ return Array.from(
+ { length: Math.min(pageLimit, totalPages - currentStartPage + 1) },
+ (_, i) => currentStartPage + i,
+ );
+ }, [currentStartPage, pageLimit, totalPages]);
+
+ return (
+ <div className="mt-6 flex items-center justify-center gap-2 text-gray-200">
+ <button
+ onClick={() => onClick(currentStartPage - pageLimit)}
+ disabled={currentPage <= pageLimit}
+ aria-label="์ด์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
+ >
+ <Arrow className={cn(currentPage > pageLimit && "text-black")} />
+ </button>
+ {pages.map((page) => (
+ <button
+ key={page}
+ onClick={() => onClick(page)}
+ aria-label={`${page}ํ์ด์ง๋ก ์ด๋`}
+ aria-current={currentPage === page && "page"}
+ className={cn("size-12 text-gray-500", currentPage === page && "font-semibold text-black")}
+ >
+ {page}
+ </button>
+ ))}
+ <button
+ onClick={() => onClick(currentStartPage + pageLimit)}
+ disabled={currentStartPage + pageLimit > totalPages}
+ aria-label="๋ค์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
+ >
+ <Arrow className={cn("scale-x-[-1] transform", currentStartPage + pageLimit <= totalPages && "text-black")} />
+ </button>
+ </div>
+ );
+} | Unknown | _:hammer_and_wrench: Refactor suggestion_
**์ ๊ทผ์ฑ ๊ฐ์ ํ์**
ํ์ด์ง๋ค์ด์
๋ฒํผ์ ์ ์ ํ aria ๋ ์ด๋ธ์ด ์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ์ ๊ทผ์ฑ์ ๊ฐ์ ํด๋ณด์ธ์:
```diff
- <button onClick={() => onClick(currentStartPage - pageLimit)} disabled={currentPage <= pageLimit}>
+ <button
+ onClick={() => onClick(currentStartPage - pageLimit)}
+ disabled={currentPage <= pageLimit}
+ aria-label="์ด์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
+ >
<Arrow className={cn(currentPage > pageLimit && "text-black")} />
</button>
```
<!-- suggestion_start -->
<details>
<summary>๐ Committable suggestion</summary>
> โผ๏ธ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
<div className="mt-6 flex items-center justify-center gap-2 text-gray-200">
<button
onClick={() => onClick(currentStartPage - pageLimit)}
disabled={currentPage <= pageLimit}
aria-label="์ด์ ํ์ด์ง ๊ทธ๋ฃน์ผ๋ก ์ด๋"
>
<Arrow className={cn(currentPage > pageLimit && "text-black")} />
</button>
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -1,8 +1,8 @@
export type User = {
id: number;
- email: string;
+ email?: string;
name: string;
- companyName: string;
+ companyName?: string;
image: string | null;
};
@@ -13,3 +13,52 @@ export type GatheringParticipant = {
joinedAt: string;
User: User;
};
+
+export type ReviewQuery = {
+ gatheringId?: string;
+ useId?: number;
+ type?: string;
+ location?: string;
+ date?: string;
+ registrationEnd?: string;
+ sortBy?: "createdAt" | "score" | "participantCount";
+ sortOrder?: "asc" | "desc";
+ limit?: number;
+ offset?: number;
+};
+
+type Gathering = {
+ teamId: string;
+ id: number;
+ type: string;
+ name: string;
+ dateTime: string;
+ location: string;
+ image: string;
+};
+
+export type Review = {
+ teamId?: string;
+ id: number;
+ score: number;
+ comment: string;
+ createdAt: string;
+ Gathering?: Gathering;
+ User: User;
+};
+
+// ์ค์ ๋ฐ์ดํฐ ์๋ต๊ฐ
+export type ReviewsResponse = {
+ data: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+};
+
+// ๋ฆฌ๋ทฐ ์ ์ ๋ฐ์ดํฐ
+export type ReviewData = {
+ reviews: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+}; | TypeScript | ReviewData๋ ๋ณด๊ธฐ์๋ ReviewsResponse๋ ๊ฐ์ ๋ณด์ด๋๋ฐ ๋ฌด์จ ์ฉ๋์ ํ์
์ธ๊ฐ์? |
@@ -1,8 +1,8 @@
export type User = {
id: number;
- email: string;
+ email?: string;
name: string;
- companyName: string;
+ companyName?: string;
image: string | null;
};
@@ -13,3 +13,52 @@ export type GatheringParticipant = {
joinedAt: string;
User: User;
};
+
+export type ReviewQuery = {
+ gatheringId?: string;
+ useId?: number;
+ type?: string;
+ location?: string;
+ date?: string;
+ registrationEnd?: string;
+ sortBy?: "createdAt" | "score" | "participantCount";
+ sortOrder?: "asc" | "desc";
+ limit?: number;
+ offset?: number;
+};
+
+type Gathering = {
+ teamId: string;
+ id: number;
+ type: string;
+ name: string;
+ dateTime: string;
+ location: string;
+ image: string;
+};
+
+export type Review = {
+ teamId?: string;
+ id: number;
+ score: number;
+ comment: string;
+ createdAt: string;
+ Gathering?: Gathering;
+ User: User;
+};
+
+// ์ค์ ๋ฐ์ดํฐ ์๋ต๊ฐ
+export type ReviewsResponse = {
+ data: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+};
+
+// ๋ฆฌ๋ทฐ ์ ์ ๋ฐ์ดํฐ
+export type ReviewData = {
+ reviews: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+}; | TypeScript | ReviewsResponse๋ ์ค์ ์๋ต ๋ฐ์ดํฐ ํ์
์ด๊ณ ReviewData๋ ์์๋ก ํด๋
ผ ๊ฑด๋ฐ ์ง๊ธ ์ฝ๋ ๋ฆฌํฉํ ๋ง ๋ง์น๋ฉด ํ์
์ ๋ฆฌํ ๊ฒ ๊ฐ์์ต.. |
@@ -1,8 +1,8 @@
export type User = {
id: number;
- email: string;
+ email?: string;
name: string;
- companyName: string;
+ companyName?: string;
image: string | null;
};
@@ -13,3 +13,52 @@ export type GatheringParticipant = {
joinedAt: string;
User: User;
};
+
+export type ReviewQuery = {
+ gatheringId?: string;
+ useId?: number;
+ type?: string;
+ location?: string;
+ date?: string;
+ registrationEnd?: string;
+ sortBy?: "createdAt" | "score" | "participantCount";
+ sortOrder?: "asc" | "desc";
+ limit?: number;
+ offset?: number;
+};
+
+type Gathering = {
+ teamId: string;
+ id: number;
+ type: string;
+ name: string;
+ dateTime: string;
+ location: string;
+ image: string;
+};
+
+export type Review = {
+ teamId?: string;
+ id: number;
+ score: number;
+ comment: string;
+ createdAt: string;
+ Gathering?: Gathering;
+ User: User;
+};
+
+// ์ค์ ๋ฐ์ดํฐ ์๋ต๊ฐ
+export type ReviewsResponse = {
+ data: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+};
+
+// ๋ฆฌ๋ทฐ ์ ์ ๋ฐ์ดํฐ
+export type ReviewData = {
+ reviews: Review[];
+ totalItemCount: number;
+ currentPage: number;
+ totalPages: number;
+}; | TypeScript | ๋ต ์๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,31 @@
+package com.sparta.tentenbackend.domain.ai.entity;
+
+import com.sparta.tentenbackend.global.BaseEntity;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
+import java.util.UUID;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Entity
+@Getter
+@Setter
+@Table(name = "p_ai_prompting")
+@NoArgsConstructor
+public class Ai extends BaseEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.UUID)
+ private UUID id;
+
+ @Column(nullable = false)
+ private String question;
+
+ @Column(nullable = false)
+ private String answer;
+} | Java | GenerationbType.AUTO๋ณด๋ค GenerationbType.UUID๋ก ๋ช
์์ ์ผ๋ก ํ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,34 @@
+package com.sparta.tentenbackend.domain.review.entity;
+
+import com.sparta.tentenbackend.global.BaseEntity;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import jakarta.persistence.JoinColumn;
+import jakarta.persistence.OneToOne;
+import jakarta.persistence.Table;
+import java.util.UUID;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Entity
+@Getter
+@Setter
+@Table(name = "p_owner_review")
+@NoArgsConstructor
+public class OwnerReview extends BaseEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.UUID)
+ private UUID id;
+
+ @Column(nullable = false)
+ private String content;
+
+ @OneToOne
+ @JoinColumn(name = "review_id", unique = true)
+ private Review review;
+} | Java | ์ ๋ถ๋ถ๋ GenerationType.UUID๋ก ๊ณ ์น๋๊ฒ ๋์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,43 @@
+package nextstep.app;
+
+import nextstep.oauth2.authentication.provider.OAuth2LoginAuthenticationProvider;
+import nextstep.oauth2.registration.ClientRegistrationRepository;
+import nextstep.oauth2.registration.OAuth2ClientProperties;
+import nextstep.oauth2.userinfo.OAuth2UserService;
+import nextstep.oauth2.web.authorizedclient.OAuth2AuthorizedClientRepository;
+import nextstep.security.authentication.AuthenticationManager;
+import nextstep.security.authentication.DaoAuthenticationProvider;
+import nextstep.security.authentication.ProviderManager;
+import nextstep.security.userdetails.UserDetailsService;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+@EnableConfigurationProperties(OAuth2ClientProperties.class)
+@Configuration
+public class OAuth2Config {
+ @Bean
+ public ClientRegistrationRepository registrationRepository(
+ OAuth2ClientProperties oauth2ClientProperties
+ ) {
+ return oauth2ClientProperties.createClientRegistrationDao();
+ }
+
+ @Bean
+ public OAuth2AuthorizedClientRepository authorizedClientRepository() {
+ return OAuth2AuthorizedClientRepository.getInstance();
+ }
+
+ @Bean
+ public AuthenticationManager authenticationManager(
+ UserDetailsService userDetailsService,
+ OAuth2UserService oAuth2UserService
+ ) {
+ return new ProviderManager(List.of(
+ new DaoAuthenticationProvider(userDetailsService),
+ new OAuth2LoginAuthenticationProvider(oAuth2UserService)
+ ));
+ }
+} | Java | ์ปค์คํ
์ ํ๊ฒ ๋๊ฒ ์ง๋ง DefaultOAuth2UserService๋ฅผ ๋์ด์ ํ์ํ ๋ก์ง๋ง ์ถ๊ฐ๋ก ๊ตฌํํด๋ณด๋ ๊ตฌ์กฐ๋ก ํด๋ณด์๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,68 @@
+package nextstep.oauth2.authentication.token;
+
+import nextstep.oauth2.authentication.OAuth2AccessToken;
+import nextstep.oauth2.endpoint.dto.OAuth2AuthorizationExchange;
+import nextstep.oauth2.registration.ClientRegistration;
+import nextstep.security.authentication.Authentication;
+
+import java.util.Set;
+
+public final class OAuth2AuthorizationCodeAuthenticationToken implements Authentication {
+ private final ClientRegistration clientRegistration;
+ private final OAuth2AuthorizationExchange authorizationExchange;
+ private final OAuth2AccessToken accessToken;
+
+ public OAuth2AuthorizationCodeAuthenticationToken(
+ ClientRegistration clientRegistration,
+ OAuth2AuthorizationExchange authorizationExchange,
+ OAuth2AccessToken accessToken
+ ) {
+ this.clientRegistration = clientRegistration;
+ this.authorizationExchange = authorizationExchange;
+ this.accessToken = accessToken;
+ }
+
+ public OAuth2AuthorizationCodeAuthenticationToken(
+ ClientRegistration clientRegistration,
+ OAuth2AuthorizationExchange authorizationExchange
+ ) {
+ this(clientRegistration, authorizationExchange, null);
+ }
+
+ public ClientRegistration getClientRegistration() {
+ return clientRegistration;
+ }
+
+ public OAuth2AuthorizationExchange getAuthorizationExchange() {
+ return authorizationExchange;
+ }
+
+ public OAuth2AccessToken getAccessToken() {
+ return accessToken;
+ }
+
+ public boolean isValid() {
+ return authorizationExchange.isSameState();
+ }
+
+ @Override
+ public Set<String> getAuthorities() {
+ return Set.of();
+ }
+
+ @Override
+ public Object getCredentials() {
+ return (accessToken != null) ? accessToken.token()
+ : authorizationExchange.authorizationResponse().code();
+ }
+
+ @Override
+ public Object getPrincipal() {
+ return clientRegistration.clientId();
+ }
+
+ @Override
+ public boolean isAuthenticated() {
+ return false;
+ }
+} | Java | authorizationCodeAuthentication๋ฅผ ์ดํด๋ณด๋ฉด Authentication์ getCredentials๋ getPrincipal๋ฅผ ๋ณ๋๋ก ์ฌ์ฉํ๊ณ ์์ง ์์๋ฐ ์ ๊ตณ์ด Authentication๋ฅผ ๊ตฌํํ๊ฒ ํ๋ ๊ฒ์ผ ์ง ์๊ฐํด๋ณด์
จ๋์? ์ ๋ต์ด ์๊ฑฐ๋ ๋ฌด์ธ๊ฐ๋ฅผ ์๋ํ๋ ์ง๋ฌธ์ ์๋๊ณ ์๊ฐํด๋ณด์๊ธธ ๋ฐ๋ผ๋ ๋ง์์์ ๋จ๊ธฐ๋ ์ฝ๋ฉํธ ์
๋๋ค! |
@@ -0,0 +1,43 @@
+package nextstep.app;
+
+import nextstep.oauth2.authentication.provider.OAuth2LoginAuthenticationProvider;
+import nextstep.oauth2.registration.ClientRegistrationRepository;
+import nextstep.oauth2.registration.OAuth2ClientProperties;
+import nextstep.oauth2.userinfo.OAuth2UserService;
+import nextstep.oauth2.web.authorizedclient.OAuth2AuthorizedClientRepository;
+import nextstep.security.authentication.AuthenticationManager;
+import nextstep.security.authentication.DaoAuthenticationProvider;
+import nextstep.security.authentication.ProviderManager;
+import nextstep.security.userdetails.UserDetailsService;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+@EnableConfigurationProperties(OAuth2ClientProperties.class)
+@Configuration
+public class OAuth2Config {
+ @Bean
+ public ClientRegistrationRepository registrationRepository(
+ OAuth2ClientProperties oauth2ClientProperties
+ ) {
+ return oauth2ClientProperties.createClientRegistrationDao();
+ }
+
+ @Bean
+ public OAuth2AuthorizedClientRepository authorizedClientRepository() {
+ return OAuth2AuthorizedClientRepository.getInstance();
+ }
+
+ @Bean
+ public AuthenticationManager authenticationManager(
+ UserDetailsService userDetailsService,
+ OAuth2UserService oAuth2UserService
+ ) {
+ return new ProviderManager(List.of(
+ new DaoAuthenticationProvider(userDetailsService),
+ new OAuth2LoginAuthenticationProvider(oAuth2UserService)
+ ));
+ }
+} | Java | ๋ฏธ์
์ ์งํํ ๋, oauth2 ํจํค์ง๋ง ํด๋ ๋ค๋ฃจ์ด์ผํ ๊ฒ ๋ฌด์ฒ ๋ง๋ค๋ณด๋, app ํจํค์ง์์์ ๋ณ๊ฒฝ์ฌํญ์ ์ต์ํํ๊ณ ,
๋ง์ฝ ์ถ๊ฐ ํด๋์ค๋ฅผ ๊ตฌํํ ๊ฒ ์๋ค๋ฉด ์ต๋ํ OAuth2Config ๋ด๋ถ์์ ํด๊ฒฐํ๋ ค๋ค๋ณด๋ ์ด๋ ๊ฒ Bean ๋ฑ๋ก์ ํ๊ฒ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
DefaultOAuth2UserService ๋ฅผ ๋ณ๋ ํด๋์ค๋ก ๋ถ๋ฆฌ์ํค๋๋ก ํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,43 @@
+package nextstep.app;
+
+import nextstep.oauth2.authentication.provider.OAuth2LoginAuthenticationProvider;
+import nextstep.oauth2.registration.ClientRegistrationRepository;
+import nextstep.oauth2.registration.OAuth2ClientProperties;
+import nextstep.oauth2.userinfo.OAuth2UserService;
+import nextstep.oauth2.web.authorizedclient.OAuth2AuthorizedClientRepository;
+import nextstep.security.authentication.AuthenticationManager;
+import nextstep.security.authentication.DaoAuthenticationProvider;
+import nextstep.security.authentication.ProviderManager;
+import nextstep.security.userdetails.UserDetailsService;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+@EnableConfigurationProperties(OAuth2ClientProperties.class)
+@Configuration
+public class OAuth2Config {
+ @Bean
+ public ClientRegistrationRepository registrationRepository(
+ OAuth2ClientProperties oauth2ClientProperties
+ ) {
+ return oauth2ClientProperties.createClientRegistrationDao();
+ }
+
+ @Bean
+ public OAuth2AuthorizedClientRepository authorizedClientRepository() {
+ return OAuth2AuthorizedClientRepository.getInstance();
+ }
+
+ @Bean
+ public AuthenticationManager authenticationManager(
+ UserDetailsService userDetailsService,
+ OAuth2UserService oAuth2UserService
+ ) {
+ return new ProviderManager(List.of(
+ new DaoAuthenticationProvider(userDetailsService),
+ new OAuth2LoginAuthenticationProvider(oAuth2UserService)
+ ));
+ }
+} | Java | [5d68d0d](https://github.com/next-step/spring-security-oauth2/pull/8/commits/5d68d0dc640af2e1fd53ebca1cc7b8a5ed58d3ec) ์ปค๋ฐ์์ ๋ฐ์ ์๋ฃํ์์ต๋๋ค. |
@@ -0,0 +1,68 @@
+package nextstep.oauth2.authentication.token;
+
+import nextstep.oauth2.authentication.OAuth2AccessToken;
+import nextstep.oauth2.endpoint.dto.OAuth2AuthorizationExchange;
+import nextstep.oauth2.registration.ClientRegistration;
+import nextstep.security.authentication.Authentication;
+
+import java.util.Set;
+
+public final class OAuth2AuthorizationCodeAuthenticationToken implements Authentication {
+ private final ClientRegistration clientRegistration;
+ private final OAuth2AuthorizationExchange authorizationExchange;
+ private final OAuth2AccessToken accessToken;
+
+ public OAuth2AuthorizationCodeAuthenticationToken(
+ ClientRegistration clientRegistration,
+ OAuth2AuthorizationExchange authorizationExchange,
+ OAuth2AccessToken accessToken
+ ) {
+ this.clientRegistration = clientRegistration;
+ this.authorizationExchange = authorizationExchange;
+ this.accessToken = accessToken;
+ }
+
+ public OAuth2AuthorizationCodeAuthenticationToken(
+ ClientRegistration clientRegistration,
+ OAuth2AuthorizationExchange authorizationExchange
+ ) {
+ this(clientRegistration, authorizationExchange, null);
+ }
+
+ public ClientRegistration getClientRegistration() {
+ return clientRegistration;
+ }
+
+ public OAuth2AuthorizationExchange getAuthorizationExchange() {
+ return authorizationExchange;
+ }
+
+ public OAuth2AccessToken getAccessToken() {
+ return accessToken;
+ }
+
+ public boolean isValid() {
+ return authorizationExchange.isSameState();
+ }
+
+ @Override
+ public Set<String> getAuthorities() {
+ return Set.of();
+ }
+
+ @Override
+ public Object getCredentials() {
+ return (accessToken != null) ? accessToken.token()
+ : authorizationExchange.authorizationResponse().code();
+ }
+
+ @Override
+ public Object getPrincipal() {
+ return clientRegistration.clientId();
+ }
+
+ @Override
+ public boolean isAuthenticated() {
+ return false;
+ }
+} | Java | [spring-security ์ OAuth2AuthorizationCodeAuthenticationToken ์์ค์ฝ๋๋ฅผ ๋ณด๋ฉด](https://github.com/spring-projects/spring-security/blob/7fc5d50adfe5546ca725f3259e4d65ee6083f7cd/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/OAuth2AuthorizationCodeAuthenticationToken.java#L112)
principal ๋ก clientId ๊ฐ์,
credentials ๋ก accessToken ํน์ code ๊ฐ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
[authenticated ๊ฐ ๋ํ true](https://github.com/spring-projects/spring-security/blob/7fc5d50adfe5546ca725f3259e4d65ee6083f7cd/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/OAuth2AuthorizationCodeAuthenticationToken.java#L106) ๋ผ๊ณ ์ค์ ๋์ด ์๊ณ ์.
ํ์ง๋ง ์ ๋ principal ๊ณผ credentials ๋ฅผ null ๊ฐ์ผ๋ก, isAuthenticated ๋ฅผ false ๋ก ์ค์ ํ์์ต๋๋ค.
์ ๋ ๋งจ ์ฒ์์ [OAuth2AuthorizationCodeGrantFilter](https://github.com/spring-projects/spring-security/blob/7fc5d50adfe5546ca725f3259e4d65ee6083f7cd/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/OAuth2AuthorizationCodeGrantFilter.java#L234) ์ฒ๋ผ OAuth2AuthorizationCodeAuthenticationToken ๋ฅผ Authorization ์ผ๋ก ํ์ฉํ๋ ํํฐ๊ฐ ์กด์ฌํ์ง๋ง,
๊ณ ๊ธ ๊ธฐ๋ฅ์ ํํฐ๋ผ์ ์ ๊ฐ ๋ฏธ์ฒ ๊ตฌํ์ ๋ชปํ์ค ์์์ต๋๋ค.
ํ์ง๋ง ์ฝ๋๋ฅผ ์์ธํ ์ฝ์ด๋ณด๋, clientRegistration, accessToken ๋ฑ์ ๊ฐ์ ๊ฐ์ ธ์ค๋ ์๋ฃ๊ตฌ์กฐ๋ก๋ง ํ์ฉํ๊ณ ์์ ๋ฟ์ด์ง, Authorization ์ผ๋ก์ ํ์ฉ์ ํ๊ณ ์๋ค๋ ๋๋์ ๋ฐ์ง ๋ชปํ์ต๋๋ค.
spring-security ์ ์ด์ ํ์คํ ๋ฆฌ๋ฅผ ์ถ์ ํ๋ค๋ณด๋
[**OAuth2LoginAuthenticationProvider ๊ณผ OAuth2AuthorizationCodeAuthenticationProvider**](https://github.com/spring-projects/spring-security/issues/5633) ์ ๋ก์ง์ด ๋น์ทํ๋ค๊ณ ๋ฆฌํฉํ ๋ง์ ์๊ตฌํ๋ ์ด์๊ฐ ์๋๊ตฐ์.
์ฒ์์๋ OAuth2LoginAuthentication ๊ณผ OAuth2AuthorizationCodeAuthentication ์ด ๋ณ๊ฐ์ Authentication ์ผ๋ก ๊ตฌํ์ ํ๋ค๊ฐ, ๋ง์ ๊ตฌํ์ ํ๋ค๋ณด๋ ์ด 2๊ฐ์ Provider ๋ก์ง์ด ๋น์ทํ๋ค๋ ๊ฒ์ ๊นจ๋ซ๊ฒ ๋์ด OAuth2LoginAuthenticationProvider ๋ก์ง๋ง์ ๋จ๊ธฐ๊ณ , OAuth2AuthorizationCodeAuthenticationToken ์ชฝ์ ์กด์ฌ๊ฐ์ ์ง์๋ฒ๋ฆฐ๊ฒ ์๋๊ฐ ํ๋ ์๊ฐ์ด ๋ค์์ต๋๋ค.
๊ทธ๋ ๋ค๊ณ ์ด์ ์์ OAuth2AuthorizationCodeAuthenticationToken ๋ฅผ Authentication ์ด ์๋๋๋ก ๋ค์ ๋ฆฌํฉํ ๋ง์ ํ์๋ ๊ท์ฐฎ์์ ธ์ ๊ทธ๋ฅ ๋จ๊ฒจ๋์๋ค๋ ์๊ฐ๋ ๋ค์๊ณ ์. |
@@ -0,0 +1,68 @@
+package nextstep.oauth2.authentication.token;
+
+import nextstep.oauth2.authentication.OAuth2AccessToken;
+import nextstep.oauth2.endpoint.dto.OAuth2AuthorizationExchange;
+import nextstep.oauth2.registration.ClientRegistration;
+import nextstep.security.authentication.Authentication;
+
+import java.util.Set;
+
+public final class OAuth2AuthorizationCodeAuthenticationToken implements Authentication {
+ private final ClientRegistration clientRegistration;
+ private final OAuth2AuthorizationExchange authorizationExchange;
+ private final OAuth2AccessToken accessToken;
+
+ public OAuth2AuthorizationCodeAuthenticationToken(
+ ClientRegistration clientRegistration,
+ OAuth2AuthorizationExchange authorizationExchange,
+ OAuth2AccessToken accessToken
+ ) {
+ this.clientRegistration = clientRegistration;
+ this.authorizationExchange = authorizationExchange;
+ this.accessToken = accessToken;
+ }
+
+ public OAuth2AuthorizationCodeAuthenticationToken(
+ ClientRegistration clientRegistration,
+ OAuth2AuthorizationExchange authorizationExchange
+ ) {
+ this(clientRegistration, authorizationExchange, null);
+ }
+
+ public ClientRegistration getClientRegistration() {
+ return clientRegistration;
+ }
+
+ public OAuth2AuthorizationExchange getAuthorizationExchange() {
+ return authorizationExchange;
+ }
+
+ public OAuth2AccessToken getAccessToken() {
+ return accessToken;
+ }
+
+ public boolean isValid() {
+ return authorizationExchange.isSameState();
+ }
+
+ @Override
+ public Set<String> getAuthorities() {
+ return Set.of();
+ }
+
+ @Override
+ public Object getCredentials() {
+ return (accessToken != null) ? accessToken.token()
+ : authorizationExchange.authorizationResponse().code();
+ }
+
+ @Override
+ public Object getPrincipal() {
+ return clientRegistration.clientId();
+ }
+
+ @Override
+ public boolean isAuthenticated() {
+ return false;
+ }
+} | Java | ์ ๋ ํด๋น ๋ถ๋ถ์ ๊ณ ๋ฏผํ๋ฉด์ ๋ค์๋ ์๊ฐ์ ์ธ์ฆ ๊ณผ์ ์์ ํ์ํ ๊ฐ์ฒด์์ ๋๋ฌ๋ด๊ธฐ์ํด Authentication์ ๊ตฌํํ ๊ฒ์ด๋ผ ์๊ฐํ์์ต๋๋ค. ์ ์๋์ ํ์คํ ๋ฆฌ ์ถ์ ์ ์ดํด๋ณด๋ ์ผ๋ฆฌ๊ฐ ์์ด ๋ณด์ด๋ค์ ๐ |
@@ -0,0 +1,58 @@
+package nextstep.app.service;
+
+import nextstep.app.domain.Member;
+import nextstep.app.domain.MemberRepository;
+import nextstep.oauth2.profile.OAuth2ProfileUser;
+import nextstep.oauth2.userinfo.OAuth2User;
+import nextstep.oauth2.userinfo.OAuth2UserRequest;
+import nextstep.oauth2.userinfo.OAuth2UserService;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Map;
+import java.util.Set;
+
+@Service
+public class DefaultOAuth2UserService implements OAuth2UserService {
+ private static final RestTemplate rest = new RestTemplate();
+
+ private final MemberRepository memberRepository;
+
+ public DefaultOAuth2UserService(MemberRepository memberRepository) {
+ this.memberRepository = memberRepository;
+ }
+
+ @Override
+ public OAuth2User loadUser(OAuth2UserRequest userRequest) {
+ final String userNameAttributeName = userRequest.clientRegistration()
+ .providerDetails().userInfoEndpoint().userNameAttributeName();
+ final Map<String, Object> attributes = exchangeAttributes(userRequest);
+ final OAuth2ProfileUser profileUser = OAuth2ProfileUser.of(
+ userRequest.clientRegistration().registrationId(),
+ attributes
+ );
+ final Set<String> authorities = memberRepository.findByEmail(
+ attributes.get(userNameAttributeName).toString()
+ ).orElseGet(
+ () -> memberRepository.save(new Member(
+ profileUser.email(), "", profileUser.name(),
+ profileUser.imageUrl(), Set.of("USER")
+ ))
+ ).getRoles();
+ return OAuth2User.of(authorities, attributes, userNameAttributeName);
+ }
+
+ private Map exchangeAttributes(OAuth2UserRequest userRequest) {
+ final HttpHeaders headers = new HttpHeaders();
+ headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + userRequest.accessToken().token());
+ return rest.exchange(
+ userRequest.clientRegistration().providerDetails().userInfoEndpoint().uri(),
+ HttpMethod.GET,
+ new HttpEntity<>(headers),
+ Map.class
+ ).getBody();
+ }
+} | Java | ๋ฐ์ ์ ํด์ฃผ์
จ์ต๋๋ค!
DefaultOAuth2UserService์์ ์ ๊ณตํด์ฃผ๋ ๊ฒ ์ธ์ ์ปค์คํ
์ด ํ์ํ ๋ถ๋ถ์ ์ด๋ค ๋ถ๋ถ์ธ์ง ํ์ธํด๋ณด๊ณ ๊ตฌํ์ ํด๋ณด๋ฉด
์ถํ ์คํ๋ง ์ํ๋ฆฌํฐ๋ฅผ ์ฌ์ฉํ ๋ ์กฐ๊ธ ๋ ์๋ค๋ฅด๊ฒ ๋ค๊ฐ์ฌ ๊ฒ ๊ฐ๋ค์ :)
์ด๋ค ๋ถ๋ถ์ด ์์ ์ง ๊ณ ๋ฏผ๋ง ํด๋ณด์
์~ |
@@ -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 | ์ํ! ์ฐธ๊ณ ํด์ ์งํํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค~ |
@@ -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์ด ๋๋ฌด ๋ชจํธํฉ๋๋ค!! ์ด๋ค ์์ด์ฝ์ธ์ง ์๋ ค์ฃผ์ธ์ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.