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;``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.