code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
final ๋กœ ์„ ์–ธํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค~
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
check ๋ฉ”์„œ๋“œ๋“ค์ด public ์ธ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”~?
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
java 8 ์˜ stream map ์„ ์จ๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
์ ‘๊ทผ์ œ์–ด์ž๋ฅผ package-private ์œผ๋กœ ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?
@@ -0,0 +1,57 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Lotto { + private final static int LOTTO_NUM_SIZE = 6; + private final List<LottoNo> lottoNums; + + public Lotto(List<LottoNo> lottoNums) { + checkSizeValid(lottoNums); + checkNumbersValid(lottoNums); + checkDuplicated(lottoNums); + + this.lottoNums = lottoNums; + } + + public List<Integer> getNums() { + List<Integer> lottoNumbers = new ArrayList<>(); + + for (LottoNo lottoNo : lottoNums) { + lottoNumbers.add(lottoNo.getLottoNumber()); + } + + return lottoNumbers; + } + + public List<LottoNo> getLottoNums() { + return lottoNums; + } + + public void checkSizeValid(List<LottoNo> lotto) { + if (!isValidLottoSize(lotto)) { + throw new IllegalArgumentException("6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + } + + public void checkNumbersValid(List<LottoNo> lotto) { + if (lotto.contains(LottoNo.INVALID_LOTTO_NO)) { + throw new IllegalArgumentException("1 ~ 45 ์•ˆ์˜ ์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } + + public void checkDuplicated(List<LottoNo> lotto) { + if (!isValidLottoSize(new HashSet<>(lotto))) { + throw new IllegalArgumentException("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + boolean isValidLottoSize(List<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } + + boolean isValidLottoSize(Set<LottoNo> lotto) { + return lotto.size() == LOTTO_NUM_SIZE; + } +}
Java
Set<LottoNo> ๋กœ ์„ ์–ธํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”~
@@ -0,0 +1,46 @@ +import java.util.Objects; + +public class LottoNo implements Comparable<LottoNo> { + private final static int INVALID_NUM = 0; + public final static LottoNo INVALID_LOTTO_NO = new LottoNo(INVALID_NUM); + + private int lottoNumber; + + public LottoNo(int lottoNumber) { + try { + this.lottoNumber = validateLottoNo(lottoNumber); + } catch (IllegalArgumentException e) { + this.lottoNumber = INVALID_NUM; + } + } + + public int getLottoNumber() { + return lottoNumber; + } + + private int validateLottoNo(int lottoNumber) { + if (lottoNumber < 1 || lottoNumber > 45) { + throw new IllegalArgumentException(); + } + + return lottoNumber; + } + + @Override + public int hashCode() { + return Objects.hashCode(lottoNumber); + } + + @Override + public boolean equals(Object obj) { + if (lottoNumber == ((LottoNo)obj).lottoNumber) + return true; + + return false; + } + + @Override + public int compareTo(LottoNo o) { + return lottoNumber - o.lottoNumber; + } +}
Java
LottoNo ๋Š” ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š” lottoNumber ํ•˜๋‚˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผํ•˜๋ฏ€๋กœ final ํ‚ค์›Œ๋“œ๋ฅผ ๋„ฃ์–ด๋„ ๋  ๊ฒƒ ๊ฐ™๋„ค์š” ใ…Žใ…Ž
@@ -0,0 +1,46 @@ +import java.util.Objects; + +public class LottoNo implements Comparable<LottoNo> { + private final static int INVALID_NUM = 0; + public final static LottoNo INVALID_LOTTO_NO = new LottoNo(INVALID_NUM); + + private int lottoNumber; + + public LottoNo(int lottoNumber) { + try { + this.lottoNumber = validateLottoNo(lottoNumber); + } catch (IllegalArgumentException e) { + this.lottoNumber = INVALID_NUM; + } + } + + public int getLottoNumber() { + return lottoNumber; + } + + private int validateLottoNo(int lottoNumber) { + if (lottoNumber < 1 || lottoNumber > 45) { + throw new IllegalArgumentException(); + } + + return lottoNumber; + } + + @Override + public int hashCode() { + return Objects.hashCode(lottoNumber); + } + + @Override + public boolean equals(Object obj) { + if (lottoNumber == ((LottoNo)obj).lottoNumber) + return true; + + return false; + } + + @Override + public int compareTo(LottoNo o) { + return lottoNumber - o.lottoNumber; + } +}
Java
์Œ.. RuntimeException ์„ ๋ฐœ์ƒ์‹œํ‚ค๊ณ  catch ๋ฅผ ๊ตณ์ด ํ•˜๋Š” ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”? checkedException ๊ณผ uncheckedException ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~
@@ -0,0 +1,46 @@ +import java.util.Objects; + +public class LottoNo implements Comparable<LottoNo> { + private final static int INVALID_NUM = 0; + public final static LottoNo INVALID_LOTTO_NO = new LottoNo(INVALID_NUM); + + private int lottoNumber; + + public LottoNo(int lottoNumber) { + try { + this.lottoNumber = validateLottoNo(lottoNumber); + } catch (IllegalArgumentException e) { + this.lottoNumber = INVALID_NUM; + } + } + + public int getLottoNumber() { + return lottoNumber; + } + + private int validateLottoNo(int lottoNumber) { + if (lottoNumber < 1 || lottoNumber > 45) { + throw new IllegalArgumentException(); + } + + return lottoNumber; + } + + @Override + public int hashCode() { + return Objects.hashCode(lottoNumber); + } + + @Override + public boolean equals(Object obj) { + if (lottoNumber == ((LottoNo)obj).lottoNumber) + return true; + + return false; + } + + @Override + public int compareTo(LottoNo o) { + return lottoNumber - o.lottoNumber; + } +}
Java
๊ตณ์ด ๋ฉ”์„œ๋“œ๋กœ ๋นผ์ง€ ์•Š์•„๋„ ๋  ๊ฒƒ ๊ฐ™์•„์š”
@@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.List; + +public class LottoRankResult { + private List<Rank> ranks; + + public LottoRankResult(WinningLotto winningLotto, LottoTicket lottoTicket) { + this.ranks = new ArrayList<>(); + + for (Lotto lotto : lottoTicket.getAllLottoGames()) { + ranks.add( + Rank.valueOf( + winningLotto.getCountOfSameNumber(lotto), + winningLotto.isWinningBonus(lotto) + ) + ); + } + } + + public int getCount(Rank rank) { + return (int) ranks.stream().filter(t -> t.equals(rank)).count(); + } + + public Money getTotalWinningMoney() { + Money earnings = Money.ZERO; + + for (Rank rank : ranks) { + earnings = earnings.add(rank.getWinningMoney()); + } + + return earnings; + } + + public double getEarningsRate(Money invest) { + Money earnings = getTotalWinningMoney(); + + return (double)(earnings.intValue()) / invest.intValue() * 100.0; + } + +} \ No newline at end of file
Java
๋ญ”๊ฐ€ ์ด๋ฆ„์ด ๊ฒฐ๊ณผ๋ฅผ ๋‹ด๋Š” ๋ฐ์ดํ„ฐ ๊ทธ๋ฆ‡ ๊ฐ™์€ ๋А๋‚Œ์ด๋ผ LottoCalculator LottoResultCalculator LottoRankCalculator ๊ฐ™์€ ๋„ค์ด๋ฐ์œผ๋กœ ๋ณ€๊ฒฝํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ๊ทธ์— ๋งž์ถฐ์„œ ๋ฉ”์„œ๋“œ ๋„ค์ด๋ฐ๋„ ๋ณ€๊ฒฝํ•˜๋ฉด ๋‹จ์ˆœํžˆ set ๋œ ๋ฐ์ดํ„ฐ๋ฅผ get ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ƒํƒœ์™€ ํ–‰์œ„๋ฅผ ๊ฐ–๋Š” ๊ฐ์ฒด์ง€ํ–ฅ์ ์ธ ๋„ค์ด๋ฐ์ด ๋  ๊ฒƒ ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค
@@ -0,0 +1,22 @@ +import java.util.ArrayList; +import java.util.List; + +public class Lottos { + private List<Lotto> lottos; + + public Lottos() { + this.lottos = new ArrayList<>(); + } + + public List<Lotto> getLottos() { + return lottos; + } + + public void addLotto(Lotto lotto) { + lottos.add(lotto); + } + + public int getSize() { + return lottos.size(); + } +}
Java
Lottos ๊ฐ€ ๊ฐ€์ง€๋Š” ํ–‰์œ„๊ฐ€ ํ•˜๋‚˜๋„ ์—†๋Š”๋ฐ์š”, ๋‹ค๋ฅธ ๊ฐ์ฒด์—์„œ ์œ„์ž„ํ• ๋งŒํ•œ๊ฒŒ ์—†์„๊นŒ์š”? get์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์€ Lottos ์˜ tell dont ask ์›์น™์ด ์•ˆ์ง€์ผœ์ง€๊ณ  ์žˆ๋‹ค๋Š” ๋œป์ด๊ณ , ์—ฌ๊ธฐ๋กœ ์œ„์ž„ํ• ๋งŒํ•œ ์ฑ…์ž„์ด ์‚ฐ์žฌํ•ด ์žˆ๋‹ค๋Š” ๋œป์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,29 @@ +import java.util.List; + +public class WinningLotto { + private Lotto winningLotto; + private LottoNo bonusNo; + + public WinningLotto(List<LottoNo> winningLottoNumbers, LottoNo lottoNo) { + if (winningLottoNumbers == null) { + throw new IllegalArgumentException("'lotto' must not be null"); + } + if (lottoNo == null) { + throw new IllegalArgumentException("'lottoNo' must not be null"); + } + + this.winningLotto = new Lotto(winningLottoNumbers); + this.bonusNo = lottoNo; + } + + public int getCountOfSameNumber(Lotto purchasedLotto) { + return (int) winningLotto.getLottoNums() + .stream() + .filter(purchasedLotto.getLottoNums()::contains) + .count(); + } + + public boolean isWinningBonus(Lotto purchasedLotto) { + return purchasedLotto.getLottoNums().contains(bonusNo); + } +}
Java
Lotto๋ฅผ ์ƒ์† ๋ฐ›์„ ์ˆ˜๋„ ์žˆ์—ˆ๋Š”๋ฐ ์ด๋ ‡๊ฒŒ ํ•ฉ์„ฑ์„ ์‚ฌ์šฉํ•˜์…จ๋„ค์š”. ๐Ÿ‘ ํ˜น์‹œ๋ผ๋„ ์šฐ์—ฐํžˆ ์ด๋ ‡๊ฒŒ ๊ตฌํ˜„ํ•˜์‹ ๊ฑฐ๋ผ๋ฉด, ์ƒ์†๊ณผ ํ•ฉ์„ฑ์„ ๊ตฌ๊ธ€๋ง ํ•ด๋ณด์‹œ๋ฉด ๊ด€๋ จ ์ž๋ฃŒ๋ฅผ ์ฐพ์œผ์‹ค ์ˆ˜ ์žˆ์„๊ฒ๋‹ˆ๋‹ค ~
@@ -0,0 +1,43 @@ +import java.util.Scanner; + +public class LottoApplication { + private static boolean APP_SUCCESS = false; + + public static void main(String[] args) { + runUntilAppSuccess(); + } + + public static void runUntilAppSuccess() { + while (!APP_SUCCESS) { + run(); + } + } + + public static void run() { + final Scanner scanner = new Scanner(System.in); + int countOfManualLotto; + + try { + LottoService lottoService = new LottoService( + InputView.scanMoney(scanner), + countOfManualLotto = InputView.scanCountOfManualLotto(scanner), + InputView.scanNumbersOfManualLotto(scanner, countOfManualLotto), + new LottoSeller() + ); + + lottoService.purchaseLottoTicket(); + lottoService.printPurchaseResult(); + + lottoService.setWinningLotto( + InputView.scanWinningLotto(scanner), + InputView.scanBonusNo(scanner) + ); + + lottoService.printWinningResult(); + + APP_SUCCESS = true; + } catch (OutOfConditionException | IllegalArgumentException e) { + e.printStackTrace(); + } + } +}
Java
LottoGame ์ด๋ผ๋Š” ๋„ค์ด๋ฐ์€ ์–ด๋–จ๊นŒ์š”
@@ -0,0 +1,43 @@ +import java.util.Scanner; + +public class LottoApplication { + private static boolean APP_SUCCESS = false; + + public static void main(String[] args) { + runUntilAppSuccess(); + } + + public static void runUntilAppSuccess() { + while (!APP_SUCCESS) { + run(); + } + } + + public static void run() { + final Scanner scanner = new Scanner(System.in); + int countOfManualLotto; + + try { + LottoService lottoService = new LottoService( + InputView.scanMoney(scanner), + countOfManualLotto = InputView.scanCountOfManualLotto(scanner), + InputView.scanNumbersOfManualLotto(scanner, countOfManualLotto), + new LottoSeller() + ); + + lottoService.purchaseLottoTicket(); + lottoService.printPurchaseResult(); + + lottoService.setWinningLotto( + InputView.scanWinningLotto(scanner), + InputView.scanBonusNo(scanner) + ); + + lottoService.printWinningResult(); + + APP_SUCCESS = true; + } catch (OutOfConditionException | IllegalArgumentException e) { + e.printStackTrace(); + } + } +}
Java
lottoService ์— set ํ•˜๊ณ  get ํ•˜๊ณ  ์ ˆ์ฐจ์ง€ํ–ฅ์ ์ธ ๋ฐฉ์‹์œผ๋กœ ์ฝ”๋“œ๊ฐ€ ์งœ์—ฌ์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ๋กœ์ง์ด lottoService ๋ฅผ ํ†ตํ•˜๋ฉด์„œ ๊ฒฐ๊ตญ ์ด ํด๋ž˜์Šค๋Š” ์ ์  ๋น„๋Œ€ํ•ด์งˆํ…๋ฐ์š” ์ข‹์€ ๊ฐœ์„  ๋ฐฉ๋ฒ•์ด ์—†์„๊นŒ์š”~?
@@ -0,0 +1,48 @@ +import java.util.Arrays; + +public enum Rank { + FIRST(6, 2000000000), + SECOND(5, 30000000), + THIRD(5, 1500000), + FOURTH(4, 50000), + FIFTH(3, 5000), + MISS(0, 0); + + private int countOfMatch; + private Money winningMoney; + + Rank(int countOfMatch, int winningMoney) { + this.countOfMatch = countOfMatch; + this.winningMoney = Money.valueOf(winningMoney); + } + + public static Rank valueOf(int countOfGame, boolean matchBonus) { + if (countOfGame == SECOND.getCountOfMatch()) { + return getSecondOrThird(matchBonus); + } + + return Arrays.stream(values()) + .filter(r -> countOfGame == r.countOfMatch) + .findFirst() + .orElse(MISS); + } + + public static Rank[] valuesNotMiss() { + return new Rank[]{FIRST, SECOND, THIRD, FOURTH, FIFTH}; + } + + private static Rank getSecondOrThird(boolean matchBonus) { + if (matchBonus) + return SECOND; + return THIRD; + } + + public int getCountOfMatch() { + return countOfMatch; + } + + public Money getWinningMoney() { + return winningMoney; + } + +}
Java
์ค‘๊ด„ํ˜ธ๊ฐ€ ๋น ์กŒ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,21 @@ +public class RankResult { + private Rank rank; + private int countOfRank; + + RankResult(Rank rank) { + this.rank = rank; + this.countOfRank = 0; + } + + public Rank getRank() { + return rank; + } + + public int getCountOfRank() { + return countOfRank; + } + + public void countUp(int count) { + countOfRank += count; + } +}
Java
๋ฐ์ดํ„ฐ๋“ค์„ ํด๋ž˜์Šค๋กœ ๋ฌถ๋Š” ๊ฒƒ์ด ๊ฐ์ฒด์ง€ํ–ฅ์€ ์•„๋‹™๋‹ˆ๋‹ค~ RankResult ๋„ ๊ฒฐ๊ตญ ๋ฐ์ดํ„ฐ์™€ get ๋งŒ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , ์œ ์˜๋ฏธํ•œ ํ–‰์œ„๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค ใ… ใ…  ๋ถˆํ•„์š”ํ•œ ๊ฐ์ฒด๊ฐ€ ์•„๋‹Œ์ง€, ์œ ์˜๋ฏธํ•œ ํ–‰์œ„๋ฅผ ๊ฐ€์ง„ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค๋ ค๋ฉด ์–ด๋–ค ํ–‰์œ„๋ฅผ ๋ถ€์—ฌํ•ด์•ผํ•˜๋Š”์ง€ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~
@@ -0,0 +1,50 @@ +import java.util.List; + +public class LottoSeller { + private LottoPurchaseService lottoPurchaseService; + private Money change; + + public LottoSeller() { + change = Money.ZERO; + lottoPurchaseService = new LottoPurchaseService(); + } + + public LottoTicket sellTicketTo(LottoUser lottoUser) throws OutOfConditionException { + Money investMoney = LottoPurchaseService + .validatePurchase( + lottoUser.getInvestMoney(), + lottoUser.getCountOfManualLotto() + ); + + this.change = LottoPurchaseService + .calculateChange(investMoney); + + return lottoPurchaseService + .createLottoTicket( + investMoney, + getCountOfAutoGame(investMoney, lottoUser.getCountOfManualLotto()), + changeToLottos(lottoUser.getNumbersOfManualLottos()) + ); + } + + public int getCountOfAutoGame(Money investMoney, int countOfManualLotto) { + return investMoney.divideBy(LottoPurchaseService.LOTTO_PRICE).intValue() + - countOfManualLotto; + } + + private Lottos changeToLottos(List<List<LottoNo>> numbers0fManualLottos) { + Lottos manualLottos = new Lottos(); + + for (List<LottoNo> lottoNums : numbers0fManualLottos) { + manualLottos.addLotto( + lottoPurchaseService.createManualLotto(lottoNums) + ); + } + + return manualLottos; + } + + public Money getChange() { + return change; + } +}
Java
Service ๋ผ๋Š” ๋„ค์ด๋ฐ์„ ์“ฐ์‹œ๋Š”๊ฑธ๋กœ ๋ด์„œ ์›น ์ชฝ ์ž๋ฃŒ๋ฅผ ๋ณด์‹  ๊ฒƒ ๊ฐ™์€๋ฐ, controller, service, repository ์ด๋Ÿฐ layered architecture ๋Š” ์ง€๊ธˆ ์ €ํฌ๊ฐ€ ํ•˜๊ณ  ์žˆ๋Š” ๊ฐ์ฒด์ง€ํ–ฅ๊ณผ ๊ฑฐ๋ฆฌ๊ฐ€ ์ข€ ์žˆ์Šต๋‹ˆ๋‹ค ~ service ๋ผ๋Š” ๋„ค์ด๋ฐ์„ ์‚ฌ์šฉํ•˜๊ธฐ๋ณด๋‹ค๋Š” ์ข€ ๋” ๊ตฌ์ฒด์ ์ด๊ณ  ๋ˆ„๊ตฌ๋‚˜ ๊ธ€ ์ฝ๋“ฏ์ด ๋ณผ ์ˆ˜ ์žˆ๋Š” ๋„ค์ด๋ฐ์„ ํ•˜์‹œ๋ฉด ํ•ด๋‹น ๊ฐ์ฒด์— ๋ถ€์—ฌํ•˜๋Š” ์ฑ…์ž„๊ณผ ํ–‰์œ„๋“ค๋„ ๋‹ฌ๋ผ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค ~ ๋„ค์ด๋ฐ์€ ๋‹จ์ˆœํžˆ ์‹œ๊ฐ์ ์ธ ํšจ๊ณผ ๊ทธ ์ด์ƒ์˜ ๊ฐ€์น˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,50 @@ +import java.util.List; + +public class LottoSeller { + private LottoPurchaseService lottoPurchaseService; + private Money change; + + public LottoSeller() { + change = Money.ZERO; + lottoPurchaseService = new LottoPurchaseService(); + } + + public LottoTicket sellTicketTo(LottoUser lottoUser) throws OutOfConditionException { + Money investMoney = LottoPurchaseService + .validatePurchase( + lottoUser.getInvestMoney(), + lottoUser.getCountOfManualLotto() + ); + + this.change = LottoPurchaseService + .calculateChange(investMoney); + + return lottoPurchaseService + .createLottoTicket( + investMoney, + getCountOfAutoGame(investMoney, lottoUser.getCountOfManualLotto()), + changeToLottos(lottoUser.getNumbersOfManualLottos()) + ); + } + + public int getCountOfAutoGame(Money investMoney, int countOfManualLotto) { + return investMoney.divideBy(LottoPurchaseService.LOTTO_PRICE).intValue() + - countOfManualLotto; + } + + private Lottos changeToLottos(List<List<LottoNo>> numbers0fManualLottos) { + Lottos manualLottos = new Lottos(); + + for (List<LottoNo> lottoNums : numbers0fManualLottos) { + manualLottos.addLotto( + lottoPurchaseService.createManualLotto(lottoNums) + ); + } + + return manualLottos; + } + + public Money getChange() { + return change; + } +}
Java
์  ํ•˜๋‚˜ ์ฐ์„ ๋•Œ๋Š” ์ค„๋ฐ”๊ฟˆ์„ ์•ˆํ•˜์‹œ๋Š”๊ฒŒ ์ผ๋ฐ˜์ ์ž…๋‹ˆ๋‹ค. ๋ฉ”์†Œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ๋„ 3๊ฐœ ์ด์ƒ๋ถ€ํ„ฐ ์—”ํ„ฐ๋ฅผ ์น˜์‹œ๋Š”๊ฒŒ ์–ด๋–จ๊นŒ์š”?
@@ -0,0 +1,42 @@ +import java.util.List; + +public class LottoService { + LottoUser lottoUser; + LottoSeller lottoSeller; + LottoTicket purchasedLottoTicket = null; + WinningLotto winningLotto = null; + PurchaseResultView purchaseResultView = null; + WinningResultView winningResultView = null; + + public LottoService(Money investMoney, int countOfManualLotto, List<List<LottoNo>> numbersOfManualLotto, + LottoSeller lottoSeller) { + this.lottoUser = new LottoUser(investMoney, countOfManualLotto, numbersOfManualLotto); + this.lottoSeller = lottoSeller; + } + + public LottoTicket purchaseLottoTicket() throws OutOfConditionException { + purchasedLottoTicket = lottoSeller.sellTicketTo(lottoUser); + lottoUser.setLottoTicket(purchasedLottoTicket); + + return purchasedLottoTicket; + } + + public void printPurchaseResult() { + purchaseResultView = new PurchaseResultView(); + + purchaseResultView.notifyIfChangeLeft(lottoSeller); + purchaseResultView.printPurchasedTicket(lottoUser); + } + + public void setWinningLotto(List<LottoNo> winningLottoNumbers, LottoNo bonusNo) { + winningLotto = new WinningLotto(winningLottoNumbers, bonusNo); + } + + public void printWinningResult() { + winningResultView = new WinningResultView(); + + winningResultView.printWinningResult(winningLotto, purchasedLottoTicket); + winningResultView.printEarningsRate(winningLotto, purchasedLottoTicket); + } + +}
Java
set์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฐ์ฒด์ง€ํ–ฅ ์ƒํ™œ์ฒด์กฐ ๊ทœ์น™์„ ์ ์šฉํ•ด๋ณด์‹œ๋ฉด ์ฝ”๋“œ์˜ ์„ค๊ณ„๊ฐ€ ๋‹ฌ๋ผ์งˆ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,43 @@ +import java.util.ArrayList; +import java.util.List; + +public class LottoTicket { + private Money ticketPrice; + private Lottos autoLottos; + private Lottos manualLottos; + + public LottoTicket(Money ticketPrice, Lottos autoLottos, Lottos manualLottos) { + this.ticketPrice = ticketPrice; + this.autoLottos = autoLottos; + this.manualLottos = manualLottos; + } + + public List<Lotto> getAllLottoGames() { + List<Lotto> lottos = new ArrayList<>(); + + lottos.addAll(getManualLottos()); + lottos.addAll(getAutoLottos()); + + return lottos; + } + + public List<Lotto> getAutoLottos() { + return autoLottos.getLottos(); + } + + public List<Lotto> getManualLottos() { + return manualLottos.getLottos(); + } + + public int getCountOfAutoLotto() { + return autoLottos.getSize(); + } + + public int getCountOfManualLotto() { + return manualLottos.getSize(); + } + + public Money getTicketPrice() { + return ticketPrice; + } +}
Java
์—ฌ๊ธฐ๋„ ํ–‰์œ„๊ฐ€ ์—†๊ณ  ๋ฐ์ดํ„ฐ + getter ๋ฟ์ด๋„ค์š”. ๊ทธ๋Ÿฐ๋ฐ ์ด๋ ‡๊ฒŒ ํด๋ž˜์Šค๋ฅผ ๋‚˜๋ˆ ๋ณด๋ ค๊ณ  ์ตœ๋Œ€ํ•œ ์‹œ๋„ํ•˜์‹  ์  ๐Ÿ‘
@@ -0,0 +1,35 @@ +import java.util.List; + +public class LottoUser { + private Money investMoney; + private int countOfManualLotto; + private List<List<LottoNo>> numbersOfManualLottos; + + private LottoTicket lottoTicket; + + public LottoUser(Money investMoney, int countOfManualLotto, List<List<LottoNo>> numbersOfManualLottos) { + this.investMoney = investMoney; + this.countOfManualLotto = countOfManualLotto; + this.numbersOfManualLottos = numbersOfManualLottos; + } + + public void setLottoTicket(LottoTicket lottoTicket) { + this.lottoTicket = lottoTicket; + } + + public LottoTicket getLottoTicket() { + return lottoTicket; + } + + public int getCountOfManualLotto() { + return countOfManualLotto; + } + + public List<List<LottoNo>> getNumbersOfManualLottos() { + return numbersOfManualLottos; + } + + public Money getInvestMoney() { + return investMoney; + } +}
Java
์—ฌ๊ธฐ๋„ setter getter ๋ฟ ์ด๋„ค์š” ใ… 
@@ -0,0 +1,65 @@ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public final class LottoPurchaseService { + public final static Money LOTTO_PRICE = Money.valueOf(1000); + + public static Money validatePurchase(Money inputMoney, int countOfManualLotto) throws OutOfConditionException { + if (inputMoney.intValue() < LOTTO_PRICE.intValue()) { + throw new OutOfConditionException(LOTTO_PRICE + "์› ์ด์ƒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค."); + } + + if (countOfManualLotto * LOTTO_PRICE.intValue() > inputMoney.intValue()) { + throw new IllegalArgumentException("๊ธˆ์•ก์ด ์ž‘์•„ ์›ํ•˜๋Š” ๋งŒํผ ์ˆ˜๋™ ๋กœ๋˜๋ฅผ ์‚ด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + + return inputMoney; + } + + public static Money calculateChange(Money inputMoney) { + return Money.valueOf(inputMoney.intValue() % LOTTO_PRICE.intValue()); + } + + public Lotto createManualLotto(List<LottoNo> lottoNums) { + Collections.sort(lottoNums); + return new Lotto(lottoNums); + } + + public Lotto createAutoLotto() { + List<LottoNo> auto = new ArrayList<>(shuffleAllLottoNo().subList(0, 6)); + Collections.sort(auto); + + return new Lotto(auto); + } + + public Lottos createAutoLottos(int countOfAutoLotto) { + Lottos autoLottos = new Lottos(); + + for (int i = 0; i < countOfAutoLotto; i++) { + autoLottos.addLotto( + createAutoLotto() + ); + } + + return autoLottos; + } + + public LottoTicket createLottoTicket(Money ticketPrice, int countOfAutoLotto, Lottos manualLottos) { + return new LottoTicket( + ticketPrice, + createAutoLottos(countOfAutoLotto), + manualLottos); + } + + private List<LottoNo> shuffleAllLottoNo() { + List<LottoNo> lottoNums = new ArrayList<>(); + + for (int i = 1; i <= 45; i++) { + lottoNums.add(new LottoNo(i)); + } + Collections.shuffle(lottoNums); + + return lottoNums; + } +}
Java
๋ฐ์ดํ„ฐ์™€ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋”ฐ๋กœ ์žˆ๋Š” ๊ฒƒ == ์ ˆ์ฐจ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ˜„ ์ƒํ™ฉ : ๋ฐ์ดํ„ฐ = LottoSeller, Ticket, User ๋“ฑ (๋ฐ์ดํ„ฐ + getter) ํ”„๋กœ์„ธ์Šค = Service (๋ฐ์ดํ„ฐ get ํ•ด์„œ ๋กœ์ง ์ฒ˜๋ฆฌ) ๋‹ต : MVC์™€ layered architecture๋ฅผ ์žŠ๊ณ  view ์™€ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ๋งŒ ๊ธฐ์–ตํ•˜๊ณ  ์งœ๋ณด๊ธฐ
@@ -0,0 +1,65 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; +import java.util.stream.Collectors; + +public final class InputView { + + public static Money scanMoney(Scanner scanner) { + System.out.println("\n๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + return Money.valueOf(Integer.parseInt(scanner.nextLine())); + } + + public static int scanCountOfManualLotto(Scanner scanner) { + System.out.println("\n์ˆ˜๋™์œผ๋กœ ๊ตฌ๋งคํ•  ๋กœ๋˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + return Integer.parseInt(scanner.nextLine()); + } + + public static List<List<LottoNo>> scanNumbersOfManualLotto(Scanner scanner, int countOfManualGame) { + System.out.println("\n์ˆ˜๋™์œผ๋กœ ๊ตฌ๋งคํ•  ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + List<List<LottoNo>> manualLotto = new ArrayList<>(); + String input = scanner.nextLine(); + int count = countOfManualGame; + + while (!input.isEmpty() && count != 0) { + count--; + addScannedNumbers(manualLotto, input); + input = scanner.nextLine(); + } + + return manualLotto; + } + + private static void addScannedNumbers(List<List<LottoNo>> manualLotto, String input) { + manualLotto.add( + Arrays.asList(input.replaceAll(" ", "").split(",")) + .stream() + .map(Integer::parseInt) + .map(LottoNo::new) + .collect(Collectors.toList()) + ); + } + + public static List<LottoNo> scanWinningLotto(Scanner scanner) { + System.out.println("\n์ง€๋‚œ ์ฃผ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + return Arrays.asList(scanner.nextLine() + .replaceAll(" ", "") + .split(",")) + .stream() + .map(Integer::parseInt) + .map(LottoNo::new) + .collect(Collectors.toList()); + } + + public static LottoNo scanBonusNo(Scanner scanner) { + System.out.println("๋ณด๋„ˆ์Šค ๋ณผ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + return new LottoNo(Integer.parseInt(scanner.nextLine())); + } + +}
Java
view ์—์„œ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ scan ํ•ด์˜ค๋Š” ์ฑ…์ž„๋งŒ ์žˆ์Šต๋‹ˆ๋‹ค. ์ง€๊ธˆ์€ ๋ณ€ํ™˜ ๋กœ์ง๊นŒ์ง€ ์—ฌ๊ธฐ์„œ ์ฒ˜๋ฆฌํ•˜๊ณ  ์žˆ๋„ค์š”~!
@@ -0,0 +1,29 @@ +public final class PurchaseResultView { + public void notifyIfChangeLeft(LottoSeller seller) { + if (!seller.getChange().equals(Money.ZERO)) { + System.out.println("์ž”๋ˆ " + seller.getChange() + "์›์ด ๋‚จ์•˜์Šต๋‹ˆ๋‹ค."); + System.out.println(); + } + } + + public void printPurchasedTicket(LottoUser lottoUser) { + LottoTicket lottoTicket = lottoUser.getLottoTicket(); + + System.out.println( + "์ˆ˜๋™์œผ๋กœ " + lottoTicket.getCountOfManualLotto() + + "์žฅ, ์ž๋™์œผ๋กœ " + lottoTicket.getCountOfAutoLotto() + + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค." + ); + + for (Lotto manualGame : lottoTicket.getManualLottos()) { + System.out.println(manualGame.getNums()); + } + + for (Lotto autoGame : lottoTicket.getAutoLottos()) { + System.out.println(autoGame.getNums()); + } + + System.out.println(); + } + +}
Java
finall class ๋กœ ํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค~
@@ -0,0 +1,79 @@ +"use client"; + +import { useRef, useState } from "react"; +import CameraIcon from "@/assets/images/icons/camera.svg"; +import FilledDeleteIcon from "@/assets/images/icons/filled_delete.svg"; +import { useSimpleImageUpload } from "@/hooks/useSimpleImageUpload"; + +export default function ReviewImageInput({ + onImageSelect, +}: { + onImageSelect: (image: File | null) => void; +}) { + const [isHovered, setIsHovered] = useState(false); + const inputRef = useRef<HTMLInputElement | null>(null); + const { + previewUrl, + handleImageUpload: handleImagePreview, + handleImageDelete, + } = useSimpleImageUpload(); + + const handleCameraclick = (e: React.MouseEvent) => { + e.stopPropagation(); + if (previewUrl) { + handleImageDelete(); + onImageSelect(null); + } else { + inputRef.current?.click(); + } + }; + + const handleImageUpload = (e: React.ChangeEvent<HTMLInputElement>) => { + const file = e.target.files?.[0] || null; + handleImagePreview(e); + onImageSelect(file); + }; + + return ( + <div> + <label className='ml-2 text-body-2-normal font-medium text-gray-300'> + ๋ชจ์ž„ ๊ด€๋ จ ์‚ฌ์ง„์ด ์žˆ๋‚˜์š”? + </label> + <div + className='mt-3 flex h-[140px] cursor-pointer flex-col items-center justify-center gap-2 rounded-xl border border-gray-800 bg-gray-900 *:text-gray-500' + onClick={handleCameraclick} + onMouseEnter={() => setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} + > + {previewUrl ? ( + <div className='relative h-full w-full'> + <img + className='h-full w-full rounded-xl object-cover' + src={previewUrl} + alt='๋ฆฌ๋ทฐ ์ด๋ฏธ์ง€' + /> + {isHovered && ( + <div className='absolute inset-0 flex items-center justify-center rounded-xl bg-black/50'> + <FilledDeleteIcon className='size-8 text-gray-800' /> + </div> + )} + </div> + ) : ( + <> + <CameraIcon className='size-8' /> + <p className='text-label-normal font-medium'> + ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š” + </p> + </> + )} + <input + ref={inputRef} + className='hidden' + type='file' + accept='image/*' + onChange={handleImageUpload} + /> + </div> + </div> + ); +}
Unknown
useUploadImage๋ฅผ ํ™œ์šฉํ•ด๋„ ๋˜์ง€ ์•Š๋‚˜์š”?.?
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
`createReviewMutation.isPending` ์‚ฌ์šฉํ•ด์„œ ์ค‘๋ณต ํ˜ธ์ถœ ๋ฐฉ์ง€ํ•˜๋ฉด ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
์ž‘์„ฑ๋œ ๋‚ด์šฉ๋“ค์„ ์ƒˆ๋กœ๊ณ ์นจ ํ–ˆ์„ ๋•Œ๋„ ์‚ฌ๋ผ์ง€์ง€ ์•Š๊ฒŒ, localStorage์— ์ €์žฅํ•˜๋ฉด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
ํ•ด๋‹น ๋ผ์ธ์€ ๋ถˆํ•„์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ํ† ํฐ์ด ์—†์œผ๋ฉด ์–ด์งœํ”ผ ์„œ๋ฒ„์—์„œ ๊ฒ€์ฆ ํ›„ ์—๋Ÿฌ๋ฅผ ๋˜์ ธ์ค๋‹ˆ๋‹ค. UX์ ์œผ๋กœ API ์š”์ฒญ ์ „ ๊ฒ€์‚ฌ ํ›„ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ๊ฐ€ ํ•„์š”ํ•˜๋ฉด `mutatonFn`์„ wrappingํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์‹œ๊ฑฐ๋‚˜ ์ค‘์•™์ง‘์ค‘์‹์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
์—ฌ๊ธฐ์„œ throw ๋œ ์—๋Ÿฌ๋Š” ์–ด๋””์„œ ์–ด๋–ป๊ฒŒ ํ•ธ๋“ค๋ง ๋ ๊นŒ์š”?
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
`Blob` ์ธ์Šคํ„ด์Šค๋กœ ๋งŒ๋“œ๋Š” ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.
@@ -0,0 +1,79 @@ +"use client"; + +import { useRef, useState } from "react"; +import CameraIcon from "@/assets/images/icons/camera.svg"; +import FilledDeleteIcon from "@/assets/images/icons/filled_delete.svg"; +import { useSimpleImageUpload } from "@/hooks/useSimpleImageUpload"; + +export default function ReviewImageInput({ + onImageSelect, +}: { + onImageSelect: (image: File | null) => void; +}) { + const [isHovered, setIsHovered] = useState(false); + const inputRef = useRef<HTMLInputElement | null>(null); + const { + previewUrl, + handleImageUpload: handleImagePreview, + handleImageDelete, + } = useSimpleImageUpload(); + + const handleCameraclick = (e: React.MouseEvent) => { + e.stopPropagation(); + if (previewUrl) { + handleImageDelete(); + onImageSelect(null); + } else { + inputRef.current?.click(); + } + }; + + const handleImageUpload = (e: React.ChangeEvent<HTMLInputElement>) => { + const file = e.target.files?.[0] || null; + handleImagePreview(e); + onImageSelect(file); + }; + + return ( + <div> + <label className='ml-2 text-body-2-normal font-medium text-gray-300'> + ๋ชจ์ž„ ๊ด€๋ จ ์‚ฌ์ง„์ด ์žˆ๋‚˜์š”? + </label> + <div + className='mt-3 flex h-[140px] cursor-pointer flex-col items-center justify-center gap-2 rounded-xl border border-gray-800 bg-gray-900 *:text-gray-500' + onClick={handleCameraclick} + onMouseEnter={() => setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} + > + {previewUrl ? ( + <div className='relative h-full w-full'> + <img + className='h-full w-full rounded-xl object-cover' + src={previewUrl} + alt='๋ฆฌ๋ทฐ ์ด๋ฏธ์ง€' + /> + {isHovered && ( + <div className='absolute inset-0 flex items-center justify-center rounded-xl bg-black/50'> + <FilledDeleteIcon className='size-8 text-gray-800' /> + </div> + )} + </div> + ) : ( + <> + <CameraIcon className='size-8' /> + <p className='text-label-normal font-medium'> + ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š” + </p> + </> + )} + <input + ref={inputRef} + className='hidden' + type='file' + accept='image/*' + onChange={handleImageUpload} + /> + </div> + </div> + ); +}
Unknown
`useSimpleImageUpload`๋Š” ์ด์ „์— IndexedDB ์ด์Šˆ๊ฐ€ ์žˆ์—ˆ์„ ๋•Œ ๊ธ‰ํ•˜๊ฒŒ ๋Œ€์ฒด ๊ตฌํ˜„์ด ํ•„์š”ํ•ด์„œ ๋งŒ๋“ค์–ด๋‘” ํ›…์ž…๋‹ˆ๋‹ค. ์ดํ›„ IndexedDB ์ด์Šˆ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ์ง€๋งŒ ์œ ์ €ํŽ˜์ด์ง€๋ฅผ ๋น„๋กฏํ•œ ๊ธฐํƒ€ ์ž‘์—…์— ์•„์ง ์‹ค์ œ ์ ์šฉ์€ ํ•ด๋ณด์ง€ ์•Š์€ ์ƒํƒœ๋ผ ์ผ๋‹จ `useSimpleImageUpload`๋กœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค! ์ถ”ํ›„ ๋ฆฌํŒฉํ† ๋ง ๋‹จ๊ณ„์—์„œ IndexedDB๋ฅผ ์ ์šฉํ•˜๋ฉด์„œ ์ด ๋ถ€๋ถ„๋„ `useUploadImage`๋กœ ๊ต์ฒดํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹น
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
๋„ต ๋ฆฌํŒฉํ† ๋ง ๋•Œ ๋ฐ˜์˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
๊ทธ๊ฒŒ ๋” ์ข‹์€ ๋ฐฉ์‹ ๊ฐ™๋„ค์š”! ๊ทธ๋ ‡๊ฒŒ ์ˆ˜์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
๋„ต ํ”ผ๋“œ๋ฐฑ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๋ง์”€ํ•˜์‹  ๋Œ€๋กœ api ๋ ˆ๋ฒจ์˜ ํ† ํฐ ์ฒดํฌ๋Š” ์ œ๊ฑฐํ•˜๊ณ , ์ปดํฌ๋„ŒํŠธ ์ง„์ž… ์‹œ์ ์— ์ฒ˜๋ฆฌํ•˜๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
`multipart/form-data`๋กœ ํŒŒ์ผ๊ณผ JSON ๊ฐ์ฒด๋ฅผ ํ•จ๊ป˜ ์ „์†กํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ํŒŒ์‹ฑ ์ด์Šˆ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ์ผ์ „์˜ ํ”„๋กœํ•„์ˆ˜์ • ์ž‘์—… ๋•Œ ๊ฐ™์€ ์ด์Šˆ๊ฐ€ ์žˆ์—ˆ๋Š”๋ฐ, ์ด ๋ฐฉ์‹์ด ์ž˜ ์ž‘๋™ํ•˜์—ฌ ๋™์ผํ•œ ํŒจํ„ด์„ ์ ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
์•—, throw๋œ ์—๋Ÿฌ๊ฐ€ ์ œ๋Œ€๋กœ ํ•ธ๋“ค๋ง๋˜์ง€ ์•Š๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค๐Ÿฅน `useReviewMutation`์˜ `onError`์—์„œ ๋ชจ๋‹ฌ ์•Œ๋ฆผ์ฐฝ์„ ๋„์šฐ๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
JSON ๊ฐ์ฒด๋ฅผ ํ•จ๊ป˜ ์ „์†ก์‹œ ์–ด๋–ค ํŒŒ์‹ฑ์ด์Šˆ๊ฐ€ ๋ฐœ์ƒํ•˜๋‚˜์š”?
@@ -0,0 +1,104 @@ +"use client"; + +import { FormProvider, useForm } from "react-hook-form"; +import SolidButton from "@/components/common/buttons/SolidButton"; +import CommonTextArea from "@/components/common/inputs/TextArea"; +import RatingInput from "@/components/create-reaview/RatingInput"; +import ReviewImageInput from "@/components/create-reaview/ReviewImageInput"; +import useCookie from "@/hooks/auths/useTokenState"; +import useReviewMutations from "@/hooks/review/useReviewMutation"; + +interface ReviewFormData { + rating: number; + content: string; + image: File | null; + meetupId: number; +} + +export default function CreateReviewForm({ meetupId }: { meetupId: string }) { + const token = useCookie("accessToken"); + const { createReviewMutation } = useReviewMutations(); + const methods = useForm<ReviewFormData>({ + defaultValues: { + rating: -1, + content: "", + image: null, + meetupId: Number(meetupId), + }, + mode: "onChange", + }); + + const { handleSubmit, setValue, watch } = methods; + + const rating = watch("rating"); + const content = watch("content"); + const isFormValid = rating !== -1 && content.trim() !== ""; + + const handleRatingChange = (value: number) => { + setValue("rating", value); + }; + + const handleImageSelect = (image: File | null) => { + setValue("image", image); + }; + + const onSubmit = handleSubmit(async (data) => { + if (!token) return; + + const formData = new FormData(); + + const requestData = { + meetupId: Number(data.meetupId), + rating: data.rating, + content: data.content, + }; + + formData.append( + "request", + new Blob([JSON.stringify(requestData)], { type: "application/json" }), + ); + + if (data.image) { + formData.append("image", data.image); + } + + if (data.image === null) { + formData.append("image", new Blob(), ""); + } + + await createReviewMutation.mutateAsync({ formData, token }); + }); + + return ( + <FormProvider {...methods}> + <form onSubmit={onSubmit}> + <div className='flex flex-col gap-12'> + <RatingInput + value={methods.watch("rating")} + onChange={handleRatingChange} + /> + <CommonTextArea + formClassName='h-40' + required={true} + name='content' + label='๊ตฌ์ฒด์ ์ธ ๊ฒฝํ—˜์„ ์•Œ๋ ค์ฃผ์„ธ์š”' + placeholder='๋ชจ์ž„์˜ ์žฅ์†Œ, ํ™˜๊ฒฝ, ์ง„ํ–‰, ๊ตฌ์„ฑ ๋“ฑ ๋งŒ์กฑ์Šค๋Ÿฌ์› ๋‚˜์š”?' + maxLength={150} + /> + <ReviewImageInput onImageSelect={handleImageSelect} /> + </div> + <SolidButton + type='submit' + className='mt-10' + state={ + createReviewMutation.isPending || !isFormValid || !token + ? "inactive" + : "activated" + } + > + {createReviewMutation.isPending ? "์ž‘์„ฑ ์ค‘..." : "์ž‘์„ฑ ์™„๋ฃŒ"} + </SolidButton> + </form> + </FormProvider> + ); +}
Unknown
์ฒ˜์Œ์— FormData์— request ๊ฐ์ฒด๋ฅผ JSON.stringify๋กœ appendํ–ˆ์„ ๋•Œ๋Š” ์š”์ฒญ์ด ์‹คํŒจํ–ˆ๋Š”๋ฐ, ์ฐพ์•„๋ณด๋‹ˆ ์ด๋ฏธ์ง€ ํŒŒ์ผ๊ณผ ํ•จ๊ป˜ ๋ณด๋‚ด๋Š” ๋ฉ€ํ‹ฐํŒŒํŠธ ํผ๋ฐ์ดํ„ฐ์—์„œ๋Š” ๋ชจ๋“  ๋ฐ์ดํ„ฐ๊ฐ€ ๋ฐ”์ด๋„ˆ๋ฆฌ ํ˜•ํƒœ์—ฌ์•ผ ์„œ๋ฒ„์—์„œ ์ œ๋Œ€๋กœ ํŒŒ์‹ฑํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•ด์„œ Blob ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ „์†กํ–ˆ๋”๋‹ˆ ์„ฑ๊ณตํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -8,7 +8,7 @@ export default class PlanMapper { toDomain(): IPlan { if (!this.plan) return null; - return new Plan({ + const returnPlan = new Plan({ id: this.plan.id, createdAt: this.plan.createdAt, updatedAt: this.plan.updatedAt, @@ -19,11 +19,19 @@ export default class PlanMapper { serviceArea: this.plan.serviceArea, details: this.plan.details, address: this.plan.address, - status: this.plan.status ?? StatusEnum.PENDING, - quotes: this.plan.quotes, + status: this.plan.status, + quotes: this.plan.quotes?.map((quote) => ({ + ...quote, + maker: { + id: quote.maker.id, + nickName: quote.maker.nickName, + image: quote.maker?.makerProfile?.image + } + })), assignees: this.plan.assignees, dreamer: this.plan.dreamer, dreamerId: this.plan.dreamerId }); + return returnPlan; } }
TypeScript
์ด๊ฑฐ ์ด์ „์— ์ฒดํฌ ์•ˆ ํ•œ ๊ฒƒ ๊ฐ™์€๋ฐ, status๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ default ๊ฐ’์ด PENDING์œผ๋กœ ์ฃผ์–ด์ง€๋‹ˆ๊นŒ mapper์—๋Š” ํ•„์š”์—†์„ ๊ฒƒ ๊ฐ™์•„์š”. ์ด์ œ mapper๋Š” repo์—์„œ๋งŒ ์“ฐ๋Š” ๊ฑธ๋กœ ์ˆ˜์ •ํ•˜์…จ๋‹ค๋ฉด ์ง€์›Œ๋„ ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~!
@@ -8,7 +8,7 @@ export default class PlanMapper { toDomain(): IPlan { if (!this.plan) return null; - return new Plan({ + const returnPlan = new Plan({ id: this.plan.id, createdAt: this.plan.createdAt, updatedAt: this.plan.updatedAt, @@ -19,11 +19,19 @@ export default class PlanMapper { serviceArea: this.plan.serviceArea, details: this.plan.details, address: this.plan.address, - status: this.plan.status ?? StatusEnum.PENDING, - quotes: this.plan.quotes, + status: this.plan.status, + quotes: this.plan.quotes?.map((quote) => ({ + ...quote, + maker: { + id: quote.maker.id, + nickName: quote.maker.nickName, + image: quote.maker?.makerProfile?.image + } + })), assignees: this.plan.assignees, dreamer: this.plan.dreamer, dreamerId: this.plan.dreamerId }); + return returnPlan; } }
TypeScript
PlanMapperProperties๋ฅผ ๋ณด๋‹ˆ makerProfile ์•ˆ์— image๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ, image ํ•„๋“œ๋Š” ๋ณ„๊ฐœ์ธ๊ฐ€์š”? makerProfile์„ undefined๋กœ ์ถ”๊ฐ€ํ•˜๋Š” ์ด์œ ๋„ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค. ``` maker?: { id: string; nickName: string; makerProfile: { image: ProfileImage }; }; ```
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
isHasReview๋ผ๋Š” ์ด๋ฆ„์ด ๋„ˆ๋ฌด ์–ด์ƒ‰ํ•ฉ๋‹ˆ๋‹ค ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ ํ˜น์‹œ ๋ฐ”๊ฟ”์ฃผ์‹ค ์ˆ˜ ์žˆ๋‚˜์š”..?
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
hasReview๋ฅผ reviewed๋กœ ์ „์ฒด ๋ฐ”๊ฟ”๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์•„์š”. ์–ด์ฐจํ”ผ ๋ฆฌ๋ทฐ๋Š” ํ•œ ๋ฒˆ๋ฐ–์— ๋ชป ์“ฐ๋‹ˆ๊นŒ
@@ -9,17 +9,15 @@ import ErrorMessage from 'src/common/constants/errorMessage.enum'; import { CreateOptionalQuoteData, QuoteQueryOptions } from 'src/common/types/quote/quote.type'; import { QuoteToClientProperties } from 'src/common/types/quote/quoteProperties'; import { CreatePlanData } from 'src/common/types/plan/plan.type'; -import QuoteMapper from 'src/common/domains/quote/quote.mapper'; import ForbiddenError from 'src/common/errors/forbiddenError'; import { ServiceArea } from 'src/common/constants/serviceArea.type'; import { RoleEnum } from 'src/common/constants/role.type'; -import PlanMapper from 'src/common/domains/plan/plan.mapper'; import BadRequestError from 'src/common/errors/badRequestError'; import { StatusEnum } from 'src/common/constants/status.type'; import { GroupByCount } from 'src/common/types/plan/plan.dto'; import { NotificationEventName } from 'src/common/types/notification/notification.types'; import UserService from '../user/user.service'; -import Quote from 'src/common/domains/quote/quote.domain'; +import Plan from 'src/common/domains/plan/plan.domain'; @Injectable() export default class PlanService { @@ -58,13 +56,27 @@ export default class PlanService { userId: string, options: PlanQueryOptions ): Promise<{ totalCount: number; list: PlanToClientProperties[] }> { + const { reviewed, readyToComplete } = options || {}; + const isReviewQuery = reviewed === true || reviewed === false; + const isWithQuote = isReviewQuery || readyToComplete; + options.userId = userId; + if (isReviewQuery) options.status = [StatusEnum.COMPLETED]; //NOTE. status COMPLETE ์ง€์ • + + if (readyToComplete) { + const today = new Date(); //NOTE. ์™„๋ฃŒํ•  ์ˆ˜ ์žˆ๋Š” ํ”Œ๋žœ ํ•„ํ„ฐ๋ง + const koreaTime = today.toLocaleString('en-US', { timeZone: 'Asia/Seoul' }); + const tripDate = new Date(koreaTime.split(',')[0]); + options.status = [StatusEnum.CONFIRMED]; + options.tripDate = tripDate; //NOTE. CONFIRMED ์ƒํƒœ๋กœ ์ง€์ • ๋ฐ tripDate ์ง€์ • + } + const [totalCount, list] = await Promise.all([ this.planRepository.totalCount(options), this.planRepository.findMany(options) ]); - const toClientList = list.map((plan) => plan.toClient()); + const toClientList = list.map((plan) => (isWithQuote ? plan.toClientWithQuotes() : plan.toClient())); return { totalCount, list: toClientList }; } @@ -104,7 +116,7 @@ export default class PlanService { } async postPlan(data: CreatePlanData): Promise<PlanToClientProperties> { - const domainData = new PlanMapper(data).toDomain(); + const domainData = Plan.create(data); const plan = await this.planRepository.create(domainData); return plan.toClientWithAddress(); } @@ -119,7 +131,7 @@ export default class PlanService { const quote = await this.quoteService.createQuote({ ...data, planId, isAssigned, makerId: userId }); const makerNickName = quote.maker.nickName; - const tripType = plan.toClient().tripType; + const tripType = plan.getTripType(); this.eventEmitter.emit('notification', { userId: plan.getDreamerId(), event: NotificationEventName.ARRIVE_QUOTE, @@ -148,7 +160,7 @@ export default class PlanService { const updatedPlan = await this.planRepository.update(plan); const nickName = updatedPlan.getDreamerNickName(); - const tripType = updatedPlan.toClient().tripType; + const tripType = updatedPlan.getTripType(); this.eventEmitter.emit('notification', { userId: assigneeId, event: NotificationEventName.ARRIVE_REQUEST,
TypeScript
hasReview๊ฐ€ boolean ๊ฐ’์ธ๋ฐ, isHasReview๋กœ ๋‹ค์‹œ ํ•œ ๋ฒˆ boolean ์œผ๋กœ ์น˜ํ™˜ํ•˜๋Š” ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
์ด๊ฑด ๋‚˜์ค‘์— ์‚ฌ์šฉํ•  ์˜ˆ์ •์ด์‹ ๊ฐ€์š”?
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
review: { is: null } | { isNot: null } ์ด๊ฑด ์–ด๋””์— ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”์ง€ ์ฝ”๋“œ๋งŒ ๋ด์„œ ์ž˜ ๋ชจ๋ฅด๊ฒ ์–ด์š”. ์„ค๋ช…ํ•ด ์ฃผ์‹ค ์ˆ˜ ์žˆ๋‚˜์š”?
@@ -9,17 +9,15 @@ import ErrorMessage from 'src/common/constants/errorMessage.enum'; import { CreateOptionalQuoteData, QuoteQueryOptions } from 'src/common/types/quote/quote.type'; import { QuoteToClientProperties } from 'src/common/types/quote/quoteProperties'; import { CreatePlanData } from 'src/common/types/plan/plan.type'; -import QuoteMapper from 'src/common/domains/quote/quote.mapper'; import ForbiddenError from 'src/common/errors/forbiddenError'; import { ServiceArea } from 'src/common/constants/serviceArea.type'; import { RoleEnum } from 'src/common/constants/role.type'; -import PlanMapper from 'src/common/domains/plan/plan.mapper'; import BadRequestError from 'src/common/errors/badRequestError'; import { StatusEnum } from 'src/common/constants/status.type'; import { GroupByCount } from 'src/common/types/plan/plan.dto'; import { NotificationEventName } from 'src/common/types/notification/notification.types'; import UserService from '../user/user.service'; -import Quote from 'src/common/domains/quote/quote.domain'; +import Plan from 'src/common/domains/plan/plan.domain'; @Injectable() export default class PlanService { @@ -58,13 +56,27 @@ export default class PlanService { userId: string, options: PlanQueryOptions ): Promise<{ totalCount: number; list: PlanToClientProperties[] }> { + const { reviewed, readyToComplete } = options || {}; + const isReviewQuery = reviewed === true || reviewed === false; + const isWithQuote = isReviewQuery || readyToComplete; + options.userId = userId; + if (isReviewQuery) options.status = [StatusEnum.COMPLETED]; //NOTE. status COMPLETE ์ง€์ • + + if (readyToComplete) { + const today = new Date(); //NOTE. ์™„๋ฃŒํ•  ์ˆ˜ ์žˆ๋Š” ํ”Œ๋žœ ํ•„ํ„ฐ๋ง + const koreaTime = today.toLocaleString('en-US', { timeZone: 'Asia/Seoul' }); + const tripDate = new Date(koreaTime.split(',')[0]); + options.status = [StatusEnum.CONFIRMED]; + options.tripDate = tripDate; //NOTE. CONFIRMED ์ƒํƒœ๋กœ ์ง€์ • ๋ฐ tripDate ์ง€์ • + } + const [totalCount, list] = await Promise.all([ this.planRepository.totalCount(options), this.planRepository.findMany(options) ]); - const toClientList = list.map((plan) => plan.toClient()); + const toClientList = list.map((plan) => (isWithQuote ? plan.toClientWithQuotes() : plan.toClient())); return { totalCount, list: toClientList }; } @@ -104,7 +116,7 @@ export default class PlanService { } async postPlan(data: CreatePlanData): Promise<PlanToClientProperties> { - const domainData = new PlanMapper(data).toDomain(); + const domainData = Plan.create(data); const plan = await this.planRepository.create(domainData); return plan.toClientWithAddress(); } @@ -119,7 +131,7 @@ export default class PlanService { const quote = await this.quoteService.createQuote({ ...data, planId, isAssigned, makerId: userId }); const makerNickName = quote.maker.nickName; - const tripType = plan.toClient().tripType; + const tripType = plan.getTripType(); this.eventEmitter.emit('notification', { userId: plan.getDreamerId(), event: NotificationEventName.ARRIVE_QUOTE, @@ -148,7 +160,7 @@ export default class PlanService { const updatedPlan = await this.planRepository.update(plan); const nickName = updatedPlan.getDreamerNickName(); - const tripType = updatedPlan.toClient().tripType; + const tripType = updatedPlan.getTripType(); this.eventEmitter.emit('notification', { userId: assigneeId, event: NotificationEventName.ARRIVE_REQUEST,
TypeScript
false๋Š” if๋ฌธ์—์„œ ํ•„ํ„ฐ๊ฐ€ ๋˜์ง€ ์•Š์•„์„œ ์กฐ๊ฑด๋ฌธ์œผ๋กœ true๊ฑฐ๋‚˜ false๊ฑฐ๋‚˜ ํ•„ํ„ฐ๋ฅผ ํ•˜๊ฒŒ ํ–ˆ์–ด์š”
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
ํ•„์š”ํ• ๊นŒ ์‹ถ์–ด์„œ ๋งŒ๋“ ๊ฑด๋ฐ ์•ˆ์ป๋‚˜๋ณด๋„ค์š” ์ง€์šฐ๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
ํ”„๋ฆฌ์ฆˆ๋งˆ์—์„œ 1:1 ๊ด€๊ณ„์„ฑ ํ•„๋“œ์ผ ๋•Œ id๋กœ ์ฒดํฌํ•˜๋Š”๊ฒŒ ๊ฐ€์žฅ ์ข‹์ง€๋งŒ plan๊ณผ review๋Š” ๋ฆฌ๋ทฐ๋งŒ ํ”Œ๋žœ id๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ฃ  ๊ทธ๋ ‡๊ธฐ์— ๋ฆฌ๋ทฐ๊ฐ€ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€๋ฅผ ์ฒดํฌํ•˜๊ธฐ ์œ„ํ•œ ๋ฌธ๋ฒ•์ž…๋‹ˆ๋‹ค. ํ˜น์‹œ ๋‹ค๋ฅธ ๋ฌธ๋ฒ•์„ ์•„์‹œ๋Š”๊ฒŒ ์žˆ์œผ์‹ ๊ฐ€์š”?
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
์ข‹์Šต๋‹ˆ๋‹ค ๋ณ€๊ฒฝํ• ๊ฒŒ์š” ใ…‹ใ…‹ใ…‹
@@ -8,7 +8,7 @@ export default class PlanMapper { toDomain(): IPlan { if (!this.plan) return null; - return new Plan({ + const returnPlan = new Plan({ id: this.plan.id, createdAt: this.plan.createdAt, updatedAt: this.plan.updatedAt, @@ -19,11 +19,19 @@ export default class PlanMapper { serviceArea: this.plan.serviceArea, details: this.plan.details, address: this.plan.address, - status: this.plan.status ?? StatusEnum.PENDING, - quotes: this.plan.quotes, + status: this.plan.status, + quotes: this.plan.quotes?.map((quote) => ({ + ...quote, + maker: { + id: quote.maker.id, + nickName: quote.maker.nickName, + image: quote.maker?.makerProfile?.image + } + })), assignees: this.plan.assignees, dreamer: this.plan.dreamer, dreamerId: this.plan.dreamerId }); + return returnPlan; } }
TypeScript
๋ฐ›์•„์˜ฌ ๋•Œ๋Š” makerProfile์— ๋‹ด๊ฒจ์˜ค์ง€๋งŒ ๋งตํผ์—์„œ makerProfile ์•ˆ์— ์žˆ๋Š” image๋ฅผ ๋ฐ–์œผ๋กœ ๋„์ง‘์–ด์˜ค๊ณ  makerProfile์ด๋ž€ ํ•„๋“œ๋ฅผ ์—†์• ์ฃผ๊ธฐ ์œ„ํ•ด undefined๋ฅผ ๋„ฃ์—ˆ์Šต๋‹ˆ๋‹ค
@@ -8,7 +8,7 @@ export default class PlanMapper { toDomain(): IPlan { if (!this.plan) return null; - return new Plan({ + const returnPlan = new Plan({ id: this.plan.id, createdAt: this.plan.createdAt, updatedAt: this.plan.updatedAt, @@ -19,11 +19,19 @@ export default class PlanMapper { serviceArea: this.plan.serviceArea, details: this.plan.details, address: this.plan.address, - status: this.plan.status ?? StatusEnum.PENDING, - quotes: this.plan.quotes, + status: this.plan.status, + quotes: this.plan.quotes?.map((quote) => ({ + ...quote, + maker: { + id: quote.maker.id, + nickName: quote.maker.nickName, + image: quote.maker?.makerProfile?.image + } + })), assignees: this.plan.assignees, dreamer: this.plan.dreamer, dreamerId: this.plan.dreamerId }); + return returnPlan; } }
TypeScript
๋„ค ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค
@@ -9,17 +9,15 @@ import ErrorMessage from 'src/common/constants/errorMessage.enum'; import { CreateOptionalQuoteData, QuoteQueryOptions } from 'src/common/types/quote/quote.type'; import { QuoteToClientProperties } from 'src/common/types/quote/quoteProperties'; import { CreatePlanData } from 'src/common/types/plan/plan.type'; -import QuoteMapper from 'src/common/domains/quote/quote.mapper'; import ForbiddenError from 'src/common/errors/forbiddenError'; import { ServiceArea } from 'src/common/constants/serviceArea.type'; import { RoleEnum } from 'src/common/constants/role.type'; -import PlanMapper from 'src/common/domains/plan/plan.mapper'; import BadRequestError from 'src/common/errors/badRequestError'; import { StatusEnum } from 'src/common/constants/status.type'; import { GroupByCount } from 'src/common/types/plan/plan.dto'; import { NotificationEventName } from 'src/common/types/notification/notification.types'; import UserService from '../user/user.service'; -import Quote from 'src/common/domains/quote/quote.domain'; +import Plan from 'src/common/domains/plan/plan.domain'; @Injectable() export default class PlanService { @@ -58,13 +56,27 @@ export default class PlanService { userId: string, options: PlanQueryOptions ): Promise<{ totalCount: number; list: PlanToClientProperties[] }> { + const { reviewed, readyToComplete } = options || {}; + const isReviewQuery = reviewed === true || reviewed === false; + const isWithQuote = isReviewQuery || readyToComplete; + options.userId = userId; + if (isReviewQuery) options.status = [StatusEnum.COMPLETED]; //NOTE. status COMPLETE ์ง€์ • + + if (readyToComplete) { + const today = new Date(); //NOTE. ์™„๋ฃŒํ•  ์ˆ˜ ์žˆ๋Š” ํ”Œ๋žœ ํ•„ํ„ฐ๋ง + const koreaTime = today.toLocaleString('en-US', { timeZone: 'Asia/Seoul' }); + const tripDate = new Date(koreaTime.split(',')[0]); + options.status = [StatusEnum.CONFIRMED]; + options.tripDate = tripDate; //NOTE. CONFIRMED ์ƒํƒœ๋กœ ์ง€์ • ๋ฐ tripDate ์ง€์ • + } + const [totalCount, list] = await Promise.all([ this.planRepository.totalCount(options), this.planRepository.findMany(options) ]); - const toClientList = list.map((plan) => plan.toClient()); + const toClientList = list.map((plan) => (isWithQuote ? plan.toClientWithQuotes() : plan.toClient())); return { totalCount, list: toClientList }; } @@ -104,7 +116,7 @@ export default class PlanService { } async postPlan(data: CreatePlanData): Promise<PlanToClientProperties> { - const domainData = new PlanMapper(data).toDomain(); + const domainData = Plan.create(data); const plan = await this.planRepository.create(domainData); return plan.toClientWithAddress(); } @@ -119,7 +131,7 @@ export default class PlanService { const quote = await this.quoteService.createQuote({ ...data, planId, isAssigned, makerId: userId }); const makerNickName = quote.maker.nickName; - const tripType = plan.toClient().tripType; + const tripType = plan.getTripType(); this.eventEmitter.emit('notification', { userId: plan.getDreamerId(), event: NotificationEventName.ARRIVE_QUOTE, @@ -148,7 +160,7 @@ export default class PlanService { const updatedPlan = await this.planRepository.update(plan); const nickName = updatedPlan.getDreamerNickName(); - const tripType = updatedPlan.toClient().tripType; + const tripType = updatedPlan.getTripType(); this.eventEmitter.emit('notification', { userId: assigneeId, event: NotificationEventName.ARRIVE_REQUEST,
TypeScript
service์—์„œ๋Š” if ์กฐ๊ฑด๋ฌธ์— hasReview=true์ธ ๊ฒฝ์šฐ๋งŒ ํ•„ํ„ฐ๋งํ•˜๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ false๋„ ํ•„์š”ํ•œ ๊ฑด๊ฐ€์š”?
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
plan์—์„œ ๋ฆฌ๋ทฐ ์œ ๋ฌด๋ฅผ ํ™•์ธํ•˜๋Š” prisma ๋ฌธ๋ฒ•์ด๊ตฐ์š”! ์ด์ „์— ์œ ๋ฌด ์ฒดํฌํ•  ๋• ์–ด๋–ป๊ฒŒ ํ–ˆ๋Š”์ง€ ๊ธฐ์–ต์ด ์•ˆ๋‚˜๋„ค์š” ใ…‹ใ…‹ใ…‹ ์•Œ๋ ค์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค~!
@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import PlanOrder from 'src/common/constants/planOrder.enum'; import { RoleEnum } from 'src/common/constants/role.type'; import SortOrder from 'src/common/constants/sortOrder.enum'; +import { StatusEnum } from 'src/common/constants/status.type'; import { TRIP_TYPE } from 'src/common/constants/tripType.type'; import IPlan from 'src/common/domains/plan/plan.interface'; import PlanMapper from 'src/common/domains/plan/plan.mapper'; @@ -16,7 +17,8 @@ export default class PlanRepository { constructor(private readonly db: DBClient) {} async findMany(options: PlanQueryOptions): Promise<IPlan[]> { - const { orderBy, page, pageSize } = options || {}; + const { orderBy, page, pageSize, reviewed } = options || {}; + const isHasReview = reviewed === true || reviewed === false; const whereConditions = this.buildWhereConditions(options); const orderByField: PlanOrderByField = @@ -29,9 +31,20 @@ export default class PlanRepository { skip: pageSize * (page - 1), include: { dreamer: { select: { id: true, nickName: true } }, - assignees: { select: { id: true, nickName: true } } + assignees: { select: { id: true, nickName: true } }, + quotes: isHasReview + ? { + where: { isConfirmed: true }, + select: { + id: true, + price: true, + maker: { select: { id: true, nickName: true, makerProfile: { select: { image: true } } } } + } + } + : {} } }); + const domainPlans = plans.map((plan) => new PlanMapper(plan).toDomain()); return domainPlans; } @@ -79,7 +92,7 @@ export default class PlanRepository { } async create(data: IPlan): Promise<IPlan> { - const { title, tripDate, tripType, serviceArea, details, address, status, dreamerId } = data.toDB(); + const { title, tripDate, tripType, serviceArea, details, address, dreamerId } = data.toDB(); const plan = await this.db.plan.create({ data: { title, @@ -88,7 +101,7 @@ export default class PlanRepository { serviceArea, details, address, - status, + status: StatusEnum.PENDING, dreamer: { connect: { id: dreamerId } } }, include: { @@ -147,7 +160,7 @@ export default class PlanRepository { } private buildWhereConditions(whereOptions: PlanQueryOptions): PlanWhereConditions { - const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role } = whereOptions; + const { keyword, tripDate, tripType, serviceArea, isAssigned, userId, status, role, reviewed } = whereOptions; const whereConditions: PlanWhereConditions = { isDeletedAt: null @@ -156,7 +169,7 @@ export default class PlanRepository { if (tripDate) { whereConditions.tripDate = { lte: tripDate }; whereConditions.status = { in: status }; - } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + } //NOTE.์Šค์ผ€์ค„๋Ÿฌ ์กฐ๊ฑด + readyToCompete ์กฐ๊ฑด if (serviceArea) whereConditions.serviceArea = { in: serviceArea }; @@ -165,13 +178,14 @@ export default class PlanRepository { if (role === RoleEnum.MAKER) { whereConditions.status = { in: status }; //NOTE. Maker ์ „์šฉ api ์กฐ๊ฑด whereConditions.quotes = { some: { makerId: { not: userId } } }; - } else if (status && userId) { - whereConditions.status = { in: status }; + if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API + } else if (userId) { whereConditions.dreamerId = userId; //NOTE. Dreamer ์ „์šฉ api ์กฐ๊ฑด + if (status) whereConditions.status = { in: status }; + if (reviewed === true) whereConditions.review = { isNot: null }; + else if (reviewed === false) whereConditions.review = { is: null }; } - if (isAssigned === true) whereConditions.assignees = { some: { id: userId } }; //NOTE. ์ง€์ •๊ฒฌ์  ์กฐํšŒ API - if (keyword) { whereConditions.OR = [ {
TypeScript
reviewed์™€ isReqviewQuery๋กœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค
@@ -9,17 +9,15 @@ import ErrorMessage from 'src/common/constants/errorMessage.enum'; import { CreateOptionalQuoteData, QuoteQueryOptions } from 'src/common/types/quote/quote.type'; import { QuoteToClientProperties } from 'src/common/types/quote/quoteProperties'; import { CreatePlanData } from 'src/common/types/plan/plan.type'; -import QuoteMapper from 'src/common/domains/quote/quote.mapper'; import ForbiddenError from 'src/common/errors/forbiddenError'; import { ServiceArea } from 'src/common/constants/serviceArea.type'; import { RoleEnum } from 'src/common/constants/role.type'; -import PlanMapper from 'src/common/domains/plan/plan.mapper'; import BadRequestError from 'src/common/errors/badRequestError'; import { StatusEnum } from 'src/common/constants/status.type'; import { GroupByCount } from 'src/common/types/plan/plan.dto'; import { NotificationEventName } from 'src/common/types/notification/notification.types'; import UserService from '../user/user.service'; -import Quote from 'src/common/domains/quote/quote.domain'; +import Plan from 'src/common/domains/plan/plan.domain'; @Injectable() export default class PlanService { @@ -58,13 +56,27 @@ export default class PlanService { userId: string, options: PlanQueryOptions ): Promise<{ totalCount: number; list: PlanToClientProperties[] }> { + const { reviewed, readyToComplete } = options || {}; + const isReviewQuery = reviewed === true || reviewed === false; + const isWithQuote = isReviewQuery || readyToComplete; + options.userId = userId; + if (isReviewQuery) options.status = [StatusEnum.COMPLETED]; //NOTE. status COMPLETE ์ง€์ • + + if (readyToComplete) { + const today = new Date(); //NOTE. ์™„๋ฃŒํ•  ์ˆ˜ ์žˆ๋Š” ํ”Œ๋žœ ํ•„ํ„ฐ๋ง + const koreaTime = today.toLocaleString('en-US', { timeZone: 'Asia/Seoul' }); + const tripDate = new Date(koreaTime.split(',')[0]); + options.status = [StatusEnum.CONFIRMED]; + options.tripDate = tripDate; //NOTE. CONFIRMED ์ƒํƒœ๋กœ ์ง€์ • ๋ฐ tripDate ์ง€์ • + } + const [totalCount, list] = await Promise.all([ this.planRepository.totalCount(options), this.planRepository.findMany(options) ]); - const toClientList = list.map((plan) => plan.toClient()); + const toClientList = list.map((plan) => (isWithQuote ? plan.toClientWithQuotes() : plan.toClient())); return { totalCount, list: toClientList }; } @@ -104,7 +116,7 @@ export default class PlanService { } async postPlan(data: CreatePlanData): Promise<PlanToClientProperties> { - const domainData = new PlanMapper(data).toDomain(); + const domainData = Plan.create(data); const plan = await this.planRepository.create(domainData); return plan.toClientWithAddress(); } @@ -119,7 +131,7 @@ export default class PlanService { const quote = await this.quoteService.createQuote({ ...data, planId, isAssigned, makerId: userId }); const makerNickName = quote.maker.nickName; - const tripType = plan.toClient().tripType; + const tripType = plan.getTripType(); this.eventEmitter.emit('notification', { userId: plan.getDreamerId(), event: NotificationEventName.ARRIVE_QUOTE, @@ -148,7 +160,7 @@ export default class PlanService { const updatedPlan = await this.planRepository.update(plan); const nickName = updatedPlan.getDreamerNickName(); - const tripType = updatedPlan.toClient().tripType; + const tripType = updatedPlan.getTripType(); this.eventEmitter.emit('notification', { userId: assigneeId, event: NotificationEventName.ARRIVE_REQUEST,
TypeScript
hasReview=false์ธ ๊ฒฝ์šฐ๋งŒ ํ•„์š”ํ•˜์ง€๋งŒ ํ•˜๋Š”๊น€์— true๋„ ๊ฐ™์ด ๋งŒ๋“ค์–ด ๋’€์Šต๋‹ˆ๋‹ค
@@ -8,7 +8,7 @@ export default class PlanMapper { toDomain(): IPlan { if (!this.plan) return null; - return new Plan({ + const returnPlan = new Plan({ id: this.plan.id, createdAt: this.plan.createdAt, updatedAt: this.plan.updatedAt, @@ -19,11 +19,19 @@ export default class PlanMapper { serviceArea: this.plan.serviceArea, details: this.plan.details, address: this.plan.address, - status: this.plan.status ?? StatusEnum.PENDING, - quotes: this.plan.quotes, + status: this.plan.status, + quotes: this.plan.quotes?.map((quote) => ({ + ...quote, + maker: { + id: quote.maker.id, + nickName: quote.maker.nickName, + image: quote.maker?.makerProfile?.image + } + })), assignees: this.plan.assignees, dreamer: this.plan.dreamer, dreamerId: this.plan.dreamerId }); + return returnPlan; } }
TypeScript
undefined ๋Œ€์‹  ๋งตํ•‘๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝ
@@ -0,0 +1,25 @@ +package nextstep.security.authentication; + +import nextstep.app.util.Base64Convertor; +import nextstep.security.authentication.exception.AuthenticationException; +import nextstep.security.user.UsernamePasswordAuthenticationToken; +import org.springframework.util.StringUtils; + +public class AuthenticationConverter { + + + public Authentication convert(String headerValue) { + if (!StringUtils.hasText(headerValue)) { + throw new AuthenticationException(); + } + + String credentials = headerValue.split(" ")[1]; + String decodedString = Base64Convertor.decode(credentials); + String[] usernameAndPassword = decodedString.split(":"); + if (usernameAndPassword.length != 2) { + throw new AuthenticationException(); + } + + return UsernamePasswordAuthenticationToken.unAuthorizedToken(usernameAndPassword[0], usernameAndPassword[1]); + } +}
Java
Convert์˜ ์ฑ…์ž„์„ ๋ถ„๋ฆฌํ•ด์ฃผ์…จ๊ตฐ์š” ๐Ÿ‘
@@ -0,0 +1,28 @@ +package nextstep.security.authentication; + +import jakarta.servlet.http.HttpServletResponse; +import nextstep.security.authentication.exception.AuthenticationException; +import nextstep.security.authentication.exception.MemberAccessDeniedException; + +import java.io.IOException; + +public class AuthenticationErrorHandler { + + protected AuthenticationErrorHandler() { + throw new UnsupportedOperationException(); + } + + public static void handleError(HttpServletResponse response, RuntimeException e) throws IOException { + if (e instanceof MemberAccessDeniedException) { + response.sendError(HttpServletResponse.SC_FORBIDDEN); + return; + } + + if (e instanceof AuthenticationException) { + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + return; + } + + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } +}
Java
error handle์˜ ์ฑ…์ž„๋„ ๋ถ„๋ฆฌํ•ด์ฃผ์…จ๊ตฐ์š” ๐Ÿ‘
@@ -0,0 +1,75 @@ +package nextstep.security.filter; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import nextstep.security.authentication.Authentication; +import nextstep.security.authentication.AuthenticationConverter; +import nextstep.security.authentication.AuthenticationErrorHandler; +import nextstep.security.authentication.AuthenticationManager; +import nextstep.security.authentication.exception.AuthenticationException; +import nextstep.security.context.SecurityContextHolder; +import org.springframework.http.HttpMethod; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Objects; + +public class BasicAuthenticationFilter extends OncePerRequestFilter { + + private final AuthenticationManager authenticationManager; + private final AuthenticationConverter converter = new AuthenticationConverter(); + + private static final String AUTHORIZATION_HEADER = "Authorization"; + private static final String[] BASIC_AUTH_PATH = new String[]{"/members"}; + + public BasicAuthenticationFilter(AuthenticationManager authenticationManager) { + this.authenticationManager = Objects.requireNonNull(authenticationManager); + } + + @Override + protected boolean shouldNotFilter(HttpServletRequest request) { + boolean isNotGetMethod = !HttpMethod.GET.name().equalsIgnoreCase(request.getMethod()); + boolean shouldNotFilterURI = Arrays.stream(BASIC_AUTH_PATH).noneMatch(it -> it.equalsIgnoreCase(request.getRequestURI())); + return isNotGetMethod || shouldNotFilterURI; + } + + @Override + protected void doFilterInternal( + HttpServletRequest request, + HttpServletResponse response, + FilterChain filterChain + ) throws IOException, ServletException { + + try { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null) { + filterChain.doFilter(request, response); + return; + } + + authentication = authenticateByRequestHeader(request); + + SecurityContextHolder.getContext().setAuthentication(authentication); + + } catch (AuthenticationException e) { + AuthenticationErrorHandler.handleError(response, e); + return; + } + + filterChain.doFilter(request, response); + } + + private Authentication authenticateByRequestHeader(HttpServletRequest request) { + Authentication authentication = converter.convert(request.getHeader(AUTHORIZATION_HEADER)); + + Authentication result = authenticationManager.authenticate(authentication); + if (!result.isAuthenticated()) { + throw new AuthenticationException(); + } + + return result; + } +}
Java
OncePerRequestFilter ์ƒ์†์„ ์ž˜ ํ•ด์ฃผ์…จ์Šต๋‹ˆ๋‹ค! OncePerRequestFilter๋ฅผ ํ™œ์šฉํ•˜์‹  ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?
@@ -0,0 +1,25 @@ +package nextstep.security.filter; + +import jakarta.servlet.http.HttpServletRequest; +import nextstep.security.authentication.Authentication; +import nextstep.security.authentication.AuthenticationManager; +import nextstep.security.context.SecurityContextRepository; +import nextstep.security.user.UsernamePasswordAuthenticationToken; +import org.springframework.http.HttpMethod; + +import java.util.Map; + +public class UserNamePasswordAuthFilter extends AbstractAuthProcessingFilter { + + public UserNamePasswordAuthFilter(AuthenticationManager authenticationManager, SecurityContextRepository securityContextRepository) { + super(authenticationManager, securityContextRepository, new String[]{"/login"}, new HttpMethod[]{HttpMethod.POST}); + } + + public Authentication getAuthentication(HttpServletRequest httpRequest) { + Map<String, String[]> parameterMap = httpRequest.getParameterMap(); + String username = parameterMap.get("username")[0]; + String password = parameterMap.get("password")[0]; + + return UsernamePasswordAuthenticationToken.unAuthorizedToken(username, password); + } +}
Java
๋ฏธ์…˜์„ ๋น ๋ฅด๊ฒŒ ์ž˜ ์ˆ˜ํ–‰ํ•ด์ฃผ์…”์„œ ์ถ”๊ฐ€์ ์œผ๋กœ ๊ณ ๋ฏผํ•ด๋ณผ ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์„ ๋“œ๋ฆฝ๋‹ˆ๋‹ค! ์‹ค์ œ ์‹œํ๋ฆฌํ‹ฐ ์ฝ”๋“œ์—์„œ UsernamePasswordAuthenticationFilter์˜ ๊ฒฝ์šฐ AbstractAuthenticationProcessingFilter๋ฅผ ์ƒ์†๋ฐ›๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. **์‹œํ๋ฆฌํ‹ฐ์˜ ์ธ์ฆ ๊ด€๋ จ ํ•„ํ„ฐ๋ฅผ ์ž˜ ํŒŒ์•…ํ•ด๋ณด๊ธฐ ์œ„ํ•œ ๋ชฉ์ **์œผ๋กœ UserNamePasswordAuthFilter์™€ AbstractAuthenticationProcessingFilter๋ฅผ ๊ตฌ๋ถ„ํ•ด๋ณด๊ณ  ๋ฆฌํŒฉํ„ฐ๋ง ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”? ํ•จ๊ป˜ ๊ณ ๋ฏผํ•ด๋ณด๋ฉด ์ข‹์„ ๋‚ด์šฉ์œผ๋กœ ์‹ค์ œ ์‹œํ๋ฆฌํ‹ฐ ์ฝ”๋“œ์—์„œ๋Š” BasicAuthenticationFilter๋Š” AbstractAuthenticationProcessingFilter๋ฅผ ์ƒ์†๋ฐ›๊ณ  ์žˆ์ง€ ์•Š๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์œ ์— ๋Œ€ํ•ด์„œ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๊ณ  ์„ธ์ค€๋‹˜์ด ๊ตฌํ˜„ํ•œ๋‹ค๋ฉด ์ด ๋ถ€๋ถ„์„ ํ•ฉ์ณ์„œ ๊ตฌํ˜„ํ•ด๋ณผ ๊ฒƒ ์ธ์ง€, ์•„๋‹ˆ๋ฉด ๊ธฐ์กด์ฒ˜๋Ÿผ ๋”ฐ๋กœ ๊ตฌํ˜„ํ•ด๋ณผ ๊ฒƒ ์ธ์ง€๋ฅผ ๊ณ ๋ฏผํ•ด๋ณด์‹œ๊ณ  ๊ทธ ์ด์œ ๋„ ํ•จ๊ป˜ ์ž‘์„ฑํ•ด๋ด์ฃผ์‹œ๋ฉด ์กฐ๊ธˆ ๋” ํญ๋„“์€ ํ•™์Šต์„ ํ•˜๋Š”๋ฐ ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค :)
@@ -0,0 +1,75 @@ +package nextstep.security.filter; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import nextstep.security.authentication.Authentication; +import nextstep.security.authentication.AuthenticationConverter; +import nextstep.security.authentication.AuthenticationErrorHandler; +import nextstep.security.authentication.AuthenticationManager; +import nextstep.security.authentication.exception.AuthenticationException; +import nextstep.security.context.SecurityContextHolder; +import org.springframework.http.HttpMethod; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Objects; + +public class BasicAuthenticationFilter extends OncePerRequestFilter { + + private final AuthenticationManager authenticationManager; + private final AuthenticationConverter converter = new AuthenticationConverter(); + + private static final String AUTHORIZATION_HEADER = "Authorization"; + private static final String[] BASIC_AUTH_PATH = new String[]{"/members"}; + + public BasicAuthenticationFilter(AuthenticationManager authenticationManager) { + this.authenticationManager = Objects.requireNonNull(authenticationManager); + } + + @Override + protected boolean shouldNotFilter(HttpServletRequest request) { + boolean isNotGetMethod = !HttpMethod.GET.name().equalsIgnoreCase(request.getMethod()); + boolean shouldNotFilterURI = Arrays.stream(BASIC_AUTH_PATH).noneMatch(it -> it.equalsIgnoreCase(request.getRequestURI())); + return isNotGetMethod || shouldNotFilterURI; + } + + @Override + protected void doFilterInternal( + HttpServletRequest request, + HttpServletResponse response, + FilterChain filterChain + ) throws IOException, ServletException { + + try { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null) { + filterChain.doFilter(request, response); + return; + } + + authentication = authenticateByRequestHeader(request); + + SecurityContextHolder.getContext().setAuthentication(authentication); + + } catch (AuthenticationException e) { + AuthenticationErrorHandler.handleError(response, e); + return; + } + + filterChain.doFilter(request, response); + } + + private Authentication authenticateByRequestHeader(HttpServletRequest request) { + Authentication authentication = converter.convert(request.getHeader(AUTHORIZATION_HEADER)); + + Authentication result = authenticationManager.authenticate(authentication); + if (!result.isAuthenticated()) { + throw new AuthenticationException(); + } + + return result; + } +}
Java
OncePerRequestFilter๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ์š”์ฒญ ๋‹น ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ์ž…๋‹ˆ๋‹ค. ์ด ํ•„ํ„ฐ์—์„œ๋Š” ServeltRequset์— attribute๋ฅผ ์„ค์ •ํ•˜๋Š”๋ฐ hasAlreadyFilteredAttribute ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์š”์ฒญ๋‚ด ์—์„œ ํ•œ๋ฒˆ ์‹คํ–‰ํ–ˆ๋‹ค๋ฉด ์ด ํ•„ํ„ฐ๋ฅผ ๋ฌด์‹œํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์š”์ฒญ์— ์†์„ฑ์ด ์—†๋‹ค๋ฉด, ์‹คํ–‰์„ ์„ฑ๊ณต์ ์œผ๋กœ ๋งˆ์นœ ํ›„ ์š”์ฒญ์— ํ•„ํ„ฐ์ด๋ฆ„.FILTERED ์†์„ฑ์— TRUE ๊ฐ’์„ ์„ค์ •ํ•ด์ค˜์„œ ๊ฐ™์€ ์š”์ฒญ๋‚ด์— ๋‹ค์‹œ ์‹คํ–‰๋˜์ง€ ์•Š๊ฒŒ ๋ง‰์•„์ค๋‹ˆ๋‹ค. ๋น„๋™๊ธฐ ์š”์ฒญ์ด๋‚˜ ์—๋Ÿฌ์ฒ˜๋ฆฌ ๋ถ€๋ถ„๋„ ์žˆ์ง€๋งŒ, OncePerRequestFilter๋ฅผ ์ƒ์†๋ฐ›๋Š” ๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” ํ•œ๋ฒˆ ์‹คํ–‰ ๋ณด์žฅ์ด๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“œ๋„ค์š”.
@@ -0,0 +1,25 @@ +package nextstep.security.filter; + +import jakarta.servlet.http.HttpServletRequest; +import nextstep.security.authentication.Authentication; +import nextstep.security.authentication.AuthenticationManager; +import nextstep.security.context.SecurityContextRepository; +import nextstep.security.user.UsernamePasswordAuthenticationToken; +import org.springframework.http.HttpMethod; + +import java.util.Map; + +public class UserNamePasswordAuthFilter extends AbstractAuthProcessingFilter { + + public UserNamePasswordAuthFilter(AuthenticationManager authenticationManager, SecurityContextRepository securityContextRepository) { + super(authenticationManager, securityContextRepository, new String[]{"/login"}, new HttpMethod[]{HttpMethod.POST}); + } + + public Authentication getAuthentication(HttpServletRequest httpRequest) { + Map<String, String[]> parameterMap = httpRequest.getParameterMap(); + String username = parameterMap.get("username")[0]; + String password = parameterMap.get("password")[0]; + + return UsernamePasswordAuthenticationToken.unAuthorizedToken(username, password); + } +}
Java
ํ•„ํ„ฐ๋งˆ๋‹ค ์ œ๊ฐ€ ์‹œํ๋ฆฌํ‹ฐ ์ฝ”๋“œ๋ฅผ ๋น„๊ตํ•ด๋ณด๋ฉด์„œ ์ดํ•ดํ•œ ๊ฒƒ์„ ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์‹œํ๋ฆฌํ‹ฐ์˜ BasicAuthenticationFilter๋Š” ๋ชจ๋“  ์š”์ฒญ๋‹น ํ•œ๋ฒˆ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  ์š”์ฒญ๋งˆ๋‹ค Request์— authRequest ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ธ์ฆ์„ ์ง„ํ–‰ํ•˜๊ณ  ์„ธ์…˜์— ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅ์‹œ์ผœ์ฃผ๋Š” ์—ญํ• ์„ ํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์š”์ฒญ์— authRequest ๊ฐ€ ์—†๊ฑฐ๋‚˜ ์ž‘์—…์ด ์ž˜ ๋๋‚œ๋‹ค๋ฉด ๋‹ค์Œ ํ•„ํ„ฐ๋กœ chain.doFilter(request, response); ์ฒด์ด๋‹์„ ํ•ด์ค๋‹ˆ๋‹ค. __์ง์ ‘ ๊ตฌํ˜„ํ•œ ํ•„ํ„ฐ์™€ ๋‹ค๋ฅธ ์ :__ ์ œ๊ฐ€ ์ง์ ‘ ๊ตฌํ˜„ํ•œ ํ•„ํ„ฐ(BasicAuthenticationFilter)๋„ OncePerRequestFilter๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ ๋‚ด๋ถ€ ์ž‘๋™์ด ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ๋งŽ์€ ์—๋Ÿฌ ์ฒ˜๋ฆฌ, ๋กœ๊ทธ ์ฒ˜๋ฆฌ๋“ฑ๋„ ๋‹ค๋ฅด์ง€๋งŒ, ๊ฐ€์žฅ ํฐ ์ฐจ์ด ์ ์€ authRequest ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ  ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์ด๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค. ์ œ๊ฐ€ ๋งŒ๋“  ํ•„ํ„ฐ๋Š” __์“ฐ๋ ˆ๋“œ ๋กœ์ปฌ__ ์—์„œ authentication ๋ฅผ ๊ฐ€์ ธ์™€์„œ ์กด์žฌํ•˜๋ฉด ๋‹ค์Œ ํ•„ํ„ฐ๋กœ ์ฒด์ด๋‹์„ํ•ด์ค๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์“ฐ๋ ˆ๋“œ ๋กœ์ปฌ์— ๋ฐ์ดํ„ฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ์— HttpServletRequest ์—์„œ authRequest ๋ฅผ ๊ฐ€์ ธ์˜จ ๋’ค ์ธ์ฆ์„ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค. ์ด๋•Œ ์š”์ฒญ์— authRequest ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด ์—๋Ÿฌ๋ฅผ ๋ณด๋ƒ…๋‹ˆ๋‹ค. ์—๋Ÿฌ์ฒ˜๋ฆฌ ๋˜ํ•œ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฒฐ๊ตญ ์‹œํ๋ฆฌํ‹ฐ์˜ BasicAuthenticationFilter๋Š” ์š”์ฒญ์—์„œ authRequest๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ์„ธ์…˜์— ๋“ฑ๋ก์‹œ์ผœ์ค€๋‹ค๋ฉด, ์ œ๊ฐ€ ๋งŒ๋“  BasicAuthenticationFilter๋Š” ์“ฐ๋ ˆ๋“œ๋กœ์ปฌ๋„ ๋ณด๊ณ  HttpServletRequest ๋„ ๋ณด๊ณ  ์—†๋Š” ๊ฒฝ์šฐ์— ์—๋Ÿฌ๋„ ๋˜์ ธ์ฃผ๋Š” ๋งŽ์€ ์—ญํ• (์“ฐ๋ ˆ๋“œ ๋กœ์ปฌ ํ™•์ธ, ์š”์ฒญ ํ™•์ธ, ์ธ์ฆ ์ฒ˜๋ฆฌ, ์—๋Ÿฌ ์ฒ˜๋ฆฌ)์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ •๋ฆฌํ•˜๋ฉด ์‹œํ๋ฆฌํ‹ฐ์—์„œ BasicAuthenticationFilter์— AbstractAuthenticationProcessingFilter๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ์ด์œ ๋Š”, ๋ชจ๋“  ์š”์ฒญ์—์„œ ๋‹จ์ˆœํžˆ Authorization ํ—ค๋”๋งŒ ํ™•์ธํ•˜๊ณ  ์„ธ์…˜์— ์ €์žฅํ•˜๋Š” ์—ญํ• ๋งŒ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด์„œ๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ญ๋‹ˆ๋‹ค. AbstractAuthenticationProcessingFilter์— ์žˆ๋Š” ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ๊ณผ ๋ณต์žกํ•œ ์ธ์ฆ ์ฒ˜๋ฆฌ๋“ค์€ ํ•„์š”๊ฐ€ ์—†์—ˆ๋˜ ๊ฒƒ ์•„๋‹๊นŒ์š”?
@@ -0,0 +1,25 @@ +package nextstep.security.filter; + +import jakarta.servlet.http.HttpServletRequest; +import nextstep.security.authentication.Authentication; +import nextstep.security.authentication.AuthenticationManager; +import nextstep.security.context.SecurityContextRepository; +import nextstep.security.user.UsernamePasswordAuthenticationToken; +import org.springframework.http.HttpMethod; + +import java.util.Map; + +public class UserNamePasswordAuthFilter extends AbstractAuthProcessingFilter { + + public UserNamePasswordAuthFilter(AuthenticationManager authenticationManager, SecurityContextRepository securityContextRepository) { + super(authenticationManager, securityContextRepository, new String[]{"/login"}, new HttpMethod[]{HttpMethod.POST}); + } + + public Authentication getAuthentication(HttpServletRequest httpRequest) { + Map<String, String[]> parameterMap = httpRequest.getParameterMap(); + String username = parameterMap.get("username")[0]; + String password = parameterMap.get("password")[0]; + + return UsernamePasswordAuthenticationToken.unAuthorizedToken(username, password); + } +}
Java
๋งˆ์ง€๋ง‰์œผ๋กœ AbstractAuthenticationProcessingFilter์˜ ์ฝ”๋“œ๋„ ์กฐ๊ธˆ ์‚ดํŽด๋ณด์•˜๋Š”๋ฐ์š”. ์ด ๊ฐ์ฒด์˜ ์˜์˜๋Š” ๋งŽ์€ ๊ธฐ๋Šฅ์˜ ์ถ”์ƒํ™”๊ฐ€ ์•„๋‹๊นŒ ํ•ฉ๋‹ˆ๋‹ค. ์ œ๊ฐ€ ๋งŒ๋“  UserNamePasswordAuthFilter๋ฅผ ๋ณด๋ฉด ํ•„ํ„ฐ๋ง ํ•ด์•ผํ• ์ง€ ํŒ๋‹จํ•ด์•ผํ•˜๋Š” ์—ญํ• ๋ถ€ํ„ฐ ์ธ์ฆ ๋ถ€๋ถ„ ๊ทธ๋ฆฌ๊ณ  ์„ธ์…˜์— ์ €์žฅํ•˜๊ฑฐ๋‚˜ ์—๋Ÿฌ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋“ฑ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ณ  ์–ด๋–ค ๊ฒƒ์€ ๋ฐ˜๋ณต๋˜๋Š” ์ฝ”๋“œ๋“ค ๊ฐ™์•„์š”. ์‹œํ๋ฆฌํ‹ฐ์—์„œ AbstractAuthenticationProcessingFilter์™€ UserNamePasswordAuthFilter๋กœ ๋‚˜๋ˆˆ ๊ฒƒ์€ UserNamePasswordAuthFilter์ด๋‚˜ ๋‹ค๋ฅธ ์ธ์ฆ ๊ตฌํ˜„์ฒด์—์„œ๋Š” Authentication๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋กœ์ง๋งŒ ๋‹ด๋‹นํ•˜๊ฒŒ ํ•˜๊ณ  AbstractAuthenticationProcessingFilter์—์„œ๋Š” ๋ฐ˜๋ณต๋˜๋Š” ๋ณด์ผ๋Ÿฌํ”Œ๋ ˆ์ดํŠธ๋“ค๋งŒ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ์‹œํ‚จ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,77 @@ +package nextstep.security.filter; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import nextstep.security.authentication.Authentication; +import nextstep.security.authentication.AuthenticationManager; +import nextstep.security.authentication.exception.AuthenticationException; +import nextstep.security.context.SecurityContext; +import nextstep.security.context.SecurityContextImpl; +import nextstep.security.context.SecurityContextRepository; +import org.springframework.http.HttpMethod; +import org.springframework.web.filter.GenericFilterBean; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Objects; + +public abstract class AbstractAuthProcessingFilter extends GenericFilterBean { + + private final AuthenticationManager authenticationManager; + private final SecurityContextRepository securityContextRepository; + private final String[] shouldFilteringPaths; + private final HttpMethod[] shouldFilteringMethods; + + protected AbstractAuthProcessingFilter(AuthenticationManager authenticationManager, SecurityContextRepository securityContextRepository, String[] shouldFilteringPaths, HttpMethod[] shouldFilteringMethods) { + this.authenticationManager = Objects.requireNonNull(authenticationManager); + this.securityContextRepository = Objects.requireNonNull(securityContextRepository); + this.shouldFilteringPaths = Objects.requireNonNull(shouldFilteringPaths); + this.shouldFilteringMethods = Objects.requireNonNull(shouldFilteringMethods); + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + if (servletRequest instanceof HttpServletRequest request + && (servletResponse instanceof HttpServletResponse response) + ) { + if (shouldNotFiltered(request)) { + filterChain.doFilter(servletRequest, servletResponse); + return; + } + + try { + Authentication authenticateRequest = getAuthentication(request); + + Authentication authentication = authenticationManager.authenticate(authenticateRequest); + if (!authentication.isAuthenticated()) { + throw new AuthenticationException(); + } + + registerSecurityOnSession(authentication, request, response); + response.setStatus(HttpServletResponse.SC_OK); + return; + } catch (AuthenticationException e) { + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage()); + } + } + + filterChain.doFilter(servletRequest, servletResponse); + } + + public abstract Authentication getAuthentication(HttpServletRequest request); + + private boolean shouldNotFiltered(HttpServletRequest request) { + boolean isNotPostMethod = Arrays.stream(shouldFilteringMethods).map(HttpMethod::name).noneMatch(it -> it.equalsIgnoreCase(request.getMethod())); + boolean isNotMatchedURI = Arrays.stream(shouldFilteringPaths).noneMatch(it -> it.equalsIgnoreCase(request.getRequestURI())); + return isNotMatchedURI || isNotPostMethod; + } + + private void registerSecurityOnSession(Authentication authentication, HttpServletRequest request, HttpServletResponse response) { + SecurityContext securityContext = new SecurityContextImpl(authentication); + securityContextRepository.saveContext(securityContext, request, response); + } +}
Java
์ธ์ฆ ๊ณตํ†ต ๋กœ์ง ์ถ”์ƒํ™” ๐Ÿ‘
@@ -0,0 +1,91 @@ +package christmas.Controller; + +import christmas.Domain.EventBenefitSettler; +import christmas.Domain.EventPlanner; +import christmas.Event.EventBadge; +import christmas.View.InputView; +import christmas.View.OutputView; +import java.util.Map; + +public class EventController { + public EventPlanner eventPlanner; + public EventBenefitSettler eventBenefitSettler; + + public void eventStart() { + OutputView.printWelcomeMessage(); + takeVisitDate(); + + takeOrder(); + + int preDiscountTotalOrderPrice = handlePreDiscountTotalOrderPrice(); + + handleBenefit(preDiscountTotalOrderPrice); + } + + public void takeVisitDate() { + try { + String visitDate = InputView.readVisitDate(); + eventBenefitSettler = new EventBenefitSettler(visitDate); + } catch (NumberFormatException e) { + OutputView.printException(e); + takeVisitDate(); + } catch (IllegalArgumentException e) { + OutputView.printException(e); + takeVisitDate(); + } + } + + public void takeOrder() { + try { + String orderMenu = InputView.readMenuOrder(); + eventPlanner = new EventPlanner(orderMenu); + OutputView.printOrderMenu(orderMenu); + } catch (NumberFormatException e) { + OutputView.printException(e); + takeOrder(); + } catch (IllegalArgumentException e) { + OutputView.printException(e); + takeOrder(); + } + } + + public void handleBenefit(int preDiscountTotalOrderPrice) { + Map<String, Integer> categoryCount = eventPlanner.calculateCategoryCount(); + + Map<String, Integer> receivedBenefits = handleReceivedBenefits(categoryCount, preDiscountTotalOrderPrice); + int benefitsTotalAmount = handlebenefitsTotalAmount(receivedBenefits); + handleDiscountedTotalAmount(receivedBenefits, preDiscountTotalOrderPrice); + handleEventBadge(benefitsTotalAmount); + } + + public Map<String, Integer> handleReceivedBenefits(Map<String, Integer> categoryCount, int preDiscountTotalOrderPrice){ + Map<String, Integer> receivedBenefits = eventBenefitSettler.calculateReceivedBenefits(categoryCount, + preDiscountTotalOrderPrice); + OutputView.printReceivedBenefits(receivedBenefits); + return receivedBenefits; + } + + public int handlebenefitsTotalAmount(Map<String, Integer> receivedBenefits){ + int benefitsTotalAmount = eventBenefitSettler.caculateBenefitsTotalAmount(receivedBenefits); + OutputView.printBenefitsTotalAmount(benefitsTotalAmount); + return benefitsTotalAmount; + } + + public void handleDiscountedTotalAmount(Map<String, Integer> receivedBenefits, int preDiscountTotalOrderPrice){ + int discountedTotalAmount = eventBenefitSettler.calculateDiscountedTotalAmount(receivedBenefits, + preDiscountTotalOrderPrice); + OutputView.printDiscountedTotalAmount(discountedTotalAmount); + } + + public void handleEventBadge(int benefitsTotalAmount){ + String eventBadgeType = EventBadge.findMyEventBadgeType(benefitsTotalAmount); + OutputView.printEventBadgeType(eventBadgeType); + } + + public int handlePreDiscountTotalOrderPrice() { + int preDiscountTotalOrderPrice = eventPlanner.calculatePreDiscountTotalOrderPrice(); + OutputView.printPreDicountTotalOrderPrice(preDiscountTotalOrderPrice); + OutputView.printGiftMenu(preDiscountTotalOrderPrice); + return preDiscountTotalOrderPrice; + } +}
Java
```suggestion public void takeVisitDate() { try { String visitDate = InputView.readVisitDate(); eventBenefitSettler = new EventBenefitSettler(visitDate); } catch (IllegalArgumentException e) { OutputView.printException(e); takeVisitDate(); } } ``` ์ €๋„ ๋ฐฉ๊ธˆ ์ฐพ์•„์„œ ์•Œ๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ `NumberFormatException` ์˜ ๋ถ€๋ชจ ์˜ˆ์™ธ๊ฐ€ `IllegalArgumentException` ์ด๋”๋ผ๊ณ ์š”! ๊ทธ๋ž˜์„œ ๊ตณ์ด ๋‘˜์˜ ์˜ˆ์™ธ๋ฅผ ๋‚˜๋ˆ„์ง€ ์•Š๊ณ  `IllegalArgumentException` ๋งŒ ์žก์•„์ค˜๋„ ๊ฐ™์ด ์žกํž ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ใ…Žใ…Ž
@@ -0,0 +1,92 @@ +package christmas.Util; + +import static christmas.Event.EventOption.EVENT_END_DATE; +import static christmas.Event.EventOption.EVENT_START_DATE; +import static christmas.Event.EventOption.MAX_ORDER_QUANTITY; +import static christmas.Message.OutputMessage.NOT_A_VALID_DATE; + +import christmas.Domain.MenuBoard; +import christmas.Message.OutputMessage; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class OrderMenuValidator { + public static void validateDate(String input) { + int number = Integer.parseInt(input); + if (number < EVENT_START_DATE || number > EVENT_END_DATE) { + throw new IllegalArgumentException(NOT_A_VALID_DATE); + } + } + + public static void checkValidOrderForm(String input) { + String pattern = "^[๊ฐ€-ํžฃ]+-[0-9]+(,\\s*[๊ฐ€-ํžฃ]+-[0-9]+)*$"; // ๋ฉ”๋‰ด ์ž…๋ ฅ ํ˜•์‹ + if (!input.matches(pattern)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + + public static void checkDuplicateMenu(String input) { + // ์ •๊ทœํ‘œํ˜„์‹ ํŒจํ„ด + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + + Set<String> menuSet = new HashSet<>(); + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + String menuName = matcher.group(1); + if (!menuSet.add(menuName)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + } + + public static void checkMaxOrderQuantity(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuQuantity = 0; + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + menuQuantity += Integer.parseInt(matcher.group(2)); + } + if (menuQuantity > MAX_ORDER_QUANTITY) { + throw new IllegalArgumentException(OutputMessage.INVALID_MAX_ORDER_QAUNTITY_ERROR); + } + } + + public static void checkMenuContainsOnlyDrink(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuNum = 0; + int drinkNum = 0; + + while (matcher.find()) { + if (isDrinkMenu(matcher.group(1))) { + drinkNum++; + } + menuNum++; + } + if (drinkNum == menuNum) { + throw new IllegalArgumentException(OutputMessage.MENU_CONTAIN_ONLY_DRINK_ERROR); + } + } + + public static boolean isDrinkMenu(String orderMenu) { + for (MenuBoard menu : MenuBoard.values()) { + if (orderMenu.equals(menu.getMenuName()) && menu.getMenuCategory().equals("์Œ๋ฃŒ")) { + return true; + } + } + return false; + } + +}
Java
์ •๊ทœํ‘œํ˜„์‹์„ ์ •๋ง ์ž˜ ํ™œ์šฉํ•˜์‹œ๋Š”๊ตฐ์š”!๐Ÿ‘๐Ÿ‘ ๊ทธ๋Ÿฐ๋ฐ `(?:,|$)` ๋Š” ์–ด๋–ค ์—ญํ• ์„ ํ•˜๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,92 @@ +package christmas.Util; + +import static christmas.Event.EventOption.EVENT_END_DATE; +import static christmas.Event.EventOption.EVENT_START_DATE; +import static christmas.Event.EventOption.MAX_ORDER_QUANTITY; +import static christmas.Message.OutputMessage.NOT_A_VALID_DATE; + +import christmas.Domain.MenuBoard; +import christmas.Message.OutputMessage; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class OrderMenuValidator { + public static void validateDate(String input) { + int number = Integer.parseInt(input); + if (number < EVENT_START_DATE || number > EVENT_END_DATE) { + throw new IllegalArgumentException(NOT_A_VALID_DATE); + } + } + + public static void checkValidOrderForm(String input) { + String pattern = "^[๊ฐ€-ํžฃ]+-[0-9]+(,\\s*[๊ฐ€-ํžฃ]+-[0-9]+)*$"; // ๋ฉ”๋‰ด ์ž…๋ ฅ ํ˜•์‹ + if (!input.matches(pattern)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + + public static void checkDuplicateMenu(String input) { + // ์ •๊ทœํ‘œํ˜„์‹ ํŒจํ„ด + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + + Set<String> menuSet = new HashSet<>(); + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + String menuName = matcher.group(1); + if (!menuSet.add(menuName)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + } + + public static void checkMaxOrderQuantity(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuQuantity = 0; + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + menuQuantity += Integer.parseInt(matcher.group(2)); + } + if (menuQuantity > MAX_ORDER_QUANTITY) { + throw new IllegalArgumentException(OutputMessage.INVALID_MAX_ORDER_QAUNTITY_ERROR); + } + } + + public static void checkMenuContainsOnlyDrink(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuNum = 0; + int drinkNum = 0; + + while (matcher.find()) { + if (isDrinkMenu(matcher.group(1))) { + drinkNum++; + } + menuNum++; + } + if (drinkNum == menuNum) { + throw new IllegalArgumentException(OutputMessage.MENU_CONTAIN_ONLY_DRINK_ERROR); + } + } + + public static boolean isDrinkMenu(String orderMenu) { + for (MenuBoard menu : MenuBoard.values()) { + if (orderMenu.equals(menu.getMenuName()) && menu.getMenuCategory().equals("์Œ๋ฃŒ")) { + return true; + } + } + return false; + } + +}
Java
`isDrinkMenu` ๋Š” `MenuBoard` ์—๊ฒŒ ๋„˜๊ฒจ์ฃผ๋ฉด ์–ด๋–จ๊นŒ์š”?? ์Œ๋ฃŒ๋ฅผ ํ™•์ธํ•˜๋Š” ์ฑ…์ž„์€ `MenuBoard` ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๊ฒŒ ๋” ์–ด์šธ๋ฆด ๊ฒƒ ๊ฐ™์•„์š”! ๐Ÿ˜
@@ -0,0 +1,92 @@ +package christmas.Util; + +import static christmas.Event.EventOption.EVENT_END_DATE; +import static christmas.Event.EventOption.EVENT_START_DATE; +import static christmas.Event.EventOption.MAX_ORDER_QUANTITY; +import static christmas.Message.OutputMessage.NOT_A_VALID_DATE; + +import christmas.Domain.MenuBoard; +import christmas.Message.OutputMessage; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class OrderMenuValidator { + public static void validateDate(String input) { + int number = Integer.parseInt(input); + if (number < EVENT_START_DATE || number > EVENT_END_DATE) { + throw new IllegalArgumentException(NOT_A_VALID_DATE); + } + } + + public static void checkValidOrderForm(String input) { + String pattern = "^[๊ฐ€-ํžฃ]+-[0-9]+(,\\s*[๊ฐ€-ํžฃ]+-[0-9]+)*$"; // ๋ฉ”๋‰ด ์ž…๋ ฅ ํ˜•์‹ + if (!input.matches(pattern)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + + public static void checkDuplicateMenu(String input) { + // ์ •๊ทœํ‘œํ˜„์‹ ํŒจํ„ด + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + + Set<String> menuSet = new HashSet<>(); + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + String menuName = matcher.group(1); + if (!menuSet.add(menuName)) { + throw new IllegalArgumentException(OutputMessage.INVALID_ORDER_FORM_ERROR); + } + } + } + + public static void checkMaxOrderQuantity(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuQuantity = 0; + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + menuQuantity += Integer.parseInt(matcher.group(2)); + } + if (menuQuantity > MAX_ORDER_QUANTITY) { + throw new IllegalArgumentException(OutputMessage.INVALID_MAX_ORDER_QAUNTITY_ERROR); + } + } + + public static void checkMenuContainsOnlyDrink(String input) { + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(input); + int menuNum = 0; + int drinkNum = 0; + + while (matcher.find()) { + if (isDrinkMenu(matcher.group(1))) { + drinkNum++; + } + menuNum++; + } + if (drinkNum == menuNum) { + throw new IllegalArgumentException(OutputMessage.MENU_CONTAIN_ONLY_DRINK_ERROR); + } + } + + public static boolean isDrinkMenu(String orderMenu) { + for (MenuBoard menu : MenuBoard.values()) { + if (orderMenu.equals(menu.getMenuName()) && menu.getMenuCategory().equals("์Œ๋ฃŒ")) { + return true; + } + } + return false; + } + +}
Java
ํ•ด๋‹น ์ •๊ทœํ‘œํ˜„์‹์ด ๋ฐ˜๋ณต๋˜๋Š” ๊ฒƒ ๊ฐ™์•„์š”! ๊ทธ๋ ‡๋‹ค๋ฉด Pattern ๊ฐ์ฒด๋ฅผ ์บ์‹ฑํ•ด์ฃผ๋ฉด ์–ด๋–จ๊นŒ์š”?? ๋””์Šค์ฝ”๋“œ ํ•จ๊ป˜ ๋‚˜๋ˆ„๊ธฐ์— ํ˜„์ง€๋‹˜์ด[ ๊ณต์œ ํ•˜์‹  ๊ธ€](https://velog.io/@dlguswl936/%EA%B3%B5%EB%B6%80%ED%95%9C-%EA%B2%83-String.matches%EB%8A%94-%EC%99%9C-%EC%84%B1%EB%8A%A5%EC%97%90-%EC%95%88-%EC%A2%8B%EC%9D%84%EA%B9%8C#%EA%B2%B0%EB%A1%A0-pattern-%EA%B0%9D%EC%B2%B4%EB%A5%BC-%EC%BA%90%EC%8B%B1%ED%95%B4%EB%91%90%EA%B8%B0)์ด ๋„์›€์ด ๋˜์‹ค ๊ฒƒ ๊ฐ™์•„์„œ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,30 @@ +package christmas.Util; + +public class CommaFormatter { + public static String formatWithComma(int number) { + String numberStr = Integer.toString(number); + int length = numberStr.length(); + + if (length <= 3) { + return numberStr; + } + String result = insertComma(numberStr, length); + + return result; + } + + private static String insertComma(String number, int length) { + int count = 0; + StringBuilder result = new StringBuilder(); + for (int i = length - 1; i >= 0; i--) { + result.insert(0, number.charAt(i)); + count++; + + if (count == 3 && i != 0) { + result.insert(0, ','); + count = 0; + } + } + return result.toString(); + } +}
Java
์ฝค๋งˆ๋ฅผ ์œ„ํ•ด ์ „์šฉ ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์ฃผ์…จ๊ตฐ์š”! ์ง์ ‘ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๊ฒƒ๋„ ์ข‹๋„ค์š”! ๊ทธ๋Ÿฐ๋ฐ ๋ˆ ๋‹จ์œ„๋ฅผ ์œ„ํ•œ ์ฝค๋งˆ๋ฅผ ๋„ฃ์–ด์ฃผ๋Š” ๊ธฐ๋Šฅ์„ ์ž๋ฐ”์—์„œ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ต๋‹ˆ๋‹ค! ใ…Žใ…Ž DecimalFormat ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”! ์ œ๊ฐ€ [์ฐธ๊ณ ํ–ˆ๋˜ ๊ธ€](https://jamesdreaming.tistory.com/203)์„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,67 @@ +package christmas.Domain; + +import christmas.Util.OrderMenuValidator; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class EventPlanner { + private final List<Menu> orderMenu; + + public EventPlanner(String menu) { + validateOrderMenuForm(menu); + List<Menu> orderMenu = createOrderMenuRepository(menu); + this.orderMenu = orderMenu; + } + + public int calculatePreDiscountTotalOrderPrice() { + int totalOrderPrice = 0; + for (Menu menu : orderMenu) { + totalOrderPrice += menu.getMenuTotalPrice(); + } + return totalOrderPrice; + } + + public Map<String, Integer> calculateCategoryCount() { + Map<String, Integer> categoryCount = new HashMap<>(); + int count = 0; + for (Menu menu : orderMenu) { + String menuCategory = menu.getMenuCategory(); + if (categoryCount.containsKey(menuCategory)) { + count = categoryCount.get(menuCategory) + menu.getMenuQuantity(); + categoryCount.put(menuCategory, count); + } + if (!categoryCount.containsKey(menuCategory)) { + categoryCount.put(menuCategory, menu.getMenuQuantity()); + } + } + return categoryCount; + } + + private List<Menu> createOrderMenuRepository(String orderMenu) { + List<Menu> menuList = new ArrayList<>(); + String pattern = "([๊ฐ€-ํžฃ]+)-([1-9]\\d*|0*[1-9]\\d+)(?:,|$)"; + + // ์ •๊ทœํ‘œํ˜„์‹์— ๋งž๋Š” ํŒจํ„ด์„ ์ƒ์„ฑ + Pattern regexPattern = Pattern.compile(pattern); + Matcher matcher = regexPattern.matcher(orderMenu); + + // ๋งค์นญ๋œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅ + while (matcher.find()) { + String menuName = matcher.group(1); + String menuQuantity = matcher.group(2); + menuList.add(new Menu(menuName, menuQuantity)); + } + return menuList; + } + + private void validateOrderMenuForm(String orderedMenu) { + OrderMenuValidator.checkValidOrderForm(orderedMenu); + OrderMenuValidator.checkDuplicateMenu(orderedMenu); + OrderMenuValidator.checkMaxOrderQuantity(orderedMenu); + OrderMenuValidator.checkMenuContainsOnlyDrink(orderedMenu); + } +}
Java
```suggestion public Map<String, Integer> calculateCategoryCount() { Map<String, Integer> categoryCount = new HashMap<>(); int count = 0; for (Menu menu : orderMenu) { String menuCategory = menu.getMenuCategory(); categoryCount.put(menuCategory, categoryCount.getOrDefault(menuCategory, 0) + 1) } return categoryCount; } ``` `getOrDefault` ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ฐ”๊ฟ”์ค„ ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค! ใ…Žใ…Ž ๊ฐ’์ด ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ณ  ์—†์œผ๋ฉด default ๋กœ ์ง€์ •ํ•ด์ค€ ๊ฐ’(์—ฌ๊ธฐ์„  0)์„ ๊ฐ€์ ธ์˜ค๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค!
@@ -0,0 +1,102 @@ +package christmas.Domain; + +import christmas.Event.EventBenefit; +import christmas.Event.EventOption; +import christmas.Event.SpecialDiscountDay; +import christmas.Util.OrderMenuValidator; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.HashMap; +import java.util.Map; + +public class EventBenefitSettler { + private final int visitDate; + + public EventBenefitSettler(String visitDate) { + OrderMenuValidator.validateDate(visitDate); + this.visitDate = Integer.parseInt(visitDate); + } + + public Map<String, Integer> calculateReceivedBenefits(Map<String, Integer> categoryCount, + int preDiscountTotalOrderPrice) { + Map<String, Integer> receivedBenefits = new HashMap<>(); + if (preDiscountTotalOrderPrice >= EventOption.MINIMUM_ORDER_PRICE_TO_GET_DISCOUNT) { + caculateChristmasDDayDiscount(receivedBenefits); + caculateWeekdayDiscount(receivedBenefits, categoryCount); + caculateWeekendDiscount(receivedBenefits, categoryCount); + caculateSpecialDiscount(receivedBenefits); + checkGiftMenu(receivedBenefits, preDiscountTotalOrderPrice); + } + return receivedBenefits; + } + + public int caculateBenefitsTotalAmount(Map<String, Integer> receivedBenefits) { + int benefitsTotalAmount = 0; + for (Map.Entry<String, Integer> benefit : receivedBenefits.entrySet()) { + benefitsTotalAmount += benefit.getValue(); + } + return benefitsTotalAmount; + } + + public int calculateDiscountedTotalAmount(Map<String, Integer> receivedBenefits, int preDiscountTotalOrderPrice) { + int discountedTotalAmount = preDiscountTotalOrderPrice; + for (Map.Entry<String, Integer> benefit : receivedBenefits.entrySet()) { + if (benefit.getKey() != EventBenefit.GIFT_MENU.getEventType()) { + discountedTotalAmount -= benefit.getValue(); + } + } + return discountedTotalAmount; + } + + private void caculateSpecialDiscount(Map<String, Integer> receivedBenefits) { + if (SpecialDiscountDay.isSpecialDay(this.visitDate)) { + receivedBenefits.put(EventBenefit.SPECIAL_DISCOUNT.getEventType(), + EventBenefit.SPECIAL_DISCOUNT.getBenefitAmount()); + } + } + + private void checkGiftMenu(Map<String, Integer> receivedBenefits, int preDiscountTotalOrderPrice) { + if (preDiscountTotalOrderPrice >= EventOption.MINIMUM_ORDER_PRICE_TO_GET_GIFT_MENU) { + receivedBenefits.put(EventBenefit.GIFT_MENU.getEventType(), EventBenefit.GIFT_MENU.getBenefitAmount()); + } + } + + private void caculateChristmasDDayDiscount(Map<String, Integer> receivedBenefits) { + int discount = 0; + if (this.visitDate <= EventOption.CHRISTMAS_D_DAY_EVENT_END_DATE) { + discount = EventOption.CHRISTMAS_D_DAY_START_DISCOUNT_AMOUNT; + discount += EventBenefit.CHRISTMAS_D_DAY_DISCOUNT.getBenefitTotalAmount(this.visitDate - 1); + receivedBenefits.put(EventBenefit.CHRISTMAS_D_DAY_DISCOUNT.getEventType(), discount); + } + } + + private void caculateWeekdayDiscount(Map<String, Integer> receivedBenefits, Map<String, Integer> categoryCount) { + int discount = 0; + if (!isWeekend()) { + try { + int countDessert = categoryCount.get(EventBenefit.WEEKDAY_DISCOUNT.getEventTarget()); // ์žˆ๋Š”์ง€๋ฅผ ์ฒดํฌ + discount += EventBenefit.WEEKDAY_DISCOUNT.getBenefitTotalAmount(countDessert); + receivedBenefits.put(EventBenefit.WEEKDAY_DISCOUNT.getEventType(), discount); + } catch (NullPointerException e) { + } + } + } + + private void caculateWeekendDiscount(Map<String, Integer> receivedBenefits, Map<String, Integer> categoryCount) { + int discount = 0; + if (isWeekend()) { + try { + int countMain = categoryCount.get(EventBenefit.WEEKEND_DISCOUNT.getEventTarget()); // ์žˆ๋Š”์ง€๋ฅผ ์ฒดํฌ + discount += EventBenefit.WEEKEND_DISCOUNT.getBenefitTotalAmount(countMain); + receivedBenefits.put(EventBenefit.WEEKDAY_DISCOUNT.getEventType(), discount); + } catch (NullPointerException e) { + } + } + } + + private boolean isWeekend() { + LocalDate date = LocalDate.of(EventOption.EVENT_YEAR, EventOption.EVENT_MONTH, this.visitDate); + DayOfWeek dayOfWeek = date.getDayOfWeek(); + return dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY; + } +}
Java
`LocalDate` ๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์š”์ผ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ตฐ์š”! ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค! ๐Ÿ˜
@@ -1,23 +1,20 @@ <template> - <button - @click=" - () => { - if (!props.disabled) props.onClick(); - } - " - :class="getNextButtonStyle()" - > - <slot></slot> + <button @click="handleNextButtonClick" :class="getNextButtonStyle()"> + <slot /> </button> </template> <script setup lang="ts"> const props = defineProps<{ - isPrimary?: boolean; + isPrimary?: boolean | undefined; onClick: () => void; - disabled?: boolean; + disabled?: boolean | undefined; }>(); +const handleNextButtonClick = () => { + if (!props.disabled) props.onClick(); +}; + const getNextButtonStyle = () => ({ 'h-fit w-[340px] rounded-2xl border-0 p-6 text-large font-bold mb-6': true, 'bg-primary-light dark:bg-primary-dark': props.isPrimary,
Unknown
๋‹จ์ˆœ ๊ถ๊ธˆ์ฆ์œผ๋กœ ์งˆ๋ฌธ๋“œ๋ฆฝ๋‹ˆ๋‹ค. undefined๋ฅผ ํƒ€์ž…์œผ๋กœ ์ง€์ •ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”? NextButton.vue์˜ ๋ถ€๋ชจ ์ปดํฌ๋„ŒํŠธ์—์„œ isPrimary ๊ฐ’์„ ๋ถ€์—ฌํ•˜์ง€ ์•Š์„ ๋•Œ๊ฐ€ ์žˆ์–ด undefined๋ฅผ ํฌํ•จํ•œ ๊ฒƒ์œผ๋กœ ๋ณด์ด๋Š”๋ฐ, ์ด ๊ฒฝ์šฐ๋Š” ? ๋งŒ์œผ๋กœ๋„ ์ถฉ๋ถ„ํžˆ ํ‘œํ˜„์ด ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํŠนํžˆ boolean์ด๊ธฐ๋•Œ๋ฌธ์— undefined์ผ ๋•Œ falsyํ•˜๊ฒŒ ์ธ์‹์ด ๋  ๊ฒƒ ๊ฐ™์€๋ฐ ์ถ”๊ฐ€ํ•˜์‹  ์ด์œ ๊ฐ€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค~
@@ -3,8 +3,8 @@ <p class="text-medium font-semi_bold">{{ title }}</p> <div class="flex gap-x-3"> <button - v-for="size in sizes" - :key="size.id" + v-for="(size, index) in sizes" + :key="getButtonKey(size, index)" class="flex flex-col items-center justify-between gap-y-[10px]" @click="handleSizeClick(size)" > @@ -23,9 +23,10 @@ </template> <script setup lang="ts"> -import { Size } from '@interface/goods'; +import { Size } from '@interface/sizes'; import { useUserSelectStore } from '@store/storeUserSelect'; import { PLACE_HOLD_IMAGE_URL } from '@constants'; +import { storeToRefs } from 'pinia'; defineProps<{ title: string; @@ -38,11 +39,12 @@ const getImageWidth = (size: Size) => { return 74; }; -const { userSelect, setUserSelectSizeId, setUserSelectSizeValue } = - useUserSelectStore(); +const store = useUserSelectStore(); +const { userSelect } = storeToRefs(store); +const { setUserSelectSizeId, setUserSelectSizeValue } = store; const handleSizeClick = (size: Size) => { - if (userSelect.sizeId === size.id) { + if (userSelect.value.sizeId === size.id) { setUserSelectSizeId(0); setUserSelectSizeValue(0); return; @@ -51,11 +53,13 @@ const handleSizeClick = (size: Size) => { setUserSelectSizeValue(size.value); }; +const getButtonKey = (size: Size, index: number) => `size-${size.id}-${index}`; + const getUserSelectStyle = (size: Size) => ({ 'flex h-[74px] w-[74px] items-center justify-center rounded-2xl border-[3px] bg-gray_01-light dark:bg-gray_01-dark': true, - 'border-secondary-light': userSelect.sizeId === size.id, + 'border-secondary-light': userSelect.value.sizeId === size.id, 'border-gray_01-light dark:border-gray_01-dark': - userSelect.sizeId !== size.id, + userSelect.value.sizeId !== size.id, }); </script>
Unknown
storeToRefs ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ฐ˜์‘์„ฑ์„ ์‚ด๋ฆฌ์…จ๋„ค์š” ๐Ÿ‘
@@ -3,16 +3,12 @@ <section class="mx-auto flex h-full flex-col items-center justify-between bg-gray_00-light text-gray_05-light dark:bg-gray_00-dark dark:text-gray_05-dark sm:w-screen md:w-96" > - <ProgressNavBar prevPage="/size" pageName="ingredient" /> - <div v-if="isLoading">๋กœ๋”ฉ์ค‘์ž…๋‹ˆ๋‹ค.</div> + <ProgressNavBar prevPage="size" pageName="ingredient" /> + <Loading v-if="isLoading" /> <IngredientBoard :ingredients="data?.ingredients ?? []" v-else /> <div v-if="!isAbleToRecommend">์žฌ๋ฃŒ๋ฅผ ์กฐ๊ธˆ ๋” ๊ณจ๋ผ๋ณผ๊นŒ์š”?</div> <NextButton - :onClick=" - () => { - mutation.mutate(userItem); - } - " + :onClick="postUserItem" isPrimary :disabled="!isAbleToRecommend || !userSelect.sizeValue" > @@ -29,6 +25,7 @@ import { storeToRefs } from 'pinia'; import ProgressNavBar from '@containers/ProgressNavBar.vue'; import IngredientBoard from '@containers/IngredientBoard.vue'; import NextButton from '@components/NextButton.vue'; +import Loading from '@src/components/Loading.vue'; import { useUserSelectStore } from '@store/storeUserSelect'; import { useGetIngredients } from '@apis/ingredients'; import { usePostRecipe } from '@apis/recipes'; @@ -38,6 +35,9 @@ const { userSelect, userItem } = storeToRefs(store); const { data, isLoading } = useGetIngredients(); const mutation = usePostRecipe(); +const postUserItem = () => { + mutation.mutate(userItem.value); +}; const allFlavorIdList = computed( () =>
Unknown
์„œ๋ฒ„ ์ƒํƒœ๊ด€๋ฆฌ์™€ ํด๋ผ์ด์–ธํŠธ ์ƒํƒœ๊ด€๋ฆฌ๋ฅผ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ด€๋ฆฌํ•˜์…จ๊ตฐ์š” ๐Ÿ‘
@@ -1,23 +1,20 @@ <template> - <button - @click=" - () => { - if (!props.disabled) props.onClick(); - } - " - :class="getNextButtonStyle()" - > - <slot></slot> + <button @click="handleNextButtonClick" :class="getNextButtonStyle()"> + <slot /> </button> </template> <script setup lang="ts"> const props = defineProps<{ - isPrimary?: boolean; + isPrimary?: boolean | undefined; onClick: () => void; - disabled?: boolean; + disabled?: boolean | undefined; }>(); +const handleNextButtonClick = () => { + if (!props.disabled) props.onClick(); +}; + const getNextButtonStyle = () => ({ 'h-fit w-[340px] rounded-2xl border-0 p-6 text-large font-bold mb-6': true, 'bg-primary-light dark:bg-primary-dark': props.isPrimary,
Unknown
์‚ฌ์‹ค ์ €๋„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์•˜๋‹ค๊ฐ€, ์ข€๋” ๊ฐ€์‹œ์ ์œผ๋กœ ํ‘œํ˜„ํ•˜๋ ค๊ณ  ์ž‘์„ฑ์„ ํ–ˆ์–ด์š”! ์Œ, ๋ฉ”์ด๋ธŒ๋‹˜ ๋ง์”€๋“ฃ๊ณ  ๋‹ค์‹œ ์ƒ๊ฐํ•ด๋ณด๋‹ˆ ๊ฐ€์‹œ์„ฑ๋งŒ์œผ๋กœ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฑด ์ข€ ์˜๋ฏธ๊ฐ€ ์—†๋Š” ๊ฒƒ ๊ฐ™๊ธดํ•˜๋„ค์š”!!
@@ -3,20 +3,18 @@ class="text-gray_05-light dark:text-gray_05-dark w-6 h-6" @click="goBack" > - <slot></slot> + <slot /> </button> </template> <script setup lang="ts"> -import { useRouter } from 'vue-router'; +import { pushPage } from '@router/route.helper'; const props = defineProps<{ prevPage: string; }>(); -const router = useRouter(); - function goBack() { - router.push(props.prevPage); + pushPage(props.prevPage); } </script>
Unknown
ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋กœ ํ•ด์ฃผ์„ธ์š”~
@@ -2,6 +2,8 @@ import React, { useState } from "react"; +// ํ…Œ์ŠคํŠธ + export interface ButtonProps { label: string; onClick: () => void;
Unknown
์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ ๋ช‡ ๊ฐ€์ง€ ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค. 1. **์ฃผ์„ ์‚ฌ์šฉ**: ์ถ”๊ฐ€ํ•œ `// ํ…Œ์ŠคํŠธ` ์ฃผ์„์€ ์˜๋ฏธ๊ฐ€ ๋ถˆ๋ถ„๋ช…ํ•ฉ๋‹ˆ๋‹ค. ์ฃผ์„์€ ์ฝ”๋“œ์˜ ์˜๋„๋ฅผ ๋ช…ํ™•ํžˆ ํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜์–ด์•ผ ํ•˜๋ฏ€๋กœ, ์™œ ํ…Œ์ŠคํŠธ ์ฃผ์„์ด ํ•„์š”ํ•œ์ง€ ๊ตฌ์ฒด์ ์œผ๋กœ ์„ค๋ช…ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, `// ๋ฒ„ํŠผ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด ์ถ”๊ฐ€๋œ ์ฃผ์„`๊ณผ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค. 2. **ํƒ€์ž… ์ •์˜**: `ButtonProps` ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์ž˜ ์ •์˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์‚ฌ์šฉ๋˜๋Š” ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์‹ค์ œ๋กœ ์žˆ๋Š” ๊ฒฝ์šฐ ์ด๋ฅผ ์ถ”๊ฐ€์ ์œผ๋กœ ๋ณด์—ฌ์ฃผ๋ฉด ์ฝ”๋“œ๊ฐ€ ๋”์šฑ ์™„์ „ํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, `Button` ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์–ด๋–ป๊ฒŒ `ButtonProps`๋ฅผ ์‚ฌ์šฉํ•˜๋Š”์ง€ ๋ณด์—ฌ์ฃผ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค. 3. **์ฃผ์„ ์œ„์น˜**: ์ฝ”๋“œ์˜ ์ƒ๋‹จ์— ์ฃผ์„์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์€ ์œ ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ๋” ๋งŽ์€ ์ •๋ณด๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ฃผ์„์ด ์ œ๋Œ€๋กœ ์„ค๋ช…๋˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ํ•„์š”ํ•œ ๋ถ€๋ถ„์— ๋Œ€ํ•ด ๋” ๊ตฌ์ฒด์ ์œผ๋กœ ์„ค๋ช…ํ•ด ์ฃผ์„ธ์š”. ์ถ”๊ฐ€ ์ฝ”๋“œ๋‚˜ ํŠน์ • ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ์„ค๋ช…์ด ์žˆ๋‹ค๋ฉด ๋” ๋‚˜์€ ํ”ผ๋“œ๋ฐฑ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํ•„์š”ํ•˜์‹œ๋ฉด ๊ณ„์† ๋ง์”€ํ•ด ์ฃผ์„ธ์š”!
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
์˜ค ๊ตฌ์กฐ๋ถ„ํ•ด ํ• ๋‹น~
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
this.state.id.includes('@') && this.state.id.length >= 5 && this.state.pw.length >= 8 ์ด๊ฑธ true/false Boolean?? ์ด๊ฐ’์„ ์‚ฌ์šฉํ•ด์„œ ์‚ผํ•ญ์—ฐ์‚ฐ์ž๋กœ ํ•ด๋„ ๋˜์ง€ ์•Š์„๊นŒ์š” ์ˆ˜์ •๋‹˜์€ ์ž˜ํ•˜์‹œ๋‹ˆ ์•„๋งˆ๊ฐ€๋Šฅํ•˜์‹ค๋“ฏ!
@@ -0,0 +1,61 @@ +.Login { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + + main { + display: flex; + flex-direction: column; + justify-content: space-around; + width: 350px; + height: 380px; + padding: 40px; + border: 1px solid #ccc; + + header { + h1 { + font-family: 'Lobster', cursive; + text-align: center; + } + } + + .loginInputBox { + form { + display: flex; + flex-direction: column; + justify-content: center; + + input { + margin-bottom: 5px; + padding: 9px 8px 7px; + background-color: rgb(250, 250, 250); + border: 1px solid rgb(38, 38, 38); + border-radius: 3px; + } + + .loginBtn { + margin-top: 10px; + padding: 9px 8px 7px; + border: none; + border-radius: 3px; + color: #fff; + background-color: #0096f6; + &:disabled { + background-color: #c0dffd; + } + } + } + } + + footer { + .findPassword { + display: block; + margin-top: 50px; + text-align: center; + color: #00376b; + font-size: 14px; + } + } + } +}
Unknown
์ด๊ฑด ์™œ ์ฃผ์„์œผ๋กœ ๋˜์žˆ๋‚˜์š”???
@@ -0,0 +1,134 @@ +[ + { + "id": 1, + "userName": "eessoo__", + "src": "../images/soojeongLee/user2.jpg", + "feedText": "๐Ÿ’Ÿ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "soojeonglee", + "content": "Hi there.", + "commnetLike": false + }, + { + "id": 3, + "userName": "jaehyunlee", + "content": "Hey.", + "commnetLike": false + }, + { + "id": 4, + "userName": "gyeongminlee", + "content": "Hi.", + "commnetLike": true + } + ], + "isLike": false + }, + { + "id": 2, + "userName": "zz_ing94", + "src": "../../images/soojeongLee/user3.jpg", + "feedText": "Toy story ๐Ÿ’š", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "jisuoh", + "content": "โœจ", + "commnetLike": true + }, + { + "id": 3, + "userName": "jungjunsung", + "content": "coffee", + "commnetLike": false + }, + { + "id": 4, + "userName": "somihwang", + "content": "ํฌํ‚ค", + "commnetLike": true + } + ], + "isLike": false + }, + { + "id": 3, + "userName": "hwayoonci", + "src": "../../images/soojeongLee/user4.jpg", + "feedText": "์˜ค๋Š˜์˜ ์ผ๊ธฐ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "yunkyunglee", + "content": "๊ท€์—ฌ์šด ์Šคํ‹ฐ์ปค", + "commnetLike": true + }, + { + "id": 3, + "userName": "summer", + "content": "๐Ÿถ", + "commnetLike": false + }, + { + "id": 4, + "userName": "uiyeonlee", + "content": "๐Ÿ‘๐Ÿป", + "commnetLike": true + } + ], + "isLike": true + }, + { + "id": 4, + "userName": "cosz_zy", + "src": "../../images/soojeongLee/user5.jpg", + "feedText": "1์ผ ํ™”๊ฐ€ ๐ŸŽจ ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "soojeonglee", + "content": "Hi there.", + "commnetLike": false + }, + { + "id": 3, + "userName": "jaehyunlee", + "content": "Hey.", + "commnetLike": true + }, + { + "id": 4, + "userName": "gyeongminlee", + "content": "Hi.", + "commnetLike": true + } + ], + "isLike": false + } +]
Unknown
์ œ์ด์Šจ ํŒŒ์ผ๋„ ์žˆ์—ˆ๊ตฐ์š”!
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
์˜ค ์ด๋ ‡๊ฒŒ ๋‹ค์‹œ ๋ณผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•๋„ ๋‚˜์˜์ง€ ์•Š์€ ๋“ฏ ? ๋‚˜์ค‘์— ๊ฐ€์„œ๋Š” ์ง€์›Œ์•ผ ๋  ์ˆ˜๋„ ์žˆ์ง€๋งŒ...?
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
๋ฒ„ํŠผ์œผ๋กœ ํ•œ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”? ๊ถ๊ธˆ
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
autoComplete ์ด๊ฑฐ๋Š” ๋ญ”๊ฐ€์š”? ๊ถ๊ธˆ~
@@ -0,0 +1,128 @@ +@import '../../../../styles/variables.scss'; + +article { + margin-bottom: 20px; + background-color: #fff; + border-radius: 3px; + border: 1px solid $border-color; + + header { + @include flex-center; + justify-content: space-between; + align-content: center; + padding: 10px; + + h1 { + @include flex-center; + + .contentHeader { + @include userProfile; + margin-right: 10px; + background-image: url('http://localhost:3000/images/soojeongLee/userImage.jpg'); + background-size: cover; + } + .userName { + font-size: 16px; + font-weight: 600; + } + } + + .ellipsis { + @include button; + font-size: 22px; + .ellipsisIcon { + font-weight: 400; + } + } + } + + .feedContent { + img { + width: 100%; + } + + .reactionsBox { + @include flex-center; + justify-content: space-between; + padding: 5px 10px; + + .reactionsLeft { + display: flex; + + .leftButton { + @include button; + font-size: 22px; + margin-right: 10px; + + .fa-external-link-alt { + font-size: 20px; + } + } + } + + .reactionsRight { + .rightButton { + @include button; + font-size: 22px; + } + } + } + + h2 { + display: flex; + align-items: center; + padding: 0 10px 10px; + font-size: 16px; + font-weight: normal; + + .feedConUser { + @include userProfile; + margin-right: 5px; + background-image: url('http://localhost:3000/images/soojeongLee/user7.jpg'); + background-size: cover; + } + + .likeCount { + @include button; + margin-left: 4px; + font-size: 16px; + } + } + + .feedText { + margin-bottom: 10px; + padding: 0 10px; + + .postTime { + @include postTime; + margin-top: 5px; + font-size: 14px; + font-weight: bold; + } + } + } + + .feedFooter { + background-color: #fff; + border-top: 1px solid $border-color; + + .inputBox { + display: flex; + padding: 10px; + + .comment { + flex: 9; + border: none; + outline: none; + } + + .commentSubmit { + @include button; + flex: 1; + &:hover { + color: $summit-color; + } + } + } + } +}
Unknown
์ด๋Ÿฐ scss ๊ธฐ๋Šฅ ์ €๋Š” ํ—ท๊ฐˆ๋ ค์„œ ์ž˜ ๋ชปํ•˜๊ฒ ๋˜๋ฐ ์ž˜ํ•˜์‹œ๋„ค์š”..
@@ -0,0 +1,23 @@ +//๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +//์ปดํฌ๋„ŒํŠธ +import { FOOTLIST } from '../FootLists/footData'; + +// css +import './FootLists.scss'; + +export class FootLists extends Component { + render() { + return FOOTLIST.map(footlists => { + return ( + <Link to="" className="listDot" key={footlists.id}> + {footlists.footlist} + </Link> + ); + }); + } +} + +export default FootLists;
JavaScript
๋Œ“๊ธ€ ํ”„๋ž์Šค!
@@ -0,0 +1,46 @@ +export const FOOTLIST = [ + { + id: 1, + footlist: '์†Œ๊ฐœ', + }, + { + id: 2, + footlist: '๋„์›€๋ง', + }, + { + id: 3, + footlist: 'ํ™๋ณด ์„ผํ„ฐ', + }, + { + id: 4, + footlist: 'API', + }, + { + id: 5, + footlist: '์ฑ„์šฉ ์ •๋ณด', + }, + { + id: 6, + footlist: '๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ', + }, + { + id: 7, + footlist: '์•ฝ๊ด€', + }, + { + id: 8, + footlist: '์œ„์น˜', + }, + { + id: 9, + footlist: '์ธ๊ธฐ ๊ณ„์ •', + }, + { + id: 10, + footlist: 'ํ•ด์‹œํƒœ๊ทธ', + }, + { + id: 11, + footlist: '์–ธ์–ด', + }, +];
JavaScript
ํ™”์ดํŒ… ํ‘ธํ„ฐ ๋งŒ๋“ค์–ด์„œ ๊ฐ•์˜ ๋ถ€ํƒ๋“œ๋ ค์š”
@@ -1,14 +1,148 @@ -// ํ•„์ˆ˜ import React from 'react'; +import { Link } from 'react-router-dom'; -// ์ปดํฌ๋„ŒํŠธ import Nav from '../../../components/Nav/Nav'; +import Feed from '../Main/Feed/Feed'; +import OtherUserPro from './OtherUserPro/OtherUserPro'; +import FootLists from '../Main/Feed/FootLists/FootLists'; + +import './Main.scss'; class Main extends React.Component { + constructor() { + super(); + this.state = { + feedList: [], + }; + } + + componentDidMount() { + fetch('/data/soojeonglee/feedData.json') + .then(res => res.json()) + .then(data => { + this.setState({ + feedList: data, + }); + }); + } + render() { + // console.log(this.state.feedList); // ๋ฐ์ดํ„ฐ ํ™•์ธ์„ ์œ„ํ•œ ์ฝ˜์†” + const { feedList } = this.state; return ( - <div> + <div className="Main"> <Nav /> + <main> + <div className="feeds"> + {feedList.map(feed => { + return ( + <Feed + key={feed.id} + userName={feed.userName} + src={feed.src} + feedText={feed.feedText} + commentData={feed.commentData} + isLike={feed.isLike} + /> + ); + })} + </div> + <div className="main-right"> + <header className="userAccount"> + <h1> + <Link to="" className="userProfile mainRightProfile"></Link> + <Link to=""> + <strong>wecode_bootcamp</strong> + <span className="accountDec">WeCode - ์œ„์ฝ”๋“œ</span> + </Link> + </h1> + </header> + <aside className="asideBox storyAside"> + <header> + <h2>์Šคํ† ๋ฆฌ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + <ul className="storyUser"> + <OtherUserPro /> + </ul> + </aside> + + <aside className="asideBox recommandAside"> + <header> + <h2>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + + <ul className="recommandUser"> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user5.jpg" + /> + </Link> + <Link to=""> + limpack_official + <span className="followReco">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user6.jpg" + /> + </Link> + <Link to=""> + les_photos_de_cat + <span className="followReco"> + geee____nie๋‹˜ ์™ธ 1๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค. + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user7.jpg" + /> + </Link> + <Link to=""> + mornstar_nail + <span className="followReco"> + effie_yxz๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + </ul> + </aside> + <footer className="main-right-footer"> + <ul className="footList"> + <FootLists /> + </ul> + <span className="copyright">ยฉ 2021 INSTAGRAM FROM FACEBOOK</span> + </footer> + </div> + </main> </div> ); }
JavaScript
๋ฐ์ดํ„ฐ ํ™•์ธ ๋‹ค ํ•˜์…จ๋‚˜์š”~~?
@@ -1,14 +1,148 @@ -// ํ•„์ˆ˜ import React from 'react'; +import { Link } from 'react-router-dom'; -// ์ปดํฌ๋„ŒํŠธ import Nav from '../../../components/Nav/Nav'; +import Feed from '../Main/Feed/Feed'; +import OtherUserPro from './OtherUserPro/OtherUserPro'; +import FootLists from '../Main/Feed/FootLists/FootLists'; + +import './Main.scss'; class Main extends React.Component { + constructor() { + super(); + this.state = { + feedList: [], + }; + } + + componentDidMount() { + fetch('/data/soojeonglee/feedData.json') + .then(res => res.json()) + .then(data => { + this.setState({ + feedList: data, + }); + }); + } + render() { + // console.log(this.state.feedList); // ๋ฐ์ดํ„ฐ ํ™•์ธ์„ ์œ„ํ•œ ์ฝ˜์†” + const { feedList } = this.state; return ( - <div> + <div className="Main"> <Nav /> + <main> + <div className="feeds"> + {feedList.map(feed => { + return ( + <Feed + key={feed.id} + userName={feed.userName} + src={feed.src} + feedText={feed.feedText} + commentData={feed.commentData} + isLike={feed.isLike} + /> + ); + })} + </div> + <div className="main-right"> + <header className="userAccount"> + <h1> + <Link to="" className="userProfile mainRightProfile"></Link> + <Link to=""> + <strong>wecode_bootcamp</strong> + <span className="accountDec">WeCode - ์œ„์ฝ”๋“œ</span> + </Link> + </h1> + </header> + <aside className="asideBox storyAside"> + <header> + <h2>์Šคํ† ๋ฆฌ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + <ul className="storyUser"> + <OtherUserPro /> + </ul> + </aside> + + <aside className="asideBox recommandAside"> + <header> + <h2>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + + <ul className="recommandUser"> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user5.jpg" + /> + </Link> + <Link to=""> + limpack_official + <span className="followReco">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user6.jpg" + /> + </Link> + <Link to=""> + les_photos_de_cat + <span className="followReco"> + geee____nie๋‹˜ ์™ธ 1๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค. + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user7.jpg" + /> + </Link> + <Link to=""> + mornstar_nail + <span className="followReco"> + effie_yxz๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + </ul> + </aside> + <footer className="main-right-footer"> + <ul className="footList"> + <FootLists /> + </ul> + <span className="copyright">ยฉ 2021 INSTAGRAM FROM FACEBOOK</span> + </footer> + </div> + </main> </div> ); }
JavaScript
ํ”ผ์–ด ๋ฆฌ๋ทฐ ์ค‘ Return์˜ ๋น„๋ฐ€์„? ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
Boolean ๋ฐ์ดํ„ฐ ํƒ€์ž… ์ ์šฉ์‹œ์ผœ๋ณด์•˜์•„์š”. ์ž˜ ์„ธ์› ๋˜ ์ฝ”๋“œ๊ฐ€ ์ž‘๋™๋˜์ง€ ์•Š์„๊นŒ ์‹œ๋„ํ•˜๊ธฐ ์–ด๋ ค์› ๋Š”๋ฐ ๊ฒฉ๋ ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹น~
@@ -0,0 +1,61 @@ +.Login { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + + main { + display: flex; + flex-direction: column; + justify-content: space-around; + width: 350px; + height: 380px; + padding: 40px; + border: 1px solid #ccc; + + header { + h1 { + font-family: 'Lobster', cursive; + text-align: center; + } + } + + .loginInputBox { + form { + display: flex; + flex-direction: column; + justify-content: center; + + input { + margin-bottom: 5px; + padding: 9px 8px 7px; + background-color: rgb(250, 250, 250); + border: 1px solid rgb(38, 38, 38); + border-radius: 3px; + } + + .loginBtn { + margin-top: 10px; + padding: 9px 8px 7px; + border: none; + border-radius: 3px; + color: #fff; + background-color: #0096f6; + &:disabled { + background-color: #c0dffd; + } + } + } + } + + footer { + .findPassword { + display: block; + margin-top: 50px; + text-align: center; + color: #00376b; + font-size: 14px; + } + } + } +}
Unknown
๊ธฐ์กด html ์ฝ”๋“œ๋ฅผ ์˜ฎ๊ธฐ๋‹ค ๋ณด๋‹ˆ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์˜€์–ด์š” :) ํ•ด๊ฒฐ๋˜์—ˆ๋‹ต๋‹ˆ๋‹น !!
@@ -0,0 +1,134 @@ +[ + { + "id": 1, + "userName": "eessoo__", + "src": "../images/soojeongLee/user2.jpg", + "feedText": "๐Ÿ’Ÿ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "soojeonglee", + "content": "Hi there.", + "commnetLike": false + }, + { + "id": 3, + "userName": "jaehyunlee", + "content": "Hey.", + "commnetLike": false + }, + { + "id": 4, + "userName": "gyeongminlee", + "content": "Hi.", + "commnetLike": true + } + ], + "isLike": false + }, + { + "id": 2, + "userName": "zz_ing94", + "src": "../../images/soojeongLee/user3.jpg", + "feedText": "Toy story ๐Ÿ’š", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "jisuoh", + "content": "โœจ", + "commnetLike": true + }, + { + "id": 3, + "userName": "jungjunsung", + "content": "coffee", + "commnetLike": false + }, + { + "id": 4, + "userName": "somihwang", + "content": "ํฌํ‚ค", + "commnetLike": true + } + ], + "isLike": false + }, + { + "id": 3, + "userName": "hwayoonci", + "src": "../../images/soojeongLee/user4.jpg", + "feedText": "์˜ค๋Š˜์˜ ์ผ๊ธฐ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "yunkyunglee", + "content": "๊ท€์—ฌ์šด ์Šคํ‹ฐ์ปค", + "commnetLike": true + }, + { + "id": 3, + "userName": "summer", + "content": "๐Ÿถ", + "commnetLike": false + }, + { + "id": 4, + "userName": "uiyeonlee", + "content": "๐Ÿ‘๐Ÿป", + "commnetLike": true + } + ], + "isLike": true + }, + { + "id": 4, + "userName": "cosz_zy", + "src": "../../images/soojeongLee/user5.jpg", + "feedText": "1์ผ ํ™”๊ฐ€ ๐ŸŽจ ", + "commentData": [ + { + "id": 1, + "userName": "wecode", + "content": "Welcome to world best coding bootcamp!", + "commnetLike": false + }, + { + "id": 2, + "userName": "soojeonglee", + "content": "Hi there.", + "commnetLike": false + }, + { + "id": 3, + "userName": "jaehyunlee", + "content": "Hey.", + "commnetLike": true + }, + { + "id": 4, + "userName": "gyeongminlee", + "content": "Hi.", + "commnetLike": true + } + ], + "isLike": false + } +]
Unknown
fetching ์„ ์—ฐ์Šตํ•ด๋ณด๋ ค๊ณ  ๋งŒ๋“ค์–ด๋ณด์•˜์–ด์š”
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
์ธ์Šคํƒ€๊ทธ๋žจ์—์„œ ์‹ค์ œ ์ข‹์•„์š”๋ฅผ ์ข‹์•„ํ•œ ์ˆซ์ž์— ์ ‘๊ทผํ•˜๊ฒŒ ๋˜๋ฉด ๋ˆ„๊ฐ€ ์ข‹์•„์š”๋ฅผ ๋ˆŒ๋ €๋Š”์ง€ ๋ชฉ๋ก์„ ๋ณผ ์ˆ˜ ์žˆ์–ด์„œ, ์ถ”ํ›„์— ๊ธฐ๋Šฅ์„ ๋„ฃ๊ฒŒ ๋œ๋‹ค๋ฉด button์„ ๋„ฃ์–ด์•ผ ํ•˜์ง€ ์•Š์„๊นŒ ์ƒ๊ฐ์ด ๋“ค์–ด์„œ ๋„ฃ์–ด๋ดค์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,23 @@ +//๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +//์ปดํฌ๋„ŒํŠธ +import { FOOTLIST } from '../FootLists/footData'; + +// css +import './FootLists.scss'; + +export class FootLists extends Component { + render() { + return FOOTLIST.map(footlists => { + return ( + <Link to="" className="listDot" key={footlists.id}> + {footlists.footlist} + </Link> + ); + }); + } +} + +export default FootLists;
JavaScript
๊ผญ ํ’‹ ๋ฆฌ์ŠคํŠธ๋ฅผ... ์ปดํฌ๋„ŒํŠธํ™”ํ•ด๋ณด๊ฒ ์–ด์š”...!!!!
@@ -1,14 +1,148 @@ -// ํ•„์ˆ˜ import React from 'react'; +import { Link } from 'react-router-dom'; -// ์ปดํฌ๋„ŒํŠธ import Nav from '../../../components/Nav/Nav'; +import Feed from '../Main/Feed/Feed'; +import OtherUserPro from './OtherUserPro/OtherUserPro'; +import FootLists from '../Main/Feed/FootLists/FootLists'; + +import './Main.scss'; class Main extends React.Component { + constructor() { + super(); + this.state = { + feedList: [], + }; + } + + componentDidMount() { + fetch('/data/soojeonglee/feedData.json') + .then(res => res.json()) + .then(data => { + this.setState({ + feedList: data, + }); + }); + } + render() { + // console.log(this.state.feedList); // ๋ฐ์ดํ„ฐ ํ™•์ธ์„ ์œ„ํ•œ ์ฝ˜์†” + const { feedList } = this.state; return ( - <div> + <div className="Main"> <Nav /> + <main> + <div className="feeds"> + {feedList.map(feed => { + return ( + <Feed + key={feed.id} + userName={feed.userName} + src={feed.src} + feedText={feed.feedText} + commentData={feed.commentData} + isLike={feed.isLike} + /> + ); + })} + </div> + <div className="main-right"> + <header className="userAccount"> + <h1> + <Link to="" className="userProfile mainRightProfile"></Link> + <Link to=""> + <strong>wecode_bootcamp</strong> + <span className="accountDec">WeCode - ์œ„์ฝ”๋“œ</span> + </Link> + </h1> + </header> + <aside className="asideBox storyAside"> + <header> + <h2>์Šคํ† ๋ฆฌ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + <ul className="storyUser"> + <OtherUserPro /> + </ul> + </aside> + + <aside className="asideBox recommandAside"> + <header> + <h2>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + + <ul className="recommandUser"> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user5.jpg" + /> + </Link> + <Link to=""> + limpack_official + <span className="followReco">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user6.jpg" + /> + </Link> + <Link to=""> + les_photos_de_cat + <span className="followReco"> + geee____nie๋‹˜ ์™ธ 1๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค. + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user7.jpg" + /> + </Link> + <Link to=""> + mornstar_nail + <span className="followReco"> + effie_yxz๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + </ul> + </aside> + <footer className="main-right-footer"> + <ul className="footList"> + <FootLists /> + </ul> + <span className="copyright">ยฉ 2021 INSTAGRAM FROM FACEBOOK</span> + </footer> + </div> + </main> </div> ); }
JavaScript
๋„ค..! ๋ฌด์—‡์ด ์–ด๋””์— ์ „๋‹ฌ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ๊ฐ€ ์–ด๋ ค์›Œ์„œ ๋„ฃ์–ด๋’€์–ด์š” ...!
@@ -1,14 +1,148 @@ -// ํ•„์ˆ˜ import React from 'react'; +import { Link } from 'react-router-dom'; -// ์ปดํฌ๋„ŒํŠธ import Nav from '../../../components/Nav/Nav'; +import Feed from '../Main/Feed/Feed'; +import OtherUserPro from './OtherUserPro/OtherUserPro'; +import FootLists from '../Main/Feed/FootLists/FootLists'; + +import './Main.scss'; class Main extends React.Component { + constructor() { + super(); + this.state = { + feedList: [], + }; + } + + componentDidMount() { + fetch('/data/soojeonglee/feedData.json') + .then(res => res.json()) + .then(data => { + this.setState({ + feedList: data, + }); + }); + } + render() { + // console.log(this.state.feedList); // ๋ฐ์ดํ„ฐ ํ™•์ธ์„ ์œ„ํ•œ ์ฝ˜์†” + const { feedList } = this.state; return ( - <div> + <div className="Main"> <Nav /> + <main> + <div className="feeds"> + {feedList.map(feed => { + return ( + <Feed + key={feed.id} + userName={feed.userName} + src={feed.src} + feedText={feed.feedText} + commentData={feed.commentData} + isLike={feed.isLike} + /> + ); + })} + </div> + <div className="main-right"> + <header className="userAccount"> + <h1> + <Link to="" className="userProfile mainRightProfile"></Link> + <Link to=""> + <strong>wecode_bootcamp</strong> + <span className="accountDec">WeCode - ์œ„์ฝ”๋“œ</span> + </Link> + </h1> + </header> + <aside className="asideBox storyAside"> + <header> + <h2>์Šคํ† ๋ฆฌ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + <ul className="storyUser"> + <OtherUserPro /> + </ul> + </aside> + + <aside className="asideBox recommandAside"> + <header> + <h2>ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</h2> + <button className="btnTextColor" type="button"> + ๋ชจ๋‘ ๋ณด๊ธฐ + </button> + </header> + + <ul className="recommandUser"> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user5.jpg" + /> + </Link> + <Link to=""> + limpack_official + <span className="followReco">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user6.jpg" + /> + </Link> + <Link to=""> + les_photos_de_cat + <span className="followReco"> + geee____nie๋‹˜ ์™ธ 1๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค. + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + <li className="otherUserProfile"> + <span className="profileBox"> + <Link to="" className="otherUserImg"> + <img + alt="User Profile" + src="images/soojeongLee/user7.jpg" + /> + </Link> + <Link to=""> + mornstar_nail + <span className="followReco"> + effie_yxz๋‹˜ ์™ธ 3๋ช…์ด ํŒ”๋กœ์šฐํ•ฉ๋‹ˆ๋‹ค + </span> + </Link> + </span> + <button className="follow" type="button"> + ํŒ”๋กœ์šฐ + </button> + </li> + </ul> + </aside> + <footer className="main-right-footer"> + <ul className="footList"> + <FootLists /> + </ul> + <span className="copyright">ยฉ 2021 INSTAGRAM FROM FACEBOOK</span> + </footer> + </div> + </main> </div> ); }
JavaScript
ใ…Žใ…Žใ…Ž Return ์€ ์ƒ๋žต๋  ์ˆ˜ ์žˆ๋‹ค ~
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
๊ณ„์‚ฐ๋œ์†์„ฑ๋ช… ๊ตฟ
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
์˜ค....
@@ -0,0 +1,175 @@ +import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import Comment from './Comment/Comment'; + +import '../Feed/Feed.scss'; + +export class Feed extends Component { + constructor() { + super(); + this.state = { + comment: '', + // commentList: [], + // isLike: false, + }; + } + + // componentDidMount() { + // this.setState({ + // commentList: this.props.commentData, + // isLike: this.props.isLike, + // }); + // } + + hadComment = event => { + this.setState({ + comment: event.target.value, + }); + }; + + // ํด๋ฆญํ•จ์ˆ˜ + submitComent = () => { + // this.setState({ + // commentList: this.state.commentList.concat([ + // { + // id: this.state.commentList.length + 1, + // userName: 'eessoo__', + // content: this.state.comment, + // commentLike: false, + // }, + // ]), + // comment: '', + // }); + }; + + handleKeyPress = event => { + if (event.key === 'Enter') { + event.preventDefault(); + this.submitComent(); + } + }; + + handleLike = () => { + this.setState({ + isLike: !this.state.isLike, + }); + }; + + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete = id => { + // const newCommentList = this.state.commentList.filter(comment => { + // return comment.id !== id; + // }); + + // this.setState({ + // commentList: newCommentList, + // }); + // }; + + render() { + return ( + <article> + <header> + <h1> + <Link className="contentHeader"></Link> + <Link className="userName">{this.props.userName}</Link> + </h1> + <button className="ellipsis" type="button"> + <i className="fas fa-ellipsis-h ellipsisIcon"></i> + </button> + </header> + <section className="feedContent"> + <img alt="feedImage" src={this.props.src} /> + <ul className="reactionsBox"> + <li className="reactionsLeft"> + <button + className="leftButton" + type="button" + onClick={this.handleLike} + > + {this.state.isLike ? ( + <i className="fas fa-heart" /> + ) : ( + <i className="far fa-heart" /> + )} + </button> + <button className="leftButton" type="button"> + <i className="far fa-comment" /> + </button> + <button className="leftButton" type="button"> + <i className="fas fa-external-link-alt" /> + </button> + </li> + <li className="reactionsRight"> + <button className="rightButton"> + <i className="far fa-bookmark" /> + </button> + </li> + </ul> + <h2> + <Link className="userProfile feedConUser"></Link> + <b>eessoo__</b>๋‹˜ ์™ธ + <button className="likeCount"> + <b> 7๋ช…</b> + </button> + ์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. + </h2> + <p className="feedText"> + {this.props.feedText} + <span className="postTime">54๋ถ„ ์ „</span> + </p> + <ul id="commnetBox"> + {/* {this.state.commentList.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} */} + {this.props.commentData.map(comment => { + return ( + <Comment + key={comment.id} + userName={comment.userName} + content={comment.content} + commnetLike={comment.commnetLike} + // ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์ค‘ + // handleCommnetDelete={this.handleCommnetDelete} + // id={comment.id} + /> + ); + })} + </ul> + </section> + <footer className="feedFooter"> + <form className="inputBox" onKeyPress={this.handleKeyPress}> + <input + autoComplete="off" + onChange={this.hadComment} + className="comment" + value={this.state.comment} + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + /> + <button + onClick={this.submitComent} + className="commentSubmit" + type="button" + > + ๊ฒŒ์‹œ + </button> + </form> + </footer> + </article> + ); + } +} + +export default Feed;
JavaScript
์ด๋Ÿฐ๋ฐฉ๋ฒ•์ด.. ํ”ผ๋“œ๋งˆ๋‹ค ๋Œ“๊ธ€ ๋ฐ์ดํ„ฐ๋ฅผ ์Šคํ…Œ์ดํŠธ๋กœ ํฌํ•จํ•˜๊ฒŒ ํ•ด์ฃผ๋‹ˆ ๋ณด๊ธฐ ์‰ฝ๊ณ  ์ข‹๋„ค์š”
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
์ด๋Ÿฐ ์ฃผ์„๋“ค์€ ๋ถˆํ•„์š”ํ•˜๋‹ˆ๊นŒ ์‚ญ์ œํ•ด์ฃผ์‹œ๋Š”๊ฒŒ ์ข‹์•„๋ณด์ž…๋‹ˆ๋‹ค!
@@ -1,8 +1,79 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = event => { + const { name, value } = event.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = () => { + this.props.history.push('/main-Soojeong#'); + }; + render() { - return <div>๋กœ๊ทธ์ธ</div>; + const isValid = + this.state.id.includes('@') && + this.state.id.length >= 5 && + this.state.pw.length >= 8; + + return ( + <div className="Login"> + <main> + <header> + <h1>Westagram</h1> + </header> + + <section className="loginInputBox"> + <h2 className="sr-only">login page</h2> + <form> + <input + name="id" + autoComplete="off" + onChange={this.handleInput} + type="text" + id="loginId" + value={this.state.id} + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + /> + <input + name="pw" + onChange={this.handleInput} + type="password" + value={this.state.pw} + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + /> + <button + onClick={this.goToMain} + type="button" + className="loginBtn" + disabled={!isValid} + > + ๋กœ๊ทธ์ธ + </button> + </form> + </section> + + <footer> + <Link to="" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </Link> + </footer> + </main> + </div> + ); } }
JavaScript
event.target ๋ฐ˜๋ณต๋˜๊ณ  ์žˆ๋Š”๋ฐ ๊ตฌ์กฐ๋ถ„ํ•ดํ•ด์„œ ํ™œ์šฉํ•ด๋ณผ ์ˆ˜ ์žˆ๊ฒ ๋„ค์š”! ```const {name,value} = event.target;```