code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,33 @@
+import letters from "../mockData";
+
+const sleep = n => new Promise(resolve => setTimeout(resolve, n));
+
+export const getLetters = async () => {
+ await sleep(500);
+ return letters;
+};
+
+export const getLetterById = async id => {
+ await sleep(100);
+ return letters.find(letter => letter.id === id);
+};
+
+export const updateLetter = async (id, payload) => {
+ await sleep(100);
+ const { title, artist, imageUrl } = payload;
+ const songStory = payload.songStory;
+
+ const foundLetter = letters.find(letter => letter.id === id);
+
+ const updatedLetter = {
+ ...foundLetter,
+ song: { title, artist, imageUrl },
+ songStory
+ };
+
+ const index = letters.indexOf(foundLetter);
+ letters.splice(index, 1);
+ letters.push(updatedLetter);
+
+ return updatedLetter;
+}; | JavaScript | ๋ฐฐ์ด์์ ์ํ๋ ์กฐ๊ฑด๊น์ง๋ง ์ฐพ๋ find method๋ฅผ ์ฌ์ฉํ ๊ฑด ์ข์๋ณด์
๋๋ค ! |
@@ -0,0 +1,24 @@
+import React from "react";
+import styled from "styled-components";
+
+const Footer = () => {
+ return (
+ <FooterBlock>
+ <p className="copyright">© Museop Kim</p>
+ </FooterBlock>
+ );
+};
+
+const FooterBlock = styled.div`
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 8rem;
+ margin-top: 6rem;
+ background-color: #f5f5f7;
+ font-weight: 500;
+ box-shadow: 0px -10px 35px 5px #f1f1f1;
+`;
+
+export default Footer; | Unknown | style components๋ฅผ ์ฌ์ฉํ์๋๊น
`box-shadow: 0px -10px 35px 5px #f1f1f1;`
๋ถ๋ถ์ ์์ ๊ฐ์ ๊ฒฝ์ฐ๋ styled-components ThemeProvider๋ฅผ ์ฌ์ฉํด ๋ณด๋๊ฑด ์ด๋จ๊น์.
๋ชจ๋ ์ปดํฌ๋ํธ๊ฐ ์ ๋ฌ๋ฐ์ ์์์ ๋์ผํ๊ฒ ์ฌ์ฉํ๋ฉด ๋คํฌ๋ชจ๋์ ๊ฐ์ ๊ธฐ๋ฅ์ ๊ตฌํํ ๋๋ ์์ฝ๊ฒ ์คํ์ผ ๋ณ๋์ด ๊ฐ๋ฅํฉ๋๋ค.
๋๋ฌด ๋ง์ด ์งํ๋ ํ๋ก์ ํธ๋ ์คํ์ผ ์์คํ
์ ๊ตฌ์ถํ๊ธฐ ์ฝ์ง ์์ผ๋๊น ์ข ์์ ๋จ์์ผ ๋ ์๋ํด ๋ณด๋๊ฒ๋ ์ข์๊ฑฐ ๊ฐ์์ ๐ |
@@ -0,0 +1,47 @@
+import React from "react";
+import styled from "styled-components";
+import { Link } from "react-router-dom";
+
+const Navigation = () => {
+ return (
+ <NavigationBlock>
+ <Link to="/">์ ์ฒญ๊ณก</Link>
+ <Link to="/ranking">์ ์ฒญ๊ณก ์์</Link>
+ <Link to="/contents">์ ์ฒญ๊ณก ์ ํ๋ธ ์์</Link>
+ <Link to="/musicsheets">๋ฆฌ์ผํผ์๋
ธ ์
๋ณด์ง</Link>
+ </NavigationBlock>
+ );
+};
+
+const NavigationBlock = styled.div`
+ height: 100%;
+ display: flex;
+ align-items: center;
+
+ & > * {
+ /* padding: 25px 5px 10px 5px; */
+ box-sizing: border-box;
+ display: flex;
+ align-items: center;
+ margin: 0px 30px;
+ padding-top: 10px;
+ font-size: 1.2rem;
+ font-weight: 600;
+ text-decoration: none;
+ align-self: center;
+ color: inherit;
+ opacity: 0.5;
+ height: 100%;
+ /* border-bottom: 1px solid rgba(0, 0, 0, 0); */
+ border-bottom: 3px solid rgba(250, 162, 193, 0);
+ transition: 0.3s;
+
+ :hover {
+ opacity: 1;
+ /* color: #faa2c1; */
+ border-bottom: 3px solid rgba(250, 162, 193, 1);
+ }
+ }
+`;
+
+export default Navigation; | Unknown | ํฐํธ์ ๊ฐ์ด ๋ฐ์ํ์ ์ํฅ์ ๋ฐ์์ผ ํ๋ ๊ธฐ์ค๊ณผ ๊ทธ๋ ์ง ์์ ์์๋ฅผ ๊ธฐ์ค์ผ๋ก px๊ณผ rem์ ์ฌ์ฉํ์๋ ๊ฑด๊ฐ์ ?
๊ทธ๋ฐ ์๋๋ผ๋ฉด ์ข์๋ณด์
๋๋ค. |
@@ -0,0 +1,147 @@
+import React from "react";
+import styled from "styled-components";
+
+const MAX_LENGTH = 100;
+
+const Letter = ({
+ id,
+ user,
+ song,
+ songStory,
+ createdDateTime,
+ onReadLetter
+}) => {
+ const { username, avatarUrl } = user;
+ const { title, artist, imageUrl } = song;
+
+ return (
+ <>
+ <LetterBlock onClick={() => onReadLetter(id)}>
+ <SongBlock>
+ <img src={imageUrl} alt="ALBUM IMAGE" className="album-image" />
+ <div className="song-about">
+ <span className="song-about__title">{title}</span>
+ <span className="song-about__artist">{artist}</span>
+ </div>
+ </SongBlock>
+ <SongStory>
+ {songStory.length > MAX_LENGTH
+ ? `${songStory.slice(0, MAX_LENGTH)} ...`
+ : songStory}
+ </SongStory>
+ <UserBlock>
+ <div className="created-time">{createdDateTime}</div>
+ <div className="user-about">
+ <img src={avatarUrl} className="user-about__avatar" />
+ <span className="user-about__name">{username}</span>
+ </div>
+ </UserBlock>
+ </LetterBlock>
+ </>
+ );
+};
+
+const LetterBlock = styled.li`
+ width: 25rem;
+ height: 23rem;
+ margin: 1.2rem;
+ margin-bottom: 5rem;
+ box-sizing: border-box;
+ display: flex;
+ flex-direction: column;
+ padding: 0.7rem;
+ border: #ffdeeb;
+ border-radius: 0.5rem;
+ cursor: pointer;
+ transition: 0.3s;
+ box-shadow: 0 13px 27px -5px rgba(50, 50, 93, 0.2),
+ 0 8px 16px -8px rgba(0, 0, 0, 0.2), 0 -6px 16px -6px rgba(0, 0, 0, 0.025);
+
+ &:hover {
+ box-shadow: 0px 25px 30px 3px rgba(0, 0, 0, 0.3);
+ }
+
+ .album-image {
+ width: 10rem;
+ height: 10rem;
+ }
+`;
+
+const SongBlock = styled.div`
+ display: flex;
+ justify-content: space-between;
+
+ .album-image {
+ position: relative;
+ top: -2.5rem;
+ box-shadow: 3px 2px 5px 1px rgba(0, 0, 0, 0.3);
+ border-radius: 5px;
+ }
+
+ .song-about {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ margin-right: auto;
+ margin-left: 2rem;
+
+ .song-about__title {
+ overflow-x: hidden;
+ font-size: 1.4rem;
+ font-weight: 500;
+ color: #2c2c2c;
+ opacity: 0.9;
+ }
+
+ .song-about__artist {
+ margin-top: 0.5rem;
+ font-size: 1.2rem;
+ opacity: 0.8;
+ }
+ }
+`;
+
+const SongStory = styled.p`
+ width: 100%;
+ max-height: 8rem;
+ line-break: anywhere;
+ margin-top: -0.3rem;
+ font-size: 1.2rem;
+ line-height: 1.9rem;
+ opacity: 0.9;
+ padding: 0rem 0.5rem;
+`;
+
+const UserBlock = styled.div`
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin: auto 5px 3px 5px;
+
+ .created-time {
+ font-size: 1.1rem;
+ margin-top: 0.8rem;
+ opacity: 0.7;
+ }
+
+ .user-about {
+ display: flex;
+ align-items: center;
+ }
+
+ .user-about__avatar {
+ max-width: 2.5rem;
+ max-height: 2.5rem;
+ border-radius: 50%;
+ box-shadow: 3px 2px 10px 1px rgba(0, 0, 0, 0.3);
+ }
+
+ .user-about__name {
+ font-size: 1.1rem;
+ margin-top: 0.5rem;
+ margin-left: 0.5rem;
+ opacity: 0.8;
+ }
+`;
+
+export default Letter; | Unknown | className ์ปจ๋ฒค์
์ค "-"์ "_"๋ ์ด๋ค ๊ธฐ์ค์ด ์์๊น์ ? ๊ถ๊ธํฉ๋๋ค ใ
|
@@ -0,0 +1,29 @@
+import React from "react";
+import styled from "styled-components";
+import LetterContainer from "../../containers/Letter/LetterContainer";
+
+const LetterList = ({ letters }) => {
+ return (
+ <LetterListBlock>
+ {letters.map(letter => (
+ <LetterContainer
+ key={letter.id}
+ id={letter.id}
+ user={letter.user}
+ song={letter.song}
+ songStory={letter.songStory}
+ createdDateTime={letter.createdDateTime}
+ />
+ ))}
+ </LetterListBlock>
+ );
+};
+
+const LetterListBlock = styled.ul`
+ width: 100%;
+ display: flex;
+ flex-wrap: wrap;
+ margin-top: 4.5rem;
+`;
+
+export default LetterList; | Unknown | ๋ณดํต Container๋ ์ข ๋ ํฐ ๋จ์์์์ ์๋ฏธ์์ ์ฌ์ฉ๋๊ณค ํ๋๊ฑฐ ๊ฐ์์.
์ฌ๋ฌ ์์ ์ปดํฌ๋ํธ๋ฅผ ๊ฐ์ง๊ณ ๋ง์ ์ด๋ฒคํธ ๋ก์ง์ ๊ฐ์ง๊ณ ์๋ ์ผํฐ์ ๋๋์ผ๋ก ๋ค์ด๋ฐ์ ํ๊ณค ํ๋๋ฐ
LetterList๋ฉด LetterItem๊ณผ ๊ฐ์ด ๋จ์ผํ๊ฒ ํํํด ์ฃผ๋๊ฒ๋ ์ข์๊ฑฐ ๊ฐ์์ ! |
@@ -0,0 +1,30 @@
+import React, { useEffect, useState } from "react";
+import ModalTemplate from "../Template/Modal/ModalTemplate";
+import LetterDetailsSong from "./LetterDetailsSong";
+import LetterDetailsSongStory from "./LetterDetailsSongStory";
+import LetterModalTemplate from "../Template/LetterModal/LetterModalTemplate";
+import LetterDetailsUser from "./LetterDetailsUser";
+import LetterModalDiv from "../LetterModal/LetterModalContents/LetterModalDiv";
+import LetterModalHiddenButtonContainer from "../../containers/LetterModal/LetterModalHiddenButtonContainer";
+import LetterModalButtonContainer from "../../containers/LetterModal/LetterModalButtonContainer";
+import { useSelector } from "react-redux";
+
+const LetterDetails = ({ letter }) => {
+ const { song, songStory, createdDateTime, user } = letter;
+
+ return (
+ <ModalTemplate>
+ <LetterModalTemplate>
+ <LetterModalHiddenButtonContainer />
+ <LetterModalDiv>
+ <LetterDetailsSong song={song} />
+ <LetterDetailsSongStory songStory={songStory} />
+ <LetterDetailsUser user={user} createdDateTime={createdDateTime} />
+ <LetterModalButtonContainer />
+ </LetterModalDiv>
+ </LetterModalTemplate>
+ </ModalTemplate>
+ );
+};
+
+export default LetterDetails; | Unknown | `const { song, songStory, createdDateTime, user } = letter;`
๋๋ฌด ๋ง์ ์์ ๊ฐ์ฒด Props๊ฐ ์๋๋ผ๋ฉด ์ด ๋ถ๋ถ ๊ฐ์ ๊ฒฝ์ฐ๋ ๊ฐ๊ฐ ์ด๋ฆ์ ๊ฐ์ง Props๋ก ์ ๋ฌํด ์ฃผ๋๊ฒ๋ ์ข์๊ฑฐ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ญ๋๋ค! ๊ทธ๋ฌ๋ฉด ๊ฐ๋จํ๊ฒ ์ปดํฌ๋ํธ์ ์ง์ ๋ค์ด์ ๋ณด์ง ์์๋ ์ ๋ฌ๋๋ Props ๋ง์ผ๋ก ์ญํ ์ ์ ์ถํด ๋ณผ ์ ์์๊ฑฐ ๊ฐ์์. |
@@ -0,0 +1,45 @@
+import React, { useEffect } from "react";
+import { MdMoreHoriz } from "react-icons/md";
+import styled, { css } from "styled-components";
+import LetterDetailsHiddenMenuButton from "./LetterDetailsHiddenMenuButton";
+
+const LetterDetailsHiddenMenu = ({
+ isMouseEnter,
+ isMenuOpen,
+ onToggle,
+ changeToEdit
+}) => {
+ return (
+ <ButtonBlock isMouseEnter={isMouseEnter} onClick={onToggle}>
+ <HiddenMenu />
+ {isMenuOpen && (
+ <LetterDetailsHiddenMenuButton changeToEdit={changeToEdit} />
+ )}
+ </ButtonBlock>
+ );
+};
+
+const ButtonBlock = styled.div`
+ ${props =>
+ props.isMouseEnter
+ ? css`
+ visibility: visible;
+ opacity: 1;
+ `
+ : css`
+ visibility: hidden;
+ opacity: 0;
+ `}
+ transition: 0.7s;
+`;
+
+const HiddenMenu = styled(MdMoreHoriz)`
+ position: absolute;
+ bottom: 93%;
+ right: 3%;
+ cursor: pointer;
+ font-size: 2.1rem;
+ color: gray;
+`;
+
+export default LetterDetailsHiddenMenu; | Unknown | visibility: hidden; , display : none ์ ์ฐจ์ด๋ฅผ ์์๋์ ? ใ
ใ
๋ชจ๋ฅด๊ณ ๊ณ์ ๋ค๋ฉด ํ๋ฒ ์์๋ณด๋๊ฒ๋ ์ข์ต๋๋ค ! ๋๋จํ๊ฑด ์๋๊ณ ๊ทธ๋ฅ DOM ํธ๋ฆฌ์ ๊ด๋ จ๋ ๋ด์ฉ์ด์์. |
@@ -0,0 +1,28 @@
+import React from "react";
+import LetterModalSong from "../LetterModal/LetterModalSong/LetterModalSong";
+import SongAbout from "../LetterModal/LetterModalSong/SongAbout";
+import SongArticle from "../LetterModal/LetterModalSong/SongArticle";
+import SongArticleItem from "../LetterModal/LetterModalSong/SongArticleItem";
+import SongArticleName from "../LetterModal/LetterModalSong/SongArticleName";
+import SongImage from "../LetterModal/LetterModalSong/SongImage";
+
+const LetterDetailsSong = ({ song }) => {
+ const { title, artist, imageUrl } = song;
+ return (
+ <LetterModalSong>
+ <SongImage imageUrl={imageUrl} />
+ <SongAbout>
+ <SongArticle>
+ <SongArticleName articleName={"TITLE"} />
+ <SongArticleItem articleName={"TITLE"} item={title} />
+ </SongArticle>
+ <SongArticle>
+ <SongArticleName articleName={"ARTIST"} />
+ <SongArticleItem articleName={"ARTIST"} item={artist} />
+ </SongArticle>
+ </SongAbout>
+ </LetterModalSong>
+ );
+};
+
+export default LetterDetailsSong; | Unknown | ์ด ๋ถ๋ถ์ ๊ฒฝ์ฐ ๋ฐ๋ณต๋๋ ์ปดํฌ๋ํธ๋ก ๋ณด์ด๋๋ฐ ์ด๊ฑธ ํ๋๋ก ๋ฌถ์ด์ ๊ด๋ฆฌํด ๋ณด๋๊ฑด ์ด๋จ๊น์ ?
<SongArticle>
<SongArticleName articleName={"TITLE"} />
<SongArticleItem articleName={"TITLE"} item={title} />
</SongArticle> |
@@ -0,0 +1,48 @@
+import React from "react";
+import styled from "styled-components";
+import { BiSearch } from "react-icons/bi";
+import useModal from "../../hooks/useModal";
+import SongSearchModal from "./SongSearchModal/SongSearchModal";
+
+const LetterEditorSearchButton = () => {
+ const [isOpened, onOpenModal, onCloseModal] = useModal();
+
+ return (
+ <>
+ <StyledButton onClick={onOpenModal}>
+ <SearchIcon />
+ ์ ์ฒญ๊ณก ๊ฒ์
+ </StyledButton>
+ <SongSearchModal isOpened={isOpened} onCloseModal={onCloseModal} />
+ </>
+ );
+};
+
+const StyledButton = styled.div`
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ position: absolute;
+ width: 11rem;
+ top: 14%;
+ right: 15%;
+
+ padding: 0.35rem 0rem;
+ border-style: none;
+ border-radius: 0.5rem;
+ font-size: 1.2rem;
+ background-color: #f06595;
+ box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, 0.15);
+ color: #fff;
+ font-weight: 500;
+ z-index: 1;
+ cursor: pointer;
+`;
+
+const SearchIcon = styled(BiSearch)`
+ font-size: 1.35rem;
+ margin-right: 0.35rem;
+ opacity: 0.9;
+`;
+
+export default LetterEditorSearchButton; | Unknown | modal๊ณผ ๊ด๋ จ๋ ๋์์ custom hook์ผ๋ก ์ฌ์ฉํ ๋ถ๋ถ ์ข์ ๋ณด์
๋๋ค ! |
@@ -0,0 +1,108 @@
+import React from "react";
+import styled from "styled-components";
+import { BiSearch } from "react-icons/bi";
+import { useDispatch } from "react-redux";
+import { searchSong } from "../../../modules/song";
+
+const SearchForm = ({ onCloseModal }) => {
+ const dispatch = useDispatch();
+
+ const onSearchSong = event => {
+ event.preventDefault();
+ dispatch(searchSong());
+ };
+
+ return (
+ <Form>
+ <SearchInputWrap>
+ <SearchLabel>์ํฐ์คํธ</SearchLabel>
+ <SearchInput type="text" name="artist" />
+ </SearchInputWrap>
+ <SearchInputWrap>
+ <SearchLabel>์ ๋ชฉ</SearchLabel>
+ <SearchInput type="text" name="title" />
+ </SearchInputWrap>
+ <SearchButton type="submit" onClick={onSearchSong}>
+ <SearchIcon />
+ </SearchButton>
+ </Form>
+ );
+};
+
+const Form = styled.form`
+ box-sizing: border-box;
+ width: 95%;
+ display: flex;
+ justify-content: center;
+ margin: 0rem auto 3.5rem auto;
+`;
+
+const SearchLabel = styled.span`
+ display: flex;
+ align-items: center;
+ position: absolute;
+ top: 0rem;
+ left: 0rem;
+ height: 2.37rem;
+ font-size: 1rem;
+ background-color: #727272;
+ padding: 0rem 0.7rem;
+ border-radius: 0.3rem 0rem 0rem 0.3rem;
+ color: white;
+ font-weight: 600;
+ box-shadow: 1px 0px 3px 1px rgba(0, 0, 0, 0.1);
+`;
+
+const SearchInput = styled.input`
+ border: none;
+ outline: none;
+ color: #868e96;
+ width: 100%;
+ margin: 0rem 0.5rem 0rem 5.5rem;
+ font-size: 1.2rem;
+ background-color: #fbfbfd;
+`;
+
+const SearchInputWrap = styled.div`
+ display: flex;
+ align-items: center;
+ position: relative;
+ border: 1px solid #e9ecef;
+ border-radius: 1rem 0rem 0rem 1rem;
+ padding: 0.1rem 0rem;
+ background: #fbfbfd;
+ height: 2.1rem;
+ flex: 11;
+
+ &:nth-child(2) {
+ & > ${SearchLabel} {
+ border-radius: 0.2rem;
+ margin-left: -0.25rem;
+ }
+
+ & > ${SearchInput} {
+ margin-left: 3.8rem;
+ }
+ }
+`;
+
+const SearchButton = styled.button`
+ display: flex;
+ position: relative;
+ justify-content: center;
+ align-items: center;
+ border: none;
+ outline: none;
+ cursor: pointer;
+ background-color: #e1999c;
+ border-radius: 0rem 0.5rem 0.5rem 0rem;
+ flex: 1;
+ box-shadow: 1px 0px 3px 1px rgba(0, 0, 0, 0.1);
+`;
+
+const SearchIcon = styled(BiSearch)`
+ color: #fff;
+ font-size: 1.4rem;
+`;
+
+export default SearchForm; | Unknown | Form์ด ์ ์ ๋ ๋ณต์กํ ์ํ๋ฅผ ๊ฐ์ง๋ฉด ๊ด๋ฆฌ๊ฐ ์ฝ์ง ์์๋ฐ ๊ทธ๋ด๋
https://react-hook-form.com/
์์ ๊ฐ์ ๋๊ตฌ๋ฅผ ๋์
ํด ๋ณผ ์๋ ์์ต๋๋ค ใ
|
@@ -0,0 +1,24 @@
+import React from "react";
+import styled from "styled-components";
+
+const Footer = () => {
+ return (
+ <FooterBlock>
+ <p className="copyright">© Museop Kim</p>
+ </FooterBlock>
+ );
+};
+
+const FooterBlock = styled.div`
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 8rem;
+ margin-top: 6rem;
+ background-color: #f5f5f7;
+ font-weight: 500;
+ box-shadow: 0px -10px 35px 5px #f1f1f1;
+`;
+
+export default Footer; | Unknown | ์ปดํฌ๋ํธ๋ฅผ ์ฌ์ฌ์ฉ ํ๋ฏ์ด ์คํ์ผ๋ ์ฌ๋ฌ ๊ณณ์ ์ฌ์ฌ์ฉ ํ๋ ๋ฐฉ๋ฒ์ด ์์๋ค์. `ThemeProvider`์ ๋ํด ์ ๋ชฐ๋๋๋ฐ ์ด๋ฒ ๊ธฐํ์ ํ๋ฒ ํ์ต ํด๋ณด๊ณ ํด๋ณผ ์ ์๋ค๋ฉด ์ ์ฉ๊น์ง ํด๋ณด๊ฒ ์ต๋๋ค! ์กฐ์ธ ํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค ๐ |
@@ -0,0 +1,47 @@
+import React from "react";
+import styled from "styled-components";
+import { Link } from "react-router-dom";
+
+const Navigation = () => {
+ return (
+ <NavigationBlock>
+ <Link to="/">์ ์ฒญ๊ณก</Link>
+ <Link to="/ranking">์ ์ฒญ๊ณก ์์</Link>
+ <Link to="/contents">์ ์ฒญ๊ณก ์ ํ๋ธ ์์</Link>
+ <Link to="/musicsheets">๋ฆฌ์ผํผ์๋
ธ ์
๋ณด์ง</Link>
+ </NavigationBlock>
+ );
+};
+
+const NavigationBlock = styled.div`
+ height: 100%;
+ display: flex;
+ align-items: center;
+
+ & > * {
+ /* padding: 25px 5px 10px 5px; */
+ box-sizing: border-box;
+ display: flex;
+ align-items: center;
+ margin: 0px 30px;
+ padding-top: 10px;
+ font-size: 1.2rem;
+ font-weight: 600;
+ text-decoration: none;
+ align-self: center;
+ color: inherit;
+ opacity: 0.5;
+ height: 100%;
+ /* border-bottom: 1px solid rgba(0, 0, 0, 0); */
+ border-bottom: 3px solid rgba(250, 162, 193, 0);
+ transition: 0.3s;
+
+ :hover {
+ opacity: 1;
+ /* color: #faa2c1; */
+ border-bottom: 3px solid rgba(250, 162, 193, 1);
+ }
+ }
+`;
+
+export default Navigation; | Unknown | ์ฒ์์๋ ๋ง์ ํ์ ๊ฒ์ฒ๋ผ px๊ณผ rem์ ๊ตฌ๋ถํด์ ์ฌ์ฉ ํ๋ค๊ฐ ์๋ ๊ฐ์ธ rem์ผ๋ก ๋จ์๋ฅผ ํต์ผํ๊ณ ์ ์ฉ ํ์ต๋๋ค. ํน์ ์ด๋ ๊ฒ ํ ๊ฒฝ์ฐ ์ฃผ์ํด์ผ ๋ ๊ณ ๋ ค์ฌํญ ๊ฐ์๊ฒ ์์๊น์? |
@@ -0,0 +1,147 @@
+import React from "react";
+import styled from "styled-components";
+
+const MAX_LENGTH = 100;
+
+const Letter = ({
+ id,
+ user,
+ song,
+ songStory,
+ createdDateTime,
+ onReadLetter
+}) => {
+ const { username, avatarUrl } = user;
+ const { title, artist, imageUrl } = song;
+
+ return (
+ <>
+ <LetterBlock onClick={() => onReadLetter(id)}>
+ <SongBlock>
+ <img src={imageUrl} alt="ALBUM IMAGE" className="album-image" />
+ <div className="song-about">
+ <span className="song-about__title">{title}</span>
+ <span className="song-about__artist">{artist}</span>
+ </div>
+ </SongBlock>
+ <SongStory>
+ {songStory.length > MAX_LENGTH
+ ? `${songStory.slice(0, MAX_LENGTH)} ...`
+ : songStory}
+ </SongStory>
+ <UserBlock>
+ <div className="created-time">{createdDateTime}</div>
+ <div className="user-about">
+ <img src={avatarUrl} className="user-about__avatar" />
+ <span className="user-about__name">{username}</span>
+ </div>
+ </UserBlock>
+ </LetterBlock>
+ </>
+ );
+};
+
+const LetterBlock = styled.li`
+ width: 25rem;
+ height: 23rem;
+ margin: 1.2rem;
+ margin-bottom: 5rem;
+ box-sizing: border-box;
+ display: flex;
+ flex-direction: column;
+ padding: 0.7rem;
+ border: #ffdeeb;
+ border-radius: 0.5rem;
+ cursor: pointer;
+ transition: 0.3s;
+ box-shadow: 0 13px 27px -5px rgba(50, 50, 93, 0.2),
+ 0 8px 16px -8px rgba(0, 0, 0, 0.2), 0 -6px 16px -6px rgba(0, 0, 0, 0.025);
+
+ &:hover {
+ box-shadow: 0px 25px 30px 3px rgba(0, 0, 0, 0.3);
+ }
+
+ .album-image {
+ width: 10rem;
+ height: 10rem;
+ }
+`;
+
+const SongBlock = styled.div`
+ display: flex;
+ justify-content: space-between;
+
+ .album-image {
+ position: relative;
+ top: -2.5rem;
+ box-shadow: 3px 2px 5px 1px rgba(0, 0, 0, 0.3);
+ border-radius: 5px;
+ }
+
+ .song-about {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ margin-right: auto;
+ margin-left: 2rem;
+
+ .song-about__title {
+ overflow-x: hidden;
+ font-size: 1.4rem;
+ font-weight: 500;
+ color: #2c2c2c;
+ opacity: 0.9;
+ }
+
+ .song-about__artist {
+ margin-top: 0.5rem;
+ font-size: 1.2rem;
+ opacity: 0.8;
+ }
+ }
+`;
+
+const SongStory = styled.p`
+ width: 100%;
+ max-height: 8rem;
+ line-break: anywhere;
+ margin-top: -0.3rem;
+ font-size: 1.2rem;
+ line-height: 1.9rem;
+ opacity: 0.9;
+ padding: 0rem 0.5rem;
+`;
+
+const UserBlock = styled.div`
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin: auto 5px 3px 5px;
+
+ .created-time {
+ font-size: 1.1rem;
+ margin-top: 0.8rem;
+ opacity: 0.7;
+ }
+
+ .user-about {
+ display: flex;
+ align-items: center;
+ }
+
+ .user-about__avatar {
+ max-width: 2.5rem;
+ max-height: 2.5rem;
+ border-radius: 50%;
+ box-shadow: 3px 2px 10px 1px rgba(0, 0, 0, 0.3);
+ }
+
+ .user-about__name {
+ font-size: 1.1rem;
+ margin-top: 0.5rem;
+ margin-left: 0.5rem;
+ opacity: 0.8;
+ }
+`;
+
+export default Letter; | Unknown | ์ปดํฌ๋ํธ ์ด์ธ์ className์ ์ง์ ์ฌ์ฉํ ๋๋ ๋๋ถ๋ถ CSS ๋ค์ด๋ฐ ์ปจ๋ฒค์
์ผ๋ก ์๋ ค์ง `BEM` ์ ์ ์ฉ ํ์ต๋๋คใ
ใ
`-`๋ ๋ ๋จ์ด๋ฅผ ์ฐ๊ฒฐํด์ผ ํ ๋, `__`๋ ํน์ ๋ธ๋ญ์ ๊ตฌ์ฑํ๋ ํ์ ์์๋ฅผ ๊ตฌ๋ถํ ๋ ์ฌ์ฉ ํ๋ ๋ฏ ํ๋ค์.
[CSS BEM](https://css-tricks.com/bem-101/) ์ ์ฐธ๊ณ ํ์ต๋๋ค :) |
@@ -0,0 +1,29 @@
+import React from "react";
+import styled from "styled-components";
+import LetterContainer from "../../containers/Letter/LetterContainer";
+
+const LetterList = ({ letters }) => {
+ return (
+ <LetterListBlock>
+ {letters.map(letter => (
+ <LetterContainer
+ key={letter.id}
+ id={letter.id}
+ user={letter.user}
+ song={letter.song}
+ songStory={letter.songStory}
+ createdDateTime={letter.createdDateTime}
+ />
+ ))}
+ </LetterListBlock>
+ );
+};
+
+const LetterListBlock = styled.ul`
+ width: 100%;
+ display: flex;
+ flex-wrap: wrap;
+ margin-top: 4.5rem;
+`;
+
+export default LetterList; | Unknown | Container๋ฅผ ์ธ์ ์ฌ์ฉํด์ผ ํ ์ง ๋ช
ํํ ๊ธฐ์ค์ด ์์๋๋ฐ, ๋ฆฌ๋ทฐ ํด์ฃผ์ ๋ด์ฉ์ ๋ณด๊ณ ๊ณ ๋ฏผ ๋๋ ๊ฒ๋ค์ด ๋ง์ด ๋์ด์ง๋ ๋๋์ด์์.
๋ค์ ์์ ๋ ๋ฐ์ ํ๊ฒ ์ต๋๋ค ๐ |
@@ -0,0 +1,30 @@
+import React, { useEffect, useState } from "react";
+import ModalTemplate from "../Template/Modal/ModalTemplate";
+import LetterDetailsSong from "./LetterDetailsSong";
+import LetterDetailsSongStory from "./LetterDetailsSongStory";
+import LetterModalTemplate from "../Template/LetterModal/LetterModalTemplate";
+import LetterDetailsUser from "./LetterDetailsUser";
+import LetterModalDiv from "../LetterModal/LetterModalContents/LetterModalDiv";
+import LetterModalHiddenButtonContainer from "../../containers/LetterModal/LetterModalHiddenButtonContainer";
+import LetterModalButtonContainer from "../../containers/LetterModal/LetterModalButtonContainer";
+import { useSelector } from "react-redux";
+
+const LetterDetails = ({ letter }) => {
+ const { song, songStory, createdDateTime, user } = letter;
+
+ return (
+ <ModalTemplate>
+ <LetterModalTemplate>
+ <LetterModalHiddenButtonContainer />
+ <LetterModalDiv>
+ <LetterDetailsSong song={song} />
+ <LetterDetailsSongStory songStory={songStory} />
+ <LetterDetailsUser user={user} createdDateTime={createdDateTime} />
+ <LetterModalButtonContainer />
+ </LetterModalDiv>
+ </LetterModalTemplate>
+ </ModalTemplate>
+ );
+};
+
+export default LetterDetails; | Unknown | ๊ฐ๋ฅํ๋ค๋ฉด ๊ฐ์ฒด ์์ฒด๋ฅผ ๋๊ธฐ๋ ๊ฒ์ด ์ฌ๋ฌ ์ธก๋ฉด์์ ๋ ์ข์๊ฑฐ ๊ฐ๋ค๋ ์๊ฐ์ด์๋๋ฐ, ์๋ ๊ฒฝ์ฐ๋ ์๊ฒ ๋ค๋ ์๊ฐ์ด ๋๋ค์!
์์ ํ ๋ ๋ฐ์ ํ๊ฒ ์ต๋๋ค ๐ |
@@ -0,0 +1,45 @@
+import React, { useEffect } from "react";
+import { MdMoreHoriz } from "react-icons/md";
+import styled, { css } from "styled-components";
+import LetterDetailsHiddenMenuButton from "./LetterDetailsHiddenMenuButton";
+
+const LetterDetailsHiddenMenu = ({
+ isMouseEnter,
+ isMenuOpen,
+ onToggle,
+ changeToEdit
+}) => {
+ return (
+ <ButtonBlock isMouseEnter={isMouseEnter} onClick={onToggle}>
+ <HiddenMenu />
+ {isMenuOpen && (
+ <LetterDetailsHiddenMenuButton changeToEdit={changeToEdit} />
+ )}
+ </ButtonBlock>
+ );
+};
+
+const ButtonBlock = styled.div`
+ ${props =>
+ props.isMouseEnter
+ ? css`
+ visibility: visible;
+ opacity: 1;
+ `
+ : css`
+ visibility: hidden;
+ opacity: 0;
+ `}
+ transition: 0.7s;
+`;
+
+const HiddenMenu = styled(MdMoreHoriz)`
+ position: absolute;
+ bottom: 93%;
+ right: 3%;
+ cursor: pointer;
+ font-size: 2.1rem;
+ color: gray;
+`;
+
+export default LetterDetailsHiddenMenu; | Unknown | `display: none`์ DOM์ ์ํฅ์ ๋ฏธ์น์ง ์๋ ๋ฐ๋ฉด `visibility: hidden` ์ DOM์ ์ํฅ์ ์ฃผ๋ ๊ฒ์ผ๋ก ์๊ณ ์์์ด์ใ
ใ
`transition` ์ `display: none`์์ ์๋ํ์ง ์์์ `visibility` ์์ฑ์ ์ฌ์ฉํ๊ฒ ๋๋๋ฐ, ํน์ ์ปจ๋ฒค์
์ด ๋ฐ๋ก ์๋ค๊ฑฐ๋ ๋ ํจ์จ์ ์ธ ๋ฐฉ๋ฒ์ด ์์๊น์? |
@@ -0,0 +1,28 @@
+import React from "react";
+import LetterModalSong from "../LetterModal/LetterModalSong/LetterModalSong";
+import SongAbout from "../LetterModal/LetterModalSong/SongAbout";
+import SongArticle from "../LetterModal/LetterModalSong/SongArticle";
+import SongArticleItem from "../LetterModal/LetterModalSong/SongArticleItem";
+import SongArticleName from "../LetterModal/LetterModalSong/SongArticleName";
+import SongImage from "../LetterModal/LetterModalSong/SongImage";
+
+const LetterDetailsSong = ({ song }) => {
+ const { title, artist, imageUrl } = song;
+ return (
+ <LetterModalSong>
+ <SongImage imageUrl={imageUrl} />
+ <SongAbout>
+ <SongArticle>
+ <SongArticleName articleName={"TITLE"} />
+ <SongArticleItem articleName={"TITLE"} item={title} />
+ </SongArticle>
+ <SongArticle>
+ <SongArticleName articleName={"ARTIST"} />
+ <SongArticleItem articleName={"ARTIST"} item={artist} />
+ </SongArticle>
+ </SongAbout>
+ </LetterModalSong>
+ );
+};
+
+export default LetterDetailsSong; | Unknown | ์ปดํฌ๋ํธ๋ฅผ ์์ ํ ๋ค ๋ถ๋ฆฌ ํ ๋ค์ ํ๋ฒ ๋ ์ ๋ฆฌ๋ฅผ ํ์ด์ผ ํ๋๋ฐ ์ด๋ฐ ์ค๋ณต์ ๋ฌถ์ด์ ์ค์ด๋๊ฒ ์ข์๊ฑฐ ๊ฐ์์. ๋ฐ์ ํด๋ณด๊ฒ ์ต๋๋ค. ์๋ ค์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,108 @@
+import React from "react";
+import styled from "styled-components";
+import { BiSearch } from "react-icons/bi";
+import { useDispatch } from "react-redux";
+import { searchSong } from "../../../modules/song";
+
+const SearchForm = ({ onCloseModal }) => {
+ const dispatch = useDispatch();
+
+ const onSearchSong = event => {
+ event.preventDefault();
+ dispatch(searchSong());
+ };
+
+ return (
+ <Form>
+ <SearchInputWrap>
+ <SearchLabel>์ํฐ์คํธ</SearchLabel>
+ <SearchInput type="text" name="artist" />
+ </SearchInputWrap>
+ <SearchInputWrap>
+ <SearchLabel>์ ๋ชฉ</SearchLabel>
+ <SearchInput type="text" name="title" />
+ </SearchInputWrap>
+ <SearchButton type="submit" onClick={onSearchSong}>
+ <SearchIcon />
+ </SearchButton>
+ </Form>
+ );
+};
+
+const Form = styled.form`
+ box-sizing: border-box;
+ width: 95%;
+ display: flex;
+ justify-content: center;
+ margin: 0rem auto 3.5rem auto;
+`;
+
+const SearchLabel = styled.span`
+ display: flex;
+ align-items: center;
+ position: absolute;
+ top: 0rem;
+ left: 0rem;
+ height: 2.37rem;
+ font-size: 1rem;
+ background-color: #727272;
+ padding: 0rem 0.7rem;
+ border-radius: 0.3rem 0rem 0rem 0.3rem;
+ color: white;
+ font-weight: 600;
+ box-shadow: 1px 0px 3px 1px rgba(0, 0, 0, 0.1);
+`;
+
+const SearchInput = styled.input`
+ border: none;
+ outline: none;
+ color: #868e96;
+ width: 100%;
+ margin: 0rem 0.5rem 0rem 5.5rem;
+ font-size: 1.2rem;
+ background-color: #fbfbfd;
+`;
+
+const SearchInputWrap = styled.div`
+ display: flex;
+ align-items: center;
+ position: relative;
+ border: 1px solid #e9ecef;
+ border-radius: 1rem 0rem 0rem 1rem;
+ padding: 0.1rem 0rem;
+ background: #fbfbfd;
+ height: 2.1rem;
+ flex: 11;
+
+ &:nth-child(2) {
+ & > ${SearchLabel} {
+ border-radius: 0.2rem;
+ margin-left: -0.25rem;
+ }
+
+ & > ${SearchInput} {
+ margin-left: 3.8rem;
+ }
+ }
+`;
+
+const SearchButton = styled.button`
+ display: flex;
+ position: relative;
+ justify-content: center;
+ align-items: center;
+ border: none;
+ outline: none;
+ cursor: pointer;
+ background-color: #e1999c;
+ border-radius: 0rem 0.5rem 0.5rem 0rem;
+ flex: 1;
+ box-shadow: 1px 0px 3px 1px rgba(0, 0, 0, 0.1);
+`;
+
+const SearchIcon = styled(BiSearch)`
+ color: #fff;
+ font-size: 1.4rem;
+`;
+
+export default SearchForm; | Unknown | ์ง๊ธ ์ ๋์ ํผ ์ฌ์ฉ์์๋ ์ง์ ๊ตฌํ๋ ๋ฌด๋ฆฌ๊ฐ ์์์ง๋ง, ํผ์ด ๋ณต์กํด์ง๋ฉด ํ์คํ ๊ด๋ฆฌํ๊ธฐ๋ ์ฝ์ง ์์ ๋ฏ ํ๋๋ผ๊ตฌ์.
๊ธฐ์ต ํด๋์๋ค๊ฐ ํ์ํ ๋ ์ ์ฉ ํด๋ณด๊ฒ ์ต๋๋ค :) ์๋ ค์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. |
@@ -1,9 +1,100 @@
-function Header(logo, searchBox) {
+import Input from './Input';
+import Button from './Button';
+import { handleSearch } from '../services/handleSeach';
+
+function Header({ logoSrc, logoAlt, onSearch }) {
const headerElement = document.createElement('header');
- headerElement.classList.add('header');
- headerElement.appendChild(logo);
- headerElement.appendChild(searchBox);
+ headerElement.innerHTML = `
+ <h1><img src="${logoSrc}" alt="${logoAlt}" loading="lazy"></h1>
+ <div class="search-box"></div>
+ `;
+
+ let page = 1;
+
+ const searchInput = Input({
+ id: 'search-input',
+ type: 'text',
+ placeholder: '๊ฒ์',
+ onKeyDown: async (event) => {
+ if (event.code === 'Enter') {
+ document.getElementById('more-movies').remove();
+ const sectionContainer = document.querySelector('.item-view');
+
+ sectionContainer.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleSearch(searchInput.value, page);
+ }
+ })
+ );
+
+ await onSearch(event.target.value, page);
+ }
+ }
+ });
+
+ const searchButton = Button({
+ classNames: ['search-button'],
+ name: '๊ฒ์',
+ type: 'button',
+ onClick: async () => {
+ document.getElementById('more-movies').remove();
+ const sectionContainer = document.querySelector('.item-view');
+
+ sectionContainer.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleSearch(searchInput.value, page);
+ }
+ })
+ );
+
+ const inputValue = document.getElementById('search-input').value;
+ await onSearch(inputValue, page);
+ }
+ });
+
+ const searchBox = headerElement.querySelector('.search-box');
+
+ searchBox.addEventListener('mouseenter', () => {
+ const width = document.querySelector('body').getBoundingClientRect().width;
+
+ if (width <= 390) {
+ const input = document.getElementById('search-input');
+ const logo = document.querySelector('header h1');
+
+ searchBox.classList.add('search-box-toggle');
+ input.classList.add('input-toggle');
+ logo.classList.add('logo-toggle');
+ }
+ });
+
+ searchBox.addEventListener('mouseleave', () => {
+ const width = document.querySelector('body').getBoundingClientRect().width;
+
+ if (width <= 390) {
+ const input = document.getElementById('search-input');
+ const logo = document.querySelector('header h1');
+
+ searchBox.classList.remove('search-box-toggle');
+ input.classList.remove('input-toggle');
+ logo.classList.remove('logo-toggle');
+ }
+ });
+
+ searchBox.appendChild(searchInput);
+ searchBox.appendChild(searchButton);
return headerElement;
} | JavaScript | ์ ๋ ์ด๋ฒคํธ์ ์ด๋ฆ์ด ์๋ฏธํ๋๊ฒ "ํ์์ ๋ฐ์" ์ด๋ผ๊ณ ์๊ฐํด์.
๊ฐ๋ น, `onChange` ๋ ์ค์ ๋ก change๊ฐ ์ผ์ด๋ฌ์ ๋์ด๊ณ , `onKeyDown` ์ ํค๋ฅผ ๋๋ ์ ๋ ์
๋๋ค.
`onSearch`๋ "๊ฒ์์ด ๋์์ ๋ ๋ฐ์" ์ธ๋ฐ, ์ด ์ปดํฌ๋ํธ์์ ์ค์ ๋ก "๊ฒ์"์ด๋ผ๋ ํ์๊ฐ ์ผ์ด๋ฌ๋ค๊ณ ํ ์ ์์๊น์?
์ง๊ธ์ "๊ฒ์"์ด๋ผ๋ ํ์๋ฅผ ๋ฐ์์ ์ฃผ์
ํด์ฃผ๊ณ , ์ด ์ปดํฌ๋ํธ ๋ด๋ถ์์ ์ผ์ด๋ ์ผ์ "์ํฐํค๋ฅผ ๋๋ ์" ์
๋๋ค.
์ฆ, ์ด๋ฒคํธ๋ "๊ฒ์ํ์ ๋ ๋ฐ์ํจ"์ ์ด์ผ๊ธฐํ๊ณ ์๋๋ฐ ๊ฒ์์ด๋ผ๋ ๊ธฐ๋ฅ์ ๋ฐ์์ ์ฃผ์
ํด์ค ์ ๋ฐ์ ์๋ ์ํฉ์ธ๊ฑฐ์ฃ . |
@@ -1,9 +1,100 @@
-function Header(logo, searchBox) {
+import Input from './Input';
+import Button from './Button';
+import { handleSearch } from '../services/handleSeach';
+
+function Header({ logoSrc, logoAlt, onSearch }) {
const headerElement = document.createElement('header');
- headerElement.classList.add('header');
- headerElement.appendChild(logo);
- headerElement.appendChild(searchBox);
+ headerElement.innerHTML = `
+ <h1><img src="${logoSrc}" alt="${logoAlt}" loading="lazy"></h1>
+ <div class="search-box"></div>
+ `;
+
+ let page = 1;
+
+ const searchInput = Input({
+ id: 'search-input',
+ type: 'text',
+ placeholder: '๊ฒ์',
+ onKeyDown: async (event) => {
+ if (event.code === 'Enter') {
+ document.getElementById('more-movies').remove();
+ const sectionContainer = document.querySelector('.item-view');
+
+ sectionContainer.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleSearch(searchInput.value, page);
+ }
+ })
+ );
+
+ await onSearch(event.target.value, page);
+ }
+ }
+ });
+
+ const searchButton = Button({
+ classNames: ['search-button'],
+ name: '๊ฒ์',
+ type: 'button',
+ onClick: async () => {
+ document.getElementById('more-movies').remove();
+ const sectionContainer = document.querySelector('.item-view');
+
+ sectionContainer.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleSearch(searchInput.value, page);
+ }
+ })
+ );
+
+ const inputValue = document.getElementById('search-input').value;
+ await onSearch(inputValue, page);
+ }
+ });
+
+ const searchBox = headerElement.querySelector('.search-box');
+
+ searchBox.addEventListener('mouseenter', () => {
+ const width = document.querySelector('body').getBoundingClientRect().width;
+
+ if (width <= 390) {
+ const input = document.getElementById('search-input');
+ const logo = document.querySelector('header h1');
+
+ searchBox.classList.add('search-box-toggle');
+ input.classList.add('input-toggle');
+ logo.classList.add('logo-toggle');
+ }
+ });
+
+ searchBox.addEventListener('mouseleave', () => {
+ const width = document.querySelector('body').getBoundingClientRect().width;
+
+ if (width <= 390) {
+ const input = document.getElementById('search-input');
+ const logo = document.querySelector('header h1');
+
+ searchBox.classList.remove('search-box-toggle');
+ input.classList.remove('input-toggle');
+ logo.classList.remove('logo-toggle');
+ }
+ });
+
+ searchBox.appendChild(searchInput);
+ searchBox.appendChild(searchButton);
return headerElement;
} | JavaScript | ์ด ๋ถ๋ถ๋ ๋์ผํฉ๋๋ค! |
@@ -1,9 +1,100 @@
-function Header(logo, searchBox) {
+import Input from './Input';
+import Button from './Button';
+import { handleSearch } from '../services/handleSeach';
+
+function Header({ logoSrc, logoAlt, onSearch }) {
const headerElement = document.createElement('header');
- headerElement.classList.add('header');
- headerElement.appendChild(logo);
- headerElement.appendChild(searchBox);
+ headerElement.innerHTML = `
+ <h1><img src="${logoSrc}" alt="${logoAlt}" loading="lazy"></h1>
+ <div class="search-box"></div>
+ `;
+
+ let page = 1;
+
+ const searchInput = Input({
+ id: 'search-input',
+ type: 'text',
+ placeholder: '๊ฒ์',
+ onKeyDown: async (event) => {
+ if (event.code === 'Enter') {
+ document.getElementById('more-movies').remove();
+ const sectionContainer = document.querySelector('.item-view');
+
+ sectionContainer.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleSearch(searchInput.value, page);
+ }
+ })
+ );
+
+ await onSearch(event.target.value, page);
+ }
+ }
+ });
+
+ const searchButton = Button({
+ classNames: ['search-button'],
+ name: '๊ฒ์',
+ type: 'button',
+ onClick: async () => {
+ document.getElementById('more-movies').remove();
+ const sectionContainer = document.querySelector('.item-view');
+
+ sectionContainer.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleSearch(searchInput.value, page);
+ }
+ })
+ );
+
+ const inputValue = document.getElementById('search-input').value;
+ await onSearch(inputValue, page);
+ }
+ });
+
+ const searchBox = headerElement.querySelector('.search-box');
+
+ searchBox.addEventListener('mouseenter', () => {
+ const width = document.querySelector('body').getBoundingClientRect().width;
+
+ if (width <= 390) {
+ const input = document.getElementById('search-input');
+ const logo = document.querySelector('header h1');
+
+ searchBox.classList.add('search-box-toggle');
+ input.classList.add('input-toggle');
+ logo.classList.add('logo-toggle');
+ }
+ });
+
+ searchBox.addEventListener('mouseleave', () => {
+ const width = document.querySelector('body').getBoundingClientRect().width;
+
+ if (width <= 390) {
+ const input = document.getElementById('search-input');
+ const logo = document.querySelector('header h1');
+
+ searchBox.classList.remove('search-box-toggle');
+ input.classList.remove('input-toggle');
+ logo.classList.remove('logo-toggle');
+ }
+ });
+
+ searchBox.appendChild(searchInput);
+ searchBox.appendChild(searchButton);
return headerElement;
} | JavaScript | ์ฌ๊ธฐ์ ์ฐ์ด๋ 390 ์ด๋ผ๋ ์ซ์๋ ์์๋ก ๋ง๋ค์ด์ ์ฌ์ฉํด์ฃผ๋ฉด ์ด๋จ๊น์!? |
@@ -1,9 +1,100 @@
-function Header(logo, searchBox) {
+import Input from './Input';
+import Button from './Button';
+import { handleSearch } from '../services/handleSeach';
+
+function Header({ logoSrc, logoAlt, onSearch }) {
const headerElement = document.createElement('header');
- headerElement.classList.add('header');
- headerElement.appendChild(logo);
- headerElement.appendChild(searchBox);
+ headerElement.innerHTML = `
+ <h1><img src="${logoSrc}" alt="${logoAlt}" loading="lazy"></h1>
+ <div class="search-box"></div>
+ `;
+
+ let page = 1;
+
+ const searchInput = Input({
+ id: 'search-input',
+ type: 'text',
+ placeholder: '๊ฒ์',
+ onKeyDown: async (event) => {
+ if (event.code === 'Enter') {
+ document.getElementById('more-movies').remove();
+ const sectionContainer = document.querySelector('.item-view');
+
+ sectionContainer.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleSearch(searchInput.value, page);
+ }
+ })
+ );
+
+ await onSearch(event.target.value, page);
+ }
+ }
+ });
+
+ const searchButton = Button({
+ classNames: ['search-button'],
+ name: '๊ฒ์',
+ type: 'button',
+ onClick: async () => {
+ document.getElementById('more-movies').remove();
+ const sectionContainer = document.querySelector('.item-view');
+
+ sectionContainer.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleSearch(searchInput.value, page);
+ }
+ })
+ );
+
+ const inputValue = document.getElementById('search-input').value;
+ await onSearch(inputValue, page);
+ }
+ });
+
+ const searchBox = headerElement.querySelector('.search-box');
+
+ searchBox.addEventListener('mouseenter', () => {
+ const width = document.querySelector('body').getBoundingClientRect().width;
+
+ if (width <= 390) {
+ const input = document.getElementById('search-input');
+ const logo = document.querySelector('header h1');
+
+ searchBox.classList.add('search-box-toggle');
+ input.classList.add('input-toggle');
+ logo.classList.add('logo-toggle');
+ }
+ });
+
+ searchBox.addEventListener('mouseleave', () => {
+ const width = document.querySelector('body').getBoundingClientRect().width;
+
+ if (width <= 390) {
+ const input = document.getElementById('search-input');
+ const logo = document.querySelector('header h1');
+
+ searchBox.classList.remove('search-box-toggle');
+ input.classList.remove('input-toggle');
+ logo.classList.remove('logo-toggle');
+ }
+ });
+
+ searchBox.appendChild(searchInput);
+ searchBox.appendChild(searchButton);
return headerElement;
} | JavaScript | ์ ๋ณด๋๊น ๋ก์ง์ด ๊ฑฐ์ ์ ์ฌํ๋ค์! |
@@ -0,0 +1,33 @@
+import handleMovie from '../services/handleMovie';
+import Button from './Button';
+
+function MainContent(initialPage) {
+ let page = initialPage;
+ const mainElement = document.createElement('main');
+ mainElement.id = 'main';
+
+ mainElement.innerHTML = `
+ <section class="item-view">
+ <h2>์ง๊ธ ์ธ๊ธฐ ์๋ ์ํ</h2>
+ <ul class="item-list"></ul>
+ </section>
+ `;
+
+ const sectionElement = mainElement.querySelector('.item-view');
+ sectionElement.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleMovie(page);
+ }
+ })
+ );
+
+ return mainElement;
+}
+
+export default MainContent; | JavaScript | ```suggestion
const mainElement = html(`
<main id="main">
<section class="item-view">
<h2>์ง๊ธ ์ธ๊ธฐ ์๋ ์ํ</h2>
<ul class="item-list"></ul>
</section>
<main>
`);
```
์ด๋ ๊ฒ ํํํ ์ ์๋๋ก ํจ์๋ฅผ ํ๋ ๋ง๋ค์ด์ฃผ์๋ฉด ์ด๋จ๊น์!? |
@@ -0,0 +1,33 @@
+import handleMovie from '../services/handleMovie';
+import Button from './Button';
+
+function MainContent(initialPage) {
+ let page = initialPage;
+ const mainElement = document.createElement('main');
+ mainElement.id = 'main';
+
+ mainElement.innerHTML = `
+ <section class="item-view">
+ <h2>์ง๊ธ ์ธ๊ธฐ ์๋ ์ํ</h2>
+ <ul class="item-list"></ul>
+ </section>
+ `;
+
+ const sectionElement = mainElement.querySelector('.item-view');
+ sectionElement.appendChild(
+ Button({
+ classNames: ['btn', 'primary', 'full-width'],
+ type: 'button',
+ id: 'more-movies',
+ name: '๋ ๋ณด๊ธฐ',
+ onClick: () => {
+ page += 1;
+ handleMovie(page);
+ }
+ })
+ );
+
+ return mainElement;
+}
+
+export default MainContent; | JavaScript | ์์์๋ html template์ผ๋ก ํํ๋๊ณ ์ฌ๊ธฐ์๋ ์ด๋ ๊ฒ ํํ๋๊ณ ์์ด์ ์ฝ๋๋ฅผ ์ฝ๋ ์ฌ๋ ์
์ฅ์์๋ ์กฐ๊ธ ํท๊ฐ๋ฆฌ์ง ์์๊น ์ถ์ด์! |
@@ -0,0 +1,47 @@
+import { BASE_URL } from '../constants/api';
+import { APIError } from '../apis/error';
+
+interface ApiClientType {
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
+ endpoint: string;
+ params?: Record<string, string>;
+ headers?: Record<string, string>;
+ body?: Record<string, any>;
+}
+
+class ApiClient {
+ static async request({ method, endpoint, params, headers = {}, body }: ApiClientType) {
+ const url = params
+ ? this.createUrlSearchParams({ baseUrl: `${BASE_URL}/${endpoint}`, params })
+ : `${BASE_URL}/${endpoint}`;
+
+ const options: RequestInit = {
+ method,
+ headers: {
+ 'Content-Type': 'application/json',
+ ...headers
+ },
+ ...(body && { body: JSON.stringify(body) })
+ };
+
+ try {
+ const response = await fetch(url, options);
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new APIError(data.status_code, data.status_message);
+ }
+ return data;
+ } catch (error: any) {
+ throw new APIError(400, error.message || 'An unknown error occurred');
+ }
+ }
+
+ static createUrlSearchParams({ baseUrl, params }: { baseUrl: string; params: Record<string, string> }) {
+ const url = new URL(baseUrl);
+ url.search = new URLSearchParams(params).toString();
+ return url.toString();
+ }
+}
+
+export default ApiClient; | TypeScript | ์ํ.. ์ด ํ์ผ ๋๋ฌธ์ tsconfig๊ฐ ์๊ธด๊ฑฐ์๊ตฐ์ |
@@ -0,0 +1,47 @@
+import { BASE_URL } from '../constants/api';
+import { APIError } from '../apis/error';
+
+interface ApiClientType {
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
+ endpoint: string;
+ params?: Record<string, string>;
+ headers?: Record<string, string>;
+ body?: Record<string, any>;
+}
+
+class ApiClient {
+ static async request({ method, endpoint, params, headers = {}, body }: ApiClientType) {
+ const url = params
+ ? this.createUrlSearchParams({ baseUrl: `${BASE_URL}/${endpoint}`, params })
+ : `${BASE_URL}/${endpoint}`;
+
+ const options: RequestInit = {
+ method,
+ headers: {
+ 'Content-Type': 'application/json',
+ ...headers
+ },
+ ...(body && { body: JSON.stringify(body) })
+ };
+
+ try {
+ const response = await fetch(url, options);
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new APIError(data.status_code, data.status_message);
+ }
+ return data;
+ } catch (error: any) {
+ throw new APIError(400, error.message || 'An unknown error occurred');
+ }
+ }
+
+ static createUrlSearchParams({ baseUrl, params }: { baseUrl: string; params: Record<string, string> }) {
+ const url = new URL(baseUrl);
+ url.search = new URLSearchParams(params).toString();
+ return url.toString();
+ }
+}
+
+export default ApiClient; | TypeScript | try ๊ตฌ๊ฐ์์ ์ค๋ฅ ๋ฐ์ -> catch๋ก ์ง์
-> ๋ฌด์กฐ๊ฑด status๋ 400์ผ๋ก ๊ณ ์ ํ์ฌ ๋ค์ error throw
์ด๋ ๊ฒ ๋ฉ๋๋ค.
์ ์๋ฏธํ ์๋ฌ ํ๋ก์ฐ์ผ๊น์~? |
@@ -0,0 +1,47 @@
+import { BASE_URL } from '../constants/api';
+import { APIError } from '../apis/error';
+
+interface ApiClientType {
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
+ endpoint: string;
+ params?: Record<string, string>;
+ headers?: Record<string, string>;
+ body?: Record<string, any>;
+}
+
+class ApiClient {
+ static async request({ method, endpoint, params, headers = {}, body }: ApiClientType) {
+ const url = params
+ ? this.createUrlSearchParams({ baseUrl: `${BASE_URL}/${endpoint}`, params })
+ : `${BASE_URL}/${endpoint}`;
+
+ const options: RequestInit = {
+ method,
+ headers: {
+ 'Content-Type': 'application/json',
+ ...headers
+ },
+ ...(body && { body: JSON.stringify(body) })
+ };
+
+ try {
+ const response = await fetch(url, options);
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new APIError(data.status_code, data.status_message);
+ }
+ return data;
+ } catch (error: any) {
+ throw new APIError(400, error.message || 'An unknown error occurred');
+ }
+ }
+
+ static createUrlSearchParams({ baseUrl, params }: { baseUrl: string; params: Record<string, string> }) {
+ const url = new URL(baseUrl);
+ url.search = new URLSearchParams(params).toString();
+ return url.toString();
+ }
+}
+
+export default ApiClient; | TypeScript | ๊ทธ๋ฐ๋ฐ ์ด ํ์ผ์ด ์ domain ์ ํด๋นํ๋๊ฑธ๊น์~?
domain์ด๋ผ๊ณ ํ๊ธฐ์ ๋ง ๊ทธ๋๋ก ์ฌ์ด๋ ์ดํํธ(client)๋ฅผ ํํํ๊ฑฐ๋ผ์... ์ ํ ์ฐ๊ด์ด ์์ด๋ณด์ฌ์! |
@@ -0,0 +1,24 @@
+import getMovieList from '../apis/getMovieList';
+import ConfirmModal from '../components/modal/ConfirmModal';
+import { Modal } from '../components/modal/container/Modal';
+import { NOT_MORE_MOVIES_MESSAGE } from '../constants/message';
+import renderMovies from '../view/renderMovies';
+import renderSkeletonMovies from '../view/renderSkeletonMovies';
+
+export default async function handleMovie(page) {
+ try {
+ renderSkeletonMovies({ loading: true });
+ const movieList = await getMovieList(page);
+ renderSkeletonMovies({ loading: false });
+
+ if (movieList.results.length === 0) {
+ document.getElementById('more-movies').remove();
+ new Modal(document.querySelector('body'), ConfirmModal(NOT_MORE_MOVIES_MESSAGE));
+ }
+
+ renderMovies({ movieList: movieList.results, resetHTML: false });
+ } catch (error) {
+ renderSkeletonMovies({ loading: false });
+ new Modal(document.querySelector('body'), ConfirmModal(error.message));
+ }
+} | JavaScript | api์์ ๋ฐ์ํ ์๋ฌ ์ค์ message๋ง ์ฌ์ฉํ๊ณ ์๋๋ฐ, CustomError๋ฅผ ๋ง๋ค์ด์ ์ฐ๋ ์๋ฏธ๊ฐ ์๋๊ฑด๊ฐ ์ถ์ด์! |
@@ -0,0 +1,47 @@
+import { BASE_URL } from '../constants/api';
+import { APIError } from '../apis/error';
+
+interface ApiClientType {
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
+ endpoint: string;
+ params?: Record<string, string>;
+ headers?: Record<string, string>;
+ body?: Record<string, any>;
+}
+
+class ApiClient {
+ static async request({ method, endpoint, params, headers = {}, body }: ApiClientType) {
+ const url = params
+ ? this.createUrlSearchParams({ baseUrl: `${BASE_URL}/${endpoint}`, params })
+ : `${BASE_URL}/${endpoint}`;
+
+ const options: RequestInit = {
+ method,
+ headers: {
+ 'Content-Type': 'application/json',
+ ...headers
+ },
+ ...(body && { body: JSON.stringify(body) })
+ };
+
+ try {
+ const response = await fetch(url, options);
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new APIError(data.status_code, data.status_message);
+ }
+ return data;
+ } catch (error: any) {
+ throw new APIError(400, error.message || 'An unknown error occurred');
+ }
+ }
+
+ static createUrlSearchParams({ baseUrl, params }: { baseUrl: string; params: Record<string, string> }) {
+ const url = new URL(baseUrl);
+ url.search = new URLSearchParams(params).toString();
+ return url.toString();
+ }
+}
+
+export default ApiClient; | TypeScript | domain์ด apis๋ฅผ ์ฐธ์กฐํ๋๊ฑด ์ด์ํด๋ณด์ฌ์! |
@@ -1,2 +1 @@
export const BASE_URL = 'https://api.themoviedb.org';
-export const IMAGE_BASE_URL = 'https://image.tmdb.org/t/p/w500'; | JavaScript | ์ด๋ฐ ์ ๋ณด๋ ์์ API๋ฅผ ์์ฒญํ๋ ์ชฝ์์ ๊ฐ์ง๊ณ ์์ผ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1 @@
+export const NOT_MORE_MOVIES_MESSAGE = '๋์ด์ ์ํ๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค.'; | JavaScript | ์ด๋ฐ ์๋ฌ ๋ฉ์ธ์ง๋ ๋ฉ์ธ์ง๋ฅผ ์ฌ์ฉํ๋ ์ชฝ์์ ๊ฐ์ง๊ณ ์์ผ๋ฉด ์ด๋จ๊น์?
๋ค๋ฅธ ๊ตฌ๊ฐ์์๋ ์์ ์ฌ์ฉ๋ ๊ฒ ๊ฐ์ง ์์์์! |
@@ -0,0 +1,75 @@
+package bridge.controller;
+
+import bridge.BridgeRandomNumberGenerator;
+import bridge.constants.GameValue;
+import bridge.domain.Bridge;
+import bridge.domain.BridgeGame;
+import bridge.domain.BridgeMaker;
+import bridge.view.handler.InputHandler;
+import bridge.view.OutputView;
+
+public class BridgeController {
+ private final InputHandler inputHandler;
+ private final OutputView outputView;
+ private final BridgeGame bridgeGame;
+ private boolean status = true;
+
+ public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) {
+ this.inputHandler = inputHandler;
+ this.outputView = outputView;
+ this.bridgeGame = bridgeGame;
+ }
+
+ public void start() {
+ outputView.printStartMessage();
+ Bridge bridge = createBridge();
+ run(bridge);
+ }
+
+ private Bridge createBridge() {
+ outputView.printBridgeSizeInputMessage();
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return inputHandler.createValidatedBridge(bridgeMaker);
+ }
+
+ private void run(Bridge bridge) {
+ while (status) {
+ move(bridge);
+ if (isFinished()) {
+ finishGame();
+ }
+ if (!isFinished()) {
+ askRetry();
+ }
+ }
+ }
+
+ private void move(Bridge bridge) {
+ for (String square : bridge.getBridge()) {
+ outputView.printMoveInputMessage();
+ String moveCommand = inputHandler.readMoving();
+ bridgeGame.move(square, moveCommand);
+ outputView.printMap(bridgeGame.getMoveResult());
+ }
+ }
+
+ private boolean isFinished() {
+ return bridgeGame.isSuccessful();
+ }
+
+ private void finishGame() {
+ outputView.printResult(bridgeGame);
+ status = false;
+ }
+
+ private void askRetry() {
+ outputView.printRetryMessage();
+ String retryCommand = inputHandler.readGameCommand();
+ if (retryCommand.equals(GameValue.RETRY_COMMAND)) {
+ bridgeGame.retry();
+ }
+ if (retryCommand.equals(GameValue.QUIT_COMMAND)) {
+ outputView.printResult(bridgeGame);
+ }
+ }
+} | Java | ๋ค๋ฆฌ๋ฅผ ๋๋ฉด์ ์ด๋์ ๋ฐ๊ณ ์๋ ํํ๋ผ์,
์ด๋์ด ์คํจํด๋ ๋ฐ๋ก ์ฌ์๋ ์ฌ๋ถ๋ฅผ ๋ฌป์ง ์๊ณ , ๊ทธ๋ฅ ์งํ์ด ๋๋ ๊ฒ ๊ฐ์ต๋๋ค..! |
@@ -0,0 +1,75 @@
+package bridge.controller;
+
+import bridge.BridgeRandomNumberGenerator;
+import bridge.constants.GameValue;
+import bridge.domain.Bridge;
+import bridge.domain.BridgeGame;
+import bridge.domain.BridgeMaker;
+import bridge.view.handler.InputHandler;
+import bridge.view.OutputView;
+
+public class BridgeController {
+ private final InputHandler inputHandler;
+ private final OutputView outputView;
+ private final BridgeGame bridgeGame;
+ private boolean status = true;
+
+ public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) {
+ this.inputHandler = inputHandler;
+ this.outputView = outputView;
+ this.bridgeGame = bridgeGame;
+ }
+
+ public void start() {
+ outputView.printStartMessage();
+ Bridge bridge = createBridge();
+ run(bridge);
+ }
+
+ private Bridge createBridge() {
+ outputView.printBridgeSizeInputMessage();
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return inputHandler.createValidatedBridge(bridgeMaker);
+ }
+
+ private void run(Bridge bridge) {
+ while (status) {
+ move(bridge);
+ if (isFinished()) {
+ finishGame();
+ }
+ if (!isFinished()) {
+ askRetry();
+ }
+ }
+ }
+
+ private void move(Bridge bridge) {
+ for (String square : bridge.getBridge()) {
+ outputView.printMoveInputMessage();
+ String moveCommand = inputHandler.readMoving();
+ bridgeGame.move(square, moveCommand);
+ outputView.printMap(bridgeGame.getMoveResult());
+ }
+ }
+
+ private boolean isFinished() {
+ return bridgeGame.isSuccessful();
+ }
+
+ private void finishGame() {
+ outputView.printResult(bridgeGame);
+ status = false;
+ }
+
+ private void askRetry() {
+ outputView.printRetryMessage();
+ String retryCommand = inputHandler.readGameCommand();
+ if (retryCommand.equals(GameValue.RETRY_COMMAND)) {
+ bridgeGame.retry();
+ }
+ if (retryCommand.equals(GameValue.QUIT_COMMAND)) {
+ outputView.printResult(bridgeGame);
+ }
+ }
+} | Java | ์คํจํ๊ณ ์ฌ์๋๋ ์ข
๋ฃ๋ฅผ ์
๋ ฅํ์ ๋, ๊ฒ์์ด ์ข
๋ฃ๋์ง ์๊ณ ๊ณ์ ๋ค์ ์ด๋ ์
๋ ฅ์ ๋ฐ๋ ๊ฒ ๊ฐ์ต๋๋ค..!
์คํจํ๊ณ ์ฌ๊ธฐ๋ก ๋ค์ด์์ status๋ฅผ false๋ก ๋ฐ๊ฟ์ฃผ๋ ๋ถ๋ถ์ด ์์ด์์ธ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,75 @@
+package bridge.controller;
+
+import bridge.BridgeRandomNumberGenerator;
+import bridge.constants.GameValue;
+import bridge.domain.Bridge;
+import bridge.domain.BridgeGame;
+import bridge.domain.BridgeMaker;
+import bridge.view.handler.InputHandler;
+import bridge.view.OutputView;
+
+public class BridgeController {
+ private final InputHandler inputHandler;
+ private final OutputView outputView;
+ private final BridgeGame bridgeGame;
+ private boolean status = true;
+
+ public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) {
+ this.inputHandler = inputHandler;
+ this.outputView = outputView;
+ this.bridgeGame = bridgeGame;
+ }
+
+ public void start() {
+ outputView.printStartMessage();
+ Bridge bridge = createBridge();
+ run(bridge);
+ }
+
+ private Bridge createBridge() {
+ outputView.printBridgeSizeInputMessage();
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return inputHandler.createValidatedBridge(bridgeMaker);
+ }
+
+ private void run(Bridge bridge) {
+ while (status) {
+ move(bridge);
+ if (isFinished()) {
+ finishGame();
+ }
+ if (!isFinished()) {
+ askRetry();
+ }
+ }
+ }
+
+ private void move(Bridge bridge) {
+ for (String square : bridge.getBridge()) {
+ outputView.printMoveInputMessage();
+ String moveCommand = inputHandler.readMoving();
+ bridgeGame.move(square, moveCommand);
+ outputView.printMap(bridgeGame.getMoveResult());
+ }
+ }
+
+ private boolean isFinished() {
+ return bridgeGame.isSuccessful();
+ }
+
+ private void finishGame() {
+ outputView.printResult(bridgeGame);
+ status = false;
+ }
+
+ private void askRetry() {
+ outputView.printRetryMessage();
+ String retryCommand = inputHandler.readGameCommand();
+ if (retryCommand.equals(GameValue.RETRY_COMMAND)) {
+ bridgeGame.retry();
+ }
+ if (retryCommand.equals(GameValue.QUIT_COMMAND)) {
+ outputView.printResult(bridgeGame);
+ }
+ }
+} | Java | ์ด๋ํ์ ๋ X๊ฐ ๋์ค๋ฉด ์ฌ์์์ด ๋์์ผํ๋๋ฐ
์ด๊ฑฐ ์ ๊ฐ ๋ฌธ์ ๋ฅผ ์ ๋ชป์ดํดํ๋ค์ ใ
ใ
.. |
@@ -0,0 +1,75 @@
+package bridge.controller;
+
+import bridge.BridgeRandomNumberGenerator;
+import bridge.constants.GameValue;
+import bridge.domain.Bridge;
+import bridge.domain.BridgeGame;
+import bridge.domain.BridgeMaker;
+import bridge.view.handler.InputHandler;
+import bridge.view.OutputView;
+
+public class BridgeController {
+ private final InputHandler inputHandler;
+ private final OutputView outputView;
+ private final BridgeGame bridgeGame;
+ private boolean status = true;
+
+ public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) {
+ this.inputHandler = inputHandler;
+ this.outputView = outputView;
+ this.bridgeGame = bridgeGame;
+ }
+
+ public void start() {
+ outputView.printStartMessage();
+ Bridge bridge = createBridge();
+ run(bridge);
+ }
+
+ private Bridge createBridge() {
+ outputView.printBridgeSizeInputMessage();
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return inputHandler.createValidatedBridge(bridgeMaker);
+ }
+
+ private void run(Bridge bridge) {
+ while (status) {
+ move(bridge);
+ if (isFinished()) {
+ finishGame();
+ }
+ if (!isFinished()) {
+ askRetry();
+ }
+ }
+ }
+
+ private void move(Bridge bridge) {
+ for (String square : bridge.getBridge()) {
+ outputView.printMoveInputMessage();
+ String moveCommand = inputHandler.readMoving();
+ bridgeGame.move(square, moveCommand);
+ outputView.printMap(bridgeGame.getMoveResult());
+ }
+ }
+
+ private boolean isFinished() {
+ return bridgeGame.isSuccessful();
+ }
+
+ private void finishGame() {
+ outputView.printResult(bridgeGame);
+ status = false;
+ }
+
+ private void askRetry() {
+ outputView.printRetryMessage();
+ String retryCommand = inputHandler.readGameCommand();
+ if (retryCommand.equals(GameValue.RETRY_COMMAND)) {
+ bridgeGame.retry();
+ }
+ if (retryCommand.equals(GameValue.QUIT_COMMAND)) {
+ outputView.printResult(bridgeGame);
+ }
+ }
+} | Java | ๊ทธ๋ฌ๋ค์ ๋ถ๋ฆฌํ๊ธฐ์ ์๋ ์ ์๋์ํด์ ๋ฆฌํฉํ ๋ง๋จ๊ณ์์ ์ค์ํ๋๋ด
๋๋ค..
๋ง์ง๋ง์ ๋ค์ ํ๋ฒ ๊ผผ๊ผผํ ์ฒดํฌํด์ผ๊ฒ ๋ค์ ๐จ |
@@ -0,0 +1,14 @@
+package bridge.constants;
+
+public class GameValue {
+
+ private GameValue() {
+ }
+
+ public static final String MOVE_UP_COMMAND = "U";
+ public static final String MOVE_DOWN_COMMAND = "D";
+ public static final String RETRY_COMMAND = "R";
+ public static final String QUIT_COMMAND = "Q";
+ public static final String MOVE = "O";
+ public static final String STOP = "X";
+} | Java | ๊ด๋ จ ์๋ ์์๋ผ๋ฆฌ Enum ์ผ๋ก ๋ฌถ์ด๋ด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค :) |
@@ -0,0 +1,17 @@
+package bridge.constants;
+
+import java.util.regex.Pattern;
+
+public enum RegexPattern {
+ ONLY_NUMBER(Pattern.compile("\\d+"));
+
+ private final Pattern pattern;
+
+ RegexPattern(Pattern pattern) {
+ this.pattern = pattern;
+ }
+
+ public boolean matches(String value) {
+ return pattern.matcher(value).matches();
+ }
+} | Java | Pattern ์์ฒด๋ฅผ Enum ์ผ๋ก ์ฌ์ฉํ๋ ๊ฒ์ ์๊ฐํด๋ณด์ง ๋ชปํ๋๋ฐ, ์ด๊ฑฐ ๊ฝค๋ ์ฌํ์ฉ์ฑ์ด ๋๊ฒ ๊ตฐ์ ๐ |
@@ -0,0 +1,75 @@
+package bridge.controller;
+
+import bridge.BridgeRandomNumberGenerator;
+import bridge.constants.GameValue;
+import bridge.domain.Bridge;
+import bridge.domain.BridgeGame;
+import bridge.domain.BridgeMaker;
+import bridge.view.handler.InputHandler;
+import bridge.view.OutputView;
+
+public class BridgeController {
+ private final InputHandler inputHandler;
+ private final OutputView outputView;
+ private final BridgeGame bridgeGame;
+ private boolean status = true;
+
+ public BridgeController(InputHandler inputHandler, OutputView outputView, BridgeGame bridgeGame) {
+ this.inputHandler = inputHandler;
+ this.outputView = outputView;
+ this.bridgeGame = bridgeGame;
+ }
+
+ public void start() {
+ outputView.printStartMessage();
+ Bridge bridge = createBridge();
+ run(bridge);
+ }
+
+ private Bridge createBridge() {
+ outputView.printBridgeSizeInputMessage();
+ BridgeMaker bridgeMaker = new BridgeMaker(new BridgeRandomNumberGenerator());
+ return inputHandler.createValidatedBridge(bridgeMaker);
+ }
+
+ private void run(Bridge bridge) {
+ while (status) {
+ move(bridge);
+ if (isFinished()) {
+ finishGame();
+ }
+ if (!isFinished()) {
+ askRetry();
+ }
+ }
+ }
+
+ private void move(Bridge bridge) {
+ for (String square : bridge.getBridge()) {
+ outputView.printMoveInputMessage();
+ String moveCommand = inputHandler.readMoving();
+ bridgeGame.move(square, moveCommand);
+ outputView.printMap(bridgeGame.getMoveResult());
+ }
+ }
+
+ private boolean isFinished() {
+ return bridgeGame.isSuccessful();
+ }
+
+ private void finishGame() {
+ outputView.printResult(bridgeGame);
+ status = false;
+ }
+
+ private void askRetry() {
+ outputView.printRetryMessage();
+ String retryCommand = inputHandler.readGameCommand();
+ if (retryCommand.equals(GameValue.RETRY_COMMAND)) {
+ bridgeGame.retry();
+ }
+ if (retryCommand.equals(GameValue.QUIT_COMMAND)) {
+ outputView.printResult(bridgeGame);
+ }
+ }
+} | Java | ์ด ๋ถ๋ถ์ ์ธ๋ดํธ๋ฅผ 1๋ก ๋ฆฌํฉํ ๋งํ๋ ๊ณ ํต์ค๋ฌ์ด(?) ๊ฒฝํ์ ํด๋ณด์
๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
์ ๋ ์ ๋ ๋ชป ์ค์ผ ๊ฒ ๊ฐ๋ ์ธ๋ดํธ๋ฅผ ์ค์ด๋ ค๊ณ ์ด๋ฆฌ์ ๋ฆฌ ๋นํ๋ค๋ณด๋(?) ๋ค์ํ ์ธ์ฌ์ดํธ๋ค์ด ๋ ์ค๋ฅด๋๋ผ๊ณ ์..! |
@@ -0,0 +1,82 @@
+package bridge.domain;
+
+import bridge.constants.GameValue;
+
+/**
+ * ๋ค๋ฆฌ ๊ฑด๋๊ธฐ ๊ฒ์์ ๊ด๋ฆฌํ๋ ํด๋์ค
+ */
+public class BridgeGame {
+
+ private int retryCount;
+ private MoveResult moveResult;
+
+ public BridgeGame(MoveResult moveResult, int retryCount) {
+ this.moveResult = moveResult;
+ this.retryCount = retryCount;
+ }
+
+ /**
+ * ์ฌ์ฉ์๊ฐ ์นธ์ ์ด๋ํ ๋ ์ฌ์ฉํ๋ ๋ฉ์๋
+ */
+ public void move(String square, String moveCommand) {
+ if (moveCommand.equals(GameValue.MOVE_UP_COMMAND)) {
+ moveUp(square, moveCommand);
+ }
+ if (moveCommand.equals(GameValue.MOVE_DOWN_COMMAND)) {
+ moveLower(square, moveCommand);
+ }
+ }
+
+ private boolean isMoveUp(String square, String moveCommand) {
+ return square.equals(moveCommand);
+ }
+
+ private void moveUp(String square, String moveCommand) {
+ if (isMoveUp(square, moveCommand)) {
+ moveResult.moveUp(GameValue.MOVE);
+ }
+ if (!isMoveUp(square, moveCommand)) {
+ moveResult.moveUp(GameValue.STOP);
+ }
+ }
+
+ private boolean isMoveLower(String square, String moveCommand) {
+ return square.equals(moveCommand);
+ }
+
+ private void moveLower(String square, String moveCommand) {
+ if (isMoveLower(square, moveCommand)) {
+ moveResult.moveLowwer(GameValue.MOVE);
+ }
+ if (!isMoveLower(square, moveCommand)) {
+ moveResult.moveLowwer(GameValue.STOP);
+ }
+ }
+
+ public boolean isSuccessful() {
+ return moveResult.isSuccessful();
+ }
+
+ public String getGameResult() {
+ if (isSuccessful()) {
+ return "์ฑ๊ณต";
+ }
+ return "์คํจ";
+ }
+
+ /**
+ * ์ฌ์ฉ์๊ฐ ๊ฒ์์ ๋ค์ ์๋ํ ๋ ์ฌ์ฉํ๋ ๋ฉ์๋
+ */
+ public void retry() {
+ retryCount++;
+ moveResult = new MoveResult();
+ }
+
+ public int getRetryCount() {
+ return retryCount;
+ }
+
+ public MoveResult getMoveResult() {
+ return moveResult;
+ }
+} | Java | ์ฌ๊ธฐ early return ์ด ๋น ์ง ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,37 @@
+package bridge.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MoveResult {
+ private final List<String> upperBridge;
+ private final List<String> lowerBridge;
+
+ public MoveResult() {
+ this.upperBridge = new ArrayList<>();
+ this.lowerBridge = new ArrayList<>();
+ }
+
+ public void moveUp(String moveResult) {
+ upperBridge.add(moveResult);
+ lowerBridge.add(" ");
+ }
+
+ public void moveLowwer(String moveResult) {
+ upperBridge.add(" ");
+ lowerBridge.add(moveResult);
+ }
+
+ public boolean isSuccessful() {
+ if (upperBridge.contains("X") || lowerBridge.contains("X")) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "[ " + String.join(" | ", upperBridge) + " ]\n" +
+ "[ " + String.join(" | ", lowerBridge) + " ]";
+ }
+} | Java | > ํต์ฌ ๋ก์ง์ ๊ตฌํํ๋ ์ฝ๋์ UI๋ฅผ ๋ด๋นํ๋ ๋ก์ง์ ๋ถ๋ฆฌํด ๊ตฌํํ๋ค.
์ด ๋ถ๋ถ์ ์๊ตฌ์ฌํญ์ด ์ง์ผ์ง์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค.
ํ๋ฆฌ์ฝ์ค ๊ธฐ๊ฐ ๋์ ๊ฐ์ฅ ๋ง์ด ์๊ตฌ๋ ํ๋ก๊ทธ๋๋ฐ ๊ธฐ๋ฒ์ด๋ผ, ์ด ๋ถ๋ถ์ ๊ผญ ๋ฆฌํฉํ ๋ง ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,56 @@
+package bridge.view;
+
+import bridge.domain.BridgeGame;
+import bridge.domain.MoveResult;
+
+/**
+ * ์ฌ์ฉ์์๊ฒ ๊ฒ์ ์งํ ์ํฉ๊ณผ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ ์ญํ ์ ํ๋ค.
+ */
+public class OutputView {
+
+ public void printStartMessage() {
+ println("๋ค๋ฆฌ ๊ฑด๋๊ธฐ ๊ฒ์์ ์์ํฉ๋๋ค.");
+ }
+
+ public void printBridgeSizeInputMessage() {
+ printNewLine();
+ println("๋ค๋ฆฌ์ ๊ธธ์ด๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.");
+ }
+
+ public void printMoveInputMessage() {
+ printNewLine();
+ println("์ด๋ํ ์นธ์ ์ ํํด์ฃผ์ธ์. (์: U, ์๋: D)");
+ }
+
+ /**
+ * ํ์ฌ๊น์ง ์ด๋ํ ๋ค๋ฆฌ์ ์ํ๋ฅผ ์ ํด์ง ํ์์ ๋ง์ถฐ ์ถ๋ ฅํ๋ค.
+ */
+ public void printMap(MoveResult moveResult) {
+ println(moveResult.toString());
+ }
+
+ /**
+ * ๊ฒ์์ ์ต์ข
๊ฒฐ๊ณผ๋ฅผ ์ ํด์ง ํ์์ ๋ง์ถฐ ์ถ๋ ฅํ๋ค.
+ */
+ public void printResult(BridgeGame bridgeGame) {
+ printNewLine();
+ println("์ต์ข
๊ฒ์ ๊ฒฐ๊ณผ");
+ printMap(bridgeGame.getMoveResult());
+ printNewLine();
+ System.out.printf("๊ฒ์ ์ฑ๊ณต ์ฌ๋ถ: %s\n", bridgeGame.getGameResult());
+ System.out.printf("์ด ์๋ํ ํ์: %d\n", bridgeGame.getRetryCount());
+ }
+
+ public void printRetryMessage() {
+ printNewLine();
+ println("๊ฒ์์ ๋ค์ ์๋ํ ์ง ์ฌ๋ถ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์. (์ฌ์๋: R, ์ข
๋ฃ: Q)");
+ }
+
+ private void println(String output) {
+ System.out.println(output);
+ }
+
+ private void printNewLine() {
+ System.out.println();
+ }
+} | Java | ํ์คํ ์ถ๋ ฅ์ฉ ๋ฉ์์ง๊ฐ ์ฌํ์ฉ๋๋ ๊ฒฝ์ฐ๊ฐ ์๋ค๋ณด๋, ์ด๋ ๊ฒ ํ๋ ์ฝ๋ฉํด๋ ๊ฝค๋ ์ง๊ด์ ์ด์์? ๋ผ๋ ๋๋์ ๋ฐ์์ต๋๋ค ๐ |
@@ -0,0 +1,42 @@
+package bridge.view.handler;
+
+import bridge.domain.Bridge;
+import bridge.domain.BridgeMaker;
+import bridge.view.ErrorView;
+import bridge.view.InputView;
+import java.util.function.Supplier;
+
+public class InputHandler {
+ private final InputView inputView;
+ private final ErrorView errorView;
+
+ public InputHandler(InputView inputView, ErrorView errorView) {
+ this.inputView = inputView;
+ this.errorView = errorView;
+ }
+
+ public Bridge createValidatedBridge(BridgeMaker bridgeMaker) {
+ return receiveValidatedInput(() -> {
+ int bridgeSize = inputView.readBridgeSize();
+ return Bridge.from(bridgeMaker.makeBridge(bridgeSize));
+ });
+ }
+
+ public String readMoving() {
+ return receiveValidatedInput(inputView::readMoving);
+ }
+
+ public String readGameCommand() {
+ return receiveValidatedInput(inputView::readGameCommand);
+ }
+
+ private <T> T receiveValidatedInput(Supplier<T> inputView) {
+ while (true) {
+ try {
+ return inputView.get();
+ } catch (IllegalArgumentException exception) {
+ errorView.printErrorMessage(exception.getMessage());
+ }
+ }
+ }
+} | Java | (๊ถ๊ธํด์!)
๊ทธ๋์ ํ์ค๋๊ณผ ๋ฆฌ๋ทฐํด์ค๋ฉด์ ์ด๋ฐ ์ฌ์๋ ๋ก์ง์ while ๋ก ์ฒ๋ฆฌํ ๊น, ์ฌ๊ท๋ก ์ฒ๋ฆฌํ ๊น ๊ณ ๋ฏผํ๋ค๊ฐ ์ ๋ ์ฌ๊ท๋ฅผ ์ ํํ์ต๋๋ค.
๊ทธ๋ฐ๋ฐ ์ฌ๊ท๋ฅผ ์ ํํด๋ ํธ์ถ ๋์ค๊ฐ ๊น์ด์ง๋๊ฒ ์๋๊ณ ๋์ค๊ฐ 1๋ก ๊ณ์ ์ ์ง๋๋ ๊ฒ ๊ฐ๋๋ผ๊ณ ์. (์ด์ฐจํผ catch๋ฅผ ํ๊ณ ์๋ฌ๋ฉ์์ง๋ฅผ ์ถ๋ ฅ์ ํ๋ฏ๋ก)
ํ์ค๋์ ์ฌ๊ท ๋์ while์ ์ ํํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค :) |
@@ -0,0 +1,82 @@
+package bridge.domain;
+
+import bridge.constants.GameValue;
+
+/**
+ * ๋ค๋ฆฌ ๊ฑด๋๊ธฐ ๊ฒ์์ ๊ด๋ฆฌํ๋ ํด๋์ค
+ */
+public class BridgeGame {
+
+ private int retryCount;
+ private MoveResult moveResult;
+
+ public BridgeGame(MoveResult moveResult, int retryCount) {
+ this.moveResult = moveResult;
+ this.retryCount = retryCount;
+ }
+
+ /**
+ * ์ฌ์ฉ์๊ฐ ์นธ์ ์ด๋ํ ๋ ์ฌ์ฉํ๋ ๋ฉ์๋
+ */
+ public void move(String square, String moveCommand) {
+ if (moveCommand.equals(GameValue.MOVE_UP_COMMAND)) {
+ moveUp(square, moveCommand);
+ }
+ if (moveCommand.equals(GameValue.MOVE_DOWN_COMMAND)) {
+ moveLower(square, moveCommand);
+ }
+ }
+
+ private boolean isMoveUp(String square, String moveCommand) {
+ return square.equals(moveCommand);
+ }
+
+ private void moveUp(String square, String moveCommand) {
+ if (isMoveUp(square, moveCommand)) {
+ moveResult.moveUp(GameValue.MOVE);
+ }
+ if (!isMoveUp(square, moveCommand)) {
+ moveResult.moveUp(GameValue.STOP);
+ }
+ }
+
+ private boolean isMoveLower(String square, String moveCommand) {
+ return square.equals(moveCommand);
+ }
+
+ private void moveLower(String square, String moveCommand) {
+ if (isMoveLower(square, moveCommand)) {
+ moveResult.moveLowwer(GameValue.MOVE);
+ }
+ if (!isMoveLower(square, moveCommand)) {
+ moveResult.moveLowwer(GameValue.STOP);
+ }
+ }
+
+ public boolean isSuccessful() {
+ return moveResult.isSuccessful();
+ }
+
+ public String getGameResult() {
+ if (isSuccessful()) {
+ return "์ฑ๊ณต";
+ }
+ return "์คํจ";
+ }
+
+ /**
+ * ์ฌ์ฉ์๊ฐ ๊ฒ์์ ๋ค์ ์๋ํ ๋ ์ฌ์ฉํ๋ ๋ฉ์๋
+ */
+ public void retry() {
+ retryCount++;
+ moveResult = new MoveResult();
+ }
+
+ public int getRetryCount() {
+ return retryCount;
+ }
+
+ public MoveResult getMoveResult() {
+ return moveResult;
+ }
+} | Java | else๋ฌธ์ด ์๋๋ผ์ ์๋ฌด๋๋ return์ ์ถ๊ฐํด ๋ค์ ์กฐ๊ฑด์ ํ์ธํ์ง ์๋๋ก ํ๋๊ฒ ์ข๊ฒ ๋ค์ ! |
@@ -0,0 +1,37 @@
+package bridge.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MoveResult {
+ private final List<String> upperBridge;
+ private final List<String> lowerBridge;
+
+ public MoveResult() {
+ this.upperBridge = new ArrayList<>();
+ this.lowerBridge = new ArrayList<>();
+ }
+
+ public void moveUp(String moveResult) {
+ upperBridge.add(moveResult);
+ lowerBridge.add(" ");
+ }
+
+ public void moveLowwer(String moveResult) {
+ upperBridge.add(" ");
+ lowerBridge.add(moveResult);
+ }
+
+ public boolean isSuccessful() {
+ if (upperBridge.contains("X") || lowerBridge.contains("X")) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "[ " + String.join(" | ", upperBridge) + " ]\n" +
+ "[ " + String.join(" | ", lowerBridge) + " ]";
+ }
+} | Java | ํ ๊ทธ ๋ถ๋ถ์ ๋์ณ๋ฒ๋ ธ๋ค์ ..
์ด๋ฒ 5๊ธฐ ์ต์ข
๊น์ง ์น๋ฉด์ ๋๋๊ฑด๋ฐ 5์๊ฐ์ด๋ผ๋ ์๊ฐ์ ์ฝ๋งค์ด์ง ์๊ณ
์ด๋ฐ์ ๊ธฐ๋ฅ ์๊ตฌ ์ฌํญ์ ๊ผผ๊ผผํ ๊ฒํ ํด์ผ ํ๋ค๋ ๊ฒ์ ๋ผ์ ๋ฆฌ๊ฒ ๋๊ผ์ต๋๋ค.. |
@@ -0,0 +1,42 @@
+package bridge.view.handler;
+
+import bridge.domain.Bridge;
+import bridge.domain.BridgeMaker;
+import bridge.view.ErrorView;
+import bridge.view.InputView;
+import java.util.function.Supplier;
+
+public class InputHandler {
+ private final InputView inputView;
+ private final ErrorView errorView;
+
+ public InputHandler(InputView inputView, ErrorView errorView) {
+ this.inputView = inputView;
+ this.errorView = errorView;
+ }
+
+ public Bridge createValidatedBridge(BridgeMaker bridgeMaker) {
+ return receiveValidatedInput(() -> {
+ int bridgeSize = inputView.readBridgeSize();
+ return Bridge.from(bridgeMaker.makeBridge(bridgeSize));
+ });
+ }
+
+ public String readMoving() {
+ return receiveValidatedInput(inputView::readMoving);
+ }
+
+ public String readGameCommand() {
+ return receiveValidatedInput(inputView::readGameCommand);
+ }
+
+ private <T> T receiveValidatedInput(Supplier<T> inputView) {
+ while (true) {
+ try {
+ return inputView.get();
+ } catch (IllegalArgumentException exception) {
+ errorView.printErrorMessage(exception.getMessage());
+ }
+ }
+ }
+} | Java | ์ฌ๊ท ํธ์ถ๋ก ๊ตฌํํ์ ๋ ์ฝ๋๊ฐ ๊ฐ๊ฒฐํด์ง๋ค๋ ์ฅ์ ์ ๊ฐ์ง๊ณ ์์ง๋ง
ํ์ ๊น์ด๊ฐ ๊น์ด ์ง ๋ ์ํํ ๊ฒ์ด๋ผ ์๊ฐํ์ต๋๋ค.
์ ํธ๋ ๋ง์๋๋ก 1๋ก ์ ์ง๋๋ค๋ฉด ์ด ์ ์ ์๋ฌด๋๋ ์ ์ธํด์ผํ ๊ฒ ๊ฐ๋ค์
ํ์ง๋ง while๋ฌธ์ ์ฌ์ฉํ์ ๋ ๋ฐ๋ณต ํ์๋ฅผ ์ ์ดํ ์ ์๋ค๋ ์ฅ์ ๋ ์๊ธฐ์ while๋ฌธ์ ์ฌ์ฉํ์์ต๋๋ค.
์๋ฅผ ๋ค์ด์ ์ค์ ๋ก๊ทธ์ธ ์ ์ฑ
์ฒ๋ผ ์๋ชป๋ ๊ฐ์ 3ํ ๋๋ 5ํ ์
๋ ฅ ํ์ ๊ฒฝ์ฐ ์
๋ ฅ์ ์ข
๋ฃ ์ํจ๋ค๋๊ฐ ๋ฑ์ ์ํฉ๋ ์๊ฐํด๋ณด์์ต๋๋ค! |
@@ -0,0 +1,42 @@
+package bridge.view.handler;
+
+import bridge.domain.Bridge;
+import bridge.domain.BridgeMaker;
+import bridge.view.ErrorView;
+import bridge.view.InputView;
+import java.util.function.Supplier;
+
+public class InputHandler {
+ private final InputView inputView;
+ private final ErrorView errorView;
+
+ public InputHandler(InputView inputView, ErrorView errorView) {
+ this.inputView = inputView;
+ this.errorView = errorView;
+ }
+
+ public Bridge createValidatedBridge(BridgeMaker bridgeMaker) {
+ return receiveValidatedInput(() -> {
+ int bridgeSize = inputView.readBridgeSize();
+ return Bridge.from(bridgeMaker.makeBridge(bridgeSize));
+ });
+ }
+
+ public String readMoving() {
+ return receiveValidatedInput(inputView::readMoving);
+ }
+
+ public String readGameCommand() {
+ return receiveValidatedInput(inputView::readGameCommand);
+ }
+
+ private <T> T receiveValidatedInput(Supplier<T> inputView) {
+ while (true) {
+ try {
+ return inputView.get();
+ } catch (IllegalArgumentException exception) {
+ errorView.printErrorMessage(exception.getMessage());
+ }
+ }
+ }
+} | Java | ํ์คํ **3ํ ๊น์ง๋ง ์ฌ์๋๊ฐ ๊ฐ๋ฅํ๋ค** ๋ผ๋ ๋ก์ง์ด ์์ ๊ฒฝ์ฐ์๋ while ๋ฌธ์ผ๋ก ์ฒ๋ฆฌํ๋๊ฒ ์ ์ฐํ๊ฒ ๋์ํ ์ ์๊ฒ ๋ค์!
์ธ์ฌ์ดํธ ๋ฐ๊ณ ๊ฐ๋๋ค :D |
@@ -1,4 +1,4 @@
-import { EstimationInputDTO, Estimation } from '#estimations/estimation.types.js';
+import { EstimationInputDTO, Estimation, IsActivate } from '#estimations/estimation.types.js';
import { IEstimationRepository } from '#estimations/interfaces/estimation.repository.interface.js';
import { PrismaService } from '#global/prisma.service.js';
import { FindOptions } from '#types/options.type.js';
@@ -88,4 +88,52 @@ export class EstimationRepository implements IEstimationRepository {
take: pageSize,
});
}
+
+ // confirmedForId ๊ฐ์ด null์ด ์๋๋ฉด์ ์ด์ฌํ์ ๋๋๊ฒ์ด๋ค..~!
+ async findReviewable(userId: string, moveInfoIds: string[], page: number, pageSize: number) {
+ const estimations = await this.prisma.estimation.findMany({
+ where: {
+ confirmedForId: { in: moveInfoIds }, // ์๋ฃ๋ ์ด์ฌ์ ์ฐ๊ฒฐ๋ ๊ฒฌ์ ์ ์กฐํ
+ },
+ include: {
+ driver: true, // ๊ฒฌ์ ๊ณผ ๊ด๋ จ๋ ๋๋ผ์ด๋ฒ ์ ๋ณด
+ moveInfo: true, // ๊ฒฌ์ ๊ณผ ๊ด๋ จ๋ ์ด์ฌ ์ ๋ณด
+ reviews: true, // ๊ฒฌ์ ์ ์์ฑ๋ ๋ฆฌ๋ทฐ๋ค
+ },
+ skip: (page - 1) * pageSize,
+ take: pageSize,
+ });
+
+ // ๋ฆฌ๋ทฐ๊ฐ ์๋ ๊ฒฌ์ ๋ง ํํฐ๋ง
+ return estimations.filter(estimation => !estimation.reviews.some(review => review.ownerId === userId));
+ }
+
+ // ์ ์ ์ ์ด์ฌ ์ ๋ณด ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ
+ async getUserMoveInfos(userId: string) {
+ return this.prisma.moveInfo.findMany({
+ where: { ownerId: userId }, // ๋ก๊ทธ์ธํ ์ ์ ์ ์ด์ฌ๋ง ์กฐํํ๊ธฐ
+ select: { id: true }, // ์ด์ฌ ID๋ง ์ ํ
+ });
+ }
+
+ // ์ง์ ๊ฒฌ์ ์์ฒญ ์ฌ๋ถ
+ async isDesignatedRequest(estimationId: string): Promise<IsActivate> {
+ const estimation = await this.prisma.estimation.findUnique({
+ where: { id: estimationId },
+ include: {
+ moveInfo: {
+ include: {
+ requests: {
+ where: {
+ status: 'APPLY', //
+ },
+ },
+ },
+ },
+ },
+ });
+
+ // ์ง์ ์์ฒญ์ด๋ฉด 'Active', ์ผ๋ฐ์์ฒญ์ด๋ฉด 'Inactive'
+ return estimation?.moveInfo.requests.length > 0 ? IsActivate.Active : IsActivate.Inactive;
+ }
} | TypeScript | ์๋ง๋ javascript ๋ ๋ฒจ์ด ์๋๋ผ prisma์์ findMany ํด์ค๋ ๋จ๊ณ์์ ์ด ์์
์ ํด์ ๊ฐ์ ธ์ฌ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. ๋์ค์ ํ ๋ฒ ์ฐพ์๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค์. |
@@ -1,4 +1,4 @@
-import { EstimationInputDTO, Estimation } from '#estimations/estimation.types.js';
+import { EstimationInputDTO, Estimation, IsActivate } from '#estimations/estimation.types.js';
import { IEstimationRepository } from '#estimations/interfaces/estimation.repository.interface.js';
import { PrismaService } from '#global/prisma.service.js';
import { FindOptions } from '#types/options.type.js';
@@ -88,4 +88,52 @@ export class EstimationRepository implements IEstimationRepository {
take: pageSize,
});
}
+
+ // confirmedForId ๊ฐ์ด null์ด ์๋๋ฉด์ ์ด์ฌํ์ ๋๋๊ฒ์ด๋ค..~!
+ async findReviewable(userId: string, moveInfoIds: string[], page: number, pageSize: number) {
+ const estimations = await this.prisma.estimation.findMany({
+ where: {
+ confirmedForId: { in: moveInfoIds }, // ์๋ฃ๋ ์ด์ฌ์ ์ฐ๊ฒฐ๋ ๊ฒฌ์ ์ ์กฐํ
+ },
+ include: {
+ driver: true, // ๊ฒฌ์ ๊ณผ ๊ด๋ จ๋ ๋๋ผ์ด๋ฒ ์ ๋ณด
+ moveInfo: true, // ๊ฒฌ์ ๊ณผ ๊ด๋ จ๋ ์ด์ฌ ์ ๋ณด
+ reviews: true, // ๊ฒฌ์ ์ ์์ฑ๋ ๋ฆฌ๋ทฐ๋ค
+ },
+ skip: (page - 1) * pageSize,
+ take: pageSize,
+ });
+
+ // ๋ฆฌ๋ทฐ๊ฐ ์๋ ๊ฒฌ์ ๋ง ํํฐ๋ง
+ return estimations.filter(estimation => !estimation.reviews.some(review => review.ownerId === userId));
+ }
+
+ // ์ ์ ์ ์ด์ฌ ์ ๋ณด ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ
+ async getUserMoveInfos(userId: string) {
+ return this.prisma.moveInfo.findMany({
+ where: { ownerId: userId }, // ๋ก๊ทธ์ธํ ์ ์ ์ ์ด์ฌ๋ง ์กฐํํ๊ธฐ
+ select: { id: true }, // ์ด์ฌ ID๋ง ์ ํ
+ });
+ }
+
+ // ์ง์ ๊ฒฌ์ ์์ฒญ ์ฌ๋ถ
+ async isDesignatedRequest(estimationId: string): Promise<IsActivate> {
+ const estimation = await this.prisma.estimation.findUnique({
+ where: { id: estimationId },
+ include: {
+ moveInfo: {
+ include: {
+ requests: {
+ where: {
+ status: 'APPLY', //
+ },
+ },
+ },
+ },
+ },
+ });
+
+ // ์ง์ ์์ฒญ์ด๋ฉด 'Active', ์ผ๋ฐ์์ฒญ์ด๋ฉด 'Inactive'
+ return estimation?.moveInfo.requests.length > 0 ? IsActivate.Active : IsActivate.Inactive;
+ }
} | TypeScript | ๋ค!! ์ฐพ์๋ณด๊ฒ ์ต๋๋ค !! ํ์๋ ์๋ ค์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค!!!! |
@@ -0,0 +1,8 @@
+import "./css/reset.css";
+import "./css/common.css";
+import App from "./App";
+
+addEventListener("DOMContentLoaded", async () => {
+ const app = new App();
+ app.init();
+}); | JavaScript | ์ ํจ์๊ฐ ๋ฐ๋ก ์ฑ์ ๊ตฌ๋์ํค๋ Entry ํฌ์ธํธ๊ตฐ์!
`controller`๋ฅผ ์ด๊ธฐํํ๋ค? ๋ณด๋ค๋ `App`์ ์ด๊ธฐํํ๋ค๋ ๋๋์ด ์ด๋จ๊น์? |
@@ -0,0 +1,14 @@
+import { apiClient } from "./apiClient";
+import { BASE_URL } from "./constants";
+
+export const fetchPopularMovies = async ({ page = 1 }) => {
+ const param = new URLSearchParams({
+ api_key: process.env.TMDB_API_KEY,
+ language: "ko-KR",
+ page,
+ });
+
+ const response = await apiClient.get(`${BASE_URL}?${param}`);
+
+ return response.results;
+}; | JavaScript | ์ค ์ข์ต๋๋ค! |
@@ -0,0 +1,34 @@
+import { ApiError } from "./apiError";
+
+export const apiClient = {
+ get: async (url, headers = {}) => {
+ return apiClient.request("GET", url, null, headers);
+ },
+
+ request: async (method, url, body = null, headers = {}) => {
+ const options = {
+ method,
+ headers: {
+ "Content-Type": "application/json",
+ ...headers,
+ },
+ body: body && JSON.stringify(body),
+ };
+
+ try {
+ const response = await fetch(url, options);
+
+ if (!response.ok) {
+ throw new ApiError(response.status);
+ }
+
+ return await response.json();
+ } catch (error) {
+ if (error instanceof ApiError) {
+ ApiError.handle(error);
+ } else {
+ throw error;
+ }
+ }
+ },
+}; | JavaScript | `request()`์ `get()`์ ์ฐจ์ด๋ ๋ฌด์์ด๊ณ ๋๋ ์ด์ ๋ ๋ฌด์์ผ๊น์? |
@@ -0,0 +1,31 @@
+import { ERROR_MSG } from "./constants";
+
+export class ApiError extends Error {
+ constructor(message, details, status = -1) {
+ super(message);
+ this.details = details;
+ this.status = status;
+ }
+
+ static handle(error) {
+ let errMsg;
+ let errDetails;
+
+ switch (parseInt(error.message)) {
+ case 401:
+ errMsg = ERROR_MSG.INVALID_API_KEY.message;
+ errDetails = ERROR_MSG.INVALID_API_KEY.details;
+ break;
+ case 404:
+ errMsg = ERROR_MSG.INVALID_REQUEST.message;
+ errDetails = ERROR_MSG.INVALID_REQUEST.details;
+ break;
+ default:
+ errMsg = ERROR_MSG.DEFAULT.message;
+ errDetails = ERROR_MSG.DEFAULT.details;
+ break;
+ }
+
+ throw new ApiError(errMsg, errDetails, error.status);
+ }
+} | JavaScript | ์ค ์ข์ ์๋์
๋๋ค ๐ |
@@ -0,0 +1,16 @@
+import { mainTitle, mainMoreButton, movieCardsList } from "./index";
+
+export const mainSection = {
+ render() {
+ const element = document.createElement("section");
+ element.classList.add("item-view");
+
+ const title = mainTitle.render();
+ const itemList = movieCardsList.render();
+ const moreButton = mainMoreButton.render();
+
+ element.append(title, itemList, moreButton);
+
+ return element;
+ },
+}; | JavaScript | [append()](https://developer.mozilla.org/en-US/docs/Web/API/Element/append)๋ฅผ ํ์ฉํด๋ณด์ธ์! |
@@ -0,0 +1,46 @@
+describe("API ํ
์คํธ", () => {
+ it("์ํ ๋ชฉ๋ก API๋ฅผ ํธ์ถํ๋ฉด 20๊ฐ์ฉ ์ํ๋ฅผ ๋ฐ์์จ๋ค.", () => {
+ const baseUrl = "https://api.themoviedb.org/3/movie/popular";
+ const param = new URLSearchParams({
+ api_key: Cypress.env("TMDB_API_KEY"),
+ language: "ko-KR",
+ page: 1,
+ });
+
+ cy.request(`${baseUrl}?${param}`).then((response) => {
+ expect(response.status).to.eq(200);
+ expect(response.body.results).to.have.length(20);
+ });
+ });
+});
+
+describe("์ํ ๋ฆฌ๋ทฐ ์น ํ
์คํธ", () => {
+ beforeEach(() => {
+ cy.visit("http://localhost:8080");
+ });
+
+ it("์ํ ์นด๋๋ ์ธ๋ค์ผ, ๋ณ์ , ์ ๋ชฉ์ ๊ฐ๋๋ค.", () => {
+ cy.get(".item-card").each(($el) => {
+ cy.wrap($el).within(() => {
+ cy.get(".item-thumbnail").should("be.visible");
+ cy.get(".item-title").should("be.visible");
+ cy.get(".item-score").should("be.visible");
+ });
+ });
+ });
+
+ it("์ํ ๋ชฉ๋ก์ ํ ํ์ด์ง์ 20๊ฐ์ฉ ๋์จ๋ค.", () => {
+ cy.get(".item-list li").should("have.length", 20);
+ });
+
+ it("๋๋ณด๊ธฐ ๋ฒํผ์ ๋๋ฅด๋ฉด 20๊ฐ์ ์ํ๊ฐ ์ถ๊ฐ๋ก ์์ฑ๋๋ค.", () => {
+ cy.get(".show-more").click();
+ cy.get(".item-list li").should("have.length", 40);
+ });
+
+ it("์ํ ๋ชฉ๋ก์ ๋ถ๋ฌ์ค๋ ๋์ ์ค์ผ๋ ํค UI๋ฅผ ๋ณด์ฌ์ค๋ค.", () => {
+ cy.get(".skeleton-card").should("have.length", 20);
+ cy.wait(1000);
+ cy.get(".skeleton-card").should("have.length", 0);
+ });
+}); | JavaScript | ์คํธ?
`exist`๋ก ๊ฒ์ฌํ๋ฉด ๋ฌด์์ด ๋ค๋ฅผ๊น์? |
@@ -0,0 +1,46 @@
+describe("API ํ
์คํธ", () => {
+ it("์ํ ๋ชฉ๋ก API๋ฅผ ํธ์ถํ๋ฉด 20๊ฐ์ฉ ์ํ๋ฅผ ๋ฐ์์จ๋ค.", () => {
+ const baseUrl = "https://api.themoviedb.org/3/movie/popular";
+ const param = new URLSearchParams({
+ api_key: Cypress.env("TMDB_API_KEY"),
+ language: "ko-KR",
+ page: 1,
+ });
+
+ cy.request(`${baseUrl}?${param}`).then((response) => {
+ expect(response.status).to.eq(200);
+ expect(response.body.results).to.have.length(20);
+ });
+ });
+});
+
+describe("์ํ ๋ฆฌ๋ทฐ ์น ํ
์คํธ", () => {
+ beforeEach(() => {
+ cy.visit("http://localhost:8080");
+ });
+
+ it("์ํ ์นด๋๋ ์ธ๋ค์ผ, ๋ณ์ , ์ ๋ชฉ์ ๊ฐ๋๋ค.", () => {
+ cy.get(".item-card").each(($el) => {
+ cy.wrap($el).within(() => {
+ cy.get(".item-thumbnail").should("be.visible");
+ cy.get(".item-title").should("be.visible");
+ cy.get(".item-score").should("be.visible");
+ });
+ });
+ });
+
+ it("์ํ ๋ชฉ๋ก์ ํ ํ์ด์ง์ 20๊ฐ์ฉ ๋์จ๋ค.", () => {
+ cy.get(".item-list li").should("have.length", 20);
+ });
+
+ it("๋๋ณด๊ธฐ ๋ฒํผ์ ๋๋ฅด๋ฉด 20๊ฐ์ ์ํ๊ฐ ์ถ๊ฐ๋ก ์์ฑ๋๋ค.", () => {
+ cy.get(".show-more").click();
+ cy.get(".item-list li").should("have.length", 40);
+ });
+
+ it("์ํ ๋ชฉ๋ก์ ๋ถ๋ฌ์ค๋ ๋์ ์ค์ผ๋ ํค UI๋ฅผ ๋ณด์ฌ์ค๋ค.", () => {
+ cy.get(".skeleton-card").should("have.length", 20);
+ cy.wait(1000);
+ cy.get(".skeleton-card").should("have.length", 0);
+ });
+}); | JavaScript | 40์ผ๋ก ๊ฒ์ฌํ๋ ์ด์ ๋ ์ด๊ธฐ ๋ฆฌ์คํธ 20 + ์ถ๊ฐ ๋๋ณด๊ธฐ 20์ผ๊น์? |
@@ -0,0 +1,34 @@
+import { ApiError } from "./apiError";
+
+export const apiClient = {
+ get: async (url, headers = {}) => {
+ return apiClient.request("GET", url, null, headers);
+ },
+
+ request: async (method, url, body = null, headers = {}) => {
+ const options = {
+ method,
+ headers: {
+ "Content-Type": "application/json",
+ ...headers,
+ },
+ body: body && JSON.stringify(body),
+ };
+
+ try {
+ const response = await fetch(url, options);
+
+ if (!response.ok) {
+ throw new ApiError(response.status);
+ }
+
+ return await response.json();
+ } catch (error) {
+ if (error instanceof ApiError) {
+ ApiError.handle(error);
+ } else {
+ throw error;
+ }
+ }
+ },
+}; | JavaScript | `request()`๋ ๋งค๊ฐ๋ณ์๋ก ๋ฐ๋ method๋ฅผ ํตํด API ์์ฒญ์ ๋ณด๋ด๋ ํจ์์ด๊ณ , `get()`์ ํด๋น `request()` ํจ์์ `GET`์์ฒญ์ ๋ณด๋ด๋ ํจ์์
๋๋ค.
์ด๋ฒ ๊ณผ์ ์์ GET ์์ฒญ๋ง ์กด์ฌํ์ฌ ์ถ๊ฐํ์ง ์์์ง๋ง ์ถํ์ ๋ค๋ฅธ ๋ฉ์๋ ์์ฒญ์ ์ถ๊ฐํ ์ ์๊ฒ ์์ฑํ์์ต๋๋ค! |
@@ -0,0 +1,46 @@
+describe("API ํ
์คํธ", () => {
+ it("์ํ ๋ชฉ๋ก API๋ฅผ ํธ์ถํ๋ฉด 20๊ฐ์ฉ ์ํ๋ฅผ ๋ฐ์์จ๋ค.", () => {
+ const baseUrl = "https://api.themoviedb.org/3/movie/popular";
+ const param = new URLSearchParams({
+ api_key: Cypress.env("TMDB_API_KEY"),
+ language: "ko-KR",
+ page: 1,
+ });
+
+ cy.request(`${baseUrl}?${param}`).then((response) => {
+ expect(response.status).to.eq(200);
+ expect(response.body.results).to.have.length(20);
+ });
+ });
+});
+
+describe("์ํ ๋ฆฌ๋ทฐ ์น ํ
์คํธ", () => {
+ beforeEach(() => {
+ cy.visit("http://localhost:8080");
+ });
+
+ it("์ํ ์นด๋๋ ์ธ๋ค์ผ, ๋ณ์ , ์ ๋ชฉ์ ๊ฐ๋๋ค.", () => {
+ cy.get(".item-card").each(($el) => {
+ cy.wrap($el).within(() => {
+ cy.get(".item-thumbnail").should("be.visible");
+ cy.get(".item-title").should("be.visible");
+ cy.get(".item-score").should("be.visible");
+ });
+ });
+ });
+
+ it("์ํ ๋ชฉ๋ก์ ํ ํ์ด์ง์ 20๊ฐ์ฉ ๋์จ๋ค.", () => {
+ cy.get(".item-list li").should("have.length", 20);
+ });
+
+ it("๋๋ณด๊ธฐ ๋ฒํผ์ ๋๋ฅด๋ฉด 20๊ฐ์ ์ํ๊ฐ ์ถ๊ฐ๋ก ์์ฑ๋๋ค.", () => {
+ cy.get(".show-more").click();
+ cy.get(".item-list li").should("have.length", 40);
+ });
+
+ it("์ํ ๋ชฉ๋ก์ ๋ถ๋ฌ์ค๋ ๋์ ์ค์ผ๋ ํค UI๋ฅผ ๋ณด์ฌ์ค๋ค.", () => {
+ cy.get(".skeleton-card").should("have.length", 20);
+ cy.wait(1000);
+ cy.get(".skeleton-card").should("have.length", 0);
+ });
+}); | JavaScript | ์์ฑ๋ `movieCard`์๋ ์ธ๋ค์ผ, ๋ณ์ , ์ ๋ชฉ element๊ฐ `์กด์ฌ`ํ๋ค๋ ์๋ฏธ์์ ์ฌ์ฉํ ๊ฒ ๊ฐ์ต๋๋ค!
๋ค์ ์๊ฐํด๋ณด๋, ํด๋น element๊ฐ ์กด์ฌํ์ง๋ง ๋ณด์ฌ์ง์ง ์๊ฑฐ๋ ์ด๋ค css issue๊ฐ ์๊ธธ ์๋ ์๋ค๋ ์๊ฐ์ `be.visible`๋ก ๋์ฒดํ์์ต๋๋ค. |
@@ -0,0 +1,46 @@
+describe("API ํ
์คํธ", () => {
+ it("์ํ ๋ชฉ๋ก API๋ฅผ ํธ์ถํ๋ฉด 20๊ฐ์ฉ ์ํ๋ฅผ ๋ฐ์์จ๋ค.", () => {
+ const baseUrl = "https://api.themoviedb.org/3/movie/popular";
+ const param = new URLSearchParams({
+ api_key: Cypress.env("TMDB_API_KEY"),
+ language: "ko-KR",
+ page: 1,
+ });
+
+ cy.request(`${baseUrl}?${param}`).then((response) => {
+ expect(response.status).to.eq(200);
+ expect(response.body.results).to.have.length(20);
+ });
+ });
+});
+
+describe("์ํ ๋ฆฌ๋ทฐ ์น ํ
์คํธ", () => {
+ beforeEach(() => {
+ cy.visit("http://localhost:8080");
+ });
+
+ it("์ํ ์นด๋๋ ์ธ๋ค์ผ, ๋ณ์ , ์ ๋ชฉ์ ๊ฐ๋๋ค.", () => {
+ cy.get(".item-card").each(($el) => {
+ cy.wrap($el).within(() => {
+ cy.get(".item-thumbnail").should("be.visible");
+ cy.get(".item-title").should("be.visible");
+ cy.get(".item-score").should("be.visible");
+ });
+ });
+ });
+
+ it("์ํ ๋ชฉ๋ก์ ํ ํ์ด์ง์ 20๊ฐ์ฉ ๋์จ๋ค.", () => {
+ cy.get(".item-list li").should("have.length", 20);
+ });
+
+ it("๋๋ณด๊ธฐ ๋ฒํผ์ ๋๋ฅด๋ฉด 20๊ฐ์ ์ํ๊ฐ ์ถ๊ฐ๋ก ์์ฑ๋๋ค.", () => {
+ cy.get(".show-more").click();
+ cy.get(".item-list li").should("have.length", 40);
+ });
+
+ it("์ํ ๋ชฉ๋ก์ ๋ถ๋ฌ์ค๋ ๋์ ์ค์ผ๋ ํค UI๋ฅผ ๋ณด์ฌ์ค๋ค.", () => {
+ cy.get(".skeleton-card").should("have.length", 20);
+ cy.wait(1000);
+ cy.get(".skeleton-card").should("have.length", 0);
+ });
+}); | JavaScript | ๋ค ๋ง์ต๋๋ค! ์ด์ ํ
์คํธ์์ 20๊ฐ๊ฐ ๋ ๋๋ง์ด ๋์๊ณ ๋ฒํผ์ ํด๋ฆญํ ํ์, 20๊ฐ๊ฐ ๋ ์ถ๊ฐ๋์ด 40๊ฐ๋ฅผ ๊ฒ์ฌํ๊ฒ ํ์์ต๋๋ค.
์๋กญ๊ฒ ๋ ๋๋ง๋ 20๊ฐ์ ๋ํด์ ํ
์คํธ๋ฅผ ์งํํ๋ ๊ฒ์ด ๋ ์ฌ๋ฐ๋ฅธ ๊ฒ์ฌ์ผ๊น์?
+) ์ถ๊ฐ๋ก, ๋จ์ํ
์คํธ์์๋ ์ํ ๊ฐ์ ํตํด ๋์ถ๋๋ ๊ฐ์ ๊ฒ์ฌํ๋ ๊ณผ์ ์ด ํ
์คํธ์ ํต์ฌ์ด์๋ค๊ณ ์๊ฐ๋๋๋ฐ,
์ด๋ฒ์ e2e์์๋ ๊ฐ์ ์ด์ฉํ์ฌ ๊ฒ์ฌํ๋ ๋ฐฉํฅ๋ณด๋ค ๋ ๋๋ง๋๋ ์์์ ๊ฐ์๋ ์์ฑ ์ฌ๋ถ๋ฅผ ์ค์ฌ์ ์ผ๋ก ์ฝ๋๋ฅผ ์์ฑํ ๊ฒ ๊ฐ์ต๋๋ค.
๊ทธ๋ฐ ๊ณผ์ ์์ ๋จ์ ํ
์คํธ๋ ๊ฐ ์ค์ฌ, e2e๋ ์ ์ฒด์ ์ธ DOM ๋ ๋๋ง ์ค์ฌ ์ด๋ ๊ฒ ์์ฐ์ค๋ ์๊ฐ์ด ์ด์ด์ง๊ฒ ๋์๋๋ฐ ์ด๊ฒ ๋ง๋ ์๊ฐ์ผ๊น ์๊ตฌ์ฌ์ด ๋ค๊ธด ํฉ๋๋ค,,! |
@@ -0,0 +1,40 @@
+package org.sopt.androidseminar1
+
+import android.content.Intent
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.widget.Toast
+import org.sopt.androidseminar1.databinding.SignInBinding
+
+class SignInActivity: AppCompatActivity() {
+ private lateinit var binding: SignInBinding // ๊ณ ์ ์ ์ธ Class ๊ฐ์ ์๋๋ค.
+ // activity_main -> ActivityMain
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ binding = SignInBinding.inflate(layoutInflater) // layoutInflater : xml์ ๋ถ๋ฌ์ฃผ๋ ์ ๋
+ setContentView(binding.root) // setContentView : xml์ ๊ทธ๋ ค์ฃผ๋ ํจ์
+
+
+ // intent ๋ณ๊ฒฝ
+ val goSignup: Intent = Intent(this, SignUpActivity::class.java)
+ val goHomeActivity: Intent = Intent(this, HomeActivity::class.java )
+
+ // ๋ก๊ทธ์ธ ๋ฒํผ
+ binding.btnLogin.setOnClickListener {
+ if (binding.etId.text.toString().isEmpty() || binding.etPw.text.toString().isEmpty()){
+ Toast.makeText(this, "๋ก๊ทธ์ธ ์คํจ", Toast.LENGTH_SHORT).show()
+ }
+ else {
+ startActivity(goHomeActivity)
+ }
+ }
+
+ // ํ์๊ฐ์
+ binding.btnSignup.setOnClickListener{
+ startActivity(goSignup)
+ }
+
+ setContentView(binding.root)
+ }
+}
\ No newline at end of file | Kotlin | ์ฝํ๋ฆฐ์์๋ ํ์
์ถ๋ก ๊ธฐ๋ฅ์ ์ง์ํด์ฃผ๊ธฐ๋๋ฌธ์
```suggestion
val goSignup = Intent(this, SignUpActivity::class.java)
val goHomeActivity = Intent(this, HomeActivity::class.java )
```
์ด๋ ๊ฒ๋ง ์์ฑํ์
๋ ๊ด์ฐฎ์ต๋๋น~:) |
@@ -0,0 +1,40 @@
+package org.sopt.androidseminar1
+
+import android.content.Intent
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.widget.Toast
+import org.sopt.androidseminar1.databinding.SignInBinding
+
+class SignInActivity: AppCompatActivity() {
+ private lateinit var binding: SignInBinding // ๊ณ ์ ์ ์ธ Class ๊ฐ์ ์๋๋ค.
+ // activity_main -> ActivityMain
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ binding = SignInBinding.inflate(layoutInflater) // layoutInflater : xml์ ๋ถ๋ฌ์ฃผ๋ ์ ๋
+ setContentView(binding.root) // setContentView : xml์ ๊ทธ๋ ค์ฃผ๋ ํจ์
+
+
+ // intent ๋ณ๊ฒฝ
+ val goSignup: Intent = Intent(this, SignUpActivity::class.java)
+ val goHomeActivity: Intent = Intent(this, HomeActivity::class.java )
+
+ // ๋ก๊ทธ์ธ ๋ฒํผ
+ binding.btnLogin.setOnClickListener {
+ if (binding.etId.text.toString().isEmpty() || binding.etPw.text.toString().isEmpty()){
+ Toast.makeText(this, "๋ก๊ทธ์ธ ์คํจ", Toast.LENGTH_SHORT).show()
+ }
+ else {
+ startActivity(goHomeActivity)
+ }
+ }
+
+ // ํ์๊ฐ์
+ binding.btnSignup.setOnClickListener{
+ startActivity(goSignup)
+ }
+
+ setContentView(binding.root)
+ }
+}
\ No newline at end of file | Kotlin | ์ฌ๊ธฐ์ toString()์ ๊ฒฝ์ฐ ๋นผ์ฃผ์
๋ ๊ด์ฐฎ์ต๋๋ค~!! |
@@ -0,0 +1,40 @@
+package org.sopt.androidseminar1
+
+import android.content.Intent
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.widget.Toast
+import org.sopt.androidseminar1.databinding.SignInBinding
+
+class SignInActivity: AppCompatActivity() {
+ private lateinit var binding: SignInBinding // ๊ณ ์ ์ ์ธ Class ๊ฐ์ ์๋๋ค.
+ // activity_main -> ActivityMain
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ binding = SignInBinding.inflate(layoutInflater) // layoutInflater : xml์ ๋ถ๋ฌ์ฃผ๋ ์ ๋
+ setContentView(binding.root) // setContentView : xml์ ๊ทธ๋ ค์ฃผ๋ ํจ์
+
+
+ // intent ๋ณ๊ฒฝ
+ val goSignup: Intent = Intent(this, SignUpActivity::class.java)
+ val goHomeActivity: Intent = Intent(this, HomeActivity::class.java )
+
+ // ๋ก๊ทธ์ธ ๋ฒํผ
+ binding.btnLogin.setOnClickListener {
+ if (binding.etId.text.toString().isEmpty() || binding.etPw.text.toString().isEmpty()){
+ Toast.makeText(this, "๋ก๊ทธ์ธ ์คํจ", Toast.LENGTH_SHORT).show()
+ }
+ else {
+ startActivity(goHomeActivity)
+ }
+ }
+
+ // ํ์๊ฐ์
+ binding.btnSignup.setOnClickListener{
+ startActivity(goSignup)
+ }
+
+ setContentView(binding.root)
+ }
+}
\ No newline at end of file | Kotlin | ํ์ฌ setContentView ํจ์๊ฐ ๋๋ฒ ํธ์ถ๋๊ณ ์๋๋ฐ ํ๋๋ ์ง์์ฃผ์
๋ ๊ด์ฐฎ์ ๊ฒ ๊ฐ์์~!! |
@@ -0,0 +1,40 @@
+package org.sopt.androidseminar1
+
+import android.content.Intent
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.widget.Toast
+import org.sopt.androidseminar1.databinding.SignInBinding
+
+class SignInActivity: AppCompatActivity() {
+ private lateinit var binding: SignInBinding // ๊ณ ์ ์ ์ธ Class ๊ฐ์ ์๋๋ค.
+ // activity_main -> ActivityMain
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ binding = SignInBinding.inflate(layoutInflater) // layoutInflater : xml์ ๋ถ๋ฌ์ฃผ๋ ์ ๋
+ setContentView(binding.root) // setContentView : xml์ ๊ทธ๋ ค์ฃผ๋ ํจ์
+
+
+ // intent ๋ณ๊ฒฝ
+ val goSignup: Intent = Intent(this, SignUpActivity::class.java)
+ val goHomeActivity: Intent = Intent(this, HomeActivity::class.java )
+
+ // ๋ก๊ทธ์ธ ๋ฒํผ
+ binding.btnLogin.setOnClickListener {
+ if (binding.etId.text.toString().isEmpty() || binding.etPw.text.toString().isEmpty()){
+ Toast.makeText(this, "๋ก๊ทธ์ธ ์คํจ", Toast.LENGTH_SHORT).show()
+ }
+ else {
+ startActivity(goHomeActivity)
+ }
+ }
+
+ // ํ์๊ฐ์
+ binding.btnSignup.setOnClickListener{
+ startActivity(goSignup)
+ }
+
+ setContentView(binding.root)
+ }
+}
\ No newline at end of file | Kotlin | ๋ชจ๋ ๋ก์ง์ ๋ค onCreate์ ๋ฃ๊ธฐ๋ณด๋ค๋ ๊ฐ๋
์ฑ, ์ฌ์ฌ์ฉ์ฑ ์ธก๋ฉด์ ๊ณ ๋ คํด์ ํจ์ํ๋ฅผ ํด์ฃผ์๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ์์~!! |
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <corners android:radius="5dip"/>
+
+ <stroke android:width="2dp"
+ android:color="#F658A6"/>
+ <solid android:color="#F658A6"/>
+ <corners
+ android:topLeftRadius="12dp"
+ android:topRightRadius="12dp"
+ android:bottomLeftRadius="12dp"
+ android:bottomRightRadius="12dp"/>
+</shape>
\ No newline at end of file | Unknown | dip๋ dp์ ๊ฐ์ ๊ฐ๋
์
๋๋ค! ์์น๋ฅผ dp๋ก ๋ฐ๊ฟ์ฃผ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์์~!!! |
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".HomeActivity">
+
+ <TextView
+ android:id="@+id/textView10"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="70dp"
+ android:text="@string/sopthub"
+ android:textColor="#F658A6"
+ android:textSize="40sp"
+ android:textStyle="bold"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+
+ <TextView
+ android:id="@+id/textView11"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="20dp"
+ android:layout_marginTop="40dp"
+ android:text="@string/kimdaeho"
+ android:textColor="@color/black"
+ android:textSize="15sp"
+ android:textStyle="bold"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.059"
+ app:layout_constraintStart_toEndOf="@+id/textView15"
+ app:layout_constraintTop_toBottomOf="@+id/imageView2" />
+
+ <TextView
+ android:id="@+id/textView12"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/old"
+ android:textColor="@color/black"
+ android:textSize="15sp"
+ android:textStyle="bold"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.193"
+ app:layout_constraintStart_toEndOf="@+id/textView16"
+ app:layout_constraintTop_toTopOf="@+id/textView16" />
+
+ <TextView
+ android:id="@+id/textView14"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="60dp"
+ android:text="@string/introduce"
+ android:textColor="@color/black"
+ android:textSize="15sp"
+ android:textStyle="bold"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.453"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/textView13" />
+
+ <TextView
+ android:id="@+id/textView13"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/entj"
+ android:textColor="@color/black"
+ android:textSize="15sp"
+ android:textStyle="bold"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.154"
+ app:layout_constraintStart_toEndOf="@+id/textView17"
+ app:layout_constraintTop_toTopOf="@+id/textView17" />
+
+ <ImageView
+ android:id="@+id/imageView2"
+ android:layout_width="119dp"
+ android:layout_height="147dp"
+ android:layout_marginTop="30dp"
+ app:layout_constraintEnd_toEndOf="@+id/textView10"
+ app:layout_constraintHorizontal_bias="0.491"
+ app:layout_constraintStart_toStartOf="@+id/textView10"
+ app:layout_constraintTop_toBottomOf="@+id/textView10"
+ app:srcCompat="@drawable/kimdaeho" />
+
+ <TextView
+ android:id="@+id/textView15"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="150dp"
+ android:text="@string/name"
+ android:textColor="@color/black"
+ android:textSize="15sp"
+ android:textStyle="bold"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="@+id/textView11" />
+
+ <TextView
+ android:id="@+id/textView16"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="40dp"
+ android:text="@string/age"
+ android:textColor="@color/black"
+ android:textSize="15sp"
+ android:textStyle="bold"
+ app:layout_constraintStart_toStartOf="@+id/textView15"
+ app:layout_constraintTop_toBottomOf="@+id/textView15" />
+
+ <TextView
+ android:id="@+id/textView17"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="40dp"
+ android:text="@string/mbti"
+ android:textColor="@color/black"
+ android:textSize="15sp"
+ android:textStyle="bold"
+ app:layout_constraintStart_toStartOf="@+id/textView16"
+ app:layout_constraintTop_toBottomOf="@+id/textView16" />
+
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file | Unknown | View ์ปดํฌ๋ํธ์ id ๊ฐ์ ๋ค์ด๋ฐ์ ์ข ๋ ๊ธฐ๋ฅ์ ๋ง๊ฒ~~ ๊ตฌ์ฒด์ ์ผ๋ก ๋ค์ด๋ฐ ํ๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ์์~!! |
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".SignInActivity">
+
+ <!--
+ text size -> sp
+ hardcoded text -> @values ํด๋๋ก text ์ฎ๊ธฐ๊ธฐ
+ @values ์๋ค๊ฐ color ์ฎ๊ธฐ๊ธฐ
+ amulator ์ action bar ์ ๊ฑฐ
+ ์คํ
์ด๋์ค๋ฐ ์๊น ๋ณ๊ฒฝํด์ผํจ -> @themas-->
+ <TextView
+ android:id="@+id/textView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="70dp"
+ android:text="@string/sopthub"
+ android:textColor="@color/pink"
+ android:textSize="40sp"
+ android:textStyle="bold"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <TextView
+ android:id="@+id/textView2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="40dp"
+ android:layout_marginTop="40dp"
+ android:text="@string/id"
+ android:textColor="@color/black"
+ android:textSize="20sp"
+ android:textStyle="bold"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/textView4" />
+
+ <EditText
+ android:id="@+id/et_id"
+ android:layout_width="0dp"
+ android:layout_height="50dp"
+ android:layout_marginTop="8dp"
+ android:layout_marginEnd="40dp"
+ android:background="@drawable/round_blank_edge"
+ android:ems="10"
+ android:inputType="textPersonName"
+ android:paddingStart="15dp"
+ android:hint="@string/input_id"
+ android:textColor="@color/gray"
+ android:textSize="15sp"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_bias="0.0"
+ app:layout_constraintStart_toStartOf="@+id/textView2"
+ app:layout_constraintTop_toBottomOf="@+id/textView2" />
+
+ <TextView
+ android:id="@+id/textView3"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="20dp"
+ android:text="@string/password"
+ android:textColor="@color/black"
+ android:textSize="20sp"
+ android:textStyle="bold"
+ app:layout_constraintStart_toStartOf="@+id/et_id"
+ app:layout_constraintTop_toBottomOf="@+id/et_id" />
+
+ <EditText
+ android:id="@+id/et_pw"
+ android:layout_width="0dp"
+ android:layout_height="50dp"
+ android:layout_marginTop="10dp"
+ android:layout_marginEnd="40dp"
+ android:background="@drawable/round_blank_edge"
+ android:ems="10"
+ android:inputType="textPassword"
+ android:minHeight="48dp"
+ android:paddingStart="15dp"
+ android:hint="@string/input_password"
+ android:textColor="@color/gray"
+ android:textSize="15sp"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="@+id/textView3"
+ app:layout_constraintTop_toBottomOf="@+id/textView3" />
+
+ <Button
+ android:id="@+id/btn_login"
+ android:layout_width="0dp"
+ android:layout_height="50dp"
+ android:layout_marginBottom="120dp"
+ android:background="@drawable/round_full_edge"
+ android:text="@string/login"
+ android:textColor="@color/white"
+ android:textSize="15sp"
+ android:textStyle="bold"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="@+id/et_pw"
+ app:layout_constraintHorizontal_bias="1.0"
+ app:layout_constraintStart_toStartOf="@+id/et_pw"
+ app:layout_constraintTop_toBottomOf="@+id/et_pw" />
+
+
+ <Button
+ android:id="@+id/btn_signup"
+ android:layout_width="0dp"
+ android:layout_height="50dp"
+ android:background="@color/white"
+ android:text="@string/signup"
+ android:textColor="@color/gray"
+ android:textSize="15sp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="@+id/btn_login"
+ app:layout_constraintStart_toStartOf="@+id/btn_login"
+ app:layout_constraintTop_toBottomOf="@+id/btn_login"
+ app:layout_constraintVertical_bias="0.0" />
+
+ <TextView
+ android:id="@+id/textView4"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="10dp"
+ android:text="@string/login"
+ android:textColor="@color/black"
+ android:textSize="25sp"
+ android:textStyle="bold"
+ app:layout_constraintEnd_toEndOf="@+id/textView"
+ app:layout_constraintHorizontal_bias="0.486"
+ app:layout_constraintStart_toStartOf="@+id/textView"
+ app:layout_constraintTop_toBottomOf="@+id/textView" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file | Unknown | ๊ณ ์ dp๋ฅผ ๋์ด๋ ๋๋น๊ฐ์ผ๋ก ์ค ๊ฒฝ์ฐ ํด๋ํฐ ๊ธฐ์ข
์ ๋ฐ๋ผ ๋ด์ฉ์ด ์๋ฆด์๋์๊ณ , ๋ชจ์์ด ์ด์ํ๊ฒ ๋์ฌ ์๋ ์์ต๋๋ค~ ํน์ ๊ณ ์ dp๋ฅผ ๋์ด ๊ฐ์ผ๋ก ์ฃผ์ ํน๋ณํ ์ด์ ๊ฐ ์์๊น์~๐๐ |
@@ -3,8 +3,10 @@ import { ParsedUrlQuery } from "querystring";
import { GetServerSideProps } from "next";
import { useState } from "react";
import { useQuery } from "@tanstack/react-query";
+import { getReviewStat, getReviews } from "@/lib/api/ReviewService";
import { getTrainerInfo } from "@/lib/api/trainerService";
import { getFavorite } from "@/lib/api/userService";
+import { ReviewResult } from "@/types/reviews";
import FindTrainerCard from "@/components/Cards/FindTrainerCard";
import { HorizontalLine } from "@/components/Common/Line";
import Loading from "@/components/Common/Loading";
@@ -38,6 +40,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
export default function DetailTrainer({ trainerId }: { trainerId: string | null }) {
const [currentPage, setCurrentPage] = useState<number>(1);
+ const pageSize = 3;
const { data, isLoading, isError } = useQuery(
["trainer-detail", trainerId],
() => getTrainerInfo(trainerId as string),
@@ -46,22 +49,42 @@ export default function DetailTrainer({ trainerId }: { trainerId: string | null
},
);
+ const { data: reviewStat } = useQuery(["review-stat"], () => getReviewStat(trainerId as string), {
+ enabled: !!trainerId,
+ cacheTime: 5 * 60 * 1000,
+ staleTime: 5 * 60 * 1000,
+ });
+ const {
+ data: reviewList,
+ isLoading: isReviewLoading,
+ isError: isReviewError,
+ } = useQuery<ReviewResult>(
+ ["reviews", currentPage],
+ () => getReviews(trainerId as string, { page: currentPage, limit: pageSize }),
+ {
+ enabled: !!trainerId,
+ keepPreviousData: true,
+ },
+ );
+
const {
data: favoriteInfo,
isLoading: isFavoriteLoading,
isError: isFavoriteError,
} = useQuery(["favorite"], () => getFavorite(trainerId as string), { enabled: !!trainerId });
- if (isError || isFavoriteError) return <div>error!!</div>;
+ if (isError || isReviewError || isFavoriteError) return <div>error!!</div>;
const trainerInfo = data?.profile;
+ const reviews = reviewList?.reviews || [];
+ const totalCount = reviewList?.totalCount || 0;
return (
<div
className={clsx(
"relative flex flex-col justify-between gap-16 m-auto mt-[2.4rem] mb-16 px-8",
"pc:flex-row pc:gap-0 pc:mt-[5.6rem] pc:max-w-[144rem]",
- "tablet:max-w-[74.4rem] mobile:max-w-[37.5rem]",
+ "tablet:max-w-[74.4rem] mobile:max-w-auto",
)}
>
<div className={"flex flex-col gap-[2.4rem] w-full pc:gap-16 pc:pr-[10rem]"}>
@@ -73,8 +96,12 @@ export default function DetailTrainer({ trainerId }: { trainerId: string | null
<HorizontalLine width="100%" />
<TrainerInfo profile={trainerInfo} />
{/* ๋ฆฌ๋ทฐ ๋ฆฌ์คํธ api ์ฐ๊ฒฐํด์ผํจ */}
- <TrainerReview reviewList={trainerInfo} />
- <Pagination currentPage={currentPage} totalPages={5} onPageChange={setCurrentPage} />
+ <TrainerReview reviewList={reviews} reviewStat={reviewStat} totalCount={totalCount} />
+ <Pagination
+ currentPage={currentPage}
+ totalPages={Math.ceil(totalCount / pageSize)}
+ onPageChange={setCurrentPage}
+ />
</div>
<div className="flex flex-col gap-[2.4rem] pc:gap-16">
<TrainerControl profile={trainerInfo} />
@@ -83,7 +110,7 @@ export default function DetailTrainer({ trainerId }: { trainerId: string | null
<ShareSNS label="๋๋ง ์๊ธฐ์ ์์ฌ์ด ๊ฐ์ฌ๋์ธ๊ฐ์?" trainerInfo={trainerInfo} />
</div>
</div>
- {isLoading || (isFavoriteLoading && <Loading />)}
+ {(isLoading || isReviewLoading || isFavoriteLoading) && <Loading />}
</div>
);
} | Unknown | ```js
useQuery(["review-stat", trainerId],
() => getReviewStat(trainerId as string),
{ enabled: !!trainerId,
cacheTime: 5 * 60 * 1000,
staleTime: 5 * 60 * 1000 });
```
๋ก ํด์ฃผ์๋๊ฒ ์ข์๋ณด์ฌ์. |
@@ -3,8 +3,10 @@ import { ParsedUrlQuery } from "querystring";
import { GetServerSideProps } from "next";
import { useState } from "react";
import { useQuery } from "@tanstack/react-query";
+import { getReviewStat, getReviews } from "@/lib/api/ReviewService";
import { getTrainerInfo } from "@/lib/api/trainerService";
import { getFavorite } from "@/lib/api/userService";
+import { ReviewResult } from "@/types/reviews";
import FindTrainerCard from "@/components/Cards/FindTrainerCard";
import { HorizontalLine } from "@/components/Common/Line";
import Loading from "@/components/Common/Loading";
@@ -38,6 +40,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
export default function DetailTrainer({ trainerId }: { trainerId: string | null }) {
const [currentPage, setCurrentPage] = useState<number>(1);
+ const pageSize = 3;
const { data, isLoading, isError } = useQuery(
["trainer-detail", trainerId],
() => getTrainerInfo(trainerId as string),
@@ -46,22 +49,42 @@ export default function DetailTrainer({ trainerId }: { trainerId: string | null
},
);
+ const { data: reviewStat } = useQuery(["review-stat"], () => getReviewStat(trainerId as string), {
+ enabled: !!trainerId,
+ cacheTime: 5 * 60 * 1000,
+ staleTime: 5 * 60 * 1000,
+ });
+ const {
+ data: reviewList,
+ isLoading: isReviewLoading,
+ isError: isReviewError,
+ } = useQuery<ReviewResult>(
+ ["reviews", currentPage],
+ () => getReviews(trainerId as string, { page: currentPage, limit: pageSize }),
+ {
+ enabled: !!trainerId,
+ keepPreviousData: true,
+ },
+ );
+
const {
data: favoriteInfo,
isLoading: isFavoriteLoading,
isError: isFavoriteError,
} = useQuery(["favorite"], () => getFavorite(trainerId as string), { enabled: !!trainerId });
- if (isError || isFavoriteError) return <div>error!!</div>;
+ if (isError || isReviewError || isFavoriteError) return <div>error!!</div>;
const trainerInfo = data?.profile;
+ const reviews = reviewList?.reviews || [];
+ const totalCount = reviewList?.totalCount || 0;
return (
<div
className={clsx(
"relative flex flex-col justify-between gap-16 m-auto mt-[2.4rem] mb-16 px-8",
"pc:flex-row pc:gap-0 pc:mt-[5.6rem] pc:max-w-[144rem]",
- "tablet:max-w-[74.4rem] mobile:max-w-[37.5rem]",
+ "tablet:max-w-[74.4rem] mobile:max-w-auto",
)}
>
<div className={"flex flex-col gap-[2.4rem] w-full pc:gap-16 pc:pr-[10rem]"}>
@@ -73,8 +96,12 @@ export default function DetailTrainer({ trainerId }: { trainerId: string | null
<HorizontalLine width="100%" />
<TrainerInfo profile={trainerInfo} />
{/* ๋ฆฌ๋ทฐ ๋ฆฌ์คํธ api ์ฐ๊ฒฐํด์ผํจ */}
- <TrainerReview reviewList={trainerInfo} />
- <Pagination currentPage={currentPage} totalPages={5} onPageChange={setCurrentPage} />
+ <TrainerReview reviewList={reviews} reviewStat={reviewStat} totalCount={totalCount} />
+ <Pagination
+ currentPage={currentPage}
+ totalPages={Math.ceil(totalCount / pageSize)}
+ onPageChange={setCurrentPage}
+ />
</div>
<div className="flex flex-col gap-[2.4rem] pc:gap-16">
<TrainerControl profile={trainerInfo} />
@@ -83,7 +110,7 @@ export default function DetailTrainer({ trainerId }: { trainerId: string | null
<ShareSNS label="๋๋ง ์๊ธฐ์ ์์ฌ์ด ๊ฐ์ฌ๋์ธ๊ฐ์?" trainerInfo={trainerInfo} />
</div>
</div>
- {isLoading || (isFavoriteLoading && <Loading />)}
+ {(isLoading || isReviewLoading || isFavoriteLoading) && <Loading />}
</div>
);
} | Unknown | ๋ต ์์ ํ๊ฒ ์ต๋๋ค! |
@@ -1,11 +1,29 @@
import { useState } from "react";
+import Header from "./components/Header/Header";
+import Product from "./pages/Product";
+import GlobalStyles from "./styles/Global.style";
+import Toast from "./components/common/Toast/Toast";
+import { QuantityContext } from "./store/QuantityContext";
+import { createPortal } from "react-dom";
function App() {
- const [count, setCount] = useState(0);
-
+ const [quantity, setQuantity] = useState(0);
+ const [showToast, setShowToast] = useState(false);
+ const [toastMessage, setToastMessage] = useState("");
+ const handleError = (message: string) => {
+ setToastMessage(message);
+ setShowToast(true);
+ setTimeout(() => setShowToast(false), 3000);
+ };
return (
<>
- <h1>React Shopping Products</h1>
+ <GlobalStyles />
+ {showToast &&
+ createPortal(<Toast message={toastMessage} />, document.body)}
+ <QuantityContext.Provider value={{ quantity, setQuantity }}>
+ <Header />
+ <Product onError={handleError} />
+ </QuantityContext.Provider>
</>
);
} | Unknown | ์ฌ๊ธฐ ์ด `showToast` ์ํ๋ฅผ ํ ์คํธ ์ปดํฌ๋ํธ๊ฐ ์ฑ
์์ ๊ฐ์ง ์ ์์ง ์์๊น ์ถ์๋๋ฐ, ๊ทธ๋ ๋ค๋ฉด createPortal์ ์ฌ์ฉํ ์ ์๊ฒ ๋๋์..? createPortal์ ์ฌ์ฉํด๋ณด์ง ์์์ ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง, ๋ฏธ๋ฆฌ ์ด์ด๋ ์ ์๋ค๋ฉด ๊ทธ์ชฝ์ผ๋ก ์ํ๋ฅผ ์ฎ๊ฒจ๋ด๋ ์ข์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,52 @@
+import { generateBasicToken } from "../util/auth";
+import { CART_ITEMS_ENDPOINT } from "./config";
+
+const USER_PASSWORD = import.meta.env.VITE_USER_PASSWORD;
+const USER_ID = import.meta.env.VITE_USER_ID;
+const token = generateBasicToken(USER_ID, USER_PASSWORD);
+
+export async function requestFetchCartItemList() {
+ const response = await fetch(`${CART_ITEMS_ENDPOINT}?size=2000`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: token,
+ },
+ });
+
+ if (!response.ok) {
+ throw new Error("Failed to fetch cart item list");
+ }
+
+ const data = await response.json();
+ return data;
+}
+
+export async function requestAddCartItem(productId: number, quantity: number) {
+ const response = await fetch(`${CART_ITEMS_ENDPOINT}`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: token,
+ },
+ body: JSON.stringify({ productId, quantity }),
+ });
+
+ if (!response.ok) {
+ throw new Error("Failed to add cart item");
+ }
+}
+
+export async function requestDeleteCartItem(cartItemId: number | undefined) {
+ const response = await fetch(`${CART_ITEMS_ENDPOINT}/${cartItemId}`, {
+ method: "DELETE",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: token,
+ },
+ });
+
+ if (!response.ok) {
+ throw new Error("Failed to delete cart item");
+ }
+} | TypeScript | ํ์๋ ์๋์ง๋ง ๋ฐ๋ณต๋๋ fetch ๋ก์ง๋ค์ ์ถ์ํํด๋ณด์
๋ ์ข์ ๊ฒ ๊ฐ์์!ใ
ใ
|
@@ -0,0 +1,52 @@
+import { generateBasicToken } from "../util/auth";
+import { CART_ITEMS_ENDPOINT } from "./config";
+
+const USER_PASSWORD = import.meta.env.VITE_USER_PASSWORD;
+const USER_ID = import.meta.env.VITE_USER_ID;
+const token = generateBasicToken(USER_ID, USER_PASSWORD);
+
+export async function requestFetchCartItemList() {
+ const response = await fetch(`${CART_ITEMS_ENDPOINT}?size=2000`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: token,
+ },
+ });
+
+ if (!response.ok) {
+ throw new Error("Failed to fetch cart item list");
+ }
+
+ const data = await response.json();
+ return data;
+}
+
+export async function requestAddCartItem(productId: number, quantity: number) {
+ const response = await fetch(`${CART_ITEMS_ENDPOINT}`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: token,
+ },
+ body: JSON.stringify({ productId, quantity }),
+ });
+
+ if (!response.ok) {
+ throw new Error("Failed to add cart item");
+ }
+}
+
+export async function requestDeleteCartItem(cartItemId: number | undefined) {
+ const response = await fetch(`${CART_ITEMS_ENDPOINT}/${cartItemId}`, {
+ method: "DELETE",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: token,
+ },
+ });
+
+ if (!response.ok) {
+ throw new Error("Failed to delete cart item");
+ }
+} | TypeScript | chat GPTํํ
'์ด ์ฝ๋ ์ถ์ํ ํด๋ด'ํ๋ฉด ๊ธฐ๊ฐ๋งํ๊ฒ ํด์ฃผ๋๋ผ๊ตฌ์ |
@@ -0,0 +1,10 @@
+import { generateBasicToken } from "../util/auth";
+
+const API_URL = import.meta.env.VITE_API_URL;
+
+export const PRODUCTS_ENDPOINT = `${API_URL}/products`;
+export const CART_ITEMS_ENDPOINT = `${API_URL}/cart-items`;
+
+export const USER_PASSWORD = import.meta.env.VITE_USER_PASSWORD;
+export const USER_ID = import.meta.env.VITE_USER_ID;
+export const token = generateBasicToken(USER_ID, USER_PASSWORD); | TypeScript | api์์ฒญ์ ํ์ํ ๋ณ์๋ค์ด ์ ๋ชจ์ฌ์์ด ๊ด๋ฆฌํ๊ธฐ ํธํ ๊ฒ ๊ฐ๋ค์! ๐ |
@@ -0,0 +1,87 @@
+import { useContext, useEffect, useRef } from "react";
+import { QuantityContext } from "../../store/QuantityContext";
+import useProductList from "../../hooks/useProductList";
+import useCartItemList from "../../hooks/useCartItemList";
+import ProductItem from "../ProductItem/ProductItem";
+import * as S from "./ProductItemList.style";
+import { Category } from "../../interfaces/Product";
+import { Sorting } from "../../interfaces/Sorting";
+import useIntersectionObserver from "../../hooks/useIntersectionObserver";
+import Spinner from "../common/Spinner/Spinner";
+
+interface ProductItemListProp {
+ category: Category;
+ sortOption: Sorting;
+ onError: (error: string) => void;
+}
+
+function ProductItemList({
+ category,
+ sortOption,
+ onError,
+}: ProductItemListProp) {
+ const {
+ productList,
+ productListError,
+ productListLoading,
+ page,
+ fetchNextPage,
+ isLastPage,
+ setPage,
+ } = useProductList({
+ category,
+ sortOption,
+ });
+ const { cartItemList, isInCart, toggleCartItem, cartItemListError } =
+ useCartItemList();
+ const target = useRef(null);
+ const [observe, unobserve] = useIntersectionObserver(() => {
+ fetchNextPage();
+ });
+
+ useEffect(() => {
+ setPage(0);
+ }, [category, sortOption]);
+
+ useEffect(() => {
+ if (page === -1 || target.current === null) return;
+ observe(target.current);
+
+ const N = productList.length;
+
+ if (0 === N || isLastPage) {
+ unobserve(target.current);
+ }
+ }, [productList, page, observe, unobserve]);
+ const quantityContext = useContext(QuantityContext);
+ const setQuantity = quantityContext ? quantityContext.setQuantity : () => {};
+ setQuantity(cartItemList.length);
+
+ if (productListError) {
+ onError("์ํ ๋ชฉ๋ก ์กฐํ ์คํจ");
+ }
+ if (cartItemListError) {
+ onError("์ฅ๋ฐ๊ตฌ๋ ๋ชฉ๋ก ์กฐํ ์คํจ");
+ }
+
+ return (
+ <>
+ <S.ProductList>
+ {productList.map((product, idx) => {
+ return (
+ <ProductItem
+ key={`${idx}_${product.id}`}
+ product={product}
+ isInCart={isInCart(product.id)}
+ toggleCartItem={() => toggleCartItem(product)}
+ />
+ );
+ })}
+ </S.ProductList>
+ <div ref={target} style={{ height: "1px" }}></div>
+ {productListLoading && <Spinner />}
+ </>
+ );
+}
+
+export default ProductItemList; | Unknown | ํ์ด์ง๋ค์ด์
๊ด๋ จ ๋ก์ง๋ ์ปค์คํ
ํ
์ผ๋ก ๋ถ๋ฆฌํ๋ฉด ์ข์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,87 @@
+import { useContext, useEffect, useRef } from "react";
+import { QuantityContext } from "../../store/QuantityContext";
+import useProductList from "../../hooks/useProductList";
+import useCartItemList from "../../hooks/useCartItemList";
+import ProductItem from "../ProductItem/ProductItem";
+import * as S from "./ProductItemList.style";
+import { Category } from "../../interfaces/Product";
+import { Sorting } from "../../interfaces/Sorting";
+import useIntersectionObserver from "../../hooks/useIntersectionObserver";
+import Spinner from "../common/Spinner/Spinner";
+
+interface ProductItemListProp {
+ category: Category;
+ sortOption: Sorting;
+ onError: (error: string) => void;
+}
+
+function ProductItemList({
+ category,
+ sortOption,
+ onError,
+}: ProductItemListProp) {
+ const {
+ productList,
+ productListError,
+ productListLoading,
+ page,
+ fetchNextPage,
+ isLastPage,
+ setPage,
+ } = useProductList({
+ category,
+ sortOption,
+ });
+ const { cartItemList, isInCart, toggleCartItem, cartItemListError } =
+ useCartItemList();
+ const target = useRef(null);
+ const [observe, unobserve] = useIntersectionObserver(() => {
+ fetchNextPage();
+ });
+
+ useEffect(() => {
+ setPage(0);
+ }, [category, sortOption]);
+
+ useEffect(() => {
+ if (page === -1 || target.current === null) return;
+ observe(target.current);
+
+ const N = productList.length;
+
+ if (0 === N || isLastPage) {
+ unobserve(target.current);
+ }
+ }, [productList, page, observe, unobserve]);
+ const quantityContext = useContext(QuantityContext);
+ const setQuantity = quantityContext ? quantityContext.setQuantity : () => {};
+ setQuantity(cartItemList.length);
+
+ if (productListError) {
+ onError("์ํ ๋ชฉ๋ก ์กฐํ ์คํจ");
+ }
+ if (cartItemListError) {
+ onError("์ฅ๋ฐ๊ตฌ๋ ๋ชฉ๋ก ์กฐํ ์คํจ");
+ }
+
+ return (
+ <>
+ <S.ProductList>
+ {productList.map((product, idx) => {
+ return (
+ <ProductItem
+ key={`${idx}_${product.id}`}
+ product={product}
+ isInCart={isInCart(product.id)}
+ toggleCartItem={() => toggleCartItem(product)}
+ />
+ );
+ })}
+ </S.ProductList>
+ <div ref={target} style={{ height: "1px" }}></div>
+ {productListLoading && <Spinner />}
+ </>
+ );
+}
+
+export default ProductItemList; | Unknown | ์๋ฌด๋๋ ์ด๋ฒ ๋ฏธ์
์์ ๊ฐ์ฅ ๋ฉ์ธ์ด ๋๋(?) ์ปดํฌ๋ํธ์ธ ๊ฒ ๊ฐ์์. ๋น์ฆ๋์ค ๋ก์ง๊ณผ UI ๋ก์ง์ด ์ข ๋ ์ ๋ถ๋ฆฌ๋๋ฉด ๋์ฑ ์ฝ๊ธฐ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,5 @@
+package model;
+
+public interface State {
+ int execute(int length);
+} | Java | ํ์ฅ ๊ฐ๋ฅ์ฑ์ ์๊ฐํ์ฌ ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ์๋ค์!! ๊ฐ ๋ค๋ฅธ ์ํ๋ง๋ค ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด์ Car์์ ๊ฐ์๋ผ์ฐ๋ ๊ฒ๋ ์ ์ ํฉ๋๋ค!! State ํจํด ์ข์ ๊ฒ ๋ฐฐ์๊ฐ๋๋ค ๐ |
@@ -0,0 +1,13 @@
+package function;
+
+import java.util.Random;
+
+public class RandomNumberMaker {
+
+ private static final Random random = new Random();
+ private static final int RANDOM_NUMBER_RANGE = 10;
+
+ public static int getRandomNumber() {
+ return random.nextInt(RANDOM_NUMBER_RANGE);
+ }
+} | Java | getRandomNumber ๊ฐ ํธ์ถ๋ ๋๋ง๋ค ์๋ก์ด Random๊ฐ์ฒด๊ฐ ๋ง๋ค์ด์ง์ง ์์๋ ๋ ๊ฒ ๊ฐ์์!!
๊ทธ๋ฆฌ๊ณ Random๊ฐ์boundary๋ฅผ ํ๋ผ๋ฏธํฐ๋ก ๋ฐ์ ์ด์ ๊ฐ ์์๊น์?? |
@@ -2,22 +2,28 @@
public class Car{
- private String name;
- private int position = 0;
+ long number;
+ int length;
+ State state;
- public Car(String name){
- this.name = name;
+ public Car(long number) {
+ this.number = number;
+ length = 0;
}
- public String getName() {
- return name;
+ public int moveCount() {
+ return length;
}
- public int getPosition(){
- return position;
+ public long getCarNum() {
+ return number;
}
- public void move(){
- position++;
+ public void changeState(State cmd) {
+ state = cmd;
+ }
+
+ public void move() {
+ length = state.execute(length);
}
}
\ No newline at end of file | Java | number๋ฅผ Car๋ฅผ ์๋ณํด์ฃผ๋ ๋ฉค๋ฒ๋ก ์ฌ์ฉํ๊ณ ์๋ ๊ฒ ๊ฐ์์!! ์ ๊ทผ์ง์ ์์ final ํค์๋๋ฅผ ๋ถ์ฌ์ฃผ๋ ๊ฒ์ ๋ํด ์ด๋ป๊ฒ ์๊ฐํ์ค๊น์? |
@@ -1,21 +1,18 @@
package view;
-import controller.RacingGame;
import model.Car;
-import java.util.Collections;
import java.util.List;
public class ResultView {
- public static void printTrialResult(List<Car> cars){
- for (Car car : cars){
- System.out.print(car.getName() + " : " + String.join("", Collections.nCopies(car.getPosition(), "*")) + "\n");
+ private static final String RESULT_SYMBOL = "-";
+
+ public static void printAllCarsState(long id, int len) {
+ System.out.println("car" + id);
+ for (int i = 0; i < len; i++) {
+ System.out.print(RESULT_SYMBOL);
}
System.out.println();
}
-
- public static void printFinalWinner(RacingGame racingGame, List<Car> cars){
- System.out.print(String.join(",", racingGame.searchWinners(cars)) + "๊ฐ ์ต์ข
์ฐ์นํ์ต๋๋ค.");
- }
}
\ No newline at end of file | Java | ํ์ฌ ์ถ๋ ฅํ๋ ์ฉ๋๋ก ์ง๊ธ --- ์ด๋ ๊ฒ ๋ณด์ฌ์ฃผ๊ณ ์์ง๋ง, ๋์ค์๋ ๋ค๋ฅธ ๊ธฐํธ๋ก ๋ฐ๋์๋ ์์ ๊ฒ ๊ฐ์์!! ์ด ๊ธฐํธ๋ค ๋ฟ๋ง ์๋๋ผ InputView์ ResultView์ ์
์ถ๋ ฅ ๋ฉ์ธ์ง, ๋งค์ง๋๋ฒ๋ค์ ์์ํ ํด์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,38 @@
+package controller;
+
+import function.RandomNumberMaker;
+import model.Car;
+import model.State;
+import model.Movable;
+import model.UnMovable;
+
+import java.util.List;
+
+public class CarController {
+
+ private static final int MOVE_CONDITION = 4;
+
+ public void registerCars(List<Car> cars, long len) {
+ for (int i = 0; i < len; i++) {
+ cars.add(new Car(i));
+ }
+ }
+
+ public void moveCar(List<Car> cars) {
+ for (Car car : cars) {
+ car.changeState(checkMoveOrStop(car));
+ car.move();
+ }
+ }
+
+ private State checkMoveOrStop(Car car) {
+ if (getRandomNumber() >= MOVE_CONDITION) {
+ return new Movable();
+ }
+ return new UnMovable();
+ }
+
+ private int getRandomNumber() {
+ return RandomNumberMaker.getRandomNumber();
+ }
+} | Java | ์ ์ฒด์ ์ผ๋ก Car๋ค์ ๊ด๋ฆฌํด์ฃผ๋ ์ญํ ์ ํ๊ณ ์๋ ๊ฒ ๊ฐ์์!
์ ๊ฐ ์๊ฐํ๋ Controller์ ์ญํ ๊ณผ๋ ์กฐ๊ธ ๋ค๋ฅด๋ค๊ณ ์๊ฐ์ด ๋ญ๋๋ค.
์ ๊ฐ ์๊ฐํ๋ Controller์ ์ญํ ์ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ์์ฒญ๊ฐ์ ๋ฐ์, ์์ฒญ๊ฐ์ ๊ฐ์ง๊ณ ๋น์ฆ๋์ค ๋ก์ง์ ์คํํ๊ณ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ๊ฐ๊ณตํด์ View์๊ฒ ๋ณด๋ด์ฃผ๋ ์ญํ ์ด๋ผ๊ณ ์๊ฐ์ ํฉ๋๋ค.
์ ๋ CarController๋ณด๋ค Cars๊ฐ์ ์ด๋ฆ์ด ๋ ์ด์ธ๋ฆฐ๋ค๊ณ ์๊ฐ์ด ๋๋๋ฐ ํ์ฐ๋์ ์ด๋ป๊ฒ ์๊ฐํ์ค๊น์??
์ด ์๋ฃ ์ฐธ๊ณ ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
https://tecoble.techcourse.co.kr/post/2020-05-08-First-Class-Collection/ |
@@ -0,0 +1,47 @@
+package engine;
+
+import controller.CarController;
+import model.Car;
+import view.InputView;
+import view.ResultView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RacingGame {
+
+ private List<Car> cars;
+ private CarController carController;
+ private InputView inputView;
+
+ public RacingGame() {
+ cars = new ArrayList<>();
+ carController = new CarController();
+ inputView = new InputView();
+ }
+
+ public void run() {
+ long carNum = inputView.inputTotalCarNum();
+ int trial = inputView.inputTotalTrial();
+
+ register(carNum);
+ executeGame(trial);
+ printAll(cars);
+ }
+
+ private void executeGame(int trial) {
+ for (int i = 0; i < trial; i++) {
+ carController.moveCar(cars);
+ }
+ }
+
+ private void register(long carNum) {
+ carController.registerCars(cars, carNum);
+ }
+
+ private void printAll(List<Car> cars) {
+ for (Car car : cars) {
+ ResultView.printAllCarsState(car.getCarNum(), car.moveCount());
+ }
+ }
+} | Java | InputView๋ ์ธ์คํด์ค๋ก ๊ด๋ฆฌํ๊ณ ResultView๋ ์ ํธ๋ฆฌํฐ ํด๋์ค๋ก ์ ์ธํ ์ด์ ๊ฐ ๊ถ๊ธํ๋ค์!! ์ ๋ View๋ฅผ ๊ตฌํ์ ํ ๋, ๊ณ ๋ฏผ์ด ๋ง์ด ๋๋๋ฐ์! View ๊ฐ์ ๊ฒฝ์ฐ์ ์ํ๊ฐ ์์ด์ ์ ํธ๋ฆฌํฐ ํด๋์ค๋ก ๊ตฌํ์ ํด๋ ๋ ๊ฒ ๊ฐ์ง๋ง, ์ ํธ์ฑ ํด๋์ค์๋ ์๊น์ด ์กฐ๊ธ ๋ค๋ฅธ ๋๋๋ ์์ด์์!! ์ ๋ต์ ์๊ฒ ์ง๋ง, ์ ๋ ์ด๋ฒ์ View ๊ตฌํ์ ํ ๋ ์ฑ๊ธํด ํจํด์ ์ฌ์ฉํด๋ณด์์ด์!! ํ์ฐ๋์ด InputView์ OutputView๋ฅผ ๋ค๋ฅด๊ฒ ๊ตฌํํ์ ์ด ๊ถ๊ธํ๋ค์! |
@@ -0,0 +1,38 @@
+package controller;
+
+import function.RandomNumberMaker;
+import model.Car;
+import model.State;
+import model.Movable;
+import model.UnMovable;
+
+import java.util.List;
+
+public class CarController {
+
+ private static final int MOVE_CONDITION = 4;
+
+ public void registerCars(List<Car> cars, long len) {
+ for (int i = 0; i < len; i++) {
+ cars.add(new Car(i));
+ }
+ }
+
+ public void moveCar(List<Car> cars) {
+ for (Car car : cars) {
+ car.changeState(checkMoveOrStop(car));
+ car.move();
+ }
+ }
+
+ private State checkMoveOrStop(Car car) {
+ if (getRandomNumber() >= MOVE_CONDITION) {
+ return new Movable();
+ }
+ return new UnMovable();
+ }
+
+ private int getRandomNumber() {
+ return RandomNumberMaker.getRandomNumber();
+ }
+} | Java | ๋๋ค๊ฐ ๋๋ฌธ์ checkMoveOrStop ๋ฉ์๋๋ฅผ ํ
์คํธ ์ฝ๋ ์์ฑํ๊ธฐ ์ด๋ ค์ ์ ๊ฑฐ์์!!
https://tecoble.techcourse.co.kr/post/2020-05-07-appropriate_method_for_test_by_parameter/
https://tecoble.techcourse.co.kr/post/2020-05-17-appropriate_method_for_test_by_interface/
์๋ฃ ์ฐธ๊ณ ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์!! ํ์ง๋ง ์ธํฐํ์ด์ค๋ฅผ ๋ถ๋ฆฌํ๋๊ฒ ๋ฌด์กฐ๊ฑด ์ข์ ๋ฐฉ๋ฒ์ ์๋๋ผ๊ณ ์๊ฐ์ด ๋ญ๋๋ค!! ์์ฌํ๋ฉด์ ๋ณด๋ฉด ์ข์ ๊ฒ ๊ฐ์์!! ํ์ฐ๋์ ์๊ฐ์ด ๋ค๋ฅด์ค ์ ๋ ์๊ตฌ์! |
@@ -0,0 +1,13 @@
+package function;
+
+import java.util.Random;
+
+public class RandomNumberMaker {
+
+ private static final Random random = new Random();
+ private static final int RANDOM_NUMBER_RANGE = 10;
+
+ public static int getRandomNumber() {
+ return random.nextInt(RANDOM_NUMBER_RANGE);
+ }
+} | Java | 1. getRandomNumber ๊ฐ ํธ์ถ๋ ๋๋ง๋ค ์๋ก์ด Random๊ฐ์ฒด๊ฐ ๋ง๋ค์ด์ง์ง ์์๋ ๋ ๊ฒ ๊ฐ์์!!
๋๊ฑด๋ ๋ง์๋๋ก getRandomNumber๋ฅผ ํธ์ถํ ๋๋ง๋ค Random ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ง ์๋ ๊ฒ์ด ์ข๋ค๊ณ ์๊ฐ์ด ๋ญ๋๋ค
Random๊ฐ์ฒด๋ฅผ ์ฑ๊ธํค ํจํด์ ์ด์ฉํ์ฌ ๊ตฌํํ๋ฉด ๋ฆฌ์์ค ๋ถ๋ถ์์ ๋ญ๋น๋ฅผ ์ค์ผ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค!! :)
2. Random๊ฐ์ boundary๋ฅผ ํ๋ผ๋ฏธํฐ๋ก ๋ฐ์ ์ด์ ๊ฐ ์์๊น์??
์ ๊ฐ ์๊ฐํ๊ธฐ์๋ ๋์ค์ 10์์ ๋ค๋ฅธ ์ซ์๋ก ๋ฐ๊พธ๊ณ ์ถ์ "๋ณ๊ฒฝ ์ฌํญ"์ ์๊ฐํด๋ดค์ต๋๋ค.
์ฐจ๋ฅผ ์์ง์ด๊ฒ ํ๋ "CarController"์์ ์์ ํด์ฃผ๋ ๊ฒ์ด ์ข๋ค๊ณ ์๊ฐํ์ต๋๋ค. |
@@ -0,0 +1,13 @@
+package function;
+
+import java.util.Random;
+
+public class RandomNumberMaker {
+
+ private static final Random random = new Random();
+ private static final int RANDOM_NUMBER_RANGE = 10;
+
+ public static int getRandomNumber() {
+ return random.nextInt(RANDOM_NUMBER_RANGE);
+ }
+} | Java | ```java
private static Random random = new Random();
private static final int RANDOM_BOUNDARY = 10;
public static int getRandomNumber() {
return random.nextInt(RANDOM_BOUNDARY);
}
```
์ด๋ผ๊ณ ํด์ค ์ ์์ ๊ฒ ๊ฐ์์์!!
๋๋ค ๊ฐ์ ์์ฑํด์ฃผ๋ ์ญํ ์ ํ๋ ๊ฒ ๊ฐ์๋ฐ, ๋๋ค๊ฐ์ ๋ฒ์๋ ๋๋ค๊ฐ์ด ์์ฑํด์ฃผ๋ ๊ณณ์์ ์์์ผ ํ์ง ์์๊น ์ถ๋ค์! |
@@ -0,0 +1,13 @@
+package function;
+
+import java.util.Random;
+
+public class RandomNumberMaker {
+
+ private static final Random random = new Random();
+ private static final int RANDOM_NUMBER_RANGE = 10;
+
+ public static int getRandomNumber() {
+ return random.nextInt(RANDOM_NUMBER_RANGE);
+ }
+} | Java | "๋๋ค๊ฐ์ ๋ฒ์๋ ๋๋ค๊ฐ์ด ์์ฑํด์ฃผ๋ ๊ณณ์์ ์์์ผ ํ์ง ์์๊น ์ถ๋ค์"
์ด ๋ถ๋ถ์ด ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค. ์๊ฐํด๋ณด๋ CarController๊ฐ ๋๋ค๊ฐ์ ๋ฒ์๋ฅผ ์ ํ๋ค๋ฉด ๊ฒฐ๊ตญ Random๊ฐ์ ์์ฑํด์ฃผ๋ ๊ณณ์ ์์กดํ๊ฒ ๋์ด ๊ฒฐํฉ๋๊ฐ ๋์์ง๊ฒ ๋ค์!!
๊ฒฐํฉ๋๋ฅผ ์ค์ด๋ ๋ฐฉ๋ฒ ๋๋ฌด ์ข์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,5 @@
+package model;
+
+public interface State {
+ int execute(int length);
+} | Java | ๊ฐ์ฌํฉ๋๋ค :) |
@@ -1,16 +1,54 @@
package view;
+import java.io.InputStream;
+import java.util.InputMismatchException;
import java.util.Scanner;
-public class InputView{
+public class InputView {
- public static String[] inputCarName(Scanner scanner){
- System.out.println("๊ฒฝ์ฃผํ ์ฐจ์ ์ด๋ฆ์ ์
๋ ฅํ์ธ์. (์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
- return scanner.nextLine().split(",");
+ Scanner sc;
+ private static final String CARS_COUNT = "์๋์ฐจ ๋์๋ ๋ช ๋ ์ธ๊ฐ์?";
+ private static final String PUT_NATURAL_NUMBER = "์์๊ฐ ์๋ ์์ฐ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์";
+ private static final String TRIAL_COUNT = "์๋ํ ํ์๋ ๋ช ํ ์ธ๊ฐ์?";
+ private static final String DO_NOT_PUT_STRING = "๋ฌธ์์ด์ด ์๋ ์์ฐ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์";
+
+ public InputView() {
+ sc = new Scanner(System.in);
+ }
+
+ public long inputTotalCarNum() {
+ System.out.println(CARS_COUNT);
+ long carCount = 0L;
+ try {
+ carCount = Long.parseLong(sc.nextLine());
+ if (carCount <= 0) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException exception) {
+ System.out.println(PUT_NATURAL_NUMBER);
+ return inputTotalCarNum();
+ } catch (InputMismatchException exception) {
+ System.out.println(DO_NOT_PUT_STRING);
+ return inputTotalCarNum();
+ }
+ return carCount;
}
- public static int inputNumberOfTrials(Scanner scanner){
- System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
- return scanner.nextInt();
+ public int inputTotalTrial() {
+ System.out.println(TRIAL_COUNT);
+ int trial = 0;
+ try {
+ trial = Integer.parseInt(sc.nextLine());
+ if (trial <= 0) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException exception) {
+ System.out.println(PUT_NATURAL_NUMBER);
+ return inputTotalTrial();
+ } catch (InputMismatchException exception) {
+ System.out.println(DO_NOT_PUT_STRING);
+ return inputTotalTrial();
+ }
+ return trial;
}
-}
\ No newline at end of file
+} | Java | ์์๊ฐ ์
๋ ฅ๋์ ๊ฒฝ์ฐ์ ์์ธ๊ฐ ๋์ ธ์ง๋๋ก ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์
จ๋ค์! ์์์ผ ๊ฒฝ์ฐ ๋ง๊ณ ๋ ์ซ์๊ฐ ์๋ ๊ฐ์ด ์
๋ ฅ ๋์ ๊ฒฝ์ฐ๋ ์์ธ๊ฐ ๋์ ธ์ง๋๋ก ๋ช
์์ ์ผ๋ก ์ฒ๋ฆฌํด์ฃผ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -1,16 +1,54 @@
package view;
+import java.io.InputStream;
+import java.util.InputMismatchException;
import java.util.Scanner;
-public class InputView{
+public class InputView {
- public static String[] inputCarName(Scanner scanner){
- System.out.println("๊ฒฝ์ฃผํ ์ฐจ์ ์ด๋ฆ์ ์
๋ ฅํ์ธ์. (์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
- return scanner.nextLine().split(",");
+ Scanner sc;
+ private static final String CARS_COUNT = "์๋์ฐจ ๋์๋ ๋ช ๋ ์ธ๊ฐ์?";
+ private static final String PUT_NATURAL_NUMBER = "์์๊ฐ ์๋ ์์ฐ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์";
+ private static final String TRIAL_COUNT = "์๋ํ ํ์๋ ๋ช ํ ์ธ๊ฐ์?";
+ private static final String DO_NOT_PUT_STRING = "๋ฌธ์์ด์ด ์๋ ์์ฐ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์";
+
+ public InputView() {
+ sc = new Scanner(System.in);
+ }
+
+ public long inputTotalCarNum() {
+ System.out.println(CARS_COUNT);
+ long carCount = 0L;
+ try {
+ carCount = Long.parseLong(sc.nextLine());
+ if (carCount <= 0) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException exception) {
+ System.out.println(PUT_NATURAL_NUMBER);
+ return inputTotalCarNum();
+ } catch (InputMismatchException exception) {
+ System.out.println(DO_NOT_PUT_STRING);
+ return inputTotalCarNum();
+ }
+ return carCount;
}
- public static int inputNumberOfTrials(Scanner scanner){
- System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
- return scanner.nextInt();
+ public int inputTotalTrial() {
+ System.out.println(TRIAL_COUNT);
+ int trial = 0;
+ try {
+ trial = Integer.parseInt(sc.nextLine());
+ if (trial <= 0) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException exception) {
+ System.out.println(PUT_NATURAL_NUMBER);
+ return inputTotalTrial();
+ } catch (InputMismatchException exception) {
+ System.out.println(DO_NOT_PUT_STRING);
+ return inputTotalTrial();
+ }
+ return trial;
}
-}
\ No newline at end of file
+} | Java | ์ ๋ ๋๊ฑด๋๊ป ๋ฐฐ์ด๊ฑด๋ฐ if๋ฌธ ๋ฐ๋๊ฐ ํ ๋ฌธ์ฅ์ด๋๋ผ๋ ์ค๊ดํธ {}๋ฅผ ์ฌ์ฉํด์ฃผ๋๊ฒ์ด ๊ด๋ก๋ผ๊ณ ํ๋ค์! |
@@ -2,22 +2,28 @@
public class Car{
- private String name;
- private int position = 0;
+ long number;
+ int length;
+ State state;
- public Car(String name){
- this.name = name;
+ public Car(long number) {
+ this.number = number;
+ length = 0;
}
- public String getName() {
- return name;
+ public int moveCount() {
+ return length;
}
- public int getPosition(){
- return position;
+ public long getCarNum() {
+ return number;
}
- public void move(){
- position++;
+ public void changeState(State cmd) {
+ state = cmd;
+ }
+
+ public void move() {
+ length = state.execute(length);
}
}
\ No newline at end of file | Java | ์ ๊ทผ์ ํ์๋ ๊ฐ๋ฅํ ๊ฐ์ฅ ์ข์ ๋ฒ์๋ก ์ ์ธํด์ฃผ๋๊ฒ์ด ์ข๋ค๊ณ ํฉ๋๋ค. number, length, state ๊ฐ์ ๊ฒฝ์ฐ์๋ private๋ก ์ ์ธํด์ฃผ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,38 @@
+package controller;
+
+import function.RandomNumberMaker;
+import model.Car;
+import model.State;
+import model.Movable;
+import model.UnMovable;
+
+import java.util.List;
+
+public class CarController {
+
+ private static final int MOVE_CONDITION = 4;
+
+ public void registerCars(List<Car> cars, long len) {
+ for (int i = 0; i < len; i++) {
+ cars.add(new Car(i));
+ }
+ }
+
+ public void moveCar(List<Car> cars) {
+ for (Car car : cars) {
+ car.changeState(checkMoveOrStop(car));
+ car.move();
+ }
+ }
+
+ private State checkMoveOrStop(Car car) {
+ if (getRandomNumber() >= MOVE_CONDITION) {
+ return new Movable();
+ }
+ return new UnMovable();
+ }
+
+ private int getRandomNumber() {
+ return RandomNumberMaker.getRandomNumber();
+ }
+} | Java | RANDOM_NUMBER_RANGE ๋ ์ด๋จ๊น์? |
@@ -1,66 +0,0 @@
-package controller;
-
-import model.Car;
-import util.RandomGenerator;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class RacingGame {
-
- public static final int CRITICAL_POINT = 5;
- public static final int MAX_NAME_LENGTH = 5;
-
- public void oneTrial(List<Car> cars){
- for (Car car : cars){
- check(car);
- }
- }
-
- public void check(Car car){
- if (RandomGenerator.randInt(10) > CRITICAL_POINT){
- car.move();
- }
- }
-
- public List<String> searchWinners(List<Car> cars){
- List<String> winnerNames = new ArrayList<>();
- int maxPosition = searchMaxPosition(cars);
-
- for (Car car : cars){
- checkWinner(car, winnerNames, maxPosition);
- }
- return winnerNames;
- }
-
- public int searchMaxPosition(List<Car> cars){
- List<Integer> carPosition = new ArrayList<>();
-
- for (Car car : cars){
- carPosition.add(car.getPosition());
- }
- return Collections.max(carPosition);
- }
-
- public void checkWinner(Car car, List<String> winnerNames, int maxPosition){
- if (car.getPosition() == maxPosition){
- winnerNames.add(car.getName());
- }
- }
-
- public static List<Car> generateCars(String[] carNames) throws StringOutOfBoundsException{
- List<Car> cars = new ArrayList<>();
- for (String carName : carNames){
- checkNameLength(carName, cars);
- }
- return cars;
- }
-
- public static void checkNameLength(String carName, List<Car> cars) throws StringOutOfBoundsException {
- if(carName.length() > MAX_NAME_LENGTH){
- throw new StringOutOfBoundsException();
- }
- cars.add(new Car(carName));
- }
-} | Java | ๋ฉ์๋๋ช
์ ํ์๋ฅผ ํํํ๋ ๋์ฌ๋ก ์์ํ๋๊ฒ ์ด๋จ๊น์? |
@@ -1,66 +0,0 @@
-package controller;
-
-import model.Car;
-import util.RandomGenerator;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class RacingGame {
-
- public static final int CRITICAL_POINT = 5;
- public static final int MAX_NAME_LENGTH = 5;
-
- public void oneTrial(List<Car> cars){
- for (Car car : cars){
- check(car);
- }
- }
-
- public void check(Car car){
- if (RandomGenerator.randInt(10) > CRITICAL_POINT){
- car.move();
- }
- }
-
- public List<String> searchWinners(List<Car> cars){
- List<String> winnerNames = new ArrayList<>();
- int maxPosition = searchMaxPosition(cars);
-
- for (Car car : cars){
- checkWinner(car, winnerNames, maxPosition);
- }
- return winnerNames;
- }
-
- public int searchMaxPosition(List<Car> cars){
- List<Integer> carPosition = new ArrayList<>();
-
- for (Car car : cars){
- carPosition.add(car.getPosition());
- }
- return Collections.max(carPosition);
- }
-
- public void checkWinner(Car car, List<String> winnerNames, int maxPosition){
- if (car.getPosition() == maxPosition){
- winnerNames.add(car.getName());
- }
- }
-
- public static List<Car> generateCars(String[] carNames) throws StringOutOfBoundsException{
- List<Car> cars = new ArrayList<>();
- for (String carName : carNames){
- checkNameLength(carName, cars);
- }
- return cars;
- }
-
- public static void checkNameLength(String carName, List<Car> cars) throws StringOutOfBoundsException {
- if(carName.length() > MAX_NAME_LENGTH){
- throw new StringOutOfBoundsException();
- }
- cars.add(new Car(carName));
- }
-} | Java | check ๋ ๋ฌด์์ ์ฒดํฌํ๋ค๋๊ฑด์ง ์๊ธฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์~ ๋ด๋ถ์์๋ง ํ์ฉ๋๋ ํด๋์ค๋ฉด private ํค์๋๋ฅผ ๋ถ์ด๊ณ ๋ฉ์๋๋ช
์ ์ข ๋ ํ์ด์จ๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,8 @@
+package model;
+
+public class Movable implements State {
+ @Override
+ public int execute(int length) {
+ return length + 1;
+ }
+} | Java | ~able ์ interface ์ ์ ๋ฏธ์ฌ๋ก ํ์ฉ๋๋๋ฐ
๊ตฌํ์ฒด์ ๋ค์ด๋ฐ์ธ ๊ฒฝ์ฐ์๋ ์ด ํ์
์ด ๋ฌด์์ด ๊ฐ๋ฅํ์ง๋ณด๋ค๋ ๋ฌด์์ ํ๋์ง ๊ตฌ์ฒด์ ์ธ ๋จ์ด๋ฅผ ํ์ฉํ๋ฉด ์ด๋จ๊น์?
์๋ฅผ ๋ค์ด Forward ๋ Stop ์ฒ๋ผ์ |
@@ -2,22 +2,28 @@
public class Car{
- private String name;
- private int position = 0;
+ long number;
+ int length;
+ State state;
- public Car(String name){
- this.name = name;
+ public Car(long number) {
+ this.number = number;
+ length = 0;
}
- public String getName() {
- return name;
+ public int moveCount() {
+ return length;
}
- public int getPosition(){
- return position;
+ public long getCarNum() {
+ return number;
}
- public void move(){
- position++;
+ public void changeState(State cmd) {
+ state = cmd;
+ }
+
+ public void move() {
+ length = state.execute(length);
}
}
\ No newline at end of file | Java | ์๋์ฐจ์ ์์น๋ฅผ ๋ํ๋ด๋ ๋ณ์ ๊ฐ์๋ฐ position ์ ์ด๋จ๊น์? |
@@ -2,22 +2,28 @@
public class Car{
- private String name;
- private int position = 0;
+ long number;
+ int length;
+ State state;
- public Car(String name){
- this.name = name;
+ public Car(long number) {
+ this.number = number;
+ length = 0;
}
- public String getName() {
- return name;
+ public int moveCount() {
+ return length;
}
- public int getPosition(){
- return position;
+ public long getCarNum() {
+ return number;
}
- public void move(){
- position++;
+ public void changeState(State cmd) {
+ state = cmd;
+ }
+
+ public void move() {
+ length = state.execute(length);
}
}
\ No newline at end of file | Java | ์๋ฏธ๊ฐ ๋ถ๋ถ๋ช
ํ number ๋ณด๋ค๋ ์๋ณ์ด ๊ฐ๋ฅํ ๊ฐ์ ํํํ๋ id ๋ ๊ด์ฐฎ์ ๊ฒ ๊ฐ์ต๋๋ค ~ |
@@ -2,22 +2,28 @@
public class Car{
- private String name;
- private int position = 0;
+ long number;
+ int length;
+ State state;
- public Car(String name){
- this.name = name;
+ public Car(long number) {
+ this.number = number;
+ length = 0;
}
- public String getName() {
- return name;
+ public int moveCount() {
+ return length;
}
- public int getPosition(){
- return position;
+ public long getCarNum() {
+ return number;
}
- public void move(){
- position++;
+ public void changeState(State cmd) {
+ state = cmd;
+ }
+
+ public void move() {
+ length = state.execute(length);
}
}
\ No newline at end of file | Java | Num ๋ ์ค์๋ง์ด๋ number, no ๋ก ํต์ผํด๋ณด๋ฉด ์ด๋จ๊น์?
๊ทธ๋ฆฌ๊ณ getter ๋ get{field๋ช
} ์ด๋ผ๋ java bean ์ปจ๋ฒค์
์ด ์์ผ๋ ๋ฐ๋ฅด๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -2,22 +2,28 @@
public class Car{
- private String name;
- private int position = 0;
+ long number;
+ int length;
+ State state;
- public Car(String name){
- this.name = name;
+ public Car(long number) {
+ this.number = number;
+ length = 0;
}
- public String getName() {
- return name;
+ public int moveCount() {
+ return length;
}
- public int getPosition(){
- return position;
+ public long getCarNum() {
+ return number;
}
- public void move(){
- position++;
+ public void changeState(State cmd) {
+ state = cmd;
+ }
+
+ public void move() {
+ length = state.execute(length);
}
}
\ No newline at end of file | Java | count ๋ฅผ ์ด๋์ํจ๋ค ๋ผ๋ ๋ป์ ๋ฉ์๋๋ช
์ธ ๊ฒ ๊ฐ์์~ getLength ๋ ์ด๋จ๊น์? |
@@ -2,22 +2,28 @@
public class Car{
- private String name;
- private int position = 0;
+ long number;
+ int length;
+ State state;
- public Car(String name){
- this.name = name;
+ public Car(long number) {
+ this.number = number;
+ length = 0;
}
- public String getName() {
- return name;
+ public int moveCount() {
+ return length;
}
- public int getPosition(){
- return position;
+ public long getCarNum() {
+ return number;
}
- public void move(){
- position++;
+ public void changeState(State cmd) {
+ state = cmd;
+ }
+
+ public void move() {
+ length = state.execute(length);
}
}
\ No newline at end of file | Java | cmd ์ ์๋ฏธ๊ฐ ๋ฌด์์ผ๊น์? command? ์คํฐ๋ ๊ท์น์ ์ถ์ฝํ ๋จ์ด๋ฅผ ์ฌ์ฉํ์ง ๋ง์~ ์
๋๋ค |
@@ -2,22 +2,28 @@
public class Car{
- private String name;
- private int position = 0;
+ long number;
+ int length;
+ State state;
- public Car(String name){
- this.name = name;
+ public Car(long number) {
+ this.number = number;
+ length = 0;
}
- public String getName() {
- return name;
+ public int moveCount() {
+ return length;
}
- public int getPosition(){
- return position;
+ public long getCarNum() {
+ return number;
}
- public void move(){
- position++;
+ public void changeState(State cmd) {
+ state = cmd;
+ }
+
+ public void move() {
+ length = state.execute(length);
}
}
\ No newline at end of file | Java | state ์ ๊ธฐ๋ณธ๊ฐ์ด ์ธํ
๋์ด์์ง ์์๋ฐ, ์ด ํด๋์ค๊ฐ state ํจํด์ ์ ์ฉํ ๊ฒ์ธ์ง ๋ชจ๋ฅด๋ ์ฌ๋์ car.move() ๋ฅผ ์ฌ์ฉํ์ ๊ฒฝ์ฐ์ NPE ๊ฐ ๋ฐ์ํ์ง ์์๊น์~? |
@@ -0,0 +1,38 @@
+package controller;
+
+import function.RandomNumberMaker;
+import model.Car;
+import model.State;
+import model.Movable;
+import model.UnMovable;
+
+import java.util.List;
+
+public class CarController {
+
+ private static final int MOVE_CONDITION = 4;
+
+ public void registerCars(List<Car> cars, long len) {
+ for (int i = 0; i < len; i++) {
+ cars.add(new Car(i));
+ }
+ }
+
+ public void moveCar(List<Car> cars) {
+ for (Car car : cars) {
+ car.changeState(checkMoveOrStop(car));
+ car.move();
+ }
+ }
+
+ private State checkMoveOrStop(Car car) {
+ if (getRandomNumber() >= MOVE_CONDITION) {
+ return new Movable();
+ }
+ return new UnMovable();
+ }
+
+ private int getRandomNumber() {
+ return RandomNumberMaker.getRandomNumber();
+ }
+} | Java | ์ํ ํจํด์ ํ์ฉํ์ ๊ฒ ์ ์ ํ๋ค์~
๋ค๋ง ์ ์ง๊ณผ ์ ์ง ๋ฟ์ด๊ณ ์ํ์ ์ ์ด๊ฐ ์์ ๋ฟ๋๋ฌ ์กฐ๊ฑด๋ฌธ์ด ๋ณต์กํ์ง ์์ ์ํ์์ ์ ์ฉํ๊ธฐ์ ๊ณผํ์ง ์๋๋ผ๋ ๊ณ ๋ฏผ๋ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์.
move(int condition) ๋ฉ์๋์์ ๋ถ๊ธฐ์ณ์ ์ ์ง, ์ ์ง๋ฅผ ์ํํ๋ ๊ฒ๊ณผ,
์์ง์ ๊ด๋ จ ์ํ๋ฅผ ์ ์ํ๊ณ , CarController ์์ ๋ถ๊ธฐ์ณ์ condition ์ฒดํฌํ๊ณ ์์ง์ ๊ด๋ จ ์ํ๋ฅผ ๋ฐ๊ฟ์ฃผ๋๋ก ๊ตฌํํ ๋ค์, Car.move ์์ ๋ ๋ถ๊ธฐ๋ฅผ ํตํด ์ํ๊ฐ์ ์ฒดํฌํด์ ํ์๋ฅผ ๊ฒฐ์ ํ๋ ๊ฒ(์ ๊ฐ์ ํ ๊ฒ์ด ์ํ ํจํด ์ ์ฉ๋ฒ์ ์ธ๋ฐ)
๋ฌด์์ด ๋ ๋ณต์กํ๊ณ ์ฌํํ์ง ๊ณ ๋ฏผํด๋ณด์
๋ ์ข์ ๊ฒ ๊ฐ์์. ๊ฐ๋จํ๊ฒ ํ์๋ก ํ ๊ฒ์ ์ํ๋ก ๋ง๋ค์ด์ ํจํด์ ์ ์ฉ์ด ์ฝ๋์ ๋ชฉ์ ์ด ๋๊ฑด ์๋์ง๋ ๊ณ ๋ฏผํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ~
ํ์ต ๋ชฉ์ ์ผ๋ก๋ ์ข์ ์๋์ธ ๊ฒ ๊ฐ์์~ |
@@ -0,0 +1,5 @@
+package model;
+
+public interface State {
+ int execute(int length);
+} | Java | state ๋ฅผ ์ ์ฉํ ๋ค๋ฅธ ์ผ์ด์ค๋ฅผ ์๊ฐํด์ ์ข ๋ ๊ตฌ์ฒด์ ์ธ ์ธํฐํ์ด์ค๋ช
์ ์ฌ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์? MoveState? |
@@ -1,16 +1,54 @@
package view;
+import java.io.InputStream;
+import java.util.InputMismatchException;
import java.util.Scanner;
-public class InputView{
+public class InputView {
- public static String[] inputCarName(Scanner scanner){
- System.out.println("๊ฒฝ์ฃผํ ์ฐจ์ ์ด๋ฆ์ ์
๋ ฅํ์ธ์. (์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
- return scanner.nextLine().split(",");
+ Scanner sc;
+ private static final String CARS_COUNT = "์๋์ฐจ ๋์๋ ๋ช ๋ ์ธ๊ฐ์?";
+ private static final String PUT_NATURAL_NUMBER = "์์๊ฐ ์๋ ์์ฐ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์";
+ private static final String TRIAL_COUNT = "์๋ํ ํ์๋ ๋ช ํ ์ธ๊ฐ์?";
+ private static final String DO_NOT_PUT_STRING = "๋ฌธ์์ด์ด ์๋ ์์ฐ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์";
+
+ public InputView() {
+ sc = new Scanner(System.in);
+ }
+
+ public long inputTotalCarNum() {
+ System.out.println(CARS_COUNT);
+ long carCount = 0L;
+ try {
+ carCount = Long.parseLong(sc.nextLine());
+ if (carCount <= 0) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException exception) {
+ System.out.println(PUT_NATURAL_NUMBER);
+ return inputTotalCarNum();
+ } catch (InputMismatchException exception) {
+ System.out.println(DO_NOT_PUT_STRING);
+ return inputTotalCarNum();
+ }
+ return carCount;
}
- public static int inputNumberOfTrials(Scanner scanner){
- System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
- return scanner.nextInt();
+ public int inputTotalTrial() {
+ System.out.println(TRIAL_COUNT);
+ int trial = 0;
+ try {
+ trial = Integer.parseInt(sc.nextLine());
+ if (trial <= 0) {
+ throw new IllegalArgumentException();
+ }
+ } catch (IllegalArgumentException exception) {
+ System.out.println(PUT_NATURAL_NUMBER);
+ return inputTotalTrial();
+ } catch (InputMismatchException exception) {
+ System.out.println(DO_NOT_PUT_STRING);
+ return inputTotalTrial();
+ }
+ return trial;
}
-}
\ No newline at end of file
+} | Java | ์ฝ๋์ ํฌ๋งทํ
๋ ์ปจ๋ฒค์
์ ์ผ์ข
์
๋๋ค.
intellij ์ ์ฝ๋ ํฌ๋งทํ
๋จ์ถํค๋ฅผ ํ์ฉํด์ ์ ๋ ฌํด๋ณด์๋ฉด ์ด๋จ๊น์? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.