code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,58 @@
+package com.subject.board.comment;
+
+import com.subject.board.article.ArticleRepository;
+import com.subject.board.entity.ArticleEntity;
+import com.subject.board.entity.CommentEntity;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Optional;
+
+@Service
+@RequiredArgsConstructor
+public class CommentService {
+ private final ArticleRepository articleRepository;
+ private final CommentRepository commentRepository;
+
+ // Create
+ public void create(
+ String content,
+ String password,
+ Long articleId) {
+ Optional<ArticleEntity> article = articleRepository.findById(articleId);
+
+ CommentEntity comment = new CommentEntity();
+ comment.setContent(content);
+ comment.setPassword(password);
+ comment.setArticle(article.orElse(null));
+ commentRepository.save(comment);
+ }
+
+ // Read
+ // ๊ฒ์๊ธ๋ณ ๋๊ธ ์กฐํ
+ public List<CommentEntity> findByArticleId(Long articleId) {
+ return commentRepository.findByArticleId(articleId);
+ }
+
+ public CommentEntity readOne(Long commentId) {
+ return commentRepository.findById(commentId)
+ .orElse(null);
+ }
+
+ // Delete
+ public void delete(Long commentId) {
+ commentRepository.deleteById(commentId);
+ }
+
+ // ๋น๋ฐ๋ฒํธ ํ์ธ
+ public Boolean checkPassword(
+ Long commentId,
+ String inputPassword
+ ) {
+ String passwrod = readOne(commentId).getPassword();
+ if (passwrod.equals(inputPassword)) {
+ return true;
+ } else return false;
+ }
+} | Java | password ์คํ์์ต๋๋ค.
return password.equals(inputPassword); ๋ก ์ค์ผ์ ์์๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,41 @@
+INSERT INTO board_entity (board_name)
+VALUES
+ ('์์ ๊ฒ์ํ'),
+ ('๊ฐ๋ฐ ๊ฒ์ํ'),
+ ('์ผ์ ๊ฒ์ํ'),
+ ('์ฌ๊ฑด์ฌ๊ณ ๊ฒ์ํ');
+
+INSERT INTO article_entity (title, content, password, board_id)
+VALUES
+ ('์๋์
๊ตฌ์ญ ๋ง์ง ์ถ์ฒ', '์๋์
๊ตฌ์ญ ๊ทผ์ฒ์ ์๋ ํํ๋จ์ ์๋น์ด ๋ง์์ด์!', '1234', 1),
+ ('์ฐ์ ํ๋ก๊ทธ๋จ์ ๋ณด๋ฉด์..', '๊ฐ๋ฐ์๋ค์ ์ํ ์๋ฅ ํ๋ก๊ทธ๋จ์ด ์์์ผ๋ฉด ์ข๊ฒ ๋ค.. ์ ๊ทผ๋ฐ ๊ฐ๋ฐ์๋ค์ด ์นด๋ฉ๋ผ ์์ ์ค๋ฆฌ๊ฐ ์์ง ใ
ใ
ใ
ใ
', '1234', 1),
+ ('GPT 3.5๋ฅผ ์ฐ๋ฉด์..', '๋ ๊ทธ๋ฅ ์ฝ๋ฉ ํ์ง ๋ง์๋ผ ์ ํฐ์ง๋ค.', '1234', 2),
+ ('JS์ Java๋ฅผ ๊ณต๋ถํ๋๊น', '๋๋ฌด ํท๊ฐ๋ ค์ ใ
ใ
ใ
๋งค๊ฐ๋ณ์ ๋ฃ์ ๋ ์๊พธ ํ์
์ ์์;;', '1234', 2),
+ ('๋ค์ด๋ฒ ๋ธ๋ก๊ทธ style ์ฝ๋ ๋ฆฌ๋ทฐ', '์ค๋์ ์ฝ๋ ๋ฆฌ๋ทฐ๋ฅผ ์์๋ณผ๊ฒ์! ์ ๋ ์ฐธ ๊ถ๊ธํ๋ค์!', '1234', 2),
+ ('์์ฆ ๊ทผํฉ', '๋ฐฅ ๋จน์ด ์ฝ๋ฉ ํด ๋ ๋ฐฅ ๋จน์ด ์ฝ๋ฉ ํด ์ ํ๋ธ ๋ด ๋ ์ฝ๋ฉ ํด', '1234', 3),
+ ('์์ฆ ๊ทผํฉ', '๋ฐฅ๋ฐฅ๋ฐฅ๋ฐฅ ์ค๋ ์ ๋
์ ์ ์ก๋ณถ์~~', '1234', 3),
+ ('์ฌ๊ฑด์ฌ๊ณ ? ๊ทธ๋ฐ๊ฑด ๋ด ์ฌ์ ์ ์๋ค.', '์๋ํ๋ฉด ์ฝ๋ฉ์ ํ ์ค๋ ์์น๊ธฐ ๋๋ฌธ์ด์ง ํํํ!', '1234', 4),
+ ('์ผ ์๋ฌ ๋จ๋ ๋๋ค ๋ด๋ผ ใ
ใ
ใ
', '์๋ฌ? ์๋ ์ปดํจํฐ ๋๊ฐ ํ๋ฆฌ๊ณ ๋ด๊ฐ ๋ง์ด', '1234', 4);
+
+INSERT INTO comment_entity(content, password, article_id)
+VALUES
+ ('ํํ๋จ์ ๊ฑฐ๊ธฐ ๋ง์์ด์!', '1234', 1),
+ ('์ธํ
๋ฆฌ์ด๊ฐ ์ด๋ป์!', '1234', 1),
+ ('๊ฐ๋ฐ์๋ฅผ ์ํ ์๋ฅ์ด๋ผ๋.. ์์ ๊ฟ์ ๊พธ์์ต๋๋ค..', '1234', 2),
+ ('์์ฃผ ํ๋ณตํ ๊ฟ์ด์์ต๋๋ค..', '1234', 2),
+ ('๊ทผ๋ฐ ์ ์ฐ๋ ๊ฒ์ด๋', '1234', 2),
+ ('๊ทธ๊ฑด ์ด๋ค์ง ์ ์๋ ๊ฟ์ด๊ธฐ ๋๋ฌธ์
๋๋ค.', '1234', 2),
+ ('GPT๋ ์คํ ์ก๊ธฐ ์ต๊ณ ๋ผ๊ณ ใ
ใ
ใ
ใ
', '1234', 3),
+ ('๋ฐฑ์๋์ ๊ทผ๋ณธ์ Java์ด์ง ใ
ใ
ใ
ใ
', '1234', 4),
+ ('js๋ ๊ทผ๋ณธ์ด ์๋ค ์์
๋๊บผ ๊ทผ๋ณธ์ด! ', '1234', 4),
+ ('์ด์ ์ด๋ ๊ฒ ๋๊ฑฐ ์ฝํ๋ฆฐ์ผ๋ก ๊ฐ๋ค.', '1234', 4),
+ ('์คํจํ๋ฉด ํ์
์คํฌ๋ฆฝํธ ์ฑ๊ณตํ๋ฉด ๋์ ์ธ์ด ์ต๊ณ ์๋๋๊น!.', '1234', 4),
+ ('ํ์
์คํฌ๋ฆฝํธ๋ Java๋ ํ์
์ฐ๋ ๋ฐฉ์์ด ๋ค๋ฆ ใ
ใ
ใ
ใ
์๊ณ ์.', '1234', 4),
+ ('๋น๋ฐ ๋๊ธ์
๋๋ค.', '1234', 5),
+ ('๋น๋ฐ ๋๊ธ์
๋๋ค.', '1234', 5),
+ ('๊ฐ๋ฐ ๊ณต๋ถํ๋ฉด ์๋ ๋ฐ์ฏค ๋ฏธ์ณ๊ฐ๋์?', '1234', 5),
+ ('์ผ์ ์๊ณ ๋ฆฌ์ฆ ํผ ๋ฏธ์ณค๋ค', '1234', 6),
+ ('๋ ์๋ ๊ธ ์ด ๋์ด์ง?', '1234', 7),
+ ('๊ฐ๋ฐ ๊ณต๋ถํ๋ฉด ์๋ ๋ฐ์ฏค ๋ฏธ์น๋์?', '1234', 7),
+ ('๊ทธ๋ฐ ๋ฐฉ๋ฒ์ด ์์๋ค ใ
ใ
ใ
ใ
ใ
ใ
', '1234', 8),
+ ('404 Not Found๋ผ๊ณ ? ๊ทธ๋ผ ์ฐพ์ด!', '1234', 9); | Unknown | ๋ฐ์ดํฐ๊ฐ ๋ค์ด์์ด์ ํ
์คํธํ๊ธฐ ์ข์์ต๋๋ค. |
@@ -0,0 +1,147 @@
+package com.subject.board.article;
+
+import com.subject.board.board.BoardService;
+import com.subject.board.comment.CommentService;
+import com.subject.board.entity.ArticleEntity;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+@Controller
+@RequestMapping("/article")
+@RequiredArgsConstructor
+public class ArticleController {
+ private final ArticleService articleService;
+ private final BoardService boardService;
+ private final CommentService commentService;
+
+ // Create
+ // ๊ฒ์๊ธ ์์ฑ view๋ก ์ด๋
+ @GetMapping("/create")
+ public String createPage() {
+ return "article/create";
+ }
+
+ // create ๋ก์ง
+ @PostMapping("/create")
+ public String create(
+ @RequestParam("board-id") Long boardId,
+ @RequestParam("title") String title,
+ @RequestParam("content") String content,
+ @RequestParam("password") String password
+ ) {
+ articleService.create(boardId, title, content, password);
+ return "redirect:/article";
+ }
+
+ // Read
+ // ์ ์ฒด ๋ณด๊ธฐ(= ์ ์ฒด ๊ฒ์ํ)
+ @GetMapping
+ public String readAll(Model model) {
+ model.addAttribute("articles", articleService.readAll());
+ return "home";
+ }
+
+ // ์์ธ ๋ณด๊ธฐ
+ @GetMapping("/{articleId}")
+ public String readOne(
+ @PathVariable("articleId") Long articleId,
+ Model model
+ ) {
+ model.addAttribute("article", articleService.readOne(articleId));
+ model.addAttribute("comments", commentService.findByArticleId(articleId));
+ return "article/read";
+ }
+
+ // Update
+ // ๋น๋ฐ๋ฒํธ view
+ @GetMapping("/{articleId}/password-view/update")
+ public String passwordViewUpdate(
+ @PathVariable("articleId") Long articleId,
+ Model model
+ ) {
+ model.addAttribute("article", articleService.readOne(articleId));
+ model.addAttribute("type", "article");
+ model.addAttribute("method", "update");
+ return "password";
+ }
+
+ // ๋น๋ฐ๋ฒํธ ํ์ธ ํ -> update view๋ก ์ด๋
+ @PostMapping("/{articleId}/passwordCheck/update")
+ public String checkPasswordUpdate(
+ @PathVariable("articleId") Long articleId,
+ @RequestParam("input-password") String inputPassword,
+ RedirectAttributes redirectAttributes,
+ Model model
+ ) {
+ if (articleService.checkPassword(articleId, inputPassword)) {
+ // ๋น๋ฐ๋ฒํธ ์ผ์น
+ model.addAttribute("article", articleService.readOne(articleId));
+ model.addAttribute("boards", boardService.readAll());
+ return "article/update";
+ } else {
+ // ๋น๋ฐ๋ฒํธ ๋ถ์ผ์น
+ redirectAttributes.addFlashAttribute("error", "๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.");
+ return "redirect:/article/" + articleId + "/password-view/update"; // ๋ค์ ๋น๋ฐ๋ฒํธ ์
๋ ฅ ํ์ด์ง๋ก ๋ฆฌ๋ค์ด๋ ํธ
+ }
+ }
+
+ // update ์คํ
+ @PostMapping("/{articleId}/update")
+ public String update(
+ @PathVariable("articleId") Long articleId,
+ @RequestParam("board-id") Long boardId,
+ @RequestParam("title") String title,
+ @RequestParam("content") String content
+ ) {
+ articleService.update(articleId, boardId, title, content);
+ return String.format("redirect:/article/%d", articleId);
+ }
+
+ // Delete
+ // ๋น๋ฐ๋ฒํธ view
+ @GetMapping("/{articleId}/password-view/delete")
+ public String passwordViewDelete(
+ @PathVariable("articleId") Long articleId,
+ Model model
+ ) {
+ model.addAttribute("article", articleService.readOne(articleId));
+ model.addAttribute("type", "article");
+ model.addAttribute("method", "delete");
+ return "password";
+ }
+
+ // ๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ๋ฉด ์ญ์ , ํ๋ฆฌ๋ฉด ๊ฒฝ๊ณ ์ฐฝ
+ @PostMapping("/{articleId}/passwordCheck/delete")
+ public String checkPasswordDelete(
+ @PathVariable("articleId") Long articleId,
+ @RequestParam("input-password") String inputPassword,
+ RedirectAttributes redirectAttributes,
+ Model model
+ ) {
+ if (articleService.checkPassword(articleId, inputPassword)) {
+ articleService.delete(articleId);
+ return "redirect:/article";
+ } else {
+ redirectAttributes.addFlashAttribute("error", "๋น๋ฐ๋ฒํธ๊ฐ ์ผ์นํ์ง ์์ต๋๋ค.");
+ return "redirect:/article/" + articleId + "/password-view/delete"; // ๋ค์ ๋น๋ฐ๋ฒํธ ์
๋ ฅ ํ์ด์ง๋ก ๋ฆฌ๋ค์ด๋ ํธ
+ }
+ }
+
+ // Search
+ @PostMapping("/search")
+ public String searchArticle(
+ @RequestParam("category") String category,
+ @RequestParam("search") String search,
+ Model model
+ ) {
+ model.addAttribute("articles", articleService.search(category, search));
+ return "article/searchArticle";
+ }
+} | Java | ArticleEntity๊ฐ ์ด๋ฏธ Comment ๋ฆฌ์คํธ๋ฅผ ๊ฐ๊ณ ์๊ธฐ ๋๋ฌธ์ ๊ตณ์ด comments๋ฅผ ๋ชจ๋ธ๋ก ๋ฐ๋ก ๋๊ธฐ์ง ์์๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,54 @@
+package christmas.constant;
+
+public final class CommentConstants {
+ public static final String EVENT_INFORMATION_MESSAGE = """
+ ์ฐํ
์ฝ ์๋น์ ์ต๋ ์ด๋ฒคํธ! 12์ ์ด๋ฒคํธ๋ฅผ ์์ํฉ๋๋ค!
+ ์ต๋ 3๋ฒ์ ์ค๋ณต ํ ์ธ๊ณผ ์ฐํ
์ฝ๊ฐ ์ค๋นํ ๋ ๊ฐ์ ๊น์ง ์ ๋ฌผ์ ๋ฐ์ ๊ฐ์ธ์!
+ * ๋ชจ๋ ์ด๋ฒคํธ๋ ํ ์ด๋ฒคํธ์ ์ค๋ณต ์ ์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.
+
+ ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด๋ฅผ ๊ฐ์ด ์ธ์ด๋ณด์์.
+ ์ต๋ 3400์ ํ ์ธ! 1์ผ 1000์์ผ๋ก ์์ํ์ฌ 25์ผ๊น์ง 100์์ฉ ์ฆ๊ฐํ๋ ํ ์ธ!
+ ํฌ๋ฆฌ์ค๋ง์ค์ ์ ๋ฌผ์ ๋๊ปด๋ณด์ธ์!
+ * 25์ผ๊น์ง
+
+ ์ง๋๊ฐ๋ 2023๋
์ ์ํ, 2,023์ ํ ์ธ ์ด๋ฒคํธ!
+ ๊ธ์์ผ, ํ ์์ผ์๋ ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2,023์์ ํ ์ธํฉ๋๋ค!
+ ๋ค๋ฅธ ๋ ๋ฐฉ๋ฌธํด๋ ์ญ์ญํดํ์ง ๋ง์ธ์.
+ ์ผ์์ผ๋ถํฐ ๋ชฉ์์ผ๊น์ง๋ ๋ฌ์ฝคํ ๋์ ํธ๋ฅผ 1๊ฐ๋น 2,023์์ ํํ์ ๋ฐ์๋ณด์ธ์.
+
+ ๋ณ์ด ๋จ๋ ๋ ์๋ ํ์ด์ด ์ฐพ์์ฌ ๊ฑฐ์ผ
+ ๋ฌ๋ ฅ์ ๋ณ์ด ๋ฌ ๋ ์๋ 1,000์์ ์ถ๊ฐํ ์ธ์ด ์ ๊ณต๋ฉ๋๋ค!
+
+ ํน๋ณํ ๋ ์ ๋ ํน๋ณํ๊ฒ, ์ดํ์ธ๊ณผ ํจ๊ปํ๋ ์ฐ์ํ ์๊ฐ
+ ์ด ์ฃผ๋ฌธ ๊ธ์ก 12๋ง ์ ์ด์ ์ ์ดํ์ธ์ ์ ๊ณตํด ๋๋ฆฝ๋๋ค.
+ * ํ ์ธ ์ ๊ธ์ก ๊ธฐ์ค
+
+ 1์ 2์กฐ, ํํ๋ ๋ฐ๊ณ , ์ํด์ ๋ฌผ๋ ๋ฐ์!
+ ํํ ๊ธ์ก์ ๋ฐ๋ผ ๋ฐ๋ ์ด๋ฒคํธ ๋ฐฐ์ง๋ก 1์ ์ํด ์ ๋ฌผ ๋ฐ์ ๊ฐ์ธ์! ์ ๋ฌผ์ ์ํด์ด๋ฒคํธ์ ๊ณต๊ฐ๋ ์์ ์
๋๋ค.
+ * 5์ฒ ์ ์ด์ : ๋ณ, 1๋ง ์ ์ด์ : ํธ๋ฆฌ, 2๋ง ์ ์ด์ : ์ฐํ
+
+ * ์ด ์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์๋ถํฐ ์ด๋ฒคํธ๊ฐ ์ ์ฉ๋ฉ๋๋ค.
+ * ์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.
+ * ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.
+
+ ------------------------ ์ฐํ
์ฝ ์๋น ๋ฉ๋ด ------------------------
+
+ <์ ํผํ์ด์ >
+ ์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+ <๋ฉ์ธ>
+ ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+ <๋์ ํธ>
+ ์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+ <์๋ฃ>
+ ์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+
+ ---------------------------------------------------------------
+ ์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.
+ """;
+
+ private CommentConstants() {
+ }
+}
\ No newline at end of file | Java | ์ ์ด๊ฑด ํน์ ์ฌ์ฉ๋๋ ์๋ ๋ฉ์์ง์ผ๊น์!? |
@@ -0,0 +1,11 @@
+package christmas.domain.discount;
+
+import christmas.constant.DiscountPolicyName;
+import christmas.service.dto.OrderDto;
+
+public interface DiscountPolicy {
+
+ int discount(final OrderDto order);
+
+ DiscountPolicyName getDiscountPolicyName();
+}
\ No newline at end of file | Java | ์ธํฐํ์ด์ค๋ฅผ ์ ์ ํ๊ฒ ์ ์ฌ์ฉํ์ ๊ฑฐ ๊ฐ์์! ๊ฐ ํ ์ธ์ ๋ํด ํ์ฅ์ด๋ ๋ณ๊ฒฝ์ด ์ฌ์ธ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,52 @@
+package christmas.domain.menu;
+
+import java.util.Arrays;
+
+public enum Menu {
+
+ MUSHROOM_SOUP("์์ก์ด์ํ", 6_000, MenuCategory.APPETIZER),
+ TAPAS("ํํ์ค", 5_500, MenuCategory.APPETIZER),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000, MenuCategory.APPETIZER),
+
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55_000, MenuCategory.MAIN),
+ BBQ_RIB("๋ฐ๋นํ๋ฆฝ", 54_000, MenuCategory.MAIN),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35_000, MenuCategory.MAIN),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000, MenuCategory.MAIN),
+
+ CHOCOLATE_CAKE("์ด์ฝ์ผ์ดํฌ", 15_000, MenuCategory.DESSERT),
+ ICE_CREAM("์์ด์คํฌ๋ฆผ", 5_000, MenuCategory.DESSERT),
+
+ ZERO_COLA("์ ๋ก์ฝ๋ผ", 3_000, MenuCategory.DRINK),
+ RED_WINE("๋ ๋์์ธ", 60_000, MenuCategory.DRINK),
+ CHAMPAGNE("์ดํ์ธ", 25_000, MenuCategory.DRINK);
+
+ private static final String INVALID_ORDER_MESSAGE = "์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private final String name;
+ private final int price;
+ private final MenuCategory menuCategory;
+
+ Menu(final String name, final int price, final MenuCategory menuCategory) {
+ this.name = name;
+ this.price = price;
+ this.menuCategory = menuCategory;
+ }
+
+ public static Menu findByName(final String name) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menu.getName().equals(name))
+ .findFirst()
+ .orElseThrow(() -> new IllegalArgumentException(INVALID_ORDER_MESSAGE));
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public MenuCategory getMenuCategory() {
+ return menuCategory;
+ }
+}
\ No newline at end of file | Java | ์ ์ฝ๋๋ ์ ๋ ๊ฑฐ์ ๋๊ฐ๋ค์ ใ
ใ
์ด๋ฆ๋ ๋๊ฐ์๋ฐ ์ ๊ธฐํ๋ค์ ใ
ใ
ใ
๋ฉ๋ด์ ๋ํ ์ถ๊ฐ์ ์ธ ๋ก์ง์ด ์์ด์ ์ด๋ ๊ฒ ๋ฉ๋ด๋ฅผ ๋ชจ์๋๋ ๊ฒ ๋ ๊ฐ๋
์ฑ์ด ์ข์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,77 @@
+package christmas.domain.discount;
+
+import christmas.constant.DiscountConstants;
+import christmas.constant.DiscountPolicyName;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.MenuCategory;
+import christmas.service.dto.OrderDto;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.Map;
+import java.util.Map.Entry;
+
+
+public class WeekendDiscountPolicy implements DiscountPolicy {
+ private static final int WEEKEND_DISCOUNT_AMOUNT = 2023;
+
+ @Override
+ public int discount(final OrderDto order) {
+ LocalDate orderDate = order.getDate();
+ if (isWithinDiscountPeriod(orderDate) && isWeekend(orderDate)) {
+ return calculateTotalDiscount(order.getMenus());
+ }
+ return DiscountConstants.NO_DISCOUNT;
+ }
+
+ @Override
+ public DiscountPolicyName getDiscountPolicyName() {
+ return DiscountPolicyName.WEEKEND_DISCOUNT;
+ }
+
+ private int calculateTotalDiscount(Map<Menu, Integer> menus) {
+ int totalDiscount = 0;
+ for (Entry<Menu, Integer> menu : menus.entrySet()) {
+ totalDiscount += calculateDiscountForMenu(menu);
+ }
+ return totalDiscount;
+ }
+
+ private int calculateDiscountForMenu(Entry<Menu, Integer> menu) {
+ if (isMainCategory(menu.getKey())) {
+ return calculateMenuDiscount(menu);
+ }
+ return 0;
+ }
+
+ private boolean isMainCategory(Menu menu) {
+ return menu.getMenuCategory() == MenuCategory.MAIN;
+ }
+
+ private int calculateMenuDiscount(Map.Entry<Menu, Integer> menu) {
+ return WEEKEND_DISCOUNT_AMOUNT * menu.getValue();
+ }
+
+ private boolean isWithinDiscountPeriod(LocalDate date) {
+ return isNotBeforeStartDate(date) && isNotAfterEndDate(date);
+ }
+
+ private boolean isNotBeforeStartDate(LocalDate date) {
+ return !date.isBefore(DiscountConstants.START_DAY_OF_MONTH);
+ }
+
+ private boolean isNotAfterEndDate(LocalDate date) {
+ return !date.isAfter(DiscountConstants.END_DAY_OF_MONTH);
+ }
+
+ private boolean isWeekend(LocalDate date) {
+ return isFriday(date) || isSaturday(date);
+ }
+
+ private boolean isFriday(LocalDate date) {
+ return date.getDayOfWeek() == DayOfWeek.FRIDAY;
+ }
+
+ private boolean isSaturday(LocalDate date) {
+ return date.getDayOfWeek() == DayOfWeek.SATURDAY;
+ }
+}
\ No newline at end of file | Java | DayOfWeek ์ฌ์ฉ๋ฒ ์ ๋ง ๋ชฐ๋๊ตฐ์.. ๋๊ฒ ์ข์ ๋ฐฉ๋ฒ์ธ ๊ฑฐ ๊ฐ์์! ๐๐ |
@@ -0,0 +1,74 @@
+package christmas.domain;
+
+import christmas.constant.DiscountConstants;
+import christmas.constant.DiscountPolicyName;
+import christmas.domain.discount.ChristmasDailyDiscountPolicy;
+import christmas.domain.discount.DiscountPolicy;
+import christmas.domain.discount.GiftEventPolicy;
+import christmas.domain.discount.SpecialDiscountPolicy;
+import christmas.domain.discount.WeekdayDiscountPolicy;
+import christmas.domain.discount.WeekendDiscountPolicy;
+import christmas.domain.menu.Menu;
+import christmas.service.dto.OrderDto;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
+public class ChristmasEvent {
+ private static final int MINIMUM_AMOUNT_FOR_DISCOUNT = 10000;
+ private static final int MINIMUM_AMOUNT_FOR_GIFT = 120000;
+ private final List<DiscountPolicy> discountPolicies;
+ private final GiftEventPolicy giftEventPolicy;
+ private final Map<Menu, Integer> giftMenu;
+
+ public ChristmasEvent() {
+ this.discountPolicies = List.of(
+ new ChristmasDailyDiscountPolicy(),
+ new WeekdayDiscountPolicy(),
+ new WeekendDiscountPolicy(),
+ new SpecialDiscountPolicy());
+ this.giftEventPolicy = new GiftEventPolicy();
+ this.giftMenu = new EnumMap<>(Menu.class);
+ }
+
+ public Map<DiscountPolicyName, Integer> calculateBenefitDetails(final OrderDto order) {
+ Map<DiscountPolicyName, Integer> benefitDetail = new EnumMap<>(DiscountPolicyName.class);
+ if (order.getTotalPrice() >= MINIMUM_AMOUNT_FOR_DISCOUNT) {
+ benefitDetail = applyDiscountPolicies(order);
+ addGift(order, benefitDetail);
+ }
+ return benefitDetail;
+ }
+
+ public int calculateTotalDiscount(final OrderDto order) {
+ Map<DiscountPolicyName, Integer> discountDetail = calculateBenefitDetails(order);
+ return discountDetail.values()
+ .stream()
+ .mapToInt(Integer::intValue)
+ .sum();
+ }
+
+ private void addGift(final OrderDto order, final Map<DiscountPolicyName, Integer> benefitDetail) {
+ if (order.getTotalPrice() >= MINIMUM_AMOUNT_FOR_GIFT) {
+ int giftPrice = giftEventPolicy.discountGiftPrice(order);
+ benefitDetail.put(DiscountPolicyName.GIFT_EVENT, giftPrice);
+ giftMenu.put(Menu.CHAMPAGNE, 1);
+ }
+ }
+
+ private Map<DiscountPolicyName, Integer> applyDiscountPolicies(final OrderDto order) {
+ Map<DiscountPolicyName, Integer> discountDetail = new EnumMap<>(DiscountPolicyName.class);
+ for (DiscountPolicy discountPolicy : discountPolicies) {
+ int discountAmount = discountPolicy.discount(order);
+ if (discountAmount != DiscountConstants.NO_DISCOUNT) {
+ discountDetail.put(discountPolicy.getDiscountPolicyName(), discountAmount);
+ }
+ }
+ return discountDetail;
+ }
+
+ public Map<Menu, Integer> getGiftMenu(final OrderDto order) {
+ calculateBenefitDetails(order);
+ return giftMenu;
+ }
+}
\ No newline at end of file | Java | ์ฆ์ ๋ฉ๋ด์ ๋ํด์ ํ์ฅ์ฑ์ด ๋ณด์ฌ์ ์ข์ ๊ฑฐ ๊ฐ์์! ๐ |
@@ -0,0 +1,115 @@
+package christmas.controller;
+
+import static christmas.model.constant.DiscountConstant.GIFT_EVENT_THRESHOLD;
+
+import christmas.model.Date;
+import christmas.model.MenuCount;
+import christmas.model.constant.PromotionConstant;
+import christmas.model.strategy.BadgeStrategy;
+import christmas.model.strategy.DiscountStrategy;
+import christmas.model.strategy.WootecoBadgeStrategy;
+import christmas.model.strategy.WootecoDiscountStrategy;
+import christmas.service.PromotionService;
+import christmas.util.Parser;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.function.Supplier;
+
+public class PromotionController {
+ private final PromotionService promotion;
+ private final DiscountStrategy discountStrategy = new WootecoDiscountStrategy();
+ private final BadgeStrategy badgeStrategy = new WootecoBadgeStrategy();
+
+ public PromotionController() {
+ this.promotion = new PromotionService(discountStrategy, badgeStrategy);
+ }
+
+ public void run() {
+ InputView.printGreetingMessage();
+ Date date = getDate();
+ MenuCount menuCount = getMenu();
+ displayEventGuideMessage(date);
+ displayMenuAndOrderAmount(menuCount);
+ displayPromotionResult(menuCount, date);
+ }
+
+ private Date getDate() {
+ return executeWithExceptionHandle(() -> {
+ int inputDate = InputView.readDate();
+ return Date.of(inputDate);
+ });
+ }
+
+ private MenuCount getMenu() {
+ return executeWithExceptionHandle(() -> {
+ String input = InputView.readMenu();
+ Map<String, Integer> parsedMenu = Parser.parseMenuCount(input);
+ return new MenuCount(parsedMenu);
+ });
+ }
+
+ private void displayMenuAndOrderAmount(MenuCount menuCount) {
+ displayMenuInfo(menuCount);
+ displayTotalOrderAmount(menuCount);
+ }
+
+ private void displayPromotionResult(MenuCount menuCount, Date date) {
+ displayGiftEvent(menuCount);
+ displayPromotionEvent(menuCount, date);
+ displayTotalPromotionAmount(menuCount, date);
+ displayExpectedPaymentAmount(menuCount, date);
+ displayEventBadge(menuCount, date);
+ }
+
+ private void displayEventGuideMessage(Date date) {
+ OutputView.printEventGuideMessage(date.getValue());
+ }
+
+
+ private void displayMenuInfo(MenuCount menuCount) {
+ OutputView.printOrderedMenu(menuCount);
+ }
+
+ private void displayTotalOrderAmount(MenuCount menuCount) {
+ OutputView.printTotalOrderAmount(menuCount.calculateTotalAmount());
+ }
+
+ private void displayGiftEvent(MenuCount menuCount) {
+ boolean canGiveGift = menuCount.calculateTotalAmount() >= GIFT_EVENT_THRESHOLD.getAmount();
+ OutputView.printGiftEvent(canGiveGift);
+ }
+
+ private void displayPromotionEvent(MenuCount menuCount, Date date) {
+ EnumMap<PromotionConstant, Integer> promotionStatus = promotion.calculatePromotionStatus(menuCount, date);
+ OutputView.printPromotionStatus(promotionStatus);
+ }
+
+ private void displayTotalPromotionAmount(MenuCount menuCount, Date date) {
+ int totalPromotionAmount = promotion.calculatePromotionAmount(menuCount, date);
+ OutputView.printPromotionAmount(totalPromotionAmount);
+ }
+
+ private void displayExpectedPaymentAmount(MenuCount menuCount, Date date) {
+ int expectedPayment =
+ menuCount.calculateTotalAmount() - promotion.calaulateTotalDiscountAmount(menuCount, date);
+ OutputView.printExpectedPaymentAmount(expectedPayment);
+ }
+
+ private void displayEventBadge(MenuCount menuCount, Date date) {
+ String badgeName = promotion.calculateBadgeStatus(menuCount, date);
+ OutputView.printEventBadge(badgeName);
+ }
+
+ private static <T> T executeWithExceptionHandle(final Supplier<T> supplier) {
+ while (true) {
+ try {
+ return supplier.get();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+} | Java | ์ปจํธ๋กค๋ฌ๋ ํ๋ฆ์ ์ ์ดํ๋ ์ฑ
์์ ๊ฐ์ง๊ณ ์๋ ๊ฒ์ผ๋ก ๋ณด์
๋๋ค. ์ด๋ฒคํธ ์ ์ฉ ์ฌ๋ถ๋ฅผ ํ์ธํ๋ ์ฑ
์์ ๋ถ๋ฆฌํ๋ ๊ฒ์ ๋ํด์๋ ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,115 @@
+package christmas.controller;
+
+import static christmas.model.constant.DiscountConstant.GIFT_EVENT_THRESHOLD;
+
+import christmas.model.Date;
+import christmas.model.MenuCount;
+import christmas.model.constant.PromotionConstant;
+import christmas.model.strategy.BadgeStrategy;
+import christmas.model.strategy.DiscountStrategy;
+import christmas.model.strategy.WootecoBadgeStrategy;
+import christmas.model.strategy.WootecoDiscountStrategy;
+import christmas.service.PromotionService;
+import christmas.util.Parser;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.function.Supplier;
+
+public class PromotionController {
+ private final PromotionService promotion;
+ private final DiscountStrategy discountStrategy = new WootecoDiscountStrategy();
+ private final BadgeStrategy badgeStrategy = new WootecoBadgeStrategy();
+
+ public PromotionController() {
+ this.promotion = new PromotionService(discountStrategy, badgeStrategy);
+ }
+
+ public void run() {
+ InputView.printGreetingMessage();
+ Date date = getDate();
+ MenuCount menuCount = getMenu();
+ displayEventGuideMessage(date);
+ displayMenuAndOrderAmount(menuCount);
+ displayPromotionResult(menuCount, date);
+ }
+
+ private Date getDate() {
+ return executeWithExceptionHandle(() -> {
+ int inputDate = InputView.readDate();
+ return Date.of(inputDate);
+ });
+ }
+
+ private MenuCount getMenu() {
+ return executeWithExceptionHandle(() -> {
+ String input = InputView.readMenu();
+ Map<String, Integer> parsedMenu = Parser.parseMenuCount(input);
+ return new MenuCount(parsedMenu);
+ });
+ }
+
+ private void displayMenuAndOrderAmount(MenuCount menuCount) {
+ displayMenuInfo(menuCount);
+ displayTotalOrderAmount(menuCount);
+ }
+
+ private void displayPromotionResult(MenuCount menuCount, Date date) {
+ displayGiftEvent(menuCount);
+ displayPromotionEvent(menuCount, date);
+ displayTotalPromotionAmount(menuCount, date);
+ displayExpectedPaymentAmount(menuCount, date);
+ displayEventBadge(menuCount, date);
+ }
+
+ private void displayEventGuideMessage(Date date) {
+ OutputView.printEventGuideMessage(date.getValue());
+ }
+
+
+ private void displayMenuInfo(MenuCount menuCount) {
+ OutputView.printOrderedMenu(menuCount);
+ }
+
+ private void displayTotalOrderAmount(MenuCount menuCount) {
+ OutputView.printTotalOrderAmount(menuCount.calculateTotalAmount());
+ }
+
+ private void displayGiftEvent(MenuCount menuCount) {
+ boolean canGiveGift = menuCount.calculateTotalAmount() >= GIFT_EVENT_THRESHOLD.getAmount();
+ OutputView.printGiftEvent(canGiveGift);
+ }
+
+ private void displayPromotionEvent(MenuCount menuCount, Date date) {
+ EnumMap<PromotionConstant, Integer> promotionStatus = promotion.calculatePromotionStatus(menuCount, date);
+ OutputView.printPromotionStatus(promotionStatus);
+ }
+
+ private void displayTotalPromotionAmount(MenuCount menuCount, Date date) {
+ int totalPromotionAmount = promotion.calculatePromotionAmount(menuCount, date);
+ OutputView.printPromotionAmount(totalPromotionAmount);
+ }
+
+ private void displayExpectedPaymentAmount(MenuCount menuCount, Date date) {
+ int expectedPayment =
+ menuCount.calculateTotalAmount() - promotion.calaulateTotalDiscountAmount(menuCount, date);
+ OutputView.printExpectedPaymentAmount(expectedPayment);
+ }
+
+ private void displayEventBadge(MenuCount menuCount, Date date) {
+ String badgeName = promotion.calculateBadgeStatus(menuCount, date);
+ OutputView.printEventBadge(badgeName);
+ }
+
+ private static <T> T executeWithExceptionHandle(final Supplier<T> supplier) {
+ while (true) {
+ try {
+ return supplier.get();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+} | Java | `๋ ์ง๋ ๋ฉ๋ด๋ฅผ ์ป๋๋ค`๋ณด๋ค `์ ํจํ ๊ฐ์ ์ป์๋๊น์ง ๋ฐ๋ณตํด์ ์
๋ ฅ๋ฐ๋๋ค`๋ผ๋ ์ข ๋ ๋ช
ํํ ์ด๋ฆ์ ์ฌ์ฉํ๋ ๋ถ๋ถ์ ๋ํด์๋ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
e.g.)`retryInputForValidVisitDate`, `returyInputForValidOrders` |
@@ -0,0 +1,70 @@
+package christmas.service;
+
+import static christmas.model.constant.DiscountConstant.MIN_DISCOUNT_SERVICE;
+import static christmas.model.constant.DiscountConstant.NO_DISCOUNT;
+import static christmas.model.constant.PromotionConstant.CHRISTMAS_DISCOUNT;
+import static christmas.model.constant.PromotionConstant.GIFT_EVENT;
+import static christmas.model.constant.PromotionConstant.SPECIAL_DISCOUNT;
+import static christmas.model.constant.PromotionConstant.WEEKDAY_DISCOUNT;
+import static christmas.model.constant.PromotionConstant.WEEKEND_DISCOUNT;
+
+import christmas.model.Date;
+import christmas.model.MenuCount;
+import christmas.model.constant.EventBadge;
+import christmas.model.constant.PromotionConstant;
+import christmas.model.strategy.BadgeStrategy;
+import christmas.model.strategy.DiscountStrategy;
+import java.util.EnumMap;
+
+public class PromotionService {
+ private final DiscountStrategy discountStrategy;
+ private final BadgeStrategy badgeStrategy;
+
+
+ public PromotionService(DiscountStrategy discountStrategy, BadgeStrategy badgeStrategy) {
+ this.discountStrategy = discountStrategy;
+ this.badgeStrategy = badgeStrategy;
+ }
+
+ public boolean canGetDiscount(MenuCount menuCount) {
+ return menuCount.calculateTotalAmount() >= MIN_DISCOUNT_SERVICE.getAmount();
+ }
+
+ public int calculatePromotionAmount(MenuCount menuCount, Date date) {
+ if (canGetDiscount(menuCount)) {
+ return calaulateTotalDiscountAmount(menuCount, date)
+ + discountStrategy.giftEventDiscount(menuCount);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ public int calaulateTotalDiscountAmount(MenuCount menuCount, Date date) {
+ if (canGetDiscount(menuCount)) {
+ return discountStrategy.christmasDiscount(date)
+ + discountStrategy.weekdayDiscount(menuCount, date)
+ + discountStrategy.specialDayDiscount(date)
+ + discountStrategy.weekendDiscount(menuCount, date);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ public EnumMap<PromotionConstant, Integer> calculatePromotionStatus(MenuCount menuCount, Date date) {
+ EnumMap<PromotionConstant, Integer> promotionStatus = new EnumMap<>(PromotionConstant.class);
+ if (canGetDiscount(menuCount)) {
+ promotionStatus.put(CHRISTMAS_DISCOUNT, discountStrategy.christmasDiscount(date));
+ promotionStatus.put(WEEKDAY_DISCOUNT, discountStrategy.weekdayDiscount(menuCount, date));
+ promotionStatus.put(WEEKEND_DISCOUNT, discountStrategy.weekendDiscount(menuCount, date));
+ promotionStatus.put(SPECIAL_DISCOUNT, discountStrategy.specialDayDiscount(date));
+ promotionStatus.put(GIFT_EVENT, discountStrategy.giftEventDiscount(menuCount));
+ return promotionStatus;
+ }
+ return promotionStatus;
+ }
+
+ public String calculateBadgeStatus(MenuCount menuCount, Date date) {
+ int promotionAmount = calculatePromotionAmount(menuCount, date);
+ EventBadge badge = badgeStrategy.calculateBadgeGrade(promotionAmount);
+ return badge.getName();
+ }
+
+} | Java | ์ด๋ฒคํธ๊ฐ ์ ๊ท๋ก ๋์
๋๊ฑฐ๋ ์ญ์ ๋๋ ๊ฒฝ์ฐ ์๋น์ค์ ์๋ ๊ณ์ฐ ๊ธฐ๋ฅ์ ์ํฅ์ ์ฃผ๋ ๊ฒ ๊ฐ์ต๋๋ค. ์์กด๋๋ฅผ ๋ฎ์ถ๋ ๊ฒ์ ๋ํด์๋ ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,15 @@
+package christmas.model.strategy;
+
+import christmas.model.constant.EventBadge;
+
+public class WootecoBadgeStrategy implements BadgeStrategy {
+ @Override
+ public EventBadge calculateBadgeGrade(int promotionAmount) {
+ for (EventBadge badge : EventBadge.values()){
+ if (promotionAmount >= badge.getBaseAmount()){
+ return badge;
+ }
+ }
+ return EventBadge.NOTHING;
+ }
+} | Java | ํ์ฌ๋ EventBadge๊ฐ ๊ธฐ์ค ๊ธ์ก์ด ๋์ ์์๋๋ก ๊ตฌํ๋์ด ์์ง๋ง ๋ง์ผ ๋ค๋ฅธ ์ฌ๋์ด ์์๋ฅผ ๋ฌด์ํ๊ณ ๋ฑ์ง๋ฅผ ์ถ๊ฐํ๋ ๊ฒฝ์ฐ๋ ๊ณ ๋ คํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,115 @@
+package christmas.controller;
+
+import static christmas.model.constant.DiscountConstant.GIFT_EVENT_THRESHOLD;
+
+import christmas.model.Date;
+import christmas.model.MenuCount;
+import christmas.model.constant.PromotionConstant;
+import christmas.model.strategy.BadgeStrategy;
+import christmas.model.strategy.DiscountStrategy;
+import christmas.model.strategy.WootecoBadgeStrategy;
+import christmas.model.strategy.WootecoDiscountStrategy;
+import christmas.service.PromotionService;
+import christmas.util.Parser;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.function.Supplier;
+
+public class PromotionController {
+ private final PromotionService promotion;
+ private final DiscountStrategy discountStrategy = new WootecoDiscountStrategy();
+ private final BadgeStrategy badgeStrategy = new WootecoBadgeStrategy();
+
+ public PromotionController() {
+ this.promotion = new PromotionService(discountStrategy, badgeStrategy);
+ }
+
+ public void run() {
+ InputView.printGreetingMessage();
+ Date date = getDate();
+ MenuCount menuCount = getMenu();
+ displayEventGuideMessage(date);
+ displayMenuAndOrderAmount(menuCount);
+ displayPromotionResult(menuCount, date);
+ }
+
+ private Date getDate() {
+ return executeWithExceptionHandle(() -> {
+ int inputDate = InputView.readDate();
+ return Date.of(inputDate);
+ });
+ }
+
+ private MenuCount getMenu() {
+ return executeWithExceptionHandle(() -> {
+ String input = InputView.readMenu();
+ Map<String, Integer> parsedMenu = Parser.parseMenuCount(input);
+ return new MenuCount(parsedMenu);
+ });
+ }
+
+ private void displayMenuAndOrderAmount(MenuCount menuCount) {
+ displayMenuInfo(menuCount);
+ displayTotalOrderAmount(menuCount);
+ }
+
+ private void displayPromotionResult(MenuCount menuCount, Date date) {
+ displayGiftEvent(menuCount);
+ displayPromotionEvent(menuCount, date);
+ displayTotalPromotionAmount(menuCount, date);
+ displayExpectedPaymentAmount(menuCount, date);
+ displayEventBadge(menuCount, date);
+ }
+
+ private void displayEventGuideMessage(Date date) {
+ OutputView.printEventGuideMessage(date.getValue());
+ }
+
+
+ private void displayMenuInfo(MenuCount menuCount) {
+ OutputView.printOrderedMenu(menuCount);
+ }
+
+ private void displayTotalOrderAmount(MenuCount menuCount) {
+ OutputView.printTotalOrderAmount(menuCount.calculateTotalAmount());
+ }
+
+ private void displayGiftEvent(MenuCount menuCount) {
+ boolean canGiveGift = menuCount.calculateTotalAmount() >= GIFT_EVENT_THRESHOLD.getAmount();
+ OutputView.printGiftEvent(canGiveGift);
+ }
+
+ private void displayPromotionEvent(MenuCount menuCount, Date date) {
+ EnumMap<PromotionConstant, Integer> promotionStatus = promotion.calculatePromotionStatus(menuCount, date);
+ OutputView.printPromotionStatus(promotionStatus);
+ }
+
+ private void displayTotalPromotionAmount(MenuCount menuCount, Date date) {
+ int totalPromotionAmount = promotion.calculatePromotionAmount(menuCount, date);
+ OutputView.printPromotionAmount(totalPromotionAmount);
+ }
+
+ private void displayExpectedPaymentAmount(MenuCount menuCount, Date date) {
+ int expectedPayment =
+ menuCount.calculateTotalAmount() - promotion.calaulateTotalDiscountAmount(menuCount, date);
+ OutputView.printExpectedPaymentAmount(expectedPayment);
+ }
+
+ private void displayEventBadge(MenuCount menuCount, Date date) {
+ String badgeName = promotion.calculateBadgeStatus(menuCount, date);
+ OutputView.printEventBadge(badgeName);
+ }
+
+ private static <T> T executeWithExceptionHandle(final Supplier<T> supplier) {
+ while (true) {
+ try {
+ return supplier.get();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+} | Java | ํจ์ํ ์ธํฐํ์ด์ค๋ฅผ ์ ํ์ฉํ์ ๊ฒ ๊ฐ์ต๋๋ค. ์ข์ ์ง์์ ๋ฐฐ์๊ฐ๋๋ค. |
@@ -0,0 +1,115 @@
+package christmas.controller;
+
+import static christmas.model.constant.DiscountConstant.GIFT_EVENT_THRESHOLD;
+
+import christmas.model.Date;
+import christmas.model.MenuCount;
+import christmas.model.constant.PromotionConstant;
+import christmas.model.strategy.BadgeStrategy;
+import christmas.model.strategy.DiscountStrategy;
+import christmas.model.strategy.WootecoBadgeStrategy;
+import christmas.model.strategy.WootecoDiscountStrategy;
+import christmas.service.PromotionService;
+import christmas.util.Parser;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.function.Supplier;
+
+public class PromotionController {
+ private final PromotionService promotion;
+ private final DiscountStrategy discountStrategy = new WootecoDiscountStrategy();
+ private final BadgeStrategy badgeStrategy = new WootecoBadgeStrategy();
+
+ public PromotionController() {
+ this.promotion = new PromotionService(discountStrategy, badgeStrategy);
+ }
+
+ public void run() {
+ InputView.printGreetingMessage();
+ Date date = getDate();
+ MenuCount menuCount = getMenu();
+ displayEventGuideMessage(date);
+ displayMenuAndOrderAmount(menuCount);
+ displayPromotionResult(menuCount, date);
+ }
+
+ private Date getDate() {
+ return executeWithExceptionHandle(() -> {
+ int inputDate = InputView.readDate();
+ return Date.of(inputDate);
+ });
+ }
+
+ private MenuCount getMenu() {
+ return executeWithExceptionHandle(() -> {
+ String input = InputView.readMenu();
+ Map<String, Integer> parsedMenu = Parser.parseMenuCount(input);
+ return new MenuCount(parsedMenu);
+ });
+ }
+
+ private void displayMenuAndOrderAmount(MenuCount menuCount) {
+ displayMenuInfo(menuCount);
+ displayTotalOrderAmount(menuCount);
+ }
+
+ private void displayPromotionResult(MenuCount menuCount, Date date) {
+ displayGiftEvent(menuCount);
+ displayPromotionEvent(menuCount, date);
+ displayTotalPromotionAmount(menuCount, date);
+ displayExpectedPaymentAmount(menuCount, date);
+ displayEventBadge(menuCount, date);
+ }
+
+ private void displayEventGuideMessage(Date date) {
+ OutputView.printEventGuideMessage(date.getValue());
+ }
+
+
+ private void displayMenuInfo(MenuCount menuCount) {
+ OutputView.printOrderedMenu(menuCount);
+ }
+
+ private void displayTotalOrderAmount(MenuCount menuCount) {
+ OutputView.printTotalOrderAmount(menuCount.calculateTotalAmount());
+ }
+
+ private void displayGiftEvent(MenuCount menuCount) {
+ boolean canGiveGift = menuCount.calculateTotalAmount() >= GIFT_EVENT_THRESHOLD.getAmount();
+ OutputView.printGiftEvent(canGiveGift);
+ }
+
+ private void displayPromotionEvent(MenuCount menuCount, Date date) {
+ EnumMap<PromotionConstant, Integer> promotionStatus = promotion.calculatePromotionStatus(menuCount, date);
+ OutputView.printPromotionStatus(promotionStatus);
+ }
+
+ private void displayTotalPromotionAmount(MenuCount menuCount, Date date) {
+ int totalPromotionAmount = promotion.calculatePromotionAmount(menuCount, date);
+ OutputView.printPromotionAmount(totalPromotionAmount);
+ }
+
+ private void displayExpectedPaymentAmount(MenuCount menuCount, Date date) {
+ int expectedPayment =
+ menuCount.calculateTotalAmount() - promotion.calaulateTotalDiscountAmount(menuCount, date);
+ OutputView.printExpectedPaymentAmount(expectedPayment);
+ }
+
+ private void displayEventBadge(MenuCount menuCount, Date date) {
+ String badgeName = promotion.calculateBadgeStatus(menuCount, date);
+ OutputView.printEventBadge(badgeName);
+ }
+
+ private static <T> T executeWithExceptionHandle(final Supplier<T> supplier) {
+ while (true) {
+ try {
+ return supplier.get();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+} | Java | ํ๋ ์ฃผ์
๋ณด๋ค, ์์ฑ์ ์ฃผ์
์ ํ์ฉํด๋ณด๋ฉด ๋ ์ ์ฐํ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,115 @@
+package christmas.controller;
+
+import static christmas.model.constant.DiscountConstant.GIFT_EVENT_THRESHOLD;
+
+import christmas.model.Date;
+import christmas.model.MenuCount;
+import christmas.model.constant.PromotionConstant;
+import christmas.model.strategy.BadgeStrategy;
+import christmas.model.strategy.DiscountStrategy;
+import christmas.model.strategy.WootecoBadgeStrategy;
+import christmas.model.strategy.WootecoDiscountStrategy;
+import christmas.service.PromotionService;
+import christmas.util.Parser;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.function.Supplier;
+
+public class PromotionController {
+ private final PromotionService promotion;
+ private final DiscountStrategy discountStrategy = new WootecoDiscountStrategy();
+ private final BadgeStrategy badgeStrategy = new WootecoBadgeStrategy();
+
+ public PromotionController() {
+ this.promotion = new PromotionService(discountStrategy, badgeStrategy);
+ }
+
+ public void run() {
+ InputView.printGreetingMessage();
+ Date date = getDate();
+ MenuCount menuCount = getMenu();
+ displayEventGuideMessage(date);
+ displayMenuAndOrderAmount(menuCount);
+ displayPromotionResult(menuCount, date);
+ }
+
+ private Date getDate() {
+ return executeWithExceptionHandle(() -> {
+ int inputDate = InputView.readDate();
+ return Date.of(inputDate);
+ });
+ }
+
+ private MenuCount getMenu() {
+ return executeWithExceptionHandle(() -> {
+ String input = InputView.readMenu();
+ Map<String, Integer> parsedMenu = Parser.parseMenuCount(input);
+ return new MenuCount(parsedMenu);
+ });
+ }
+
+ private void displayMenuAndOrderAmount(MenuCount menuCount) {
+ displayMenuInfo(menuCount);
+ displayTotalOrderAmount(menuCount);
+ }
+
+ private void displayPromotionResult(MenuCount menuCount, Date date) {
+ displayGiftEvent(menuCount);
+ displayPromotionEvent(menuCount, date);
+ displayTotalPromotionAmount(menuCount, date);
+ displayExpectedPaymentAmount(menuCount, date);
+ displayEventBadge(menuCount, date);
+ }
+
+ private void displayEventGuideMessage(Date date) {
+ OutputView.printEventGuideMessage(date.getValue());
+ }
+
+
+ private void displayMenuInfo(MenuCount menuCount) {
+ OutputView.printOrderedMenu(menuCount);
+ }
+
+ private void displayTotalOrderAmount(MenuCount menuCount) {
+ OutputView.printTotalOrderAmount(menuCount.calculateTotalAmount());
+ }
+
+ private void displayGiftEvent(MenuCount menuCount) {
+ boolean canGiveGift = menuCount.calculateTotalAmount() >= GIFT_EVENT_THRESHOLD.getAmount();
+ OutputView.printGiftEvent(canGiveGift);
+ }
+
+ private void displayPromotionEvent(MenuCount menuCount, Date date) {
+ EnumMap<PromotionConstant, Integer> promotionStatus = promotion.calculatePromotionStatus(menuCount, date);
+ OutputView.printPromotionStatus(promotionStatus);
+ }
+
+ private void displayTotalPromotionAmount(MenuCount menuCount, Date date) {
+ int totalPromotionAmount = promotion.calculatePromotionAmount(menuCount, date);
+ OutputView.printPromotionAmount(totalPromotionAmount);
+ }
+
+ private void displayExpectedPaymentAmount(MenuCount menuCount, Date date) {
+ int expectedPayment =
+ menuCount.calculateTotalAmount() - promotion.calaulateTotalDiscountAmount(menuCount, date);
+ OutputView.printExpectedPaymentAmount(expectedPayment);
+ }
+
+ private void displayEventBadge(MenuCount menuCount, Date date) {
+ String badgeName = promotion.calculateBadgeStatus(menuCount, date);
+ OutputView.printEventBadge(badgeName);
+ }
+
+ private static <T> T executeWithExceptionHandle(final Supplier<T> supplier) {
+ while (true) {
+ try {
+ return supplier.get();
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+} | Java | ํด๋น ํด๋์ค๊ฐ static์ผ๋ก ์์ฑํ์ ์ด์ ๊ฐ ์์๊น์?
static์ด ์๋์ด๋ ๋ฌธ์ ๊ฐ ์์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,29 @@
+package christmas.view;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.util.Parser;
+import christmas.validator.MenuValidator;
+
+public class InputView {
+
+ public static void printGreetingMessage() {
+ System.out.println(ViewMessage.GREETING.getMessage());
+ }
+
+
+ public static int readDate() {
+ System.out.println(ViewMessage.DATE.getMessage());
+
+ String input = Console.readLine();
+ return Parser.parseDate(input);
+ }
+
+
+ public static String readMenu() {
+ System.out.println(ViewMessage.MENU.getMessage());
+ String input = Console.readLine();
+ MenuValidator.validateMenuInputFormat(input);
+ return input;
+ }
+
+} | Java | static ๋ฉ์๋๋ฐ์ ์๋ ์ ํธ๋ฆฌํฐ ํด๋์ค์ ๊ฒฝ์ฐ, ์ธ์คํด์คํ๊ฐ ํ์ ์๊ธฐ ๋๋ฌธ์ ์์ฑ์๋ฅผ private์ผ๋ก ํ์ฌ ์ธ์คํด์คํ๋ฅผ ๋ง์์ฃผ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค
https://rules.sonarsource.com/java/RSPEC-1118/ |
@@ -0,0 +1,44 @@
+package christmas.model.constant;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public enum DateConstant {
+ MIN_DATE(1),
+ MAX_DATE(31),
+ XMAS(25);
+
+ public static final Set<Integer> WEEKDAYS = new HashSet<>();
+ public static final Set<Integer> WEEKENDS = new HashSet<>();
+ public static final Set<Integer> SPECIAL_DAYS = new HashSet<>(Arrays.asList(
+ 3, 10, 17, 24, 25, 31
+ ));
+
+ static {
+ LocalDate start = LocalDate.of(2023, 12, MIN_DATE.date);
+ LocalDate end = LocalDate.of(2023, 12, MAX_DATE.date);
+
+ for (LocalDate date = start; !date.isAfter(end); date = date.plusDays(1)) {
+ DayOfWeek day = date.getDayOfWeek();
+ if (day == DayOfWeek.SATURDAY || day == DayOfWeek.FRIDAY) {
+ WEEKENDS.add(date.getDayOfMonth());
+ continue;
+ }
+ WEEKDAYS.add(date.getDayOfMonth());
+ }
+ }
+
+ private final int date;
+
+ DateConstant(int date) {
+ this.date = date;
+ }
+
+ public int getDate() {
+ return date;
+ }
+
+} | Java | ```suggestion
public static final Set<Integer> SPECIAL_DAYS = Set.of(3, 10, 17, 24, 25, 31);
```
`Set.of` ๋ฅผ ํ์ฉํด์ ๋ ์ฝ๋๋ฅผ ๊ฐ๊ฒฐํ๊ฒ ๋ง๋ค ์ ์์ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,44 @@
+package christmas.model.constant;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public enum DateConstant {
+ MIN_DATE(1),
+ MAX_DATE(31),
+ XMAS(25);
+
+ public static final Set<Integer> WEEKDAYS = new HashSet<>();
+ public static final Set<Integer> WEEKENDS = new HashSet<>();
+ public static final Set<Integer> SPECIAL_DAYS = new HashSet<>(Arrays.asList(
+ 3, 10, 17, 24, 25, 31
+ ));
+
+ static {
+ LocalDate start = LocalDate.of(2023, 12, MIN_DATE.date);
+ LocalDate end = LocalDate.of(2023, 12, MAX_DATE.date);
+
+ for (LocalDate date = start; !date.isAfter(end); date = date.plusDays(1)) {
+ DayOfWeek day = date.getDayOfWeek();
+ if (day == DayOfWeek.SATURDAY || day == DayOfWeek.FRIDAY) {
+ WEEKENDS.add(date.getDayOfMonth());
+ continue;
+ }
+ WEEKDAYS.add(date.getDayOfMonth());
+ }
+ }
+
+ private final int date;
+
+ DateConstant(int date) {
+ this.date = date;
+ }
+
+ public int getDate() {
+ return date;
+ }
+
+} | Java | SPECIAL_DAYS๊ฐ public์ผ๋ก ์ด๋ ค์์ผ๋ฉด์ ๋ถ๋ณ์ด ์๋๋ฏ๋ก (HashMap) ์ธ๋ถ์์ ๊ฐ์ ์์ ํ๋ ํดํน์ด ๊ฐ๋ฅํ ๊ฒ์ผ๋ก ๋ณด์
๋๋ค!
์์์
๋๋ค
```java
DateConstant.SPECIAL_DAYS.add(-1);
``` |
@@ -0,0 +1,40 @@
+package christmas.exception;
+
+public class CustomException extends IllegalArgumentException {
+ private static final String MENU_ERROR_MESSAGE = "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String DATE_ERROR_MESSAGE = "[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ public CustomException(String s) {
+ super(s);
+ }
+
+ @Override
+ public synchronized Throwable fillInStackTrace(){
+ return this;
+ }
+
+ public static final CustomException DATE_NOT_INTEGER_EXCEPTION =
+ new CustomException(DATE_ERROR_MESSAGE);
+
+ public static final CustomException DATE_RANGE_EXCEPTION =
+ new CustomException(DATE_ERROR_MESSAGE);
+
+ public static final CustomException DUPLICATE_MENU_EXCEPTION =
+ new CustomException(MENU_ERROR_MESSAGE);
+
+ public static final CustomException MENU_COUNT_ZERO_EXCEPTION =
+ new CustomException(MENU_ERROR_MESSAGE);
+
+ public static final CustomException MENU_FORMAT_EXCEPTION =
+ new CustomException(MENU_ERROR_MESSAGE);
+
+ public static final CustomException MENU_NOT_FOUND_EXCEPTION =
+ new CustomException(MENU_ERROR_MESSAGE);
+
+ public static final CustomException ONLY_DRINK_EXCEPTION =
+ new CustomException(MENU_ERROR_MESSAGE);
+
+ public static final CustomException MENU_AMOUNT_OVER_LIMIT_EXCEPTION =
+ new CustomException(MENU_ERROR_MESSAGE);
+
+
+} | Java | ์ปค์คํ
์ต์
์
์ด๋ผ๋ ์ด๋ฆ๋ณด๋ค, ์กฐ๊ธ ๋ ์์ธ์ ์ด์ ๋ฑ์ ์๋ฏธ๊ฐ ๋๋ฌ๋๋ ์ด๋ฆ์ด๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,56 @@
+package christmas.model.constant;
+
+import java.util.Arrays;
+
+public enum Menu {
+ SOUP("์ ํผํ์ด์ ", "์์ก์ด์ํ", 6000),
+ TAPAS("์ ํผํ์ด์ ", "ํํ์ค", 5500),
+ SALAD("์ ํผํ์ด์ ", "์์ ์๋ฌ๋", 8000),
+ STEAK("๋ฉ์ธ", "ํฐ๋ณธ์คํ
์ดํฌ", 55000),
+ BBQ("๋ฉ์ธ", "๋ฐ๋นํ๋ฆฝ", 54000),
+ SEAFOOD_PASTA("๋ฉ์ธ", "ํด์ฐ๋ฌผํ์คํ", 35000),
+ XMAS_PASTA("๋ฉ์ธ", "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ CHOCO_CAKE("๋์ ํธ", "์ด์ฝ์ผ์ดํฌ", 15000),
+ ICECREAM("๋์ ํธ", "์์ด์คํฌ๋ฆผ", 5000),
+ ZEROCOKE("์๋ฃ", "์ ๋ก์ฝ๋ผ", 3000),
+ REDWINE("์๋ฃ", "๋ ๋์์ธ", 60000),
+ CHAMPAGNE("์๋ฃ", "์ดํ์ธ", 25000);
+
+
+ private final String category;
+ private final String name;
+ private final int price;
+
+ Menu(String category, String name, int price) {
+ this.category = category;
+ this.name = name;
+ this.price = price;
+ }
+
+ public static Menu of(String name) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menu.getName().equals(name))
+ .findFirst()
+ .orElse(null);
+ }
+
+ public boolean isMainCategory() {
+ return "๋ฉ์ธ".equals(this.category);
+ }
+
+ public boolean isDessertCategory() {
+ return "๋์ ํธ".equals(this.category);
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+} | Java | String ๋ฆฌํฐ๋ด๋ก "๋ฉ์ธ"๊ณผ ๊ฐ์ด ์์ฑํ๋ ๊ฒ๋ณด๋ค ๋ฉ๋ด์ ์นดํ
๊ณ ๋ฆฌ๋ enum์ผ๋ก ๊ด๋ฆฌํ๋ฉด ์กฐ๊ธ ๋ ์ฉ์ดํ์ง ์์๊น์? |
@@ -0,0 +1,52 @@
+package christmas.model;
+
+import static christmas.exception.CustomException.DATE_RANGE_EXCEPTION;
+import static christmas.model.constant.DateConstant.SPECIAL_DAYS;
+import static christmas.model.constant.DateConstant.WEEKDAYS;
+import static christmas.model.constant.DateConstant.WEEKENDS;
+import static christmas.model.constant.DateConstant.XMAS;
+
+import christmas.model.constant.DateConstant;
+
+public class Date {
+ private final int MIN_DATE = DateConstant.MIN_DATE.getDate();
+ private final int MAX_DATE = DateConstant.MAX_DATE.getDate();
+ private final int date;
+
+ private Date(int date) {
+ validateDateRange(date);
+ this.date = date;
+ }
+
+ public static Date of(int date) {
+ return new Date(date);
+ }
+
+ public int getValue() {
+ return date;
+ }
+
+ private void validateDateRange(int date) {
+ if (date < MIN_DATE || date > MAX_DATE) {
+ throw DATE_RANGE_EXCEPTION;
+ }
+ }
+
+ public boolean isWeekday() {
+ return WEEKDAYS.contains(date);
+ }
+
+ public boolean isWeekend() {
+ return WEEKENDS.contains(date);
+ }
+
+ public boolean isBeforeXmas() {
+ return XMAS.getDate() >= date;
+ }
+
+ public boolean isSpecialDay() {
+ return SPECIAL_DAYS.contains(date);
+ }
+
+
+} | Java | ์๋ฐ์ ๋นํธ์ธ ๊ฐ์ฒด์ธ [Date](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html)์ ํผ๋์ ์ฌ์ง๊ฐ ์์ ๊ฒ ๊ฐ์ต๋๋ค..!
(์ผ๋จ ์ ํท๊ฐ๋ ธ์ด์ ๐ญ) |
@@ -0,0 +1,22 @@
+package christmas.model.constant;
+
+public enum PromotionConstant {
+
+ CHRISTMAS_DISCOUNT("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ"),
+ WEEKDAY_DISCOUNT("ํ์ผ ํ ์ธ"),
+ WEEKEND_DISCOUNT("์ฃผ๋ง ํ ์ธ"),
+ SPECIAL_DISCOUNT("ํน๋ณ ํ ์ธ"),
+ GIFT_EVENT("์ฆ์ ์ด๋ฒคํธ");
+
+ private String name;
+
+ PromotionConstant(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+
+} | Java | private final๋ก ๋ง๋ค ์ ์์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,75 @@
+package christmas.model.strategy;
+
+import static christmas.model.constant.DiscountConstant.CHRISTMAS_START_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.DISCOUNT_INCREMENT;
+import static christmas.model.constant.DiscountConstant.FIXED_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.GIFT_EVENT_THRESHOLD;
+import static christmas.model.constant.DiscountConstant.NO_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.SPECIAL_DAY_DISCOUNT;
+
+import christmas.model.Date;
+import christmas.model.constant.Menu;
+import christmas.model.MenuCount;
+
+public class WootecoDiscountStrategy implements DiscountStrategy {
+
+ @Override
+ public int christmasDiscount(Date date) {
+ if (date.isBeforeXmas()) {
+ return (CHRISTMAS_START_DISCOUNT.getAmount() + (date.getValue() - 1)
+ * DISCOUNT_INCREMENT.getAmount());
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int weekendDiscount(MenuCount menuCount, Date date) {
+ if (date.isWeekend()) {
+ return calculateWeekendDiscountAmount(menuCount);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int weekdayDiscount(MenuCount menuCount, Date date) {
+ if (date.isWeekday()) {
+ return calculateWeekdayDiscountAmount(menuCount);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int specialDayDiscount(Date date) {
+ if (date.isSpecialDay()) {
+ return SPECIAL_DAY_DISCOUNT.getAmount();
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int giftEventDiscount(MenuCount menuCount) {
+ if (menuCount.calculateTotalAmount() >= GIFT_EVENT_THRESHOLD.getAmount()) {
+ return Menu.CHAMPAGNE.getPrice();
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+
+ private int calculateWeekendDiscountAmount(MenuCount menuCount) {
+ return menuCount.getValue()
+ .entrySet()
+ .stream()
+ .filter(entry -> entry.getKey().isMainCategory())
+ .mapToInt(entry -> FIXED_DISCOUNT.getAmount() * entry.getValue())
+ .sum();
+ }
+
+ private int calculateWeekdayDiscountAmount(MenuCount menuCount) {
+ return menuCount.getValue()
+ .entrySet()
+ .stream()
+ .filter(entry -> entry.getKey().isDessertCategory())
+ .mapToInt(entry -> FIXED_DISCOUNT.getAmount() * entry.getValue())
+ .sum();
+ }
+} | Java | ์ฌ๋ฌ ํ ์ธ ์ ๋ต์ ํ ํด๋์ค์ ๋ชฐ์๋ฃ๊ธฐ๋ณด๋ค๋ ๊ฐ๊ฐ ํด๋์ค๋ก ๋ถ๋ฅํ ์ ์์ ๊ฒ ๊ฐ์์
+ ๊ทธ๋ฆฌ๊ณ ๊ทธ๋ ๊ฒ ๋๋์ด์, ์ฐํ
์ฝ ํ ์ธ ์ ๋ต์ด๋ผ๋ ์ด๋ฆ๋ณด๋ค๋ ๋ฌด์จ ํ ์ธ ์ ๋ต์ธ์ง์ ๋ํ ์๋ฏธ๊ฐ ๋๋ฌ๋๋ ์ด๋ฆ์ด๋ฉด ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,75 @@
+package christmas.model.strategy;
+
+import static christmas.model.constant.DiscountConstant.CHRISTMAS_START_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.DISCOUNT_INCREMENT;
+import static christmas.model.constant.DiscountConstant.FIXED_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.GIFT_EVENT_THRESHOLD;
+import static christmas.model.constant.DiscountConstant.NO_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.SPECIAL_DAY_DISCOUNT;
+
+import christmas.model.Date;
+import christmas.model.constant.Menu;
+import christmas.model.MenuCount;
+
+public class WootecoDiscountStrategy implements DiscountStrategy {
+
+ @Override
+ public int christmasDiscount(Date date) {
+ if (date.isBeforeXmas()) {
+ return (CHRISTMAS_START_DISCOUNT.getAmount() + (date.getValue() - 1)
+ * DISCOUNT_INCREMENT.getAmount());
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int weekendDiscount(MenuCount menuCount, Date date) {
+ if (date.isWeekend()) {
+ return calculateWeekendDiscountAmount(menuCount);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int weekdayDiscount(MenuCount menuCount, Date date) {
+ if (date.isWeekday()) {
+ return calculateWeekdayDiscountAmount(menuCount);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int specialDayDiscount(Date date) {
+ if (date.isSpecialDay()) {
+ return SPECIAL_DAY_DISCOUNT.getAmount();
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int giftEventDiscount(MenuCount menuCount) {
+ if (menuCount.calculateTotalAmount() >= GIFT_EVENT_THRESHOLD.getAmount()) {
+ return Menu.CHAMPAGNE.getPrice();
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+
+ private int calculateWeekendDiscountAmount(MenuCount menuCount) {
+ return menuCount.getValue()
+ .entrySet()
+ .stream()
+ .filter(entry -> entry.getKey().isMainCategory())
+ .mapToInt(entry -> FIXED_DISCOUNT.getAmount() * entry.getValue())
+ .sum();
+ }
+
+ private int calculateWeekdayDiscountAmount(MenuCount menuCount) {
+ return menuCount.getValue()
+ .entrySet()
+ .stream()
+ .filter(entry -> entry.getKey().isDessertCategory())
+ .mapToInt(entry -> FIXED_DISCOUNT.getAmount() * entry.getValue())
+ .sum();
+ }
+} | Java | ํฌ๋ฆฌ์ค๋ง์ค ํ ์ธ ์ ๋ต์์ ๋ณ๋์ด ์๊ธฐ๊ฒ ๋๋ค๋ฉด (์: ์์ํ ์ธ์ก์ด 1000์์์ 2000์์ผ๋ก ๋ณ๊ฒฝ), ํด๋น ๋ณ๊ฒฝ์ฌํญ์ ๋ํ ์ฌํ๊ฐ ํ ์ธ ์ ๋ต๋ง ์ฌํ๋ฅผ ๋ฏธ์ณ์ผ ํ ๊ฒ ๊ฐ์๋ฐ enum์ธ DiscountConstant์ ์ํฅ์ ๋ฏธ์น๊ฒ ๋ผ์.
๋ง์ฐฌ๊ฐ์ง๋ก ์ฃผ๋ง ํ ์ธ ์ ๋ต์๋ ๋ณ๋์ด ์๊ธด๋ค๋ฉด DiscountConstant์ด ๋ฐ๋์ด์ผ ํ๋๋ฐ, ์ด๋ `ํด๋์ค๊ฐ ๋ณ๊ฒฝ๋ ์ด์ ๋ ํ ๊ฐ์ง์ฌ์ผ ํ๋ค`๋ผ๋ SRP์์น์ ์๋ฐํ๋ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,75 @@
+package christmas.model.strategy;
+
+import static christmas.model.constant.DiscountConstant.CHRISTMAS_START_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.DISCOUNT_INCREMENT;
+import static christmas.model.constant.DiscountConstant.FIXED_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.GIFT_EVENT_THRESHOLD;
+import static christmas.model.constant.DiscountConstant.NO_DISCOUNT;
+import static christmas.model.constant.DiscountConstant.SPECIAL_DAY_DISCOUNT;
+
+import christmas.model.Date;
+import christmas.model.constant.Menu;
+import christmas.model.MenuCount;
+
+public class WootecoDiscountStrategy implements DiscountStrategy {
+
+ @Override
+ public int christmasDiscount(Date date) {
+ if (date.isBeforeXmas()) {
+ return (CHRISTMAS_START_DISCOUNT.getAmount() + (date.getValue() - 1)
+ * DISCOUNT_INCREMENT.getAmount());
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int weekendDiscount(MenuCount menuCount, Date date) {
+ if (date.isWeekend()) {
+ return calculateWeekendDiscountAmount(menuCount);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int weekdayDiscount(MenuCount menuCount, Date date) {
+ if (date.isWeekday()) {
+ return calculateWeekdayDiscountAmount(menuCount);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int specialDayDiscount(Date date) {
+ if (date.isSpecialDay()) {
+ return SPECIAL_DAY_DISCOUNT.getAmount();
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ @Override
+ public int giftEventDiscount(MenuCount menuCount) {
+ if (menuCount.calculateTotalAmount() >= GIFT_EVENT_THRESHOLD.getAmount()) {
+ return Menu.CHAMPAGNE.getPrice();
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+
+ private int calculateWeekendDiscountAmount(MenuCount menuCount) {
+ return menuCount.getValue()
+ .entrySet()
+ .stream()
+ .filter(entry -> entry.getKey().isMainCategory())
+ .mapToInt(entry -> FIXED_DISCOUNT.getAmount() * entry.getValue())
+ .sum();
+ }
+
+ private int calculateWeekdayDiscountAmount(MenuCount menuCount) {
+ return menuCount.getValue()
+ .entrySet()
+ .stream()
+ .filter(entry -> entry.getKey().isDessertCategory())
+ .mapToInt(entry -> FIXED_DISCOUNT.getAmount() * entry.getValue())
+ .sum();
+ }
+} | Java | ๊ทธ๋ฐ ์ด์ ์์, CHRISTMAS_START_DISCOUNT๋ enum์ผ๋ก publicํ๊ฒ ์๋ฌด ํด๋์ค์์๋ ๊ณต๊ฐ๋ ํ์๊ฐ ์์ด, ํด๋น ํ ์ธ ์ ์ฑ
ํด๋์ค์์ `private static final`๊ณผ ๊ฐ์ด ๊ด๋ฆฌํ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์์
(ํ ์ธ ์ ์ฑ
์ด ๋ฐ๋๋๋ผ๋ ํ ์ธ ์ ์ฑ
ํด๋์ค๋ง ์ํฅ์ ๋ฐ๊ฒ ๋๊ฒ ์ฃ ) |
@@ -0,0 +1,70 @@
+package christmas.service;
+
+import static christmas.model.constant.DiscountConstant.MIN_DISCOUNT_SERVICE;
+import static christmas.model.constant.DiscountConstant.NO_DISCOUNT;
+import static christmas.model.constant.PromotionConstant.CHRISTMAS_DISCOUNT;
+import static christmas.model.constant.PromotionConstant.GIFT_EVENT;
+import static christmas.model.constant.PromotionConstant.SPECIAL_DISCOUNT;
+import static christmas.model.constant.PromotionConstant.WEEKDAY_DISCOUNT;
+import static christmas.model.constant.PromotionConstant.WEEKEND_DISCOUNT;
+
+import christmas.model.Date;
+import christmas.model.MenuCount;
+import christmas.model.constant.EventBadge;
+import christmas.model.constant.PromotionConstant;
+import christmas.model.strategy.BadgeStrategy;
+import christmas.model.strategy.DiscountStrategy;
+import java.util.EnumMap;
+
+public class PromotionService {
+ private final DiscountStrategy discountStrategy;
+ private final BadgeStrategy badgeStrategy;
+
+
+ public PromotionService(DiscountStrategy discountStrategy, BadgeStrategy badgeStrategy) {
+ this.discountStrategy = discountStrategy;
+ this.badgeStrategy = badgeStrategy;
+ }
+
+ public boolean canGetDiscount(MenuCount menuCount) {
+ return menuCount.calculateTotalAmount() >= MIN_DISCOUNT_SERVICE.getAmount();
+ }
+
+ public int calculatePromotionAmount(MenuCount menuCount, Date date) {
+ if (canGetDiscount(menuCount)) {
+ return calaulateTotalDiscountAmount(menuCount, date)
+ + discountStrategy.giftEventDiscount(menuCount);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ public int calaulateTotalDiscountAmount(MenuCount menuCount, Date date) {
+ if (canGetDiscount(menuCount)) {
+ return discountStrategy.christmasDiscount(date)
+ + discountStrategy.weekdayDiscount(menuCount, date)
+ + discountStrategy.specialDayDiscount(date)
+ + discountStrategy.weekendDiscount(menuCount, date);
+ }
+ return NO_DISCOUNT.getAmount();
+ }
+
+ public EnumMap<PromotionConstant, Integer> calculatePromotionStatus(MenuCount menuCount, Date date) {
+ EnumMap<PromotionConstant, Integer> promotionStatus = new EnumMap<>(PromotionConstant.class);
+ if (canGetDiscount(menuCount)) {
+ promotionStatus.put(CHRISTMAS_DISCOUNT, discountStrategy.christmasDiscount(date));
+ promotionStatus.put(WEEKDAY_DISCOUNT, discountStrategy.weekdayDiscount(menuCount, date));
+ promotionStatus.put(WEEKEND_DISCOUNT, discountStrategy.weekendDiscount(menuCount, date));
+ promotionStatus.put(SPECIAL_DISCOUNT, discountStrategy.specialDayDiscount(date));
+ promotionStatus.put(GIFT_EVENT, discountStrategy.giftEventDiscount(menuCount));
+ return promotionStatus;
+ }
+ return promotionStatus;
+ }
+
+ public String calculateBadgeStatus(MenuCount menuCount, Date date) {
+ int promotionAmount = calculatePromotionAmount(menuCount, date);
+ EventBadge badge = badgeStrategy.calculateBadgeGrade(promotionAmount);
+ return badge.getName();
+ }
+
+} | Java | early return์ ์ฌ์ฉํ๋ฉด ์กฐ๊ธ ๋ ์ฝ๋๊ฐ ๊น๋ํด์ง ๊ฒ ๊ฐ์์
```java
if(!canGetDiscount(menuCount) {
return Collections.EMPTY_MAP;
}
EnumMap<PromotionConstant, Integer> promotionStatus = new EnumMap<>(PromotionConstant.class);
promotionStatus.put(CHRISTMAS_DISCOUNT, discountStrategy.christmasDiscount(date));
promotionStatus.put(WEEKDAY_DISCOUNT, discountStrategy.weekdayDiscount(menuCount, date));
promotionStatus.put(WEEKEND_DISCOUNT, discountStrategy.weekendDiscount(menuCount, date));
promotionStatus.put(SPECIAL_DISCOUNT, discountStrategy.specialDayDiscount(date));
promotionStatus.put(GIFT_EVENT, discountStrategy.giftEventDiscount(menuCount));
return promotionStatus;
```
์ด๋ ๊ฒ ๋ฆฌํฉํ ๋ง์ ํ๋๋ enummap์ ๋ง๋๋ ๊ณผ์ ์ private ๋ฉ์๋๋ก ์ถ์ถํด์ผ๊ฒ ๋ค๋ ๋๋๋ ์ค๋ ๊ฒ ๊ฐ์ต๋๋ค
(if๋ฌธ์ผ๋ก ํ ์ธ ํ์ธํ๋ ๋ก์ง, map ๋ง๋๋ ๋ก์ง๊น์ง ์ด 2๊ฐ์ ์ญํ ์ ํ๊ณ ์์ผ๋๊น์) |
@@ -0,0 +1,52 @@
+package christmas.model;
+
+import static christmas.exception.CustomException.DATE_RANGE_EXCEPTION;
+import static christmas.model.constant.DateConstant.SPECIAL_DAYS;
+import static christmas.model.constant.DateConstant.WEEKDAYS;
+import static christmas.model.constant.DateConstant.WEEKENDS;
+import static christmas.model.constant.DateConstant.XMAS;
+
+import christmas.model.constant.DateConstant;
+
+public class Date {
+ private final int MIN_DATE = DateConstant.MIN_DATE.getDate();
+ private final int MAX_DATE = DateConstant.MAX_DATE.getDate();
+ private final int date;
+
+ private Date(int date) {
+ validateDateRange(date);
+ this.date = date;
+ }
+
+ public static Date of(int date) {
+ return new Date(date);
+ }
+
+ public int getValue() {
+ return date;
+ }
+
+ private void validateDateRange(int date) {
+ if (date < MIN_DATE || date > MAX_DATE) {
+ throw DATE_RANGE_EXCEPTION;
+ }
+ }
+
+ public boolean isWeekday() {
+ return WEEKDAYS.contains(date);
+ }
+
+ public boolean isWeekend() {
+ return WEEKENDS.contains(date);
+ }
+
+ public boolean isBeforeXmas() {
+ return XMAS.getDate() >= date;
+ }
+
+ public boolean isSpecialDay() {
+ return SPECIAL_DAYS.contains(date);
+ }
+
+
+} | Java | ์ฃผ๋ง์ธ์ง ํ์ผ์ธ์ง๋ฅผ ์ฒดํฌํ๋ ๋ก์ง์ `DateConstant`์ ๋ชฐ๊ธฐ๋ณด๋ค, Date ํด๋์ค์์ ์ฒ๋ฆฌํ๋ฉด ์ด๋จ๊น์?
์์ ํด๋์ค์ ๋ก์ง์ด ๋ค์ด์๋ ๊ฒ์ ์ด์ํ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ค์ด์ |
@@ -0,0 +1,44 @@
+package christmas.model.constant;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public enum DateConstant {
+ MIN_DATE(1),
+ MAX_DATE(31),
+ XMAS(25);
+
+ public static final Set<Integer> WEEKDAYS = new HashSet<>();
+ public static final Set<Integer> WEEKENDS = new HashSet<>();
+ public static final Set<Integer> SPECIAL_DAYS = new HashSet<>(Arrays.asList(
+ 3, 10, 17, 24, 25, 31
+ ));
+
+ static {
+ LocalDate start = LocalDate.of(2023, 12, MIN_DATE.date);
+ LocalDate end = LocalDate.of(2023, 12, MAX_DATE.date);
+
+ for (LocalDate date = start; !date.isAfter(end); date = date.plusDays(1)) {
+ DayOfWeek day = date.getDayOfWeek();
+ if (day == DayOfWeek.SATURDAY || day == DayOfWeek.FRIDAY) {
+ WEEKENDS.add(date.getDayOfMonth());
+ continue;
+ }
+ WEEKDAYS.add(date.getDayOfMonth());
+ }
+ }
+
+ private final int date;
+
+ DateConstant(int date) {
+ this.date = date;
+ }
+
+ public int getDate() {
+ return date;
+ }
+
+} | Java | ๋ฆฌํฐ๋ด ๊ฐ๋ ์ปจ๋ฒค์
์ ๋ง๊ฒ ์์ ์ฒ๋ฆฌ๋ฅผ ํ๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,56 @@
+package christmas.model.constant;
+
+import java.util.Arrays;
+
+public enum Menu {
+ SOUP("์ ํผํ์ด์ ", "์์ก์ด์ํ", 6000),
+ TAPAS("์ ํผํ์ด์ ", "ํํ์ค", 5500),
+ SALAD("์ ํผํ์ด์ ", "์์ ์๋ฌ๋", 8000),
+ STEAK("๋ฉ์ธ", "ํฐ๋ณธ์คํ
์ดํฌ", 55000),
+ BBQ("๋ฉ์ธ", "๋ฐ๋นํ๋ฆฝ", 54000),
+ SEAFOOD_PASTA("๋ฉ์ธ", "ํด์ฐ๋ฌผํ์คํ", 35000),
+ XMAS_PASTA("๋ฉ์ธ", "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ CHOCO_CAKE("๋์ ํธ", "์ด์ฝ์ผ์ดํฌ", 15000),
+ ICECREAM("๋์ ํธ", "์์ด์คํฌ๋ฆผ", 5000),
+ ZEROCOKE("์๋ฃ", "์ ๋ก์ฝ๋ผ", 3000),
+ REDWINE("์๋ฃ", "๋ ๋์์ธ", 60000),
+ CHAMPAGNE("์๋ฃ", "์ดํ์ธ", 25000);
+
+
+ private final String category;
+ private final String name;
+ private final int price;
+
+ Menu(String category, String name, int price) {
+ this.category = category;
+ this.name = name;
+ this.price = price;
+ }
+
+ public static Menu of(String name) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menu.getName().equals(name))
+ .findFirst()
+ .orElse(null);
+ }
+
+ public boolean isMainCategory() {
+ return "๋ฉ์ธ".equals(this.category);
+ }
+
+ public boolean isDessertCategory() {
+ return "๋์ ํธ".equals(this.category);
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+} | Java | ์์์ ์ข
๋ฅ๋ Enum์ผ๋ก ์ฒ๋ฆฌํ๋ฉด ํน์ ๋ฉ๋ด ์ข
๋ฅ์ ํด๋น๋๋ ์์์ธ์ง ํ์ธํ๋ ๋ก์ง์ ์งค ๋ ๋์์ด ๋ ์ ์์ ๊ฒ ๊ฐ์์:) |
@@ -0,0 +1,52 @@
+package christmas.model;
+
+import static christmas.exception.CustomException.DATE_RANGE_EXCEPTION;
+import static christmas.model.constant.DateConstant.SPECIAL_DAYS;
+import static christmas.model.constant.DateConstant.WEEKDAYS;
+import static christmas.model.constant.DateConstant.WEEKENDS;
+import static christmas.model.constant.DateConstant.XMAS;
+
+import christmas.model.constant.DateConstant;
+
+public class Date {
+ private final int MIN_DATE = DateConstant.MIN_DATE.getDate();
+ private final int MAX_DATE = DateConstant.MAX_DATE.getDate();
+ private final int date;
+
+ private Date(int date) {
+ validateDateRange(date);
+ this.date = date;
+ }
+
+ public static Date of(int date) {
+ return new Date(date);
+ }
+
+ public int getValue() {
+ return date;
+ }
+
+ private void validateDateRange(int date) {
+ if (date < MIN_DATE || date > MAX_DATE) {
+ throw DATE_RANGE_EXCEPTION;
+ }
+ }
+
+ public boolean isWeekday() {
+ return WEEKDAYS.contains(date);
+ }
+
+ public boolean isWeekend() {
+ return WEEKENDS.contains(date);
+ }
+
+ public boolean isBeforeXmas() {
+ return XMAS.getDate() >= date;
+ }
+
+ public boolean isSpecialDay() {
+ return SPECIAL_DAYS.contains(date);
+ }
+
+
+} | Java | ๋นํธ์ธ ๊ฐ์ฒด Date์ ํผ๋๋ ์ ์์ด์ ๋ค๋ฅธ ๋ค์ด๋ฐ์ ๋ฐ์ํ๋๊ฒ๋ ์ข์ ๊ฒ ๊ฐ์์ |
@@ -21,7 +21,9 @@
<body>
<div class="create-account">
<h1 class="heading xl3">Create <br />Account</h1>
- <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ <div class="file-wrapper">
+ <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ </div>
<div class="account-info">
<input type="email" class="input md" placeholder="Email">
<div class="password">
@@ -43,7 +45,6 @@ <h1 class="heading xl3">Create <br />Account</h1>
<button class="btn lg3 blue radius-16 btn-done" onclick="goCreate()">Done</button>
<p class="text md3 btn-cancel" onclick="goCancel()">Cancel</p>
</div>
- <!-- <script type="module" src="./js/common.js" defer></script> -->
<script defer>
//์๋ก์ด ํ์ด์ง ์ด๋ํ๊ธฐ
const goCreate = () => { | Unknown | ๊ฐ์ธ์ฐจ๊ฐ ์๊ฒ ์ง๋ง, ์ ๊ฐ์ธ์ ์ผ๋ก ์ด๋ฒคํธ๋ js์์ ๋ชจ๋ ์ฒ๋ฆฌํ๋ํธ์
๋๋ค..
react๋ฉด ์ปดํผ๋ํธ๋ก ๊ด๋ฆฌ๋๊ธฐ๋๋ฌธ์ ๋ฌด๊ดํ์ง๋ง.. html์์ ๋์ค์ ๋ชจ๋ ํ์ด์ง ์ฐพ์๊ฐ๋ฉด์ ํด๋น ํจ์๋ฅผ ์ ๊ฑฐ ๋๋ ์ถ๊ฐํด์ผ๋ ๊ฒฝ์ฐ๊ฐ ์๊ฑฐ๋ ์. |
@@ -21,7 +21,9 @@
<body>
<div class="create-account">
<h1 class="heading xl3">Create <br />Account</h1>
- <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ <div class="file-wrapper">
+ <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ </div>
<div class="account-info">
<input type="email" class="input md" placeholder="Email">
<div class="password">
@@ -43,7 +45,6 @@ <h1 class="heading xl3">Create <br />Account</h1>
<button class="btn lg3 blue radius-16 btn-done" onclick="goCreate()">Done</button>
<p class="text md3 btn-cancel" onclick="goCancel()">Cancel</p>
</div>
- <!-- <script type="module" src="./js/common.js" defer></script> -->
<script defer>
//์๋ก์ด ํ์ด์ง ์ด๋ํ๊ธฐ
const goCreate = () => { | Unknown | ๋ชจ๋ ์จ๋ผ์ธ์์์๋ title๋๋ label์ด ์์ด์ผ ํฉ๋๋ค. |
@@ -21,7 +21,9 @@
<body>
<div class="create-account">
<h1 class="heading xl3">Create <br />Account</h1>
- <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ <div class="file-wrapper">
+ <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ </div>
<div class="account-info">
<input type="email" class="input md" placeholder="Email">
<div class="password">
@@ -43,7 +45,6 @@ <h1 class="heading xl3">Create <br />Account</h1>
<button class="btn lg3 blue radius-16 btn-done" onclick="goCreate()">Done</button>
<p class="text md3 btn-cancel" onclick="goCancel()">Cancel</p>
</div>
- <!-- <script type="module" src="./js/common.js" defer></script> -->
<script defer>
//์๋ก์ด ํ์ด์ง ์ด๋ํ๊ธฐ
const goCreate = () => { | Unknown | ์คํฌ๋ฆฝํธ๋ ์ธ๋ถํ์ผ๋ก..
alert๋ณด๋จ dialog๋ฅผ ์ด์ฉํด์ ๊ฒฝ๊ณ ์ฐฝ์ ๊พธ๋ฉฐ๋ณด๋๊ฒ๋ ๋์๋ฉ๋๋ค.
๊ธฐ๋ฅ๋ณ๋ก ํจ์๋ก ๊ตฌํํ์
์ moduleํ ํ๋ก๊ทธ๋๋ฐ์ ์๋ํด๋ณด์ธ์~ |
@@ -1,11 +1,32 @@
-import { useState } from "react";
+import '@styles/App.css';
+import '@styles/reset.css';
+import '@styles/global.css';
+import { Header, Layout, PageRequestError } from '@components/index';
+import { lazy, Suspense } from 'react';
+import { ErrorBoundary } from 'react-error-boundary';
+
+import { CartItemsContext } from './contexts';
+import { useCartItemIds } from './hooks';
+import ProductListPageSkeleton from './pages/ProductListPage/Skeleton/ProductListPageSkeleton/index.';
+
+const ProductListPage = lazy(() => import('@pages/ProductListPage'));
function App() {
- const [count, setCount] = useState(0);
+ const { cartItemIds, refreshCartItemIds, error: cartItemsFetchError } = useCartItemIds();
+ const cartItemsLength = cartItemIds ? Array.from(cartItemIds).length : 0;
return (
<>
- <h1>React Shopping Products</h1>
+ <Header cartItemsLength={cartItemsLength} cartItemsFetchError={cartItemsFetchError} />
+ <Layout>
+ <ErrorBoundary FallbackComponent={({ error }) => <PageRequestError error={error} />}>
+ <CartItemsContext.Provider value={{ cartItemIds, refreshCartItemIds }}>
+ <Suspense fallback={<ProductListPageSkeleton />}>
+ <ProductListPage />
+ </Suspense>
+ </CartItemsContext.Provider>
+ </ErrorBoundary>
+ </Layout>
</>
);
} | Unknown | ์ํ์ ์ฅ๋ฐ๊ตฌ๋ ๋ด๊ธฐ/๋นผ๊ธฐ ํด๋ฆญ ์ api์์ฒญ ํ ๊ฒฐ๊ณผ์ ๋ง์ถ์ด Header ์ ์ฅ๋ฐ๊ตฌ๋ ์์ด์ฝ์ ์ฅ๋ฐ๊ตฌ๋ ๋ชฉ๋ก ์๋์ด ์
๋ฐ์ดํธ ๋์ด์ผํด์
์ฅ๋ฐ๊ตฌ๋ ๋ด๊ธฐ/๋นผ๊ธฐ + ์ฅ๋ฐ๊ตฌ๋ ๋ชฉ๋ก ์ํ๋ฅผ ์
๋ฐ์ดํธํด์ฃผ๋ handleCartActionํจ์๋ฅผ context api๋ก ๋ด๋ ค์ฃผ๊ณ ์์ด์.
ํฌ๋ฃจ๋ ํด๋น ๊ธฐ๋ฅ์ ์ด๋ป๊ฒ ๊ตฌํํ์
จ๋์? |
@@ -1,11 +1,32 @@
-import { useState } from "react";
+import '@styles/App.css';
+import '@styles/reset.css';
+import '@styles/global.css';
+import { Header, Layout, PageRequestError } from '@components/index';
+import { lazy, Suspense } from 'react';
+import { ErrorBoundary } from 'react-error-boundary';
+
+import { CartItemsContext } from './contexts';
+import { useCartItemIds } from './hooks';
+import ProductListPageSkeleton from './pages/ProductListPage/Skeleton/ProductListPageSkeleton/index.';
+
+const ProductListPage = lazy(() => import('@pages/ProductListPage'));
function App() {
- const [count, setCount] = useState(0);
+ const { cartItemIds, refreshCartItemIds, error: cartItemsFetchError } = useCartItemIds();
+ const cartItemsLength = cartItemIds ? Array.from(cartItemIds).length : 0;
return (
<>
- <h1>React Shopping Products</h1>
+ <Header cartItemsLength={cartItemsLength} cartItemsFetchError={cartItemsFetchError} />
+ <Layout>
+ <ErrorBoundary FallbackComponent={({ error }) => <PageRequestError error={error} />}>
+ <CartItemsContext.Provider value={{ cartItemIds, refreshCartItemIds }}>
+ <Suspense fallback={<ProductListPageSkeleton />}>
+ <ProductListPage />
+ </Suspense>
+ </CartItemsContext.Provider>
+ </ErrorBoundary>
+ </Layout>
</>
);
} | Unknown | ์ ํฌ๋ ์ฅ๋ฐ๊ตฌ๋ api์ธ cart-tiems์ ๋ฐ์ดํฐ๋ context๋ก ๊ด๋ฆฌํ๊ณ ์์ต๋๋ค! |
@@ -0,0 +1,39 @@
+import { Filtering, Product, ApiResponse } from '@appTypes/index';
+import { LOAD_MORE_PRODUCTS_AMOUNT } from '@constants/index';
+import { fetchWithToken } from '@utils/index';
+
+import { END_POINTS } from './endPoints';
+
+interface FetchProductParameter {
+ filtering: Filtering;
+ page?: number;
+}
+
+const getSearchParams = ({ filtering, page }: FetchProductParameter): URLSearchParams => {
+ const searchParams = new URLSearchParams();
+
+ if (filtering.category !== '') {
+ searchParams.append('category', filtering.category);
+ }
+
+ searchParams.append('sort', filtering.sort);
+ searchParams.append('page', String(page));
+
+ if (page !== 0) {
+ searchParams.append('size', LOAD_MORE_PRODUCTS_AMOUNT.toString());
+ }
+
+ return searchParams;
+};
+
+export async function fetchProduct(params: FetchProductParameter): Promise<{ products: Product[]; isLast: boolean }> {
+ const searchParams = '?' + getSearchParams({ ...params, page: params.page ?? 0 }).toString();
+
+ const data = await fetchWithToken({
+ url: END_POINTS.products + searchParams,
+ method: 'GET',
+ });
+ const result = (await data.json()) as ApiResponse<Product[]>;
+
+ return { products: result.content, isLast: result.last };
+} | TypeScript | page์ ํ์
์ด number์ฌ์ string์ผ๋ก ๋ง๋ค์ด ์ฃผ์ ๊ฒ ๊ฐ์๋ฐ, ์ ๊ฐ ์๊ธฐ๋ก๋ ๊ทธ๋ฅ ์ซ์๋ฅผ ๋ฃ์ด๋ ๋๋ค๊ณ ์๊ณ ์์ต๋๋ค..! ํน์ string์ผ๋ก ๋ณํํ์ฌ ๋ฃ์ ๊ฒ์ ๋ํด ์๋ฏธ๊ฐ ์๋ ๊ฑธ ๊น์??
(๊ทผ๋ฐ ํ์คํ์ง ์์์ง.. ํ๋ฆฌ๋จผ ์ค๋ฃจ ํด์ฃผ์ญ์ผ..)
https://developer.mozilla.org/ko/docs/Web/API/URLSearchParams/get |
@@ -0,0 +1,15 @@
+export type Category = '' | 'fashion' | 'beverage' | 'electronics' | 'kitchen' | 'fitness' | 'books';
+export type PriceSort = 'price,asc' | 'price,desc';
+
+export interface Product {
+ id: number;
+ name: string;
+ price: number;
+ imageUrl: string;
+ category: Category;
+}
+
+export interface Filtering {
+ category: Category;
+ sort: PriceSort;
+} | TypeScript | ๋น ๋ฌธ์์ด์ด **์ ์ฒด** ๋๋ฌธ์ ์๋ ๊ฒ์ผ๋ก ๋ณด์ด๋๋ฐ,
Category๋ฅผ ์ฌ์ฉํ๋ ๊ณณ์์ `Category | undefined`์ ๊ฐ์ ํํ๊ฐ ์๋ ๋น ๋ฌธ์์ด๋ก ๋ฃ์ด์ค ์ด์ ๊ฐ ์์๊น์?? |
@@ -0,0 +1,32 @@
+/**
+ * ์๋ฒ ์๋ต์ ๊ณตํต ๊ตฌ์กฐ๋ฅผ ์ ์ํ๋ ์ธํฐํ์ด์ค
+ * @template T - response์ contentํ์
+ */
+export interface ApiResponse<T> {
+ totalPages: number;
+ totalElements: number;
+ sort: {
+ sorted: boolean;
+ unsorted: boolean;
+ empty: boolean;
+ };
+ first: boolean;
+ last: boolean;
+ pageable: {
+ sort: {
+ sorted: boolean;
+ unsorted: boolean;
+ empty: boolean;
+ };
+ pageNumber: number;
+ pageSize: number;
+ paged: boolean;
+ unpaged: boolean;
+ offset: number;
+ };
+ number: number;
+ numberOfElements: number;
+ size: number;
+ content: T;
+ empty: boolean;
+} | TypeScript | ์ค.. ์ด๋ ๊ฒ ๋ฐ๋ก ๋ถ๋ฆฌํ๋ ๊ฒ๋ ์ข๋ค์~! |
@@ -0,0 +1,30 @@
+import { DropdownOption } from '@appTypes/dropdown';
+
+import style from './style.module.css';
+
+interface DropdownProps extends Omit<React.HTMLProps<HTMLSelectElement>, 'onChange'> {
+ options: DropdownOption[];
+ onChange: (event: React.ChangeEvent<HTMLSelectElement>) => void;
+ label: string;
+}
+
+function Dropdown({ options, label, onChange, name, ...rest }: DropdownProps) {
+ const selectId = `select-${label}`;
+
+ return (
+ <>
+ <label className="scr-only" htmlFor={selectId}>
+ {label}
+ </label>
+ <select id={selectId} name={name} className={style.select} onChange={onChange} {...rest}>
+ {options.map((item) => (
+ <option key={item.value} value={item.value}>
+ {item.label}
+ </option>
+ ))}
+ </select>
+ </>
+ );
+}
+
+export default Dropdown; | Unknown | ํ๋ฃจ๊ฐ ๋๋ฌด ์ข์ ํ ๊ฒ ๊ฐ์! |
@@ -0,0 +1,15 @@
+export type Category = '' | 'fashion' | 'beverage' | 'electronics' | 'kitchen' | 'fitness' | 'books';
+export type PriceSort = 'price,asc' | 'price,desc';
+
+export interface Product {
+ id: number;
+ name: string;
+ price: number;
+ imageUrl: string;
+ category: Category;
+}
+
+export interface Filtering {
+ category: Category;
+ sort: PriceSort;
+} | TypeScript | api ์์ฒญ ๋ณด๋ด๋ ๊ฒ๊ณผ ํ์
์ ๋ง์ถ์์ด์.
์ง๊ธ๋ณด๋, ''๋ฅผ ALL์ด๋ผ๋ ์์๋ฅผ ๋ฐ๋๋ ๊ฒ์ด ์ ์ธ์ ์ผ๋ก ๋ ์ข์ ๊ฒ ๊ฐ๋ค์. |
@@ -0,0 +1,22 @@
+package christmas.constant;
+
+public enum ResultMessage {
+ BENEFIT_PREVIEW("12์ 3์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!"),
+ ORDER_MENU("\n<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ ALL_ORDER_PRICE_WITHOUT_DISCOUNT("\n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ GIVE_MENU("\n<์ฆ์ ๋ฉ๋ด>"),
+ BENEFIT("\n<ํํ ๋ด์ญ>"),
+ ALL_BENEFIT_AMOUNT("\n<์ดํํ ๊ธ์ก>"),
+ PAYMENT_PRICE("\n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ BADGE("\n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>");
+
+ private String message;
+
+ ResultMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | ๊ฐ์ธ์ ์ผ๋ก ๋ฌธ์์ด์ ๊ฐํ์ด ๋ค์ด๊ฐ ์์ผ๋ฉด ๋์ค์ ๋๋ฒ๊น
์ด ์ฝ์ง ์๋๊ตฐ์.. |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ์ถ๋ ฅ๋ถ๋ฌธ์ด ์๋น์ค์ ๊ฒฐํฉ๋์ด ์๋๊ฒ ๋ง์ ๊ฒ ๊ฐ์๋ฐ, ์์ ์๋น์ค ์์์ ์ฒ๋ฆฌํ๋ ๊ฒ๋ ์ข์๋ณด์
๋๋ค! |
@@ -0,0 +1,55 @@
+package christmas.domain.customer;
+
+import christmas.constant.NumConstant;
+import christmas.validator.DateValidator;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+
+public class VisitDate {
+ private final int visitDate;
+
+ private VisitDate(int visitDate) {
+ DateValidator.validateVisitDateBound(visitDate);
+ this.visitDate = visitDate;
+ }
+
+ public static VisitDate from(int visitDate) {
+ return new VisitDate(visitDate);
+ }
+
+ public DayOfWeek getDayOfWeek() {
+ LocalDate date = LocalDate.of(
+ NumConstant.THIS_YEAR.getValue(),
+ NumConstant.THIS_MONTH.getValue(),
+ visitDate
+ );
+ return date.getDayOfWeek();
+ }
+
+ public boolean isVisitDateWeekend() {
+ DayOfWeek dayOfWeek = getDayOfWeek();
+ if (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isOverChristmas() {
+ if(visitDate > NumConstant.CHRISTMAS_DAY.getValue()) {
+ return true;
+ }
+ return false;
+ }
+
+ public int calculateDdayEventApplyDay() {
+ return visitDate - 1;
+ }
+
+ public boolean isSpecialDay() {
+ if (visitDate == NumConstant.CHRISTMAS_DAY.getValue() || getDayOfWeek() == DayOfWeek.SUNDAY) {
+ return true;
+ }
+ return false;
+ }
+} | Java | ์ด๋ค ๊ฑธ ์๋ํ์
จ๋์ง ์ฌ์ญค๋ด๋ ๋ ๊น์? |
@@ -0,0 +1,68 @@
+package christmas.service;
+
+import christmas.constant.Badge;
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.event.EventStatus;
+import christmas.handler.EventHandler;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class EventService {
+ private final EventHandler eventHandler;
+ private final CustomerInfo customerInfo;
+
+ private EventService(CustomerInfo customerInfo) {
+ eventHandler = EventHandler.from(EventStatus.createInstance());
+ this.customerInfo = customerInfo;
+ }
+
+ public static EventService of(CustomerInfo customerInfo) {
+ return new EventService(customerInfo);
+ }
+
+ public void applyDiscount() {
+ eventHandler.applyDiscount(customerInfo);
+ }
+
+ public int getTotalBenefitAmount() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getTotalBenefitAmount();
+ }
+ return 0;
+ }
+
+ public Map<String, Integer> getBenefits() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getBenefits();
+ }
+ return Collections.emptyMap();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return customerInfo.getOrderList();
+ }
+
+ public String getGiveaway() {
+ if (customerInfo.isApplyGiveawayEvent()) {
+ return "์ดํ์ธ 1๊ฐ";
+ }
+ return "์์";
+ }
+
+ public int getTotalOrderAmount() {
+ return customerInfo.getTotalOrderAmount();
+ }
+
+ public int getTotalDiscountAmount() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getTotalDiscountAmount();
+ }
+ return 0;
+ }
+
+ public String getBadge() {
+ return Badge.getBadge(eventHandler.getTotalBenefitAmount());
+ }
+
+} | Java | ๋ฌธ์์ด์ ๋ฐํํ๊ธฐ๋ณด๋ค ์ฆ์ ํ์ ๋ํ ๊ฐ์ฒด๊ฐ ์์ด์ ๊ทธ ์ ๋ณด๋ฅผ ๋ฐํํ๋ ๊ฒ์ด ์ด๋จ๊น์? |
@@ -0,0 +1,31 @@
+package christmas.constant;
+
+public enum Badge {
+ MISS("์์"),
+ STAR("๋ณ"),
+ TREE("ํธ๋ฆฌ"),
+ SANTA("์ฐํ");
+ private String name;
+
+ Badge(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static String getBadge(int totalBenefitAmount) {
+ totalBenefitAmount = Math.abs(totalBenefitAmount);
+ if(totalBenefitAmount >= NumConstant.STAR_BADGE_AMOUNT.getValue() && totalBenefitAmount < NumConstant.TREE_BADGE_AMOUNT.getValue()) {
+ return STAR.name;
+ }
+ if(totalBenefitAmount >= NumConstant.TREE_BADGE_AMOUNT.getValue() && totalBenefitAmount < NumConstant.SANTA_BADGE_AMOUNT.getValue()) {
+ return TREE.name;
+ }
+ if(totalBenefitAmount >= NumConstant.SANTA_BADGE_AMOUNT.getValue()) {
+ return SANTA.name;
+ }
+ return MISS.name;
+ }
+} | Java | ์ ๋ ๋๊ฐ์ด ๋ฐ์๋ ํผ๋๋ฐฑ์ธ๋ฐ,
```
SANTA("์ฐํ, 25_000");
public static String getBadge(final int totalBenefitAmount) {
for(Badge b : Badge.values()){
if(totalBenefitAmount>=b.getValue()){
return b.name;
}
}
return "์์";
}
```
๋ก ๊ณ ์ณ๋ณด๋ฉด ์ด๋จ๊น์?
๋ ๊ฐ๋จํด ์ง ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ์! ์ธ์คํด์ค ํ๋๋ฅผ ์ ์ ํ๊ฒ ์ ์ค์ธ๊ฒ ๊ฐ์์ ์์ฒญ ์ข๋ค์!! |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ์ด ๋ถ๋ถ์
- ์
๋ ฅ๊ฐ์ ๋ฐ์์จ๋ค
- ์๋น์ค ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค
๋ผ๋ ๋ก์ง์ ๋์์ ์ฒ๋ฆฌํ๊ณ ์์ด ๋ถ๋ฆฌ๊ฐ ํ์ฉํด ๋ณด์
๋๋ค! |
@@ -0,0 +1,63 @@
+package christmas.domain.customer;
+
+import christmas.constant.MenuType;
+import christmas.constant.NumConstant;
+import christmas.domain.order.Orders;
+
+import java.util.Map;
+
+public class CustomerInfo {
+ private final VisitDate visitDate;
+ private final Orders orders;
+
+ private CustomerInfo(VisitDate visitDate, Orders orders) {
+ this.visitDate = visitDate;
+ this.orders = orders;
+ }
+
+ public static CustomerInfo of(VisitDate visitDate, Orders orders) {
+ return new CustomerInfo(visitDate, orders);
+ }
+
+ public boolean isOverMinAmount() {
+ if (getTotalOrderAmount() > NumConstant.MIN_EVENT_APPLY_AMOUNT.getValue()) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isVisitDateWeekend() {
+ return visitDate.isVisitDateWeekend();
+ }
+
+ public boolean isOverChristmas() {
+ return visitDate.isOverChristmas();
+ }
+
+ public int getTotalOrderAmount() {
+ return orders.getTotalOrderAmount();
+ }
+
+ public int getDdayEventApplyDay() {
+ return visitDate.calculateDdayEventApplyDay();
+ }
+
+ public int getOrderNumByMenuType(MenuType menuType) {
+ return orders.getOrderNumByMenuType(menuType);
+ }
+
+ public boolean isApplyGiveawayEvent() {
+ if (orders.getTotalOrderAmount() >= NumConstant.MIN_GIVEAWAY_AMOUNT.getValue()) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isSpecialDay() {
+ return visitDate.isSpecialDay();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return orders.getOrderList();
+ }
+} | Java | ์ฝ๋ ์ปจ๋ฒค์
์์์ ๋ง์ถฐ ๋น์ง๋์ค ๋ก์ง๋ณด๋ค getter๋ฅผ ์๋์ ๋๋ ๊ฒ์ด ๊น๋ํด๋ณด์
๋๋ค! |
@@ -0,0 +1,38 @@
+package christmas.domain.order;
+
+import christmas.constant.MenuType;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Orders {
+ private final List<Order> orders;
+
+ private Orders(List<Order> orders) {
+ this.orders = orders;
+ }
+
+ public static Orders from(List<Order> orders) {
+ return new Orders(orders);
+ }
+
+ public int getTotalOrderAmount() {
+ return orders.stream()
+ .map(Order::getOrderAmount)
+ .reduce(0, Integer::sum);
+ }
+
+ public int getOrderNumByMenuType(MenuType menuType) {
+ return orders.stream()
+ .filter(order -> order.isMatchMenuType(menuType))
+ .mapToInt(Order::getMenuNum)
+ .sum();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return orders.stream()
+ .collect(Collectors.toMap(Order::getMenuName, Order::getMenuNum));
+ }
+} | Java | list๋ผ๋ ์๋ฃ๊ตฌ์กฐ์ ๊ทธ๋๋ก๋ค์ด๋ฐ์ผ๋ก ์ฌ์ฉํ๋ ๊ฒ์ ์ง์ํ๋ผ๊ณ ํผ๋๋ฐฑ์ ๋์์์์ต๋๋ค!
๋, getter๋ก list์๋ฐํ์์ list์ ๋ณ๊ฒฝ๊ฐ๋ฅ์ฑ์ด ์์ผ๋ฏ๋ก Collections.unmodifi...๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ์ ํด๋ณด์ด๋ค์! |
@@ -0,0 +1,48 @@
+package christmas.domain.menu;
+
+import christmas.constant.MenuType;
+
+import java.util.*;
+
+public class Menus {
+ private final List<Menu> menus;
+ private static Menus instance;
+
+ private Menus(List<Menu> menus) {
+ this.menus = menus;
+ }
+
+ public static Menus getInstance() {
+ if(instance == null) {
+ instance = new Menus(initialMenus());
+ }
+ return instance;
+ }
+
+ private static List<Menu> initialMenus() {
+ List<Menu> initialMenus = new ArrayList<>();
+
+ initialMenus.add(Menu.of("์์ก์ด์ํ", 6000, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("ํํ์ค", 5500, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("์์ ์๋ฌ๋", 8000, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, MenuType.MAIN));
+ initialMenus.add(Menu.of("๋ฐ๋นํ๋ฆฝ", 54000, MenuType.MAIN));
+ initialMenus.add(Menu.of("ํด์ฐ๋ฌผํ์คํ", 35000, MenuType.MAIN));
+ initialMenus.add(Menu.of("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000, MenuType.MAIN));
+ initialMenus.add(Menu.of("์ด์ฝ์ผ์ดํฌ", 15000, MenuType.DESSERT));
+ initialMenus.add(Menu.of("์์ด์คํฌ๋ฆผ", 5000, MenuType.DESSERT));
+ initialMenus.add(Menu.of("์ ๋ก์ฝ๋ผ", 3000, MenuType.DRINK));
+ initialMenus.add(Menu.of("๋ ๋์์ธ", 60000, MenuType.DRINK));
+ initialMenus.add(Menu.of("์ดํ์ธ", 25000, MenuType.DRINK));
+
+ return initialMenus;
+ }
+
+ public Optional<Menu> getMenuByMenuName(String menuName) {
+ return menus.stream()
+ .filter(menu -> menu.getMenuName().equals(menuName))
+ .findFirst();
+
+ }
+
+} | Java | ์ด๋ ๊ฒ ์ฑ๊ธํค ๋ฐฉ์์ผ๋ก ์ ์ธํ์ ์ด์ ๊ฐ ์์๊น์? enum์ ์ฌ์ฉํด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,22 @@
+package christmas.constant;
+
+public enum ResultMessage {
+ BENEFIT_PREVIEW("12์ 3์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!"),
+ ORDER_MENU("\n<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ ALL_ORDER_PRICE_WITHOUT_DISCOUNT("\n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ GIVE_MENU("\n<์ฆ์ ๋ฉ๋ด>"),
+ BENEFIT("\n<ํํ ๋ด์ญ>"),
+ ALL_BENEFIT_AMOUNT("\n<์ดํํ ๊ธ์ก>"),
+ PAYMENT_PRICE("\n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ BADGE("\n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>");
+
+ private String message;
+
+ ResultMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | ์... ๊ทธ๋ฐ ๋ฌธ์ ๊ฐ ์ข ์์๊ตฐ์ ๐ฑ |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ํ๋ก๊ทธ๋จ์ ์ ์ฒด ํ๋ฆ์ ๋ํ๋ด๋ ๋ฉ์๋์ธ๋ฐ ์ด๋ค ์์ผ๋ก ๋ถ๋ฆฌํ๋๊ฒ ์ข์๊น์....?
์ ๋ ์ผ๋จ ํ๋ก๊ทธ๋จ์ด ๋์๊ฐ๊ธด ํด์ผํ๋ ํ๋์ ๋ฉ์๋์์ ํ๋ก๊ทธ๋จ ์ ์ฒด์ ํ๋ฆ์ ๋ํด ๋ค๋ค์ผ ํ๋ค๊ณ ์๊ฐํ๊ฑฐ๋ ์!
์ง๊ธ ๋ณด๋ EventService๊ฐ์ฒด์ ์์ฑ์ ๋ฉ์๋๋ก ๋ฐ๋ก ๋นผ๋๊ฒ๋ ์ข์์๊ฑฐ๊ฐ๋ค์ |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ์ ํ๋ก๊ทธ๋จ ๊ตฌ์กฐ์ ๊ฒฝ์ฐ
view->controller -> service ์ธ ๊ฒฝ์ฐ๋ผ controller์์ ์ฒ๋ฆฌํด์ฃผ๊ธด ํ์ต๋๋ค
<- <- |
@@ -0,0 +1,55 @@
+package christmas.domain.customer;
+
+import christmas.constant.NumConstant;
+import christmas.validator.DateValidator;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+
+public class VisitDate {
+ private final int visitDate;
+
+ private VisitDate(int visitDate) {
+ DateValidator.validateVisitDateBound(visitDate);
+ this.visitDate = visitDate;
+ }
+
+ public static VisitDate from(int visitDate) {
+ return new VisitDate(visitDate);
+ }
+
+ public DayOfWeek getDayOfWeek() {
+ LocalDate date = LocalDate.of(
+ NumConstant.THIS_YEAR.getValue(),
+ NumConstant.THIS_MONTH.getValue(),
+ visitDate
+ );
+ return date.getDayOfWeek();
+ }
+
+ public boolean isVisitDateWeekend() {
+ DayOfWeek dayOfWeek = getDayOfWeek();
+ if (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isOverChristmas() {
+ if(visitDate > NumConstant.CHRISTMAS_DAY.getValue()) {
+ return true;
+ }
+ return false;
+ }
+
+ public int calculateDdayEventApplyDay() {
+ return visitDate - 1;
+ }
+
+ public boolean isSpecialDay() {
+ if (visitDate == NumConstant.CHRISTMAS_DAY.getValue() || getDayOfWeek() == DayOfWeek.SUNDAY) {
+ return true;
+ }
+ return false;
+ }
+} | Java | Dday์ด๋ฒคํธ๊ฐ ์ต์ 1000์์ผ๋ก ์์ํ๊ณ 1์ผ ์ดํ๋ถํฐ 100์์ฉ ๋ถ๊ฒ๋๋๋ฐ
100์์ฉ ๋ถ๊ฒ๋๋ ๋ ์ ๊ฐ์๋ฅผ ๊ตฌํ๋ ๋ฉ์๋์
๋๋ค!
1์ด ๋ฐฉ๋ฌธ ๋ ์ง์ธ ๊ฒฝ์ฐ 0์ returnํ๋ฏ๋ก 100์ ์ ์ฉ์ด ์๋๋ ๊ฒ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.service;
+
+import christmas.constant.Badge;
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.event.EventStatus;
+import christmas.handler.EventHandler;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class EventService {
+ private final EventHandler eventHandler;
+ private final CustomerInfo customerInfo;
+
+ private EventService(CustomerInfo customerInfo) {
+ eventHandler = EventHandler.from(EventStatus.createInstance());
+ this.customerInfo = customerInfo;
+ }
+
+ public static EventService of(CustomerInfo customerInfo) {
+ return new EventService(customerInfo);
+ }
+
+ public void applyDiscount() {
+ eventHandler.applyDiscount(customerInfo);
+ }
+
+ public int getTotalBenefitAmount() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getTotalBenefitAmount();
+ }
+ return 0;
+ }
+
+ public Map<String, Integer> getBenefits() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getBenefits();
+ }
+ return Collections.emptyMap();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return customerInfo.getOrderList();
+ }
+
+ public String getGiveaway() {
+ if (customerInfo.isApplyGiveawayEvent()) {
+ return "์ดํ์ธ 1๊ฐ";
+ }
+ return "์์";
+ }
+
+ public int getTotalOrderAmount() {
+ return customerInfo.getTotalOrderAmount();
+ }
+
+ public int getTotalDiscountAmount() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getTotalDiscountAmount();
+ }
+ return 0;
+ }
+
+ public String getBadge() {
+ return Badge.getBadge(eventHandler.getTotalBenefitAmount());
+ }
+
+} | Java | ๋ฆฌํฉํ ๋ง ๋์์ด์๋๋ฐ ์ ์ ์์ด ๊ฐ๋ฐํ๋ค๋ณด๋ ๋์น ๋ถ๋ถ์ด๋ค์ ์ง์ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,31 @@
+package christmas.constant;
+
+public enum Badge {
+ MISS("์์"),
+ STAR("๋ณ"),
+ TREE("ํธ๋ฆฌ"),
+ SANTA("์ฐํ");
+ private String name;
+
+ Badge(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static String getBadge(int totalBenefitAmount) {
+ totalBenefitAmount = Math.abs(totalBenefitAmount);
+ if(totalBenefitAmount >= NumConstant.STAR_BADGE_AMOUNT.getValue() && totalBenefitAmount < NumConstant.TREE_BADGE_AMOUNT.getValue()) {
+ return STAR.name;
+ }
+ if(totalBenefitAmount >= NumConstant.TREE_BADGE_AMOUNT.getValue() && totalBenefitAmount < NumConstant.SANTA_BADGE_AMOUNT.getValue()) {
+ return TREE.name;
+ }
+ if(totalBenefitAmount >= NumConstant.SANTA_BADGE_AMOUNT.getValue()) {
+ return SANTA.name;
+ }
+ return MISS.name;
+ }
+} | Java | ์ค ์ ๋ ์ด ์ฝ๋๋ฅผ ๋ณด๊ณ ๋์ ๊น๋ํ๋ค๊ณ ๋๊ผ์๋๋ฐ.. ๊ฐ์ฌํฉ๋๋ค!! |
@@ -0,0 +1,38 @@
+package christmas.domain.order;
+
+import christmas.constant.MenuType;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Orders {
+ private final List<Order> orders;
+
+ private Orders(List<Order> orders) {
+ this.orders = orders;
+ }
+
+ public static Orders from(List<Order> orders) {
+ return new Orders(orders);
+ }
+
+ public int getTotalOrderAmount() {
+ return orders.stream()
+ .map(Order::getOrderAmount)
+ .reduce(0, Integer::sum);
+ }
+
+ public int getOrderNumByMenuType(MenuType menuType) {
+ return orders.stream()
+ .filter(order -> order.isMatchMenuType(menuType))
+ .mapToInt(Order::getMenuNum)
+ .sum();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return orders.stream()
+ .collect(Collectors.toMap(Order::getMenuName, Order::getMenuNum));
+ }
+} | Java | ๋ฉ์๋ ๋ค์ด๋ฐ์์ ์ฌ๋ฌ ์ฃผ๋ฌธ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ์ข์ ์ด๋ฆ์ด ๋ญ๊ฐ ์์๊น ํ๋ค๊ฐ ๋์จ๊ฒ ์ด๊ฑด๋ฐ ๋ค์ด๋ฐ ์ด๋ ต๋ค์ ใ
ใ
|
@@ -0,0 +1,48 @@
+package christmas.domain.menu;
+
+import christmas.constant.MenuType;
+
+import java.util.*;
+
+public class Menus {
+ private final List<Menu> menus;
+ private static Menus instance;
+
+ private Menus(List<Menu> menus) {
+ this.menus = menus;
+ }
+
+ public static Menus getInstance() {
+ if(instance == null) {
+ instance = new Menus(initialMenus());
+ }
+ return instance;
+ }
+
+ private static List<Menu> initialMenus() {
+ List<Menu> initialMenus = new ArrayList<>();
+
+ initialMenus.add(Menu.of("์์ก์ด์ํ", 6000, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("ํํ์ค", 5500, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("์์ ์๋ฌ๋", 8000, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, MenuType.MAIN));
+ initialMenus.add(Menu.of("๋ฐ๋นํ๋ฆฝ", 54000, MenuType.MAIN));
+ initialMenus.add(Menu.of("ํด์ฐ๋ฌผํ์คํ", 35000, MenuType.MAIN));
+ initialMenus.add(Menu.of("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000, MenuType.MAIN));
+ initialMenus.add(Menu.of("์ด์ฝ์ผ์ดํฌ", 15000, MenuType.DESSERT));
+ initialMenus.add(Menu.of("์์ด์คํฌ๋ฆผ", 5000, MenuType.DESSERT));
+ initialMenus.add(Menu.of("์ ๋ก์ฝ๋ผ", 3000, MenuType.DRINK));
+ initialMenus.add(Menu.of("๋ ๋์์ธ", 60000, MenuType.DRINK));
+ initialMenus.add(Menu.of("์ดํ์ธ", 25000, MenuType.DRINK));
+
+ return initialMenus;
+ }
+
+ public Optional<Menu> getMenuByMenuName(String menuName) {
+ return menus.stream()
+ .filter(menu -> menu.getMenuName().equals(menuName))
+ .findFirst();
+
+ }
+
+} | Java | Menus๋ ์ฝ๊ฒ๋งํด ๋ฉ๋ดํ์ผ๋ก ์ฌ์ฉ๋ ๊ฐ์ฒด์
๋๋ค! ๋ฐํ์ ์์ ์ ๋ณ๊ฒฝ๋ ์ผ์ด ์์๋ฏํ์ฌ ์ฑ๊ธํค ๋ฐฉ์์ผ๋ก ์ ์ธํ์์ต๋๋ค. ์ด์ ๋ํด ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,102 @@
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
+
+์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.31
+
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - ์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.25
+ - 1,000์์ผ๋ก ์์ํ์ฌ ํฌ๋ฆฌ์ค๋ง์ค๊ฐ ๋ค๊ฐ์ฌ์๋ก ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+ - ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํด๋น ๊ธ์ก๋งํผ ํ ์ธ
+ - (e.g. ์์์ผ์ธ 12์ 1์ผ์ 1,000์, 2์ผ์ 1,100์, ..., 25์ผ์ 3,400์ ํ ์ธ)
+- ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ): ํ์ผ์๋ ๋์ ํธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ): ์ฃผ๋ง์๋ ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ: ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์์ผ๋ฉด ์ด์ฃผ๋ฌธ ๊ธ์ก์์ 1,000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์
+
+
+```
+<์ ํผํ์ด์ >
+์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+<๋ฉ์ธ>
+ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+<๋์ ํธ>
+์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+<์๋ฃ>
+์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+```
+
+
+## ๊ธฐ๋ฅ ๋ชฉ๋ก
+- [x] ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์
๋ ฅ ๋ฐ๋ ๊ธฐ๋ฅ `getDate()`
+ - ์ซ์๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+- [x] ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๊ธฐ๋ฅ (์๋ฃ๋ง ์ฃผ๋ฌธ ํ ์ ์์, ์ต๋ 20๊ฐ๊น์ง ์ฃผ๋ฌธ) `getOrder()`
+ - e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1
+- [x] ์ฃผ๋ฌธ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printMenu(List<String> menus)`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ `calculateTotalOrderAmount()`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printTotalOrderAmount()`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 120,000์ ์ด์์ ์ดํ์ธ์ ์ฆ์ ํ๋ ๊ธฐ๋ฅ `calculateGiftMenu(int totalOrderAmount, int totalDiscount)`
+ - 120,000์ ๋ฏธ๋ง์ "์์" ์ถ๋ ฅ
+- [x] ํฌ๋ฆฌ์ค ๋ง์ค ๋๋ฐ์ด ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ `ddayDiscount(int date)`
+ - 1์ผ ~ 25์ผ ํฌ๋ฆฌ์ค๋ง์ค์ ๋ค๊ฐ์ฌ์๋ก 1,000์ ์์ 100์์ฉ ์ฆ๊ฐ
+- [x] ํ์ผ ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (์ฃผ๋ง ์ ์ธ) `weekDayDiscount(int date, List<String> menus)`
+ - ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- [x] ์ฃผ๋ง ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (1,2,8,9,15,16,22,23,29,30) `weekendDayDiscount(int date, List<String> menus)`
+ - ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- [x] ํน๋ณ ํ ์ธ์ด ๊ฐ๋ฅํ ๋ ์ธ์ง ํ์ธ ํ๋ ๊ธฐ๋ฅ (3,10,17,24,25,31) `starDayDiscount(int date)`
+ - 1,000์ ํ ์ธ
+- [x] ํํ ๋ด์ญ์ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printDiscountAmount(int date, List<String> menus, int totalOrderAmount)`
+ - ๋ฐ์ ํํ์ด ์๋ค๋ฉด "์์" ์ถ๋ ฅ
+- [x] ์ด ํํ ๊ธ์ก์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ์ดํ์ธ์ ๊ฐ๊ฒฉ) `calculateTotalDiscount(int date)`
+ - ํํ ๊ธ์ก์ด ์์ ์ "0์" ์ถ๋ ฅ
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ(ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก - ํ ์ธ ๊ธ์ก) `calculatePayment(int totalOrderAmount, int totalDiscount)`
+- [x] ์ด ํํ ๊ธ์ก์ ๋ฐ๋ผ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `calculateBadge(int totalBenefits)`
+ - 5์ฒ ์ ๋ฏธ๋ง: ์์
+ - 5์ฒ ์ ์ด์: ๋ณ
+ - 1๋ง ์ ์ด์: ํธ๋ฆฌ
+ - 2๋ง ์ ์ด์: ์ฐํ
+
+
+## ํ์ผ ๋ชฉ๋ก
+#### `EventPlanner.java` : ์ด๋ฒคํธ๋ฅผ ๊ณํํ๊ณ ์คํํ๋ ํด๋์ค
+#### `EventProcessor.java` : ์ด๋ฒคํธ ์ฒ๋ฆฌ๋ฅผ ๋ด๋นํ๋ ํด๋์ค
+#### `NoEventProcessor.java` : ์ด๋ฒคํธ๊ฐ ์์ ๋ ์ฒ๋ฆฌ๋ฅผ ๋ด๋นํ๋ ํด๋์ค
+#### `Badge.java` : ์ด๋ฒคํธ ๋ฐฐ์ง ์ด๊ฑฐํ ํด๋์ค
+#### `DateDiscount.java` : ๋ ์ง์ ๋ฐ๋ฅธ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `Menu.java` : ์์ ๋ฉ๋ด ์ด๊ฑฐํ ํด๋์ค
+#### `Order.java` : ์ฃผ๋ฌธ์ ๋ํ๋ด๋ ํด๋์ค
+#### `OrderItem.java` : ์ฃผ๋ฌธ ํญ๋ชฉ์ ๋ํ๋ด๋ ํด๋์ค
+#### `StarDiscount.java` : ๋ณ์ด ํ์๋ ๋ ์ ๋ํ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `TotalDiscountCalculator.java` : ์ด ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `WeekendWeekdayDiscount.java` : ์ฃผ๋ง๊ณผ ํ์ผ์ ๋ํ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `ErrorMessage.java` : ์ค๋ฅ ๋ฉ์์ง ์ด๊ฑฐํ ํด๋์ค
+#### `OrderValidator.java` : ์ฃผ๋ฌธ์ ์ ํจ์ฑ์ ๊ฒ์ฆํ๋ ํด๋์ค
+#### `DiscountOutputPrinter.java` : ํ ์ธ ๋ด์ญ์ ์ถ๋ ฅํ๋ ํด๋์ค
+#### `InputView.java` : ์ฌ์ฉ์ ์
๋ ฅ์ ๋ฐ๋ ํด๋์ค
+#### `OrderOutputPrinter.java` : ์ฃผ๋ฌธ ๋ด์ญ์ ์ถ๋ ฅํ๋ ํด๋์ค
+#### `OutputView.java` : ์ถ๋ ฅ ๊ด๋ จ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ํด๋์ค
+#### `Application.java` : ํ๋ก๊ทธ๋จ์ ์์์ ์ด ๋๋ ํด๋์ค
+
+
+## ํ๋ก๊ทธ๋จ ์ฌ์ฉ๋ฒ
+1. Application ํด๋์ค๋ฅผ ์คํํ์ฌ ํ๋ก๊ทธ๋จ์ ์์ํฉ๋๋ค.
+2. ํ๋ก๊ทธ๋จ์ ์ฌ์ฉ์์๊ฒ ๋ฐฉ๋ฌธ ๋ ์ง์ ์ฃผ๋ฌธ์ ์
๋ ฅํ๋๋ก ์๋ดํฉ๋๋ค.
+3. ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ซ์๋ก ์
๋ ฅํ๋ฉฐ, ์ ํจํ ๋ ์ง์ฌ์ผ ํฉ๋๋ค (1 ~ 31).
+4. ์ฃผ๋ฌธ์ ๋ฉ๋ด์ ์๋์ ์
๋ ฅํ๋ ํ์์ผ๋ก ์ด๋ฃจ์ด์ง๋๋ค (e.g., ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1).
+5. ํ๋ก๊ทธ๋จ์ ์
๋ ฅ๋ ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฒคํธ๋ฅผ ๊ณํํ๊ณ ์ถ๋ ฅํฉ๋๋ค.
+6. ํ ์ธ ๋ด์ญ, ์ฃผ๋ฌธ ๋ฉ๋ด, ์ด ์ฃผ๋ฌธ ๊ธ์ก, ์ด ํํ ๊ธ์ก, ์์ ๊ฒฐ์ ๊ธ์ก, ์ด๋ฒคํธ ๋ฐฐ์ง ๋ฑ์ด ์ถ๋ ฅ๋ฉ๋๋ค.
+
+
+## ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ
+- ์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.31
+- ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000 ์ด์๋ถํฐ ์ด๋ฒคํธ ์ ์ฉ
+- ์๋ฃ๋ง ์ฃผ๋ฌธ์, ์ฃผ๋ฌธํ ์ ์๋ค.
+- ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธ ํ ์ ์๋ค.
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ : 1,000์์ผ๋ก ์์ํ์ฌ ํฌ๋ฆฌ์ค๋ง์ค๊ฐ ๋ค๊ฐ์ฌ์๋ก ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ (2023.12.1 ~ 2023.12.31)
+- ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ): ํ์ผ์๋ ๋์ ํธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ): ์ฃผ๋ง์๋ ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ: ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์์ผ๋ฉด ์ด์ฃผ๋ฌธ ๊ธ์ก์์ 1,000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์ (25,000)
+- ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํด๋น ๊ธ์ก๋งํผ ํ ์ธ
+- ์ดํํ ๊ธ์ก์ ๋ฐ๋ผ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ๋ถ์ฌ (๋ณ, ํธ๋ฆฌ, ์ฐํ) | Unknown | ๊ธฐ๋ฅ ๋ช
์ธ ๊ผผ๊ผผํ๊ฒ ์์ฑํด์ฃผ์
จ๋ค์ ๐๐๐ |
@@ -0,0 +1,32 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.view.OrderOutputPrinter;
+import christmas.view.OutputView;
+
+public class EventPlanner {
+ private static final int MIN_TOTAL_ORDER_AMOUNT_FOR_EVENTS = 10000;
+
+ public static void planEvent(Order order, int date) {
+ int totalOrderAmount = order.calculateTotalOrderAmount();
+
+ printOrderDetails(order, totalOrderAmount);
+
+ processEventBasedOnTotalAmount(order, date, totalOrderAmount);
+ }
+
+ private static void printOrderDetails(Order order, int totalOrderAmount) {
+ OrderOutputPrinter.printMenu(order.getMenus());
+ OutputView.printTotalOrderAmount(totalOrderAmount);
+ }
+
+ private static void processEventBasedOnTotalAmount(Order order, int date, int totalOrderAmount) {
+ if (totalOrderAmount >= MIN_TOTAL_ORDER_AMOUNT_FOR_EVENTS) {
+ EventProcessor.processEvent(order, date, totalOrderAmount);
+ }
+
+ if (totalOrderAmount < MIN_TOTAL_ORDER_AMOUNT_FOR_EVENTS) {
+ NoEventProcessor.processNoEvent(order, date, totalOrderAmount);
+ }
+ }
+} | Java | ํด๋น ๋ฉ์๋ ๋ฐ EventProcessor๋ค์ controller๊ฐ ์๋ ๋น์ฆ๋์ค ๋ก์ง์ ์์ด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค.
controller์ ์ญํ ์ view์ ๊ฐ์ model์๊ฒ ๊ฑด๋ค์ฃผ๊ฑฐ๋, model์ ๊ฐ์ view์๊ฒ ๊ฑด๋ค์ฃผ๋ ์ญํ ๋ก ์ถฉ๋ถํฉ๋๋ค. |
@@ -0,0 +1,43 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.model.OrderItem;
+import christmas.model.TotalDiscountCalculator;
+import christmas.view.DiscountOutputPrinter;
+import christmas.view.OrderOutputPrinter;
+import christmas.view.OutputView;
+import java.util.Set;
+
+public class EventProcessor {
+ public static void processEvent(Order order, int date, int totalOrderAmount) {
+ int totalDiscount = calculateTotalDiscount(order, date);
+ int totalBenefits = TotalDiscountCalculator.calculateGiftMenu(totalOrderAmount, totalDiscount);
+ int totalPayment = TotalDiscountCalculator.calculatePayment(totalOrderAmount, totalDiscount);
+ String giftMenu = OrderOutputPrinter.printGiftMenuMessage(totalOrderAmount);
+
+ OutputView.printGiftMenuPhrase(giftMenu);
+ printDiscountAmount(date, order.getMenus(), totalOrderAmount);
+ printBenefits(totalBenefits);
+ printPayment(totalPayment);
+
+ String badge = TotalDiscountCalculator.calculateBadge(totalOrderAmount, totalDiscount);
+ OutputView.printBadge(badge);
+ }
+
+ public static int calculateTotalDiscount(Order order, int date) {
+ return order.calculateTotalDiscount(date);
+ }
+
+ public static void printDiscountAmount(int date, Set<OrderItem> menus, int totalOrderAmount) {
+ DiscountOutputPrinter.printDiscountAmount(date, menus, totalOrderAmount);
+ }
+
+ public static void printBenefits(int totalBenefits) {
+ DiscountOutputPrinter.printBenefits(totalBenefits);
+ }
+
+ public static void printPayment(int totalPayment) {
+ OutputView.printPayment(totalPayment);
+ }
+
+} | Java | ํด๋น ๋ฉ์๋๋ค ์ ๋ง ๋ถ๋ฆฌํ ํ์๊ฐ ์์์๊น์? |
@@ -0,0 +1,19 @@
+package christmas.controller;
+
+import christmas.model.Badge;
+import christmas.model.Order;
+import christmas.view.OutputView;
+
+public class NoEventProcessor {
+ public static void processNoEvent(Order order, int date, int totalOrderAmount) {
+ int totalDiscount = 0;
+ int totalBenefits = 0;
+ int totalPayment = totalOrderAmount - totalDiscount;
+
+ EventProcessor.printDiscountAmount(date, order.getMenus(), totalDiscount);
+ EventProcessor.printBenefits(totalBenefits);
+ EventProcessor.printPayment(totalPayment);
+
+ OutputView.printBadge(Badge.NONE.getName());
+ }
+} | Java | ํด๋น ๊ฐ ์ญ์ model์ ์ํด ๊ฒฐ์ ๋์ด์ผํฉ๋๋ค.
๊ทธ๋ ๊ฒ ๋ฐ๊พผ๋ค๋ฉด Processor ๊ฐ์ฒด๋ค์ด ํ์๊ฐ ์์ด์ง๊ฒ ๋ค์ |
@@ -0,0 +1,53 @@
+package christmas.model;
+
+import java.util.Arrays;
+
+public enum Menu {
+ ์์ก์ด์ํ(6_000),
+ ํํ์ค(5_500),
+ ์์ ์๋ฌ๋(8_000),
+ ํฐ๋ณธ์คํ
์ดํฌ(55_000),
+ ๋ฐ๋นํ๋ฆฝ(54_000),
+ ํด์ฐ๋ฌผํ์คํ(35_000),
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25_000),
+ ์ด์ฝ์ผ์ดํฌ(15_000),
+ ์์ด์คํฌ๋ฆผ(5_000),
+ ์ ๋ก์ฝ๋ผ(3_000),
+ ๋ ๋์์ธ(60_000),
+ ์ดํ์ธ(25_000);
+
+ private final int price;
+
+ Menu(int price) {
+ this.price = price;
+ }
+
+ public static int getChampagnePrice() {
+ return ์ดํ์ธ.getPrice();
+ }
+
+ public static int getPriceByMenuName(String menuName) {
+ return Menu.valueOf(menuName).getPrice();
+ }
+
+ public static boolean containsMenu(String menuName) {
+ return Arrays.stream(values()).anyMatch(menu -> menu.name().equals(menuName));
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public boolean containsBeverageMenu(String menuName) {
+ return Arrays.asList(์ ๋ก์ฝ๋ผ.name(), ๋ ๋์์ธ.name(), ์ดํ์ธ.name()).contains(menuName);
+ }
+
+ public boolean containsMainMenu(String menuName) {
+ return Arrays.asList(ํฐ๋ณธ์คํ
์ดํฌ.name(), ๋ฐ๋นํ๋ฆฝ.name(), ํด์ฐ๋ฌผํ์คํ.name(), ํฌ๋ฆฌ์ค๋ง์คํ์คํ.name()).contains(menuName);
+ }
+
+ public boolean containsDessertMenu(String menuName) {
+ return Arrays.asList(์ด์ฝ์ผ์ดํฌ.name(), ์์ด์คํฌ๋ฆผ.name()).contains(menuName);
+ }
+
+} | Java | [๊ฐ์ฒด์งํฅ์ํ์ฒด์กฐ ์์น4. ํ ์ค์ ์ ์ ํ๋๋ง ์ฐ๋๋ค.](https://hudi.blog/thoughtworks-anthology-object-calisthenics/)์ ๋ํด ์์๋ณผ๊น์? |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | MVC ํจํด์ ๋น์ฆ๋์ค ๋ก์ง(model)๊ณผ ๋ทฐ ๋ก์ง์ ๋ถ๋ฆฌํ๊ธฐ ์ํด ์ฌ์ฉ๋ฉ๋๋ค.
model ๋ด๋ถ์์ view๊ฐ ์ฌ์ฉ๋๋ค๋ฉด mvc ํจํด์ ์๋ชป ์ฌ์ฉํ๊ณ ์๋ค๋ ์ ํธ์
๋๋ค |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | ๋งค์ง๋๋ฒ ์์ํ ๐๐๐ |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | `"-"` ํด๋น ๊ฐ๋ ์์ํ ํด์ฃผ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,23 @@
+package christmas.model;
+
+public class OrderItem {
+ private final String menuName;
+ private final int quantity;
+
+ public OrderItem(String menuName, int quantity) {
+ this.menuName = menuName;
+ this.quantity = quantity;
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public int calculateMenuAmount() {
+ return quantity * Menu.getPriceByMenuName(menuName);
+ }
+} | Java | ๋ณดํต getter ๋ฉ์๋๋ ์๋ฐ ์ปจ๋ฒค์
์ ๊ฐ์ฅ ์๋์ชฝ์ ์์นํฉ๋๋ค |
@@ -0,0 +1,48 @@
+package christmas.model;
+
+import java.util.Set;
+
+public class TotalDiscountCalculator {
+
+ private static final int GIFT_MENU_ORDER_AMOUNT_THRESHOLD = 120000;
+ private static final int DEFAULT_DISCOUNT = 0;
+
+ public static int calculateDateDiscount(int date, Set<OrderItem> menus) {
+ int dateDiscount = DateDiscount.ddayDiscount(date);
+ int weekDayDiscount = WeekendWeekdayDiscount.weekDayDiscount(date, menus);
+ int weekendDayDiscount = WeekendWeekdayDiscount.weekendDayDiscount(date, menus);
+ return dateDiscount + weekDayDiscount + weekendDayDiscount;
+ }
+
+ public static int calculateStarDiscount(int date) {
+ return StarDiscount.starDayDiscount(date);
+ }
+
+ public static int calculateGiftMenu(int totalOrderAmount, int totalDiscount) {
+ int totalBenefits = totalDiscount;
+ if (totalOrderAmount >= GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ totalBenefits += getGiftMenuPrice();
+ }
+ return totalBenefits;
+ }
+
+ public static int printGiftMenuPrice(int totalOrderAmount) {
+ if (totalOrderAmount < GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ return DEFAULT_DISCOUNT;
+ }
+ return getGiftMenuPrice();
+ }
+
+ public static String calculateBadge(int totalOrderAmount, int calculateTotalDiscount) {
+ int totalBenefits = calculateGiftMenu(totalOrderAmount, calculateTotalDiscount);
+ return Badge.calculateBadge(totalBenefits);
+ }
+
+ public static int calculatePayment(int totalOrderAmount, int totalDiscount) {
+ return totalOrderAmount - totalDiscount;
+ }
+
+ private static int getGiftMenuPrice() {
+ return Menu.getChampagnePrice();
+ }
+} | Java | Discount ๊ด๋ จ ๊ฐ์ฒด๋ค์ด ๋ชจ๋ ์ ํธ์ฑ ํด๋์ค๋ค์.
์ง๋์น๊ฒ ๋จ์ฉ๋๋ค๋ ์๊ฐ์ด ๋ญ๋๋ค.
์ด๋ค ๋ฐฉ๋ฒ์ ์ฐ๋ฉด static ๋ฉ์๋ ์์ด ์ข ๋ ๊ฐ์ฒด์งํฅ์ ์ผ๋ก ์์ฑ์ด ๊ฐ๋ฅํ ๊น์? |
@@ -0,0 +1,139 @@
+package christmas.validator;
+
+import christmas.model.Menu;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Predicate;
+
+public class OrderValidator {
+
+ private static final int MAX_MENU_COUNT = 20;
+ private static final String MENU_REGEX = "^[๊ฐ-ํฃ]+-[1-9]\\d*$";
+ private static final String ENGLISH_REGEX = ".*[a-zA-Z]+.*";
+
+ public static String validateAndGetOrder(String order) {
+ validateOrder(order);
+ return order;
+ }
+
+ private static void validateOrder(String order) {
+ validateOrderCommaFormat(order);
+ validateInvalidMenuInOrder(order);
+ validateOrderFormat(order);
+ validateNoEnglishCharacters(order);
+ validateNoBeverageOnlyOrder(order);
+ validateMenusExist(order);
+ }
+
+ private static void validateNoBeverageOnlyOrder(String order) {
+ if (containsBeverageOnly(order)) {
+ throw new IllegalArgumentException(ErrorMessage.BEVERAGE_ONLY_ORDER.getMessage());
+ }
+ }
+
+ private static void validateInvalidMenuInOrder(String order) {
+ if (isInvalidMenuInOrder(order)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ private static boolean isInvalidMenuInOrder(String order) {
+ return allMatch(order, menuInfo -> {
+ String menuName = menuInfo.split("-")[0].trim();
+ return !Menu.containsMenu(menuName);
+ });
+ }
+
+ private static boolean containsBeverageOnly(String order) {
+ return allMatch(order, menuInfo -> isBeverageMenu(menuInfo.split("-")[0].trim()));
+ }
+
+ private static boolean isBeverageMenu(String menuName) {
+ return Menu.valueOf(menuName).containsBeverageMenu(menuName);
+ }
+
+ private static void validateOrderFormat(String order) {
+ if (!allMatch(order, OrderValidator::isValidMenuEntryFormat)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ private static void validateOrderCommaFormat(String order) {
+ if (order.startsWith(",") || order.endsWith(",")) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ private static boolean allMatch(String order, Predicate<String> predicate) {
+ return Arrays.stream(order.split(",")).allMatch(predicate);
+ }
+
+ private static boolean isValidMenuEntryFormat(String menuEntry) {
+ return menuEntry.matches(MENU_REGEX);
+ }
+
+ private static void validateNoEnglishCharacters(String order) {
+ if (containsEnglish(order)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ private static boolean containsEnglish(String order) {
+ return order.matches(ENGLISH_REGEX);
+ }
+
+ private static void validateMenusExist(String order) {
+ Set<String> uniqueMenus = checkForDuplicateMenus(order);
+ validateTotalMenuCount(order, uniqueMenus.size());
+ }
+
+ private static Set<String> checkForDuplicateMenus(String order) {
+ Set<String> uniqueMenus = new HashSet<>();
+
+ allMatch(order, menuInfo -> {
+ String menuName = menuInfo.split("-")[0].trim();
+ if (!uniqueMenus.add(menuName)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ return true;
+ });
+
+ return uniqueMenus;
+ }
+
+ private static void validateTotalMenuCount(String order, int uniqueMenuCount) {
+ int totalMenuCount = Arrays.stream(order.split(","))
+ .mapToInt(OrderValidator::validateAndGetQuantity)
+ .sum();
+
+ if (totalMenuCount > MAX_MENU_COUNT || uniqueMenuCount > MAX_MENU_COUNT) {
+ throw new IllegalArgumentException(ErrorMessage.MAX_MENU_EXCEEDED.getMessage());
+ }
+ }
+
+ private static int validateAndGetQuantity(String menuInfo) {
+ String[] menuDetails = menuInfo.split("-");
+ validateMenu(menuDetails);
+ return Integer.parseInt(menuDetails[1].trim());
+ }
+
+ private static void validateMenu(String[] menuDetails) {
+ String menuName = menuDetails[0].trim();
+ if (!isValidMenu(menuName)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ validateQuantity(menuDetails[1].trim());
+ }
+
+ private static boolean isValidMenu(String menuName) {
+ return Arrays.stream(Menu.values()).anyMatch(menu -> menu.name().equals(menuName));
+ }
+
+ private static void validateQuantity(String quantityStr) {
+ int quantity = Integer.parseInt(quantityStr);
+ if (quantity < 1) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+} | Java | Validator๋ค ์์ View์ ์์ด์ผํ ๋ก์ง๋ค๊ณผ model์ ์์ด์ผํ ๋ก์ง๋ค์ด ํผ์ฌ๋์ด ์๋ค์.
View์์ ์ฌ์ฉํ Validator์ model์ ์ฌ์ฉํ Validator๋ก ๋ถ๋ฆฌํ๊ณ
๊ฐ๊ฐ์ ํจํค์ง์ ์์น์์ผ๋ณผ๊น์? |
@@ -0,0 +1,28 @@
+package christmas.view;
+
+import christmas.model.OrderItem;
+import java.util.Set;
+
+public class OrderOutputPrinter {
+ private static final String GIFT_MENU_MESSAGE = "์ดํ์ธ 1๊ฐ";
+ private static final String NONE_BENEFIT_MESSAGE = "์์";
+
+ public static void printMenu(Set<OrderItem> menus) {
+ OutputView.printMessage("<์ฃผ๋ฌธ ๋ฉ๋ด>");
+ menus.forEach(OrderOutputPrinter::printMenuItem);
+ OutputView.printEmptyLine();
+ }
+
+ private static void printMenuItem(OrderItem orderItem) {
+ String menuName = orderItem.getMenuName();
+ int quantity = orderItem.getQuantity();
+ OutputView.printMessage(menuName + " " + quantity + "๊ฐ");
+ }
+
+ public static String printGiftMenuMessage(int totalOrderAmount) {
+ if (totalOrderAmount >= 120000) {
+ return GIFT_MENU_MESSAGE;
+ }
+ return NONE_BENEFIT_MESSAGE;
+ }
+} | Java | ์ฃผ๋ฌธ๊ธ์ก์ด 120000์ ๋์ผ๋ฉด ์ดํ์ธ์ ์ฆ์ ํ๋ค๋ ๋น์ฆ๋์ค ๋ก์ง ์๋๊น์? |
@@ -0,0 +1,102 @@
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
+
+์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.31
+
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - ์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.25
+ - 1,000์์ผ๋ก ์์ํ์ฌ ํฌ๋ฆฌ์ค๋ง์ค๊ฐ ๋ค๊ฐ์ฌ์๋ก ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+ - ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํด๋น ๊ธ์ก๋งํผ ํ ์ธ
+ - (e.g. ์์์ผ์ธ 12์ 1์ผ์ 1,000์, 2์ผ์ 1,100์, ..., 25์ผ์ 3,400์ ํ ์ธ)
+- ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ): ํ์ผ์๋ ๋์ ํธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ): ์ฃผ๋ง์๋ ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ: ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์์ผ๋ฉด ์ด์ฃผ๋ฌธ ๊ธ์ก์์ 1,000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์
+
+
+```
+<์ ํผํ์ด์ >
+์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+<๋ฉ์ธ>
+ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+<๋์ ํธ>
+์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+<์๋ฃ>
+์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+```
+
+
+## ๊ธฐ๋ฅ ๋ชฉ๋ก
+- [x] ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์
๋ ฅ ๋ฐ๋ ๊ธฐ๋ฅ `getDate()`
+ - ์ซ์๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+- [x] ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๊ธฐ๋ฅ (์๋ฃ๋ง ์ฃผ๋ฌธ ํ ์ ์์, ์ต๋ 20๊ฐ๊น์ง ์ฃผ๋ฌธ) `getOrder()`
+ - e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1
+- [x] ์ฃผ๋ฌธ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printMenu(List<String> menus)`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ `calculateTotalOrderAmount()`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printTotalOrderAmount()`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 120,000์ ์ด์์ ์ดํ์ธ์ ์ฆ์ ํ๋ ๊ธฐ๋ฅ `calculateGiftMenu(int totalOrderAmount, int totalDiscount)`
+ - 120,000์ ๋ฏธ๋ง์ "์์" ์ถ๋ ฅ
+- [x] ํฌ๋ฆฌ์ค ๋ง์ค ๋๋ฐ์ด ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ `ddayDiscount(int date)`
+ - 1์ผ ~ 25์ผ ํฌ๋ฆฌ์ค๋ง์ค์ ๋ค๊ฐ์ฌ์๋ก 1,000์ ์์ 100์์ฉ ์ฆ๊ฐ
+- [x] ํ์ผ ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (์ฃผ๋ง ์ ์ธ) `weekDayDiscount(int date, List<String> menus)`
+ - ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- [x] ์ฃผ๋ง ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (1,2,8,9,15,16,22,23,29,30) `weekendDayDiscount(int date, List<String> menus)`
+ - ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- [x] ํน๋ณ ํ ์ธ์ด ๊ฐ๋ฅํ ๋ ์ธ์ง ํ์ธ ํ๋ ๊ธฐ๋ฅ (3,10,17,24,25,31) `starDayDiscount(int date)`
+ - 1,000์ ํ ์ธ
+- [x] ํํ ๋ด์ญ์ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printDiscountAmount(int date, List<String> menus, int totalOrderAmount)`
+ - ๋ฐ์ ํํ์ด ์๋ค๋ฉด "์์" ์ถ๋ ฅ
+- [x] ์ด ํํ ๊ธ์ก์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ์ดํ์ธ์ ๊ฐ๊ฒฉ) `calculateTotalDiscount(int date)`
+ - ํํ ๊ธ์ก์ด ์์ ์ "0์" ์ถ๋ ฅ
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ(ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก - ํ ์ธ ๊ธ์ก) `calculatePayment(int totalOrderAmount, int totalDiscount)`
+- [x] ์ด ํํ ๊ธ์ก์ ๋ฐ๋ผ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `calculateBadge(int totalBenefits)`
+ - 5์ฒ ์ ๋ฏธ๋ง: ์์
+ - 5์ฒ ์ ์ด์: ๋ณ
+ - 1๋ง ์ ์ด์: ํธ๋ฆฌ
+ - 2๋ง ์ ์ด์: ์ฐํ
+
+
+## ํ์ผ ๋ชฉ๋ก
+#### `EventPlanner.java` : ์ด๋ฒคํธ๋ฅผ ๊ณํํ๊ณ ์คํํ๋ ํด๋์ค
+#### `EventProcessor.java` : ์ด๋ฒคํธ ์ฒ๋ฆฌ๋ฅผ ๋ด๋นํ๋ ํด๋์ค
+#### `NoEventProcessor.java` : ์ด๋ฒคํธ๊ฐ ์์ ๋ ์ฒ๋ฆฌ๋ฅผ ๋ด๋นํ๋ ํด๋์ค
+#### `Badge.java` : ์ด๋ฒคํธ ๋ฐฐ์ง ์ด๊ฑฐํ ํด๋์ค
+#### `DateDiscount.java` : ๋ ์ง์ ๋ฐ๋ฅธ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `Menu.java` : ์์ ๋ฉ๋ด ์ด๊ฑฐํ ํด๋์ค
+#### `Order.java` : ์ฃผ๋ฌธ์ ๋ํ๋ด๋ ํด๋์ค
+#### `OrderItem.java` : ์ฃผ๋ฌธ ํญ๋ชฉ์ ๋ํ๋ด๋ ํด๋์ค
+#### `StarDiscount.java` : ๋ณ์ด ํ์๋ ๋ ์ ๋ํ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `TotalDiscountCalculator.java` : ์ด ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `WeekendWeekdayDiscount.java` : ์ฃผ๋ง๊ณผ ํ์ผ์ ๋ํ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `ErrorMessage.java` : ์ค๋ฅ ๋ฉ์์ง ์ด๊ฑฐํ ํด๋์ค
+#### `OrderValidator.java` : ์ฃผ๋ฌธ์ ์ ํจ์ฑ์ ๊ฒ์ฆํ๋ ํด๋์ค
+#### `DiscountOutputPrinter.java` : ํ ์ธ ๋ด์ญ์ ์ถ๋ ฅํ๋ ํด๋์ค
+#### `InputView.java` : ์ฌ์ฉ์ ์
๋ ฅ์ ๋ฐ๋ ํด๋์ค
+#### `OrderOutputPrinter.java` : ์ฃผ๋ฌธ ๋ด์ญ์ ์ถ๋ ฅํ๋ ํด๋์ค
+#### `OutputView.java` : ์ถ๋ ฅ ๊ด๋ จ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ํด๋์ค
+#### `Application.java` : ํ๋ก๊ทธ๋จ์ ์์์ ์ด ๋๋ ํด๋์ค
+
+
+## ํ๋ก๊ทธ๋จ ์ฌ์ฉ๋ฒ
+1. Application ํด๋์ค๋ฅผ ์คํํ์ฌ ํ๋ก๊ทธ๋จ์ ์์ํฉ๋๋ค.
+2. ํ๋ก๊ทธ๋จ์ ์ฌ์ฉ์์๊ฒ ๋ฐฉ๋ฌธ ๋ ์ง์ ์ฃผ๋ฌธ์ ์
๋ ฅํ๋๋ก ์๋ดํฉ๋๋ค.
+3. ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ซ์๋ก ์
๋ ฅํ๋ฉฐ, ์ ํจํ ๋ ์ง์ฌ์ผ ํฉ๋๋ค (1 ~ 31).
+4. ์ฃผ๋ฌธ์ ๋ฉ๋ด์ ์๋์ ์
๋ ฅํ๋ ํ์์ผ๋ก ์ด๋ฃจ์ด์ง๋๋ค (e.g., ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1).
+5. ํ๋ก๊ทธ๋จ์ ์
๋ ฅ๋ ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฒคํธ๋ฅผ ๊ณํํ๊ณ ์ถ๋ ฅํฉ๋๋ค.
+6. ํ ์ธ ๋ด์ญ, ์ฃผ๋ฌธ ๋ฉ๋ด, ์ด ์ฃผ๋ฌธ ๊ธ์ก, ์ด ํํ ๊ธ์ก, ์์ ๊ฒฐ์ ๊ธ์ก, ์ด๋ฒคํธ ๋ฐฐ์ง ๋ฑ์ด ์ถ๋ ฅ๋ฉ๋๋ค.
+
+
+## ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ
+- ์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.31
+- ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000 ์ด์๋ถํฐ ์ด๋ฒคํธ ์ ์ฉ
+- ์๋ฃ๋ง ์ฃผ๋ฌธ์, ์ฃผ๋ฌธํ ์ ์๋ค.
+- ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธ ํ ์ ์๋ค.
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ : 1,000์์ผ๋ก ์์ํ์ฌ ํฌ๋ฆฌ์ค๋ง์ค๊ฐ ๋ค๊ฐ์ฌ์๋ก ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ (2023.12.1 ~ 2023.12.31)
+- ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ): ํ์ผ์๋ ๋์ ํธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ): ์ฃผ๋ง์๋ ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ: ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์์ผ๋ฉด ์ด์ฃผ๋ฌธ ๊ธ์ก์์ 1,000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์ (25,000)
+- ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํด๋น ๊ธ์ก๋งํผ ํ ์ธ
+- ์ดํํ ๊ธ์ก์ ๋ฐ๋ผ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ๋ถ์ฌ (๋ณ, ํธ๋ฆฌ, ์ฐํ) | Unknown | ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,23 @@
+package christmas.model;
+
+public class OrderItem {
+ private final String menuName;
+ private final int quantity;
+
+ public OrderItem(String menuName, int quantity) {
+ this.menuName = menuName;
+ this.quantity = quantity;
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public int calculateMenuAmount() {
+ return quantity * Menu.getPriceByMenuName(menuName);
+ }
+} | Java | ํ์ธํ๋ค๊ณ ํ๋๋ฐ ๋์น ๋ถ๋ถ์ด ์์๋ค์ ใ
ใ
์์ ํ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | ์ ์ ์์ํ ๊ณต๋ถ์ค ๋ธ๋ก๊ทธ ๊ธ์์ ","(comma)๋ฅผ ์์ํ ํ๋๊ฒ ์๋ฏธ์๋ ์์ํ๋ผ๋ ๊ธ์ ๋ณธ ์ ์ด ์์ต๋๋ค.
"-" ํด๋น ๊ฐ๋ ์์ํ ํด์ฃผ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ๋ค๊ณ ๋ง์ํด ์ฃผ์
จ๋๋ฐ ํน์ ","(comma)์ ๋ค๋ฅธ ์ด์ ๊ฐ ์๋์ง ์ฌ์ญค๋ณด๊ณ ์ถ์ต๋๋ค. |
@@ -0,0 +1,48 @@
+package christmas.model;
+
+import java.util.Set;
+
+public class TotalDiscountCalculator {
+
+ private static final int GIFT_MENU_ORDER_AMOUNT_THRESHOLD = 120000;
+ private static final int DEFAULT_DISCOUNT = 0;
+
+ public static int calculateDateDiscount(int date, Set<OrderItem> menus) {
+ int dateDiscount = DateDiscount.ddayDiscount(date);
+ int weekDayDiscount = WeekendWeekdayDiscount.weekDayDiscount(date, menus);
+ int weekendDayDiscount = WeekendWeekdayDiscount.weekendDayDiscount(date, menus);
+ return dateDiscount + weekDayDiscount + weekendDayDiscount;
+ }
+
+ public static int calculateStarDiscount(int date) {
+ return StarDiscount.starDayDiscount(date);
+ }
+
+ public static int calculateGiftMenu(int totalOrderAmount, int totalDiscount) {
+ int totalBenefits = totalDiscount;
+ if (totalOrderAmount >= GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ totalBenefits += getGiftMenuPrice();
+ }
+ return totalBenefits;
+ }
+
+ public static int printGiftMenuPrice(int totalOrderAmount) {
+ if (totalOrderAmount < GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ return DEFAULT_DISCOUNT;
+ }
+ return getGiftMenuPrice();
+ }
+
+ public static String calculateBadge(int totalOrderAmount, int calculateTotalDiscount) {
+ int totalBenefits = calculateGiftMenu(totalOrderAmount, calculateTotalDiscount);
+ return Badge.calculateBadge(totalBenefits);
+ }
+
+ public static int calculatePayment(int totalOrderAmount, int totalDiscount) {
+ return totalOrderAmount - totalDiscount;
+ }
+
+ private static int getGiftMenuPrice() {
+ return Menu.getChampagnePrice();
+ }
+} | Java | TotalDiscountCalculator ํด๋์ค๋ฅผ ๊ฐ์ฒด๋ก ๋ณ๊ฒฝํ๊ณ ํ์ํ Discount ๊ณ์ฐ ๋ก์ง์ ์ฌ๋ฌ ์ธ์คํด์ค ๋ฉ์๋๋ก ๋ถํ ํ๋ค๋ฉด static ๋ฉ์๋ ์์ด ์ข ๋ ๊ฐ์ฒด์งํฅ์ ์ผ๋ก ๋ณ๊ฒฝํ ์ ์์๊ฒ ๊ฐ์๋ฐ ์ ๊ฐ ์๊ฐํ ๋ฐฉ๋ฒ์ด ๋ง์์ง ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,48 @@
+package christmas.model;
+
+import java.util.Set;
+
+public class TotalDiscountCalculator {
+
+ private static final int GIFT_MENU_ORDER_AMOUNT_THRESHOLD = 120000;
+ private static final int DEFAULT_DISCOUNT = 0;
+
+ public static int calculateDateDiscount(int date, Set<OrderItem> menus) {
+ int dateDiscount = DateDiscount.ddayDiscount(date);
+ int weekDayDiscount = WeekendWeekdayDiscount.weekDayDiscount(date, menus);
+ int weekendDayDiscount = WeekendWeekdayDiscount.weekendDayDiscount(date, menus);
+ return dateDiscount + weekDayDiscount + weekendDayDiscount;
+ }
+
+ public static int calculateStarDiscount(int date) {
+ return StarDiscount.starDayDiscount(date);
+ }
+
+ public static int calculateGiftMenu(int totalOrderAmount, int totalDiscount) {
+ int totalBenefits = totalDiscount;
+ if (totalOrderAmount >= GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ totalBenefits += getGiftMenuPrice();
+ }
+ return totalBenefits;
+ }
+
+ public static int printGiftMenuPrice(int totalOrderAmount) {
+ if (totalOrderAmount < GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ return DEFAULT_DISCOUNT;
+ }
+ return getGiftMenuPrice();
+ }
+
+ public static String calculateBadge(int totalOrderAmount, int calculateTotalDiscount) {
+ int totalBenefits = calculateGiftMenu(totalOrderAmount, calculateTotalDiscount);
+ return Badge.calculateBadge(totalBenefits);
+ }
+
+ public static int calculatePayment(int totalOrderAmount, int totalDiscount) {
+ return totalOrderAmount - totalDiscount;
+ }
+
+ private static int getGiftMenuPrice() {
+ return Menu.getChampagnePrice();
+ }
+} | Java | ์ ๊ฐ ์ฝ๋๋ฅผ ์๋ชป ์์ฑํ๋ค์..
๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | ์์ํ๋ฅผ ํ๋ ๋ชฉ์ ์ ๋ฌด์์ผ๊น์?
๊ฐ์ฅ ํฐ ์ด์ ๋ ํด๋น ๊ฐ์ด ์ฝ๋์ ๋งฅ๋ฝ์
`์ด๋ค ์ญํ `์ ํ๋์ง ๋ํ๋ด๊ธฐ ์ํด ์ ์ ํ ์ด๋ฆ์ ๋ถ์ด๋ ๊ฒ์
๋๋ค.
`","`๋ฅผ `comma`๋ผ๊ณ ๋ค์ด๋ฐํ๋ ๊ฒ์ ์ ์๋ฏธ ์๋ ์์ํ์ผ๊น์?
1. comma๋ผ๋ ์ด๋ฆ์ ํด๋น ๋ฌธ์ฅ ๋ถํธ์ ์ด๋ฆ์ด์ง, ์ฝ๋์์ ํด๋น ๋ฌธ์ฅ ๋ถํธ์ ์ญํ ์ ๋ํด ํํํ ์ด๋ฆ์ด ์๋๋๋ค.
2. menu๋ผ๋ String์ ํ์์ด ๋ฐ๋์ด ๋ฉ๋ด ์ด๋ฆ๊ณผ ์๋์ ๊ตฌ๋ถํ๋ ๊ตฌ๋ถ์๊ฐ `","`์์ `"-"`๋ก ๋ณํํ๋ค๋ฉด
์์์ ๋ค์ด๋ฐ๋ `comma`์์ `hyphen`์ผ๋ก ๋ณ๊ฒฝํด์ค์ผํฉ๋๋ค.
๊ตฌ๋ถ์๊ฐ ๋ฐ๋๋๋ง๋ค ์์์ ์ด๋ฆ์ ๋ฐ๊พธ๊ณ ํด๋น ์์๋ฅผ ์ฌ์ฉํ๋ ๋ชจ๋ ๊ณณ์์ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํด์ผํ๋ค๋ฉด
์์ํ๋ฅผ ํ๋ ๋ชฉ์ ์ ๋ฌ์ฑํ๋ค๊ณ ๋ณด๊ธฐ ํ๋ค๊ฒ ์ฃ .
๊ทธ๋ฐ ์ด์ ์์ ","(comma)๋ฅผ ์์ํ ํ๋๊ฒ ์๋ฏธ์๋ ์์ํ๋ผ๊ณ ํํํ ๊ฒ์
๋๋ค.
์ด ์๋ฏธ๋ ๋งค์ง ๋ฆฌํฐ๋ด์ ์์ํํ์ง ๋ง๋ผ๋ ์๋ฏธ๊ฐ ์๋, ์ ์๋ฏธํ ๋ค์ด๋ฐ์ผ๋ก ์์ํํ๋ผ๋ ์๋ฏธ์
๋๋ค. |
@@ -0,0 +1,48 @@
+package christmas.model;
+
+import java.util.Set;
+
+public class TotalDiscountCalculator {
+
+ private static final int GIFT_MENU_ORDER_AMOUNT_THRESHOLD = 120000;
+ private static final int DEFAULT_DISCOUNT = 0;
+
+ public static int calculateDateDiscount(int date, Set<OrderItem> menus) {
+ int dateDiscount = DateDiscount.ddayDiscount(date);
+ int weekDayDiscount = WeekendWeekdayDiscount.weekDayDiscount(date, menus);
+ int weekendDayDiscount = WeekendWeekdayDiscount.weekendDayDiscount(date, menus);
+ return dateDiscount + weekDayDiscount + weekendDayDiscount;
+ }
+
+ public static int calculateStarDiscount(int date) {
+ return StarDiscount.starDayDiscount(date);
+ }
+
+ public static int calculateGiftMenu(int totalOrderAmount, int totalDiscount) {
+ int totalBenefits = totalDiscount;
+ if (totalOrderAmount >= GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ totalBenefits += getGiftMenuPrice();
+ }
+ return totalBenefits;
+ }
+
+ public static int printGiftMenuPrice(int totalOrderAmount) {
+ if (totalOrderAmount < GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ return DEFAULT_DISCOUNT;
+ }
+ return getGiftMenuPrice();
+ }
+
+ public static String calculateBadge(int totalOrderAmount, int calculateTotalDiscount) {
+ int totalBenefits = calculateGiftMenu(totalOrderAmount, calculateTotalDiscount);
+ return Badge.calculateBadge(totalBenefits);
+ }
+
+ public static int calculatePayment(int totalOrderAmount, int totalDiscount) {
+ return totalOrderAmount - totalDiscount;
+ }
+
+ private static int getGiftMenuPrice() {
+ return Menu.getChampagnePrice();
+ }
+} | Java | ๊ฐ์ฒด์งํฅ์์ ๊ฐ์ฒด๋ ๋ฌด์์ผ๊น์?
์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ฒด๋ `์ํ(State)` ์ `ํ๋(Behavior)` ์ ๊ฐ์ง๋ ๊ฒ์ ๋งํฉ๋๋ค.
์ฝ๋์ ์ผ๋ก๋ ์๊ณ ์๋ ๊ฒ๋ค(์ํ)๋ฅผ ์ธ์คํด์ค ๋ณ์๋ก ๋ํ๋ด๊ณ ,
ํ ์ ์๋ ๊ฒ๋ค(ํ๋)์ ๋ฉ์๋๋ก ๋ํ๋ด๋ ๊ฒ์ ์๋ฏธํ๊ฒ ์ฃ .
์ด๋ฌํ ๊ด์ ์์ ์ ์ฒด์ ์ธ ์ค๊ณ๋ฅผ ์ฌ๊ฒํ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ใ
ใ
|
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | ํ
์คํธ์์ ์ฐ์ด๋ ๋ฐ์ดํฐ๋ค์ ํ ๊ณณ์ ๋ชจ์๋์ผ์
จ๋ค์. ํ
์คํธ ์ผ์ด์ค๊ฐ ๋ง์์ง๋ฉด ๋ง์์ง์๋ก ํ
์คํธ ์ฝ๋ ์์ฒด๊ฐ ๊ธธ์ด์ง๋๋ฐ, ์ด๋ฐ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ฉด ๋ฐฉ์งํ ์ ์๊ฒ ์ด์!
๊ทธ๋ฐ๋ฐ ์ด ๋ฐฉ์์ ์ฑํํ๋ฉด ํ์ฌ ํ
์คํธํ๋ ์ผ์ด์ค๊ฐ ๋ฌด์์ธ์ง ํ
์คํธ ์ฝ๋์ ์ง์ ์ ์ผ๋ก ๋๋ฌ๋์ง ์์์, ์ด๋ค ๊ฐ์ด ์
๋ ฅ๋๊ณ ๊ทธ์ ๋ํ ๊ฒฐ๊ณผ ๊ฐ์ ๋ฌด์์ธ์ง ์๊ธฐ๊ฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์. ๋ ํ
์คํธ ๋ด์ฉ์ด ๋ฐ๋๋ค๋ฉด, ํ
์คํธ ์ผ์ด์ค ํ์ผ๋ก ๋์ด๊ฐ์ ํ
์คํธ ์ผ์ด์ค๋ฅผ ๋ณ๊ฒฝํด์ผ ํ ์๋ ์์ ๊ฒ์๋ฐ, ๊ด๋ฆฌํ๊ธฐ ์ด๋ ต์ง ์์๊น ์ถ์ด์.
์ด๋ค ์ด์ ์์ ์ด ๋ฐฉ๋ฒ์ ์ฑํํ์
จ๋์ง๊ฐ ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,17 @@
+import { EOL as LINE_SEPARATOR } from "os";
+
+export const COMMON_STRINGS = {
+ LINE_SEPARATOR,
+ EMPTY: "",
+ WHITE_SPACE: " ",
+ COLON: ":",
+ DASH: "-",
+ COMMA: ",",
+};
+
+export const CATEGORY_DICT = {
+ appetizer: "appetizer",
+ main: "main",
+ dessert: "dessert",
+ drink: "drink",
+}; | JavaScript | ์ด ๋ถ๋ถ์ ๋ค๋ฅธ common ํ์ผ์ ์์ฑํ์ ์ด์ ๊ฐ ์๋์? domain์์ ์ฌ์ฉํ๊ณ ์๋๋ฐ, domain์ ์ง์ ์์ฑํ๋ค๊ฑฐ๋, 'category'๋ผ๋ ์์ ํ์ผ์ ๋ฐ๋ก ๋ง๋ ๋ค๊ฑฐ๋ ํ์ง ์๊ณ ์ฌ๊ธฐ์ ์์ฑํ์ ์ด์ ๊ฐ ๊ถ๊ธํด์. Enum๊ฐ์ ๊ฐ๋
์ด๋ผ ๋ฐ๋ก ๋นผ์ ๊ฑธ๊น์? |
@@ -0,0 +1,5 @@
+export { default as DOMAIN } from "./domain.js";
+export { default as INPUT } from "./input.js";
+export { default as OUTPUT } from "./output.js";
+export { default as ERROR } from "./error.js";
+export { default as VALIDATION } from "./validation.js"; | JavaScript | ์์๋ฅผ ์ ์ธํ ํ์ผ์์๋ `export default`๋ฅผ ํด์ฃผ๊ณ ์๋๋ฐ, ๊ทธ๋ฐ ์์ ํ์ผ๋ค์ ๊ฐ์ธ๋ ํ์ผ์ ์ฌ์ฉํ๋ ์ด์ ๊ฐ ๊ถ๊ธํด์. ์ด๋ค ์ด์ ๋๋ฌธ์ ์ด๋ฐ ๋ฐฉ์์ ์ฑํํ์ ๊ฑด๊ฐ์? |
@@ -0,0 +1,27 @@
+import { ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class BasicCalculator {
+ /** @param {MainOrder} mainOrder */
+ static originalTotal(mainOrder) {
+ const nestedMenus = mainOrder.getMenus();
+ const result = Object.values(nestedMenus)
+ .map((menus) => BasicCalculator.calcMenus(menus));
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {{[menu: string]: number}} menus */
+ static calcMenus(menus) {
+ const result = Object.entries(menus)
+ .map(([k, v]) => DOMAIN.MENU_DICT[k].price * v);
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static calcEventFlag(mainOrder) {
+ const originalTotal = BasicCalculator.originalTotal(mainOrder);
+ return Boolean(DOMAIN.EVENT_THRESHOLD_INCLUSIVE <= originalTotal);
+ }
+}
+
+export default BasicCalculator; | JavaScript | `key`, `value`์๋ ์ด๋ฆ์ ๋ถ์ด๋ฉด ๋ ์ดํดํ๊ธฐ ์ฌ์ธ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,27 @@
+import { ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class BasicCalculator {
+ /** @param {MainOrder} mainOrder */
+ static originalTotal(mainOrder) {
+ const nestedMenus = mainOrder.getMenus();
+ const result = Object.values(nestedMenus)
+ .map((menus) => BasicCalculator.calcMenus(menus));
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {{[menu: string]: number}} menus */
+ static calcMenus(menus) {
+ const result = Object.entries(menus)
+ .map(([k, v]) => DOMAIN.MENU_DICT[k].price * v);
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static calcEventFlag(mainOrder) {
+ const originalTotal = BasicCalculator.originalTotal(mainOrder);
+ return Boolean(DOMAIN.EVENT_THRESHOLD_INCLUSIVE <= originalTotal);
+ }
+}
+
+export default BasicCalculator; | JavaScript | `Boolean()`์ ์ฌ์ฉํ์ง ์์๋ ๊ฒฐ๊ณผ๊ฐ ๊ฐ์๋ฐ ์ ๊ฑฐํด๋ ๋์ง ์์๊น์? |
@@ -0,0 +1,75 @@
+// eslint-disable-next-line no-unused-vars
+import MainOrder from "./MainOrder.js";
+import BasicCalculator from "./BasicCalculator.js";
+import { DayCalc, ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class DiscountCalculator {
+ // ์์ ๋ฉ์๋(๋
ผ๋ฆฌ์ )
+ /** @param {MainOrder} mainOrder */
+ static #calcEventFlag(mainOrder) {
+ return BasicCalculator.calcEventFlag(mainOrder);
+ }
+
+ // ๊ณ ์ ๋ฉ์๋
+ /** @param {MainOrder} mainOrder */
+ static discountInfo(mainOrder) {
+ const christmas = DiscountCalculator.christmasDiscount(mainOrder);
+ const weekday = DiscountCalculator.weekdayDiscount(mainOrder);
+ const weekend = DiscountCalculator.weekendDiscount(mainOrder);
+ const special = DiscountCalculator.specialDiscount(mainOrder);
+
+ return {
+ christmas, weekday, weekend, special,
+ };
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static weekdayDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (DayCalc.isWeekend(day)) return 0;
+ const { dessert } = mainOrder.getMenus();
+ const quantity = ItemCalc.sumObjValue(dessert);
+ return quantity * DOMAIN.WEEKDAY_DISCOUNT_PER_MENUS;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static weekendDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (!DayCalc.isWeekend(day)) return 0;
+ const { main } = mainOrder.getMenus();
+ const quantity = ItemCalc.sumObjValue(main);
+ return quantity * DOMAIN.WEEKEND_DISCOUNT_PER_MENUS;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static specialDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (!DayCalc.isSpecialDay(day)) return 0;
+ return DOMAIN.SPECIAL_DAY_DISCOUNT;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static christmasDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ const [start, end] = [DOMAIN.D_DAY_START_INCLUSIVE, DOMAIN.D_DAY_END_INCLUSIVE];
+
+ if (end < day) return 0;
+ const multiplier = DayCalc.eventMoneyMultiplier(start, end, day);
+ return DOMAIN.D_DAY_DEFAULT_DISCOUNT + multiplier * DOMAIN.D_DAY_BONUS_DISCOUNT;
+ }
+}
+
+export default DiscountCalculator; | JavaScript | `eventFlag`๋ฅผ ํ์ธํ๋ ๋ถ๋ถ์ด ๋ค๋ฅธ ๊ณ์ฐ ๋ฉ์๋์์๋ ์ค๋ณตํ์ฌ ์ํ๋๊ณ ์๋๋ฐ, ์ด๊ฑธ ๋ฐ๊นฅ์ผ๋ก ๋นผ๋ด์ ์ฌ์ฌ์ฉํ๋ ๊ฑด ์ด๋จ๊น์? ์๋๋ฉด `eventFlag`๋ฅผ ํ์ธํ๋ ์์น๋ฅผ ๋ค๋ฅธ ๊ณณ์ ๋ ์๋ ์์ ๊ฒ ๊ฐ์์. ๊ฐ๊ฐ์ ๋ฉ์๋ ์์ ๋ฃ์ผ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค.
```javascript
calculate(detailFunction) {
const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
if (!eventFlag) return 0;
detailFunction();
}
weekdayDiscount(mainOrder) {
const day = mainOrder.getDate();
if (DayCalc.isWeekend(day)) return 0;
const { dessert } = mainOrder.getMenus();
const quantity = ItemCalc.sumObjValue(dessert);
return quantity * DOMAIN.WEEKDAY_DISCOUNT_PER_MENUS;
}
calculate(() => weekdayDscount(mainOrder));
``` |
@@ -0,0 +1,34 @@
+import { DomainValidator } from "../utils/Validator/index.js";
+import { DomainParser } from "../utils/Parser/index.js";
+
+class MainOrder {
+ /** @type {number} */
+ #date;
+
+ /** @type {{appetizer: {}, main: {}, dessert:{}, drink: {}}} */
+ #menus;
+
+ /** @param {number} date */
+ constructor(date) {
+ DomainValidator.date(date);
+ this.#date = date;
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ /** @param {[string]} rawOrder */
+ setMenus(rawOrder) {
+ if (this.#menus) throw new Error();
+ DomainValidator.menus(rawOrder);
+ const parsedMenu = DomainParser.menus(rawOrder);
+ this.#menus = parsedMenu;
+ }
+
+ getMenus() {
+ return this.#menus;
+ }
+}
+
+export default MainOrder; | JavaScript | ๋ฉ๋ด๋ฅผ ์นดํ
๊ณ ๋ฆฌ๋ณ๋ก ๋๋์ด์ ์ ์ฅํ๋ ๊ฒ ํธ๋ฆฌํ๊ณ ์ข์ ๊ฒ ๊ฐ์์ ๐ |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | ์ ํน๋ณํ ๋ฆฌ๋ทฐ๋ฅผ ๋ง ๋ฐ์์ผ๊ฒ ๋ค๋ ๋ง์์ผ๋ก ๋ฆฌ๋ทฐ๋ฅผ ๋จ๊ธด ๊ฒ์ ์๋์ง๋ง ์์ฃผ์
์ ๋๋ฌด ๊ฐ์ฌํฉ๋๋ค.
์ฐ์ `static`๋ง ์ฐ๋ ๋ฉ์๋์ ๋ํด์ ๋ง์๋๋ฆฌ๊ฒ ์ต๋๋ค. ์ฌ์ค ์ ๋ ์ด๋ฒ ์ฐํ
์ฝ๊ฐ ํด๋์ค๋ฅผ ๊ตฌํํด์ ํ๋ก๊ทธ๋๋ฐํ๋ ๊ฒ์ด ์ฒ์์ธ๋ฐ์... ๋ฏธ์
์ ํธ์ ๊ตฌ์กฐ์์ `static`์ ์ฐ๋ ๊ฒ์ ๋ณด๊ณ ์ผ๋จ์ `static` ๋ฉ์๋๋ฅผ ์ค์ฌ์ผ๋ก ์ฐ๊ฒ ๋์์ด์. ์ ๊ฐ์ฒด๋ณด๋ค ํด๋์ค๋ฅผ ์ ํธํ๋์ง ๋ฌผ์ด๋ณด์ ๋ค๋ฉด... ์ผ๋จ์ ๋ฉ์๋๋ฅผ ํธ์ถํ ๋ ์๋ฌด๋๋ ๋๋ฌธ์๋ฅผ ์ฐ๊ณ ์ถ๊ธฐ๋ ํ๊ณ (ํด๋์ค, ์์ฑ์๊ฐ ์๋ ๊ฒฝ์ฐ ๋๋ฌธ์๋ฅผ ์ฐ๋ ๊ฑด ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋ ์ปจ๋ฒค์
์ ์๋ฐฐ๋๋๊น), ๋ ๊ฐ์ฒด์ ๊ฒฝ์ฐ์ ์๋ฌด๋๋ ๋ฐํ์์์ ์กฐ์๋ ์ ์๋ค๋ ์๊ฐ์ด ๋ค์ด์. ํด๋์ค๋ผ๊ณ ๋ ์์ ํ ๊ฑด ์๋๊ฒ ์ง๋ง... ์๋ฌด๋๋ ๊ทธ๋ฅ ์ฐํ
์ฝ์์ ์ฐ๋๊น ์ด์ ๊ฐ ์๊ฒ ๊ฑฐ๋ ํ ๋ถ๋ถ์ด ํฝ๋๋ค.
๋ง๋ถ์ฌ์ `static` ๋ฉ์๋๋ฅผ ์ฐ๋ ์ด์ ๋.. ์๋ฌด๋๋ ์ธ์คํด์ค๋ฅผ ์ ๋ง๋ค๊ณ ์ถ๋ค๋ ์๊ฐ์ด ํฐ ๊ฒ ๊ฐ๋ค์. ์ธ์คํด์ค๋ฅผ ์์ฑ์ํค๊ณ '๊ฒฐ๊ณผ'๋ฅผ ์ค๊ฐ ์ํ๋ก ๊ด๋ฆฌํ๊ฒ ๋ ๊ฒฝ์ฐ์, ์ฃผ๋ฌธ์ด ๋ฐ๋๊ฑฐ๋ ๋ฐฉ๋ฌธ ์ผ์ ์ ๋ฐ๊พผ๋ค๊ฑฐ๋ ํ๋ ์กฐ์์ ํ์ ๊ฒฝ์ฐ์ ์ค๊ฐ ๊ฒฐ๊ณผ๊น์ง ๋ฐ๊พธ์ด์ผ ํ๋๋ฐ ๊ทธ๊ฒ ์กฐ๊ธ ๋ฒ๊ฑฐ๋ก์ธ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ ์ธ์คํด์ค๋ฅผ ๊ฐ์ง ์๋ ํด๋์ค๋ฅผ ๋ง์ด ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ถฉ๋ถํ ๋๋ต์ ์๋๊ฒ ์ง๋ง ๋์ถฉ์ ์ด๋ ๋ค์ ๐ |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | > ํ
์คํธ์์ ์ฐ์ด๋ ๋ฐ์ดํฐ๋ค์ ํ ๊ณณ์ ๋ชจ์๋์ผ์
จ๋ค์. ํ
์คํธ ์ผ์ด์ค๊ฐ ๋ง์์ง๋ฉด ๋ง์์ง์๋ก ํ
์คํธ ์ฝ๋ ์์ฒด๊ฐ ๊ธธ์ด์ง๋๋ฐ, ์ด๋ฐ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ฉด ๋ฐฉ์งํ ์ ์๊ฒ ์ด์!
>
> ๊ทธ๋ฐ๋ฐ ์ด ๋ฐฉ์์ ์ฑํํ๋ฉด ํ์ฌ ํ
์คํธํ๋ ์ผ์ด์ค๊ฐ ๋ฌด์์ธ์ง ํ
์คํธ ์ฝ๋์ ์ง์ ์ ์ผ๋ก ๋๋ฌ๋์ง ์์์, ์ด๋ค ๊ฐ์ด ์
๋ ฅ๋๊ณ ๊ทธ์ ๋ํ ๊ฒฐ๊ณผ ๊ฐ์ ๋ฌด์์ธ์ง ์๊ธฐ๊ฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์. ๋ ํ
์คํธ ๋ด์ฉ์ด ๋ฐ๋๋ค๋ฉด, ํ
์คํธ ์ผ์ด์ค ํ์ผ๋ก ๋์ด๊ฐ์ ํ
์คํธ ์ผ์ด์ค๋ฅผ ๋ณ๊ฒฝํด์ผ ํ ์๋ ์์ ๊ฒ์๋ฐ, ๊ด๋ฆฌํ๊ธฐ ์ด๋ ต์ง ์์๊น ์ถ์ด์.
>
> ์ด๋ค ์ด์ ์์ ์ด ๋ฐฉ๋ฒ์ ์ฑํํ์
จ๋์ง๊ฐ ๊ถ๊ธํฉ๋๋ค!
ํ
์คํธ ์ผ์ด์ค์ ๊ฒฝ์ฐ์๋ ์ฌ์ค ์ ๋ 3์ฃผ์ฐจ๊น์ง ์ด๋ฐ ๋ฐฉ๋ฒ์ ์ฐ์ง๋ ์์๋๋ฐ์.. 4์ฃผ์ฐจ์๋ ํ๋์ ์ผ์ด์ค๊ฐ ์ฌ๋ฌ ์๋๋ฆฌ์ค(ํ์ผ, ์ฃผ๋ง, ํน๋ณ ๋ฑ)์ ์ ์ฉ๋์ด์ผ ํ ๊ฒฝ์ฐ๊ฐ ๋ง๋๋ผ๊ณ ์. ์ด๋ฐ ๊ฒฝ์ฐ์ ๊ตณ์ด ๋ฉ๋ด๋ฅผ ๋งค๋ฒ ์ฐ๊ณ ์์๋๋ ๊ฒฐ๊ณผ๋ฅผ ์ฐ๋ ๊ฒ ์ฐธ ๋ถํธํ์ต๋๋ค. ๋ ๊ฒฐ๊ณผ๊ฐ์ด์ด์ผ ํ๋ ๊ฒ์ด ๋ค์์๋ ์ค๊ฐ ์ธ์๊ฐ ๋๊ธฐ๋ ํ๊ณ ์.
๊ทธ๋ฆฌ๊ณ ์ฌ์ค ์ฒ์์ ํ
์คํธ ์ฝ๋๋ฅผ ์ง๊ณ ๋ฉ์๋๋ฅผ ๊ตฌํํ๋ ๋ฐฉ์์ผ๋ก ๊ฐ๋ฐ์ ํด๋ดค๋๋ฐ์. ์์ํ๋ ์ค๊ฐ ์ธ์๋ค์ด ์๊พธ ๋ฐ๋๋๋ผ๊ณ ์. ๊ทธ๋ฌ๋๊น ์ฌ์ค ์ฒ์ ํ
์คํธ ์ฝ๋๋ฅผ ์งค ๋น์์, `์ด ํํ ๊ธ์ก`์ ๊ตฌํ๋ ํ
์คํธ์ ์ธ์๋ `์ด ํ ์ธ ๊ธ์ก`๊ณผ `reward` ๊ฐ์ฒด์๋๋ฐ์... ์ค๊ฐ์ ํ๋ผ๋ฏธํฐ๊ฐ ๋ฐ๋๋๊น ํ
์คํธ ์ฝ๋ ์ ์ฒด๋ฅผ ์์ด์ผ ํ๋๋ผ๊ณ ์. ๊ทธ๋์ ๊ฒฐ๊ตญ ํ
์คํธ ๋๋ ์ค๊ฐ ์ธ์๋ฅผ ์๊ฐํ์ง ๋ง๊ณ ์
๋ ฅ๊ณผ ๊ทธ์ ํด๋นํ๋ ์ค๊ฐ, ์ต์ข
๊ฒฐ๊ณผ๋ฅผ ๋ชจ๋ ๊ฐ์ฒด์ ๋ชฐ์์ ๊ด๋ฆฌํ๊ณ ํ
์คํธ๊ฐ ๋ฐ๋ ๋ ์ค๊ฐ ์ค๊ฐ ์ธ์๋ฅผ ๋ฐ๊พธ์๋ ์๊ฐ์ผ๋ก ์ด๋ฐ ๊ตฌํ์ด ๋๊ฒ ๋์์ด์.
๋ง์ฝ ์ ์ง ๋ณด์์ ๊ด์ ์์ ์๊ฐํด๋ณธ๋ค๋ฉด ์ค๊ฐ ์ธ์๋ฅผ ์ข ์์ ํ๊ณ , jest ์ต์
์ --verbose๋ฅผ ๋ฃ์ด์ ํ
์คํธ๋ฅผ ํ๋ ์ค๊ฐ์ ๋ฌด์์ด ํ
์คํธ๋๋์ง ๋ณผ ์ ์์ ๊ฒ ๊ฐ๊ธฐ๋ ํ๋ค์.
์... ์ฌ์ค ๊ฐ๋ฐ ์ค๊ฐ๊น์ง๋ ์ ํํ
๋ ๊ต์ฅํ ์ ์ง ๋ณด์์ ํธ๋ฆฌํ ์ฝ๋์๋๋ฐ์(ํ
์คํธ ์ธ์๊ฐ ๋ฐ๋์ด๋ ์ ํ๊ธฐ๋ฒ์ผ๋ก ์ ๊ทผํ๋ ํ๋๋ง ๋ฐ๊พธ๋ฉด ๋๋๊น์) ๋ค ์์ฑํ๊ณ ๋ณด๋ ๋ค์ ์ฌ๋์๊ฒ๋ ์๋นํ ๋ถ์น์ ํ ์ฝ๋๊ฐ ๋์๋ค์.
์ด๋ป๊ฒ ํ๋ ๊ฒ ์ข์์ง ์ ๋ ๊ณ ๋ฏผ์ด ๋ฉ๋๋ค. uraflower๋๊ป์๋ ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,17 @@
+import { EOL as LINE_SEPARATOR } from "os";
+
+export const COMMON_STRINGS = {
+ LINE_SEPARATOR,
+ EMPTY: "",
+ WHITE_SPACE: " ",
+ COLON: ":",
+ DASH: "-",
+ COMMA: ",",
+};
+
+export const CATEGORY_DICT = {
+ appetizer: "appetizer",
+ main: "main",
+ dessert: "dessert",
+ drink: "drink",
+}; | JavaScript | ์ฌ์ค validation์์๋ ์ฌ์ฉ๋๊ธฐ์ domain์์ ์ฐ๋ ๊ฒ์ ๋ฐ๋ก ๋นผ๋ฒ๋ ธ์ต๋๋ค. ํํธ์ผ๋ก๋ ์ด ๋
์์ด ๋๋ฉ์ธ์ ์ฑ๊ฒฉ์ ๊ฐ๊ณ ์๋ ๊ฒ์ ๋ถ๋ช
ํ์ง๋ง ๋ ๊ทธ ์์ฒด๋ก๋ ๋๋ฉ์ธ์ด ์๋๊ธฐ๋ ํด์(์ด๋ฆ์ด ๋๋ฉ์ธ ์ง์์ด๋ผ๊ธฐ์๋ ์ ๋งคํ๋๊น์) ๋ฐ๋ก ๋ถ๋ฅํ๊ณ ์ถ๋ค๋ ์๊ฐ์ด ๋ ๋ค๊ธฐ๋ ํ์ต๋๋ค. ๋ฌผ๋ก common์ผ๋ก ๋บ ๊ฒ์ด ์ข์ ์ผ์ด์๋์ง๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง์.
Enum๊ฐ์ ๊ฒฝ์ฐ๋ ์ ๊ฐ ์ฌ์ค ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง, ์์๋ณด๊ณ ๋ง๋ถ์ฌ์ผ ํ ๋ด์ฉ์ด ์๋ค๋ ์๊ฐ์ด ๋ค๋ฉด ๋ ๋จ๊ธฐ๋๋ก ํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,5 @@
+export { default as DOMAIN } from "./domain.js";
+export { default as INPUT } from "./input.js";
+export { default as OUTPUT } from "./output.js";
+export { default as ERROR } from "./error.js";
+export { default as VALIDATION } from "./validation.js"; | JavaScript | ์ค์ ๋ก ๊ทธ๋ด ์ผ์ ๊ฑฐ์ ์๊ฒ ์ง๋ง `VALIDATION`, `DOMAIN`, `INPUT`, ๊ทธ๋ฆฌ๊ณ `OUTPUT`์ ๋์์ ์ํฌํธํด์ผ ํ๋ ์ํฉ์ ๊ณ ๋ คํ ๋ถ๋ถ์
๋๋ค.
```javascript
import DOMAIN from "../Constants/domain.js";
import VALIDATION from "../Constants/validation.js";
import INPUT from "../Constants/input.js";
import OUTPUT from "../Constants/output.js";
```
์์ ๊ฐ์ด ์์ `import`์ 4์ค์ ์ฌ์ฉํด์ผ ํ๋ ์ ์ด ๋ณ๋ก ๋ง์์ ๋ค์ง ์์์ `index.js`๋ฅผ ํตํด ๋ค์ ๋ด๋ณด๋ด๋ ๊ตฌ์กฐ๋ฅผ ์ทจํ ๊ฒ์ด๊ณ , ํน๋ณํ ์ด๋ค ์ด์ ๋ ์ด์ ์ด ํฌ์ง ์์๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,27 @@
+import { ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class BasicCalculator {
+ /** @param {MainOrder} mainOrder */
+ static originalTotal(mainOrder) {
+ const nestedMenus = mainOrder.getMenus();
+ const result = Object.values(nestedMenus)
+ .map((menus) => BasicCalculator.calcMenus(menus));
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {{[menu: string]: number}} menus */
+ static calcMenus(menus) {
+ const result = Object.entries(menus)
+ .map(([k, v]) => DOMAIN.MENU_DICT[k].price * v);
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static calcEventFlag(mainOrder) {
+ const originalTotal = BasicCalculator.originalTotal(mainOrder);
+ return Boolean(DOMAIN.EVENT_THRESHOLD_INCLUSIVE <= originalTotal);
+ }
+}
+
+export default BasicCalculator; | JavaScript | ์ฌ์ค ์ด ๋
์์ ์ฌ์ค `ItemCalc`๋ผ๊ณ ๋ฐ๋ก ํ์คํ ์ ํธ์ ์ธ ์ฑ๊ฒฉ์ธ ๊ณ์ฐ ํจ์๋ค์ ๋นผ๋์ ๋ชจ๋์ ์์๋๋ฐ, ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ ๋ณธ๋ค๋ ์ ์ด ํ์คํ ๋๋ฉ์ธ์ด๋ผ ์ด์ชฝ์ผ๋ก ์ด์ฌ๋ฅผ ์ค๊ฒ ๋์์ต๋๋ค. ์ฎ๊ธฐ๋ ๊ณผ์ ์์ ์กฐ๊ธ ๋ถ์ฃผ์ํ๋๋ด์. ๋ง์ํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,27 @@
+import { ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class BasicCalculator {
+ /** @param {MainOrder} mainOrder */
+ static originalTotal(mainOrder) {
+ const nestedMenus = mainOrder.getMenus();
+ const result = Object.values(nestedMenus)
+ .map((menus) => BasicCalculator.calcMenus(menus));
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {{[menu: string]: number}} menus */
+ static calcMenus(menus) {
+ const result = Object.entries(menus)
+ .map(([k, v]) => DOMAIN.MENU_DICT[k].price * v);
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static calcEventFlag(mainOrder) {
+ const originalTotal = BasicCalculator.originalTotal(mainOrder);
+ return Boolean(DOMAIN.EVENT_THRESHOLD_INCLUSIVE <= originalTotal);
+ }
+}
+
+export default BasicCalculator; | JavaScript | ์ฌ์ค ์ ๋ ์ด๋ฐ ๊ฒฝ์ฐ ๊ทธ๋ฅ ๊ฐ์ธ์ ์ธ ์ด์ ๋ก `Boolean()`์ ์ฐ๋ ๊ฒ์ ์ข์ํฉ๋๋ค. ์๊ฐํด๋ณด๋ฉด ์ค๊ฐ์ ์ ๋ฃ์ ๊ฒ๋ ๋ง์ด ์๊ธด ํ ํ
๋ฐ, ์์ผ๋ก ๋ฆฌํดํ๊ธฐ๋ณด๋ค๋ ๊ฐ์ผ๋ก ๋ฆฌํดํ๋ ๊ฒ์ด ๋ญ๊ฐ ์ง๊ด์ ์ผ๋ก ๋ง๋ ๊ฒ ๊ฐ๋ค๋ ๋๋์ด ๋ ๋ฌ๊น์. ๊ทธ๋ฅ ๊ฐ์ธ์ ์ผ๋ก ์์ ๊ฐ์ด ๋๋ ๋ถ๋ถ์
๋๋ค. ์๋ฐ์คํฌ๋ฆฝํธ ํน์ฑ ์, ์ ์๋์ง ์์ ๋ณ์์ฌ๋ ์ด๋ป๊ฒ๋ ๋น๊ตํด์ ๋ฐํํด์ค ๊ฑฐ๋๊น ๋ถ์ํ ๋ง์์ด ๋๋ ๊ฑธ๊น์? ์๋ฌด๋๋ ๊ทธ๋ ๊ฒ ํ๊ฒ ๋ฉ๋๋ค. |
@@ -0,0 +1,75 @@
+// eslint-disable-next-line no-unused-vars
+import MainOrder from "./MainOrder.js";
+import BasicCalculator from "./BasicCalculator.js";
+import { DayCalc, ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class DiscountCalculator {
+ // ์์ ๋ฉ์๋(๋
ผ๋ฆฌ์ )
+ /** @param {MainOrder} mainOrder */
+ static #calcEventFlag(mainOrder) {
+ return BasicCalculator.calcEventFlag(mainOrder);
+ }
+
+ // ๊ณ ์ ๋ฉ์๋
+ /** @param {MainOrder} mainOrder */
+ static discountInfo(mainOrder) {
+ const christmas = DiscountCalculator.christmasDiscount(mainOrder);
+ const weekday = DiscountCalculator.weekdayDiscount(mainOrder);
+ const weekend = DiscountCalculator.weekendDiscount(mainOrder);
+ const special = DiscountCalculator.specialDiscount(mainOrder);
+
+ return {
+ christmas, weekday, weekend, special,
+ };
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static weekdayDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (DayCalc.isWeekend(day)) return 0;
+ const { dessert } = mainOrder.getMenus();
+ const quantity = ItemCalc.sumObjValue(dessert);
+ return quantity * DOMAIN.WEEKDAY_DISCOUNT_PER_MENUS;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static weekendDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (!DayCalc.isWeekend(day)) return 0;
+ const { main } = mainOrder.getMenus();
+ const quantity = ItemCalc.sumObjValue(main);
+ return quantity * DOMAIN.WEEKEND_DISCOUNT_PER_MENUS;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static specialDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (!DayCalc.isSpecialDay(day)) return 0;
+ return DOMAIN.SPECIAL_DAY_DISCOUNT;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static christmasDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ const [start, end] = [DOMAIN.D_DAY_START_INCLUSIVE, DOMAIN.D_DAY_END_INCLUSIVE];
+
+ if (end < day) return 0;
+ const multiplier = DayCalc.eventMoneyMultiplier(start, end, day);
+ return DOMAIN.D_DAY_DEFAULT_DISCOUNT + multiplier * DOMAIN.D_DAY_BONUS_DISCOUNT;
+ }
+}
+
+export default DiscountCalculator; | JavaScript | ์ด ๋ถ๋ถ๊ณผ ๊ฐ์ ๊ฒฝ์ฐ๋ ์๋ ๋ฐ๋ก ๋ถ๋ฆฌ๋์ด์์๋๋ฐ์. ํ ์ธ์ด ์๋๋ผ ์ฆ์ ํ ๋๋ฌธ์ ๊ทธ๋ฅ eventFlag๋ก ๋น ์ง๊ฒ ๋์์ต๋๋ค. `reward`์ ๊ฒฝ์ฐ ๋ฐํ๊ฐ์ด 0์ด ์๋๋ผ {}์ธ๋ฐ ์ด๋ด ๊ฒฝ์ฐ ํธ์ถํ๋ ํจ์๊ฐ ๋๋ก ๊ฐ๋ฆฌ๊ฒ ๋๊ณ , ์ด ๊ฒฝ์ฐ ์ ์ง ๋ณด์์ ์์ด์๋ ๊ทธ๋ ๊ณ ๋ถํ์ํ๊ฒ ๋ฉ์๋๋ฅผ ๋๋ฆฌ๊ณ ์ถ์ง๋ ์๋ค๋ ์๊ฐ์ ๊ทธ๋ฅ `eventFlag`๋ฅผ ์ ์งํ๊ฒ ๋์๋ค์.
๊ทธ๋ฐ๋ฐ ๋ง์์ ๋ฃ๊ณ ๋๋... ์ฌ์ ํ ๋ถ๋ฆฌ๊ฐ ๋๋ค์. ์ธ์๋ก true์ผ ๊ฒฝ์ฐ ๋ฐํํ ๊ฐ์ ๋ฃ์ด์ฃผ๋ฉด ๋๋๊น์. ์๋ฌด๋๋.. ์ ๊ฐ ๋ ์๊ฐํ ๋ถ๋ถ์
๋๋ค. |
@@ -0,0 +1,34 @@
+import { DomainValidator } from "../utils/Validator/index.js";
+import { DomainParser } from "../utils/Parser/index.js";
+
+class MainOrder {
+ /** @type {number} */
+ #date;
+
+ /** @type {{appetizer: {}, main: {}, dessert:{}, drink: {}}} */
+ #menus;
+
+ /** @param {number} date */
+ constructor(date) {
+ DomainValidator.date(date);
+ this.#date = date;
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ /** @param {[string]} rawOrder */
+ setMenus(rawOrder) {
+ if (this.#menus) throw new Error();
+ DomainValidator.menus(rawOrder);
+ const parsedMenu = DomainParser.menus(rawOrder);
+ this.#menus = parsedMenu;
+ }
+
+ getMenus() {
+ return this.#menus;
+ }
+}
+
+export default MainOrder; | JavaScript | ๋์ ์ค์ฒฉ์ด ๋ฐ์ํด์ ๊ทธ๋ฅ ์ํํด์๋ ํฉ๊ณ๋ฅผ ๊ตฌํ ์ ์๋ค๋ ๊ฒ์ด ๋จ์ ์ด๋๋๋ค๐ |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | `Jest`์ `--verbose`๋ผ๋ ์ต์
์ด ์๋์ง ๋ชฐ๋๋ค์. ๊ทธ๋ฐ๋ฐ ์ฐพ์๋ณด๋ `--verbose`๋ ํ
์คํธ์ ์ฌ์ฉ๋ ๊ฐ๋ค์ ๋ณด์ฌ์ฃผ๋ ๊ฒ ์๋๋ผ ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ๊ณ์ธต ๊ตฌ์กฐ๋ก ๋ณด์ฌ์ฃผ๋ ์ต์
์ธ ๊ฒ ๊ฐ์์. ํน์ ์ ๊ฐ ์๋ชป ์ดํดํ ๊ฒ์ด๋ผ๋ฉด ์๋ ค์ฃผ์ธ์!
---
### ํ
์คํธ ์ฝ๋์ ๋ชฉ์
์ ๊ฐ ๋ฆฌ๋ทฐ๋๋ฆฐ ์๋๋ "์ด๋ค ๊ฐ์ผ๋ก ํ
์คํธ๋ฅผ ์งํํ๋์ง๋ฅผ **ํ
์คํธ ์ฝ๋ ๋ด๋ถ** ์์ ํ์ธํ๊ณ ๊ด๋ฆฌํด์ผ ์ฝ๋๋ฅผ ์ดํดํ๊ณ ์ ์ง๋ณด์ํ๊ธฐ ์ฝ์ง ์์๊น?"๋ผ๋ ๋ป์ด์์ต๋๋ค.
๋ฌผ๋ก ์ง๊ธ์ฒ๋ผ ํ
์คํธ ์ฝ๋์ ํ
์คํธ์ ์ฌ์ฉ๋๋ ๊ฐ๋ค์ ๋ฐ๋ก ๋ถ๋ฆฌํ์ฌ ์ ์ฅํด๋ ๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด ๊ฐ์ด ๋ค ๋์ค๊ธด ํ์ง๋ง, ์ฝ๋๋ฅผ ๋ฑ ๋ดค์ ๋ ์ด๋ค ๊ฐ์ด ์์ธ๋ฅผ ์ผ์ผํค๋์ง, ๋ ์ ์์ธ์ง, ์ด๋ค ์ผ์ด์ค๋ค์ด ์ด๋ค ๊ฒฐ๊ณผ๋ฅผ ๋ด๋์ง ์ ์ ์๊ฒ๋ ๋ฌธ์ ์ญํ ๋ ์ํํ๋ ๊ฒ ํ
์คํธ ์ฝ๋๋ผ๊ณ ์๊ฐํด์. ๊ทธ๋์ ํ
์คํธ ์ฝ๋ ๋ด๋ถ์์ ๊ฐ๋ค์ด ๊ด๋ฆฌ๋์ด์ผ ํ์ง ์์๊น ์๊ฐํด๋ด
๋๋ค.
### ๊ณตํต์ ์ผ๋ก ์ฌ์ฉ๋๋ ๊ฐ์ ์ถ์ถํ๋ ๊ฒ์ ์ฅ๋จ์
๋ง์ํ์ ๊ฒ์ฒ๋ผ ์ฌ๋ฌ ๊ตฐ๋ฐ์์ ๋์ผํ๊ฒ ์ฌ์ฉ๋๋ ๊ฐ๋ค์ด ์์ ๋, ํ๋ก๋์
์ฝ๋์์ ์ถ์ถํ๋ฏ ํ
์คํธ ์ฝ๋์์๋ ์ถ์ถํด์ผ ํ๋์ง ๊ณ ๋ฏผ์ด ๋๊ธด ํ๋ค์๐ค. ๋์ผํ ๊ฐ์ ์ฌ์ฉํ๋ ํ
์คํธ๊ฐ ๋ง์์ง์๋ก ์ถ์ถํ๋ ๊ฒ ๋ ํธํ ์๋ ์์ ๊ฒ ๊ฐ๊ตฌ์.
๊ทธ๋ฐ๋ฐ A,B,C ... ์ฌ๋ฌ ๊ฐ์ ํ
์คํธ๊ฐ "Z" ๋ผ๋ ํ
์คํธ ์ผ์ด์ค๋ฅผ ์ฌ์ฉํ๋๋ฐ, A ํ
์คํธ๊ฐ ๋ชจ์ข
์ ์ด์ ๋ก ํด๋น ํ
์คํธ ์ผ์ด์ค์์ ๋ฑ ํ๋๋ง ๋นผ๊ณ ์ฌ์ฉํ๊ฒ ๋๋ค๊ณ ํ๋ฉด ๊ณจ์น์ํ์ง ๊ฒ ๊ฐ์์.
์๋ฅผ ๋ค๋ฉด "Z" ํ
์คํธ ์ผ์ด์ค๊ฐ ์์ ์ ์๊ฐ ์๋ ๊ฐ๋ค์ ๋ชจ์์ผ ๋, "Z"์๋ ์์ ๊ฐ์ด ์์ ์ ์๋๋ฐ์. ๊ทธ๋ผ A,B,C ... ์ฌ๋ฌ ๊ฐ์ ํ
์คํธ๋ "Z"๋ฅผ ๋ฝ์์ ์ฌ์ฉํ ๊ฒ์
๋๋ค. ๊ทธ๋ฐ๋ฐ A ๋ผ๋ ๊ธฐ๋ฅ์ด ๋ชจ์ข
์ ์ด์ ๋ก ์ธํด ์์๊ฐ ๋ค์ด์๋ ๋๋๋ก ๋ณ๊ฒฝ๋๋ค๋ฉด, "Z" ์ผ์ด์ค๋ฅผ ์ง๊ธ์ฒ๋ผ ์ ๋ฝ์๋ค ์ธ ์ ์์ ๊ฒ ๊ฐ์์.
---
์ ๋ ๋ฌด์์ด ์ ๋ต์ธ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค๐
. ์ ํฌ๊ฐ ์์ ๊ท๋ชจ์ ํ๋ก์ ํธ์๋ง ํ
์คํธ ์ฝ๋๋ฅผ ์ ์ฉํด๋ด์ ํท๊ฐ๋ คํ๋ ๊ฑธ์๋ ์๋ค๋ ์๊ฐ๋ ๋ค๊ตฌ์. ํ
์คํธ ์ฝ๋์ ๊ดํ ์ฑ
์ ์ฝ์ด๋ณด๊ฑฐ๋ ์ ์ ํฐ ๊ท๋ชจ์ ์ ์ฉ์์ผ๋ณธ๋ค๋ฉด ์ข์ ๋ฐฉ์์ ๋ํ ํ์ ์ ๊ฐ์ง ์ ์์ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | ์ ์ด ๋ถ๋ถ์ ์ ๊ฐ ์คํดํ๊ธฐ๋ ํ๊ณ , ๋ ์ค๋ช
์ด ์ข ๋ถ์ถฉ๋ถํ๋๋ฐ์...
์ฐ์ verbose๋ฅผ ์ฐ๊ณ ์ธ์์ ๋๊ธธ ๋, ์ ์ฒด๋ฅผ ๋๊ธฐ๋ ๊ฒ์ด ์๋๋ผ ์ ํ๊ธฐ๋ฒ์ผ๋ก ํน์ ํ๋๋ฅผ ํน์ ํด์ ๋๊ธฐ๊ฒ ๋๋ค๋ฉด ํ
์คํธ๋ฅผ '๋๋ ธ์ ๋' ์ด๋ค ๊ฐ์ด ํ
์คํธ๊ฐ ๋๋์ง ์ ์ ์์ ๊ฒ์ด๋ ๋ง์ด์์ต๋๋ค. ๋ฌผ๋ก ์ด๋ ๊ฒ ํ๋ค๊ณ ํ๋๋ผ๋ 'ํ
์คํธ ์ฝ๋'์๋ ์ง์ ์ ์ผ๋ก ์ด๋ค ๊ฐ์ด ๋ค์ด์ค๋์ง ์ ์๋ ์์ง๋ง์. ๋ง์ํด์ฃผ์ ๋ฌธ์ ๊ฐ ์ด๋ ์ ๋ ํด์๊ฐ ๋๋ฆฌ๋ผ๋ ์๊ฐ์ด์์ต๋๋ค.
๋ฌผ๋ก `๋ฌธ์`์ ์ญํ ์ ํด์ผ ํ๋ค๋ฉด ์ด ํ
์คํธ ์ฝ๋๋ ์ด๋ค ๋ถ๋ถ์์ ๊ธฐ๋ฅ์ ๋ชปํ๊ณ ์๋ ๊ฒ์ด ์ฌ์ค์
๋๋ค. ์ด ๋ถ๋ถ์ ๊น๋ํ๊ฒ ์ธ์ ํ ์๋ฐ์ ์๊ฒ ๋ค์.
ํ์ง๋ง ์ผ์ด์ค๊ฐ ํน์ํ๊ฒ ๋ฐ๋๋ ์ํฉ์ด๋ผ๋ฉด ํ
์คํธ ์ผ์ด์ค๋ฅผ ๋ชฐ์์ ๊ด๋ฆฌํ๋ ํธ์ด ํ์คํ ํธ๋ฆฌํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋ง์ฝ `ํ์ผ ํ ์ธ`์ ๋์์ด ๋๋ ํ๋ชฉ์ ์ด๋ค ์ด์ ์์์ธ์ง `์ ๋ก์ฝ๋ผ`๊ฐ ์ถ๊ฐ ๋์๋ค๊ณ ํ๋ฉด, (๋๊ธฐ๋ ์ธ์์ ์ข
๋ฅ์ ๋ฐ๋ผ ๋ค๋ฅด๊ฒ ์ง๋ง) ํต์์ ์ธ ๋ฐฉ๋ฒ์ผ๋ก๋ 1. ํ์ผ ํ ์ธ ๊ณ์ฐ ํ
์คํธ, 2. ์ ์ฒด ํ ์ธ ๊ณ์ฐ ํ
์คํธ, 3. ํํ ๊ณ์ฐ ํ
์คํธ, 4. ๋ฐฐ์ง ํ
์คํธ๊ฐ ์ํฅ์ ๋ฐ๊ฒ ๋ฉ๋๋ค. ๊ฒฐ๊ตญ ์ด ๋ค ๊ฐ์ ํ
์คํธ ์ฝ๋๋ฅผ ์ฐพ์์ ์ ๋ก ์ฝ๋ผ ๊ด๋ จ ์ผ์ด์ค๋ฅผ ๋ค ์์ ํด์ผ ํ๋ ๋ฐ๋ฉด, ํ
์คํธ ์ผ์ด์ค๋ฅผ ๋ชฐ์์ ๊ด๋ฆฌํ๊ฒ ๋๋ฉด `์ ๋ก ์ฝ๋ผ` ์ผ์ด์ค๋ฅผ ์ฐพ์ ๋ค์ ์ 4๊ฐ์ ๋ด์ฉ์ ๊ณ ์ณ์ฃผ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.
๋ง์ฝ ์ฑ ๋นผ๋ ๊ฒ์ด ํ๋ค๋ค๋ ๊ฒ์ด ๋ฌธ์ ๋ผ๋ฉด ์๋ง๋ ํ
์คํธ ์ผ์ด์ค๋ง๋ค ํ์ฉ๋๋ ์๋๋ฆฌ์ค๋ ์์ค์ ํ๋๋ก ์ ํด์ค ์๋ ์๊ฒ ์ฃ ? ๊ทธ๋ฌ๋ฉด A์์ ํ
์คํธํ ๋ Z์์ `inputLevel`์ ์ ์ธํ๊ณ ํํฐํ๊ฑฐ๋ `domainLevel`์ธ ๊ฒ๋ค๋ง ํํฐ๋ฅผ ํด์ ํ
์คํธ๋ฅผ ํ ์ ์์ผ๋ ๋๋ฆ์ ๋ฐฉ๋ฒ์ด ๋ ๊ฒ ๊ฐ๊ธฐ๋ ํฉ๋๋ค.
์ฌ์ค ์ด๋ฐ ๋ฌธ์ ๋๋ฌธ์ ์ง๊ธ๋ `inputCase`์ `validCase` ๊ทธ๋ฆฌ๊ณ `tryErrorCase`๋ผ๋ 3๊ฐ์ง ๋ณ๋์ ํ์ผ์ ํต์ผ๋ ํ์ ์์ด ์ด์ฉํ๊ณ ์์๋๋ฐ์. ๋ง์ํด์ฃผ์ ๋ถ๋ถ์ ์๊ฐํ๊ณ ๋ณด๋ ์กฐ๊ธ ๋ ํต์ผ์ฑ ์๋ ํ์์ผ๋ก ์ฌ์ฉํ๋ฉด์๋ ๋ ์ผ์ด์ค๋ฅผ ๋นผ์ ์ฐ๊ธฐ ์ด๋ ค์ด ์ํฉ๋ค์ด ๋๋๋ ๋ถ๋ถ๋ ์กฐ๊ธ์ ํด๊ฒฐํ ๊ธธ์ด ๋ณด์ด๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ฌผ๋ก ์ด๋ฐ ๋ฐฉ๋ฒ์ด ๊ทธ๋ฆฌ ๊น๋ํ์ง๋ ์์ง๋ง ๋ง์ด์ฃ . ๊ทธ๋๋ ๋ง์ํด์ฃผ์ ๋ถ๋ถ์ด ๋ง์ ๋์์ด ๋์์ต๋๋ค.
์์ผ๋ก ํ์ฅ์์ ํด๋๊ฐ๋ฉด์ ๋ฌด์์ด ์ด๋ค ์ํฉ์์ ๋ ์ข์์ง, ๋ ์ด๋ค ์ฅ์ ๊ณผ ๋จ์ ์ด ์๋์ง ๋ ๋ฐฐ์ฐ๊ฒ ๋๊ฒ ์ฃ . ๋๋ถ์ ๊ทธ๋ฐ ๋ฐฐ์์ ์๊ฐ์ด ์์ ๋ ์กฐ๊ธ ๋ ์ด๋ฆฐ ์ฌ๋์ด ๋ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,118 @@
+import React, { useEffect, useState } from "react";
+import { Link, useNavigate } from "react-router-dom";
+import { signin } from "../../api";
+import styled from "styled-components";
+
+function SignIn() {
+ const navigate = useNavigate();
+ const [auth, setAuth] = useState({
+ email: "",
+ password: "",
+ });
+ const [isValid, setValid] = useState(false);
+ const [errorMessage, setError] = useState("");
+
+ const handleAuth = (e) => {
+ const { name, value } = e.target;
+ setValid(true);
+ setAuth((prev) => ({
+ ...prev,
+ [name]: value,
+ }));
+ };
+
+ const handleSignIn = async (e) => {
+ e.preventDefault();
+ setValid(false);
+ if (!auth?.email || !auth.email.includes("@")) {
+ setError("์ด๋ฉ์ผ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.");
+ } else if (!auth?.password || auth.password.length < 8) {
+ setError("๋น๋ฐ๋ฒํธ๋ ์ต์ 8์ ์ด์์ด์ด์ผ ํฉ๋๋ค.");
+ } else {
+ setError("");
+ setValid(true);
+ const isSign = await signin(auth);
+ if (isSign) return navigate("/todo");
+ }
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (token) {
+ return navigate("/todo");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ return (
+ <Container>
+ <h1>SIGN IN</h1>
+ <form onSubmit={handleSignIn}>
+ <input
+ data-testid="email-input"
+ type="text"
+ name="email"
+ onChange={handleAuth}
+ />
+ <input
+ data-testid="password-input"
+ type="password"
+ name="password"
+ onChange={handleAuth}
+ />
+ <button data-testid="signin-button" disabled={!isValid}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ {!isValid && <span>{errorMessage}</span>}
+ <StyledLink to="/signup">ํ์๊ฐ์
</StyledLink>
+ </Container>
+ );
+}
+
+export default SignIn;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const StyledLink = styled(Link)`
+ box-sizing: border-box;
+ display: block;
+ padding: 4px 8px;
+ margin: 0 auto;
+ text-align: center;
+ color: white;
+ text-decoration: none;
+`; | JavaScript | placeholder๋ก ํ์์ ์๋ ค์ฃผ๋ฉด ์ฌ์ฉ์ ๊ฒฝํ์ด ์ข ๋ ์ข์ง ์์๊น ์๊ฐํฉ๋๋ค!_! `@`๋ฅผ ํฌํจํด์ผ ํ๋ค๊ฑฐ๋ ๋น๋ฐ๋ฒํธ๋ 8์ ์ด์์ด์ด์ผ ํ๋ค๊ฑฐ๋..! |
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="theme-color" content="#000000" />
+ <meta
+ name="description"
+ content="Web site created using create-react-app"
+ />
+ <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
+ <!--
+ manifest.json provides metadata used when your web app is installed on a
+ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
+ -->
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
+ <!--
+ Notice the use of %PUBLIC_URL% in the tags above.
+ It will be replaced with the URL of the `public` folder during the build.
+ Only files inside the `public` folder can be referenced from the HTML.
+
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
+ work correctly both with client-side routing and a non-root public URL.
+ Learn how to configure a non-root public URL by running `npm run build`.
+ -->
+ <title>React App</title>
+ </head>
+ <body>
+ <noscript>You need to enable JavaScript to run this app.</noscript>
+ <div id="root"></div>
+ <!--
+ This HTML file is a template.
+ If you open it directly in the browser, you will see an empty page.
+
+ You can add webfonts, meta tags, or analytics to this file.
+ The build step will place the bundled scripts into the <body> tag.
+
+ To begin the development, run `npm start` or `yarn start`.
+ To create a production bundle, use `npm run build` or `yarn build`.
+ -->
+ </body>
+</html> | Unknown | ์์ด์ฝ์ด ํฌํจ๋ ํ๊ทธ๋ ํฌ๋์ฑ๊ณผ ํฐ ์๊ด์ด ์๋ค๊ณ ์๊ฐํ๋๋ฐ, ์ ๊ฑฐํด๋ ์ข์ง์์๊น ์ถ์ต๋๋ค! |
@@ -0,0 +1,34 @@
+import { Navigate, createBrowserRouter } from "react-router-dom";
+import App from "./App";
+import SignIn from "./Page/Auth/SignIn";
+import SignUp from "./Page/Auth/SignUp";
+import ToDoList from "./Page/ToDos/ToDoList";
+
+const routes = [
+ {
+ path: "",
+ element: <App />,
+ children: [
+ {
+ path: "/",
+ element: <Navigate to="/signin" />,
+ },
+ {
+ path: "/signin",
+ element: <SignIn />,
+ },
+ {
+ path: "/signup",
+ element: <SignUp />,
+ },
+ {
+ path: "/todo",
+ element: <ToDoList />,
+ },
+ ],
+ },
+];
+
+const router = createBrowserRouter(routes);
+
+export default router; | JavaScript | ์ค ๋ผ์ฐํฐ๋ฅผ ์ค์ฒฉํด์ ์์ฑํ ์๋ ์๊ตฐ์..! |
@@ -0,0 +1,118 @@
+import React, { useEffect, useState } from "react";
+import { Link, useNavigate } from "react-router-dom";
+import { signin } from "../../api";
+import styled from "styled-components";
+
+function SignIn() {
+ const navigate = useNavigate();
+ const [auth, setAuth] = useState({
+ email: "",
+ password: "",
+ });
+ const [isValid, setValid] = useState(false);
+ const [errorMessage, setError] = useState("");
+
+ const handleAuth = (e) => {
+ const { name, value } = e.target;
+ setValid(true);
+ setAuth((prev) => ({
+ ...prev,
+ [name]: value,
+ }));
+ };
+
+ const handleSignIn = async (e) => {
+ e.preventDefault();
+ setValid(false);
+ if (!auth?.email || !auth.email.includes("@")) {
+ setError("์ด๋ฉ์ผ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.");
+ } else if (!auth?.password || auth.password.length < 8) {
+ setError("๋น๋ฐ๋ฒํธ๋ ์ต์ 8์ ์ด์์ด์ด์ผ ํฉ๋๋ค.");
+ } else {
+ setError("");
+ setValid(true);
+ const isSign = await signin(auth);
+ if (isSign) return navigate("/todo");
+ }
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (token) {
+ return navigate("/todo");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ return (
+ <Container>
+ <h1>SIGN IN</h1>
+ <form onSubmit={handleSignIn}>
+ <input
+ data-testid="email-input"
+ type="text"
+ name="email"
+ onChange={handleAuth}
+ />
+ <input
+ data-testid="password-input"
+ type="password"
+ name="password"
+ onChange={handleAuth}
+ />
+ <button data-testid="signin-button" disabled={!isValid}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ {!isValid && <span>{errorMessage}</span>}
+ <StyledLink to="/signup">ํ์๊ฐ์
</StyledLink>
+ </Container>
+ );
+}
+
+export default SignIn;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const StyledLink = styled(Link)`
+ box-sizing: border-box;
+ display: block;
+ padding: 4px 8px;
+ margin: 0 auto;
+ text-align: center;
+ color: white;
+ text-decoration: none;
+`; | JavaScript | ์ด๋ฉ์ผ, ๋น๋ฐ๋ฒํธ input ์ด๋ฒคํธ ํธ๋ค๋ฌ๊ฐ ๊ณต์ ํด์ ์ฌ์ฉํ ์ ์๊ฒ
์ ์ถ์ํ๋ ๊ธฐ๋ฅ์ธ ๊ฒ ๊ฐ์์!
์ ๊ทผ๋ฐ ์ธํ์ด ๋ค์ด์ค๋ฉด ํญ์ valid ์ํ๊ฐ true๋ก ์ธํ
๋๋๋ฐ
๊ฒ์ฌํ ํ์ valid์ฒดํฌํ๋ ๊ฒ ๋ก์ง์ ๋ง์ง์๋์..?! ๐ |
@@ -0,0 +1,118 @@
+import React, { useEffect, useState } from "react";
+import { Link, useNavigate } from "react-router-dom";
+import { signin } from "../../api";
+import styled from "styled-components";
+
+function SignIn() {
+ const navigate = useNavigate();
+ const [auth, setAuth] = useState({
+ email: "",
+ password: "",
+ });
+ const [isValid, setValid] = useState(false);
+ const [errorMessage, setError] = useState("");
+
+ const handleAuth = (e) => {
+ const { name, value } = e.target;
+ setValid(true);
+ setAuth((prev) => ({
+ ...prev,
+ [name]: value,
+ }));
+ };
+
+ const handleSignIn = async (e) => {
+ e.preventDefault();
+ setValid(false);
+ if (!auth?.email || !auth.email.includes("@")) {
+ setError("์ด๋ฉ์ผ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.");
+ } else if (!auth?.password || auth.password.length < 8) {
+ setError("๋น๋ฐ๋ฒํธ๋ ์ต์ 8์ ์ด์์ด์ด์ผ ํฉ๋๋ค.");
+ } else {
+ setError("");
+ setValid(true);
+ const isSign = await signin(auth);
+ if (isSign) return navigate("/todo");
+ }
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (token) {
+ return navigate("/todo");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ return (
+ <Container>
+ <h1>SIGN IN</h1>
+ <form onSubmit={handleSignIn}>
+ <input
+ data-testid="email-input"
+ type="text"
+ name="email"
+ onChange={handleAuth}
+ />
+ <input
+ data-testid="password-input"
+ type="password"
+ name="password"
+ onChange={handleAuth}
+ />
+ <button data-testid="signin-button" disabled={!isValid}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ {!isValid && <span>{errorMessage}</span>}
+ <StyledLink to="/signup">ํ์๊ฐ์
</StyledLink>
+ </Container>
+ );
+}
+
+export default SignIn;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const StyledLink = styled(Link)`
+ box-sizing: border-box;
+ display: block;
+ padding: 4px 8px;
+ margin: 0 auto;
+ text-align: center;
+ color: white;
+ text-decoration: none;
+`; | JavaScript | ๊ฐ์์๊ธฐ๋ผ ๋ต๊ธ ๋ต๋๋ค!
handleAuth์์๋ setValid(true)๋ง ํ ๊ฒ์ด ์๋๋ผ ํ์ฌ ์ํ๊ฐ validํ์ง ํ๋จํ๋ ๋ก์ง์ด ์ถ๊ฐ์ ์ผ๋ก ํ์ํ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,118 @@
+import React, { useEffect, useState } from "react";
+import { Link, useNavigate } from "react-router-dom";
+import { signin } from "../../api";
+import styled from "styled-components";
+
+function SignIn() {
+ const navigate = useNavigate();
+ const [auth, setAuth] = useState({
+ email: "",
+ password: "",
+ });
+ const [isValid, setValid] = useState(false);
+ const [errorMessage, setError] = useState("");
+
+ const handleAuth = (e) => {
+ const { name, value } = e.target;
+ setValid(true);
+ setAuth((prev) => ({
+ ...prev,
+ [name]: value,
+ }));
+ };
+
+ const handleSignIn = async (e) => {
+ e.preventDefault();
+ setValid(false);
+ if (!auth?.email || !auth.email.includes("@")) {
+ setError("์ด๋ฉ์ผ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.");
+ } else if (!auth?.password || auth.password.length < 8) {
+ setError("๋น๋ฐ๋ฒํธ๋ ์ต์ 8์ ์ด์์ด์ด์ผ ํฉ๋๋ค.");
+ } else {
+ setError("");
+ setValid(true);
+ const isSign = await signin(auth);
+ if (isSign) return navigate("/todo");
+ }
+ };
+
+ useEffect(() => {
+ const token = localStorage.getItem("token");
+ if (token) {
+ return navigate("/todo");
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ return (
+ <Container>
+ <h1>SIGN IN</h1>
+ <form onSubmit={handleSignIn}>
+ <input
+ data-testid="email-input"
+ type="text"
+ name="email"
+ onChange={handleAuth}
+ />
+ <input
+ data-testid="password-input"
+ type="password"
+ name="password"
+ onChange={handleAuth}
+ />
+ <button data-testid="signin-button" disabled={!isValid}>
+ ๋ก๊ทธ์ธ
+ </button>
+ </form>
+ {!isValid && <span>{errorMessage}</span>}
+ <StyledLink to="/signup">ํ์๊ฐ์
</StyledLink>
+ </Container>
+ );
+}
+
+export default SignIn;
+
+const Container = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ form {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 1rem;
+ width: 300px;
+ input {
+ padding: 0.5rem;
+ font-size: 1rem;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ margin-bottom: 8px;
+ }
+ button {
+ padding: 0.5rem 1rem;
+ font-size: 1rem;
+ background-color: black;
+ color: #fff;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+ :disabled {
+ color: gray;
+ cursor: default;
+ }
+ }
+ }
+ span {
+ color: red;
+ }
+`;
+
+const StyledLink = styled(Link)`
+ box-sizing: border-box;
+ display: block;
+ padding: 4px 8px;
+ margin: 0 auto;
+ text-align: center;
+ color: white;
+ text-decoration: none;
+`; | JavaScript | ์์์๋ ๋งํ๋ฏ์ด ๊ณผ์ ์ ๊ตฌํ ์ฌํญ์
`์
๋ ฅ๋ ์ด๋ฉ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๊ฐ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํต๊ณผํ์ง ๋ชปํ๋ค๋ฉด button์ disabled ์์ฑ์ ๋ถ์ฌํด์ฃผ์ธ์`
์ฆ submit์ด์ ์ ์ ํจ์ฑ๊ฒ์ฌ๋ฅผ ์ฒดํฌ ํ๊ณ disabled ์ํ๋ฅผ ๊ด๋ฆฌ ํด ์ค์ผ ํฉ๋๋ค. submit ์ ์ถ์์ ๊ฒ์ฌํ๋ฉด ์ ๋ ๊ฒ ๊ฐ์ต๋๋ค(๊ตฌํ์ฌํญ๋๋ก๋ผ๋ฉด) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.