code
stringlengths
41
34.3k
lang
stringclasses
8 values
review
stringlengths
1
4.74k
@@ -0,0 +1,18 @@ +export interface PageInfoData { + title: string; + description: string; + src: string; +} + +export interface PageNavData { + id: string; + label: string; + icon?: string; + active: boolean; + subItems?: PageNavData[]; +} + +export interface FilteringData { + label: string; + value: string; +}
TypeScript
[p5] type ํŒŒ์ผ์„ ๋”ฐ๋กœ ๋ถ„๋ฆฌํ•ด์„œ ๊ฐ€๋…์„ฑ์ด ์ข‹์•„์กŒ๋„ค์š”~๐Ÿ˜
@@ -0,0 +1,16 @@ +export interface ReviewScore { + teamId: number; + gatheringId: number; + type: string; + averageScore: number; + oneStar: number; + twoStars: number; + threeStars: number; + fourStars: number; + fiveStars: number; +} + +export interface GetReviewsParams { + gatheringId?: string; + type?: '' | 'DALLAEMFIT' | 'OFFICE_STRETCHING' | 'MINDFULNESS' | 'WORKATION'; +}
TypeScript
[p5] type ํŒŒ์ผ์„ ๋”ฐ๋กœ ๋ถ„๋ฆฌํ•ด์„œ ๋ณด๊ธฐ ์ข‹์Šต๋‹ˆ๋‹ค~!๐Ÿฑ
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react"; import styled from "@emotion/styled"; import { css, Theme } from "@emotion/react"; import CheckIcon from "components/inputs/TextInput/CheckIcon"; -import { TConditionCheck } from "./types/TConditionCheck"; +import { TConditionCheck } from "components/inputs/TextInput/types/TConditionCheck"; interface Props { name?: string; @@ -12,6 +12,7 @@ interface Props { conditionList?: string[]; conditionCheckList?: TConditionCheck[]; multiline?: boolean; + height?: string; onTextChange?: (value: string, isValid: boolean) => void; } @@ -23,6 +24,7 @@ const TextInput: React.FC<Props> = ({ conditionList, conditionCheckList, multiline = false, + height, onTextChange, }) => { const [status, setStatus] = useState(value === "" ? "default" : "success"); // default / success / invalid / focus @@ -76,7 +78,7 @@ const TextInput: React.FC<Props> = ({ }, [enteredValue, status, onTextChange]); return ( - <EmotionWrapper> + <EmotionWrapper height={height}> {label && <span className="label">{label}</span>} {conditionList && ( <div className="spanList"> @@ -179,6 +181,7 @@ const EmotionWrapper = styled.div<Props>` ${({ theme }) => commonStyles(theme)}; position: relative; resize: none; + height: ${({ height }) => height ?? "auto"}; } `;
Unknown
์‚ฌ์†Œํ•˜์ง€๋งŒ `height ?? "auto"` ๋„ ๊ดœ์ฐฎ์„ ๊ฒƒ ๊ฐ™์•„์š”!
@@ -0,0 +1,170 @@ +import styled from "@emotion/styled"; +import IconStarFilled from "components/rating/icons/IconStarFilled"; +import IconStarHalf from "components/rating/icons/IconStarHalf"; +import IconStarOutlined from "components/rating/icons/IconStarOutlined"; +import { HTMLAttributes, useEffect, useState, useRef, useCallback } from "react"; + +interface Props extends HTMLAttributes<HTMLDivElement> { + value: number; // 0 ~ 5 ์‚ฌ์ด์˜ ์ˆซ์ž, ๋ณ„ ๊ฐœ์ˆ˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด 0.5 ๋‹จ์œ„๋กœ ๋ฐ˜์˜ฌ๋ฆผ + isInput?: boolean; // input ๊ธฐ๋Šฅ์„ ํ•˜๋„๋ก ํ•  ์ง€ ์„ค์ • + onSelectedValueChange?: (value: number) => void; +} + +const Rating = ({ value, isInput = false, onSelectedValueChange, ...props }: Props) => { + const [selectedValue, setSelectedValue] = useState<number>(value); + const isMouseDown = useRef<boolean>(false); + const containerRef = useRef<HTMLDivElement>(null); + + // round value to the nearest 0.5 + const startCount = Math.round(selectedValue * 2) / 2; + + const filledStarCount = Math.floor(startCount); + const hasHalfStar = startCount % 1 !== 0; + const emptyStarCount = 5 - filledStarCount - (hasHalfStar ? 1 : 0); + + useEffect(() => { + if (onSelectedValueChange) { + onSelectedValueChange(selectedValue); + } + }, [selectedValue, onSelectedValueChange]); + + const handleOnClick = (event: React.MouseEvent, index: number) => { + const clickX = event.nativeEvent.clientX; // ํด๋ฆญํ•œ ์œ„์น˜์˜ X ์ขŒํ‘œ + + // IconStar... ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ํด๋ฆญํ•œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํŒ๋ณ„ + const containerRect = event.currentTarget.getBoundingClientRect(); + const containerCenterX = (containerRect.left + containerRect.right) / 2; + + if (clickX < containerCenterX) { + setSelectedValue(index + 0.5); + } else { + setSelectedValue(index + 1); + } + }; + + const calculateScore = useCallback((currentX: number) => { + const container = containerRef.current; + if (container) { + const unitSize = container.getBoundingClientRect().width / 10; + const relativeX = currentX - container.getBoundingClientRect().x; + if (relativeX <= 0) setSelectedValue(0.5); + else { + const score = (Math.floor(relativeX / unitSize) + 1) * 0.5; + score > 5 ? setSelectedValue(5) : setSelectedValue(score); + } + } + }, []); + + const handleOnMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = true; + }, []); + + const handleOnMouseLeave = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = false; + }, []); + + const handleOnMouseMove = useCallback( + (event: React.MouseEvent) => { + if (isMouseDown.current) calculateScore(event.clientX); + }, + [calculateScore] + ); + + const handleOnMouseUp = useCallback((event: React.MouseEvent) => { + isMouseDown.current = false; + }, []); + + // For mobile view + const handleOnTouchMove = useCallback( + (event: React.TouchEvent) => { + calculateScore(event.changedTouches[0].clientX); + }, + [calculateScore] + ); + + return ( + <EmotionWrapper isInput={isInput} {...props}> + <div + className="star-container" + onMouseDown={handleOnMouseDown} + onMouseUp={handleOnMouseUp} + onMouseMove={handleOnMouseMove} + onMouseLeave={handleOnMouseLeave} + onTouchMove={handleOnTouchMove} + ref={containerRef} + > + {Array.from({ length: filledStarCount }, (_, index) => + isInput ? ( + <IconStarFilled + key={index} + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, index)} + /> + ) : ( + <IconStarFilled key={index} /> + ) + )} + {hasHalfStar && + (isInput ? ( + <IconStarHalf + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, filledStarCount)} + /> + ) : ( + <IconStarHalf /> + ))} + {Array.from({ length: emptyStarCount }, (_, index) => + isInput ? ( + <IconStarOutlined + key={index} + size={40} + onClick={(event: React.MouseEvent) => + handleOnClick(event, filledStarCount + index + (hasHalfStar ? 1 : 0)) + } + /> + ) : ( + <IconStarOutlined key={index} /> + ) + )} + </div> + {isInput ? ( + <div> + <span className="rating-value-selected">{selectedValue}</span> + <span className="rating-full-marks"> / 5</span> + </div> + ) : ( + <p className="rating-value">{value}</p> + )} + </EmotionWrapper> + ); +}; + +export default Rating; + +const EmotionWrapper = styled.div<{ isInput: boolean }>` + display: flex; + align-items: center; + ${({ isInput }) => (isInput ? "flex-direction: column; gap: 20px;" : "column-gap: 4px;")} + + .star-container { + display: flex; + column-gap: 2px; + } + + color: ${({ theme }) => theme.color.gray400}; + + .rating-full-marks { + font-size: 16px; + font-weight: 300; + } + + .rating-value-selected { + font-size: 32px; + font-weight: 500; + color: ${({ theme }) => theme.color.gray700}; + } + + .rating-value { + font-size: 12px; + } +`;
Unknown
์˜ค ์ด ์ปดํฌ๋„ŒํŠธ๋Š” ์•„์ง Rating์ชฝ์ด ๋จธ์ง€ ๋˜์ง€ ์•Š์•„์„œ ์ผ๋ถ€ ๋‚ด์šฉ์„ ๊ทธ๋Œ€๋กœ ๊ฐ€์ง€๊ณ  ์˜ค์‹  ๋ถ€๋ถ„์ธ๊ฐ€์šฉ~? (+ `isInput` ๋ชจ๋“œ ์ถ”๊ฐ€๋กœ์š”?)
@@ -0,0 +1,170 @@ +import styled from "@emotion/styled"; +import IconStarFilled from "components/rating/icons/IconStarFilled"; +import IconStarHalf from "components/rating/icons/IconStarHalf"; +import IconStarOutlined from "components/rating/icons/IconStarOutlined"; +import { HTMLAttributes, useEffect, useState, useRef, useCallback } from "react"; + +interface Props extends HTMLAttributes<HTMLDivElement> { + value: number; // 0 ~ 5 ์‚ฌ์ด์˜ ์ˆซ์ž, ๋ณ„ ๊ฐœ์ˆ˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด 0.5 ๋‹จ์œ„๋กœ ๋ฐ˜์˜ฌ๋ฆผ + isInput?: boolean; // input ๊ธฐ๋Šฅ์„ ํ•˜๋„๋ก ํ•  ์ง€ ์„ค์ • + onSelectedValueChange?: (value: number) => void; +} + +const Rating = ({ value, isInput = false, onSelectedValueChange, ...props }: Props) => { + const [selectedValue, setSelectedValue] = useState<number>(value); + const isMouseDown = useRef<boolean>(false); + const containerRef = useRef<HTMLDivElement>(null); + + // round value to the nearest 0.5 + const startCount = Math.round(selectedValue * 2) / 2; + + const filledStarCount = Math.floor(startCount); + const hasHalfStar = startCount % 1 !== 0; + const emptyStarCount = 5 - filledStarCount - (hasHalfStar ? 1 : 0); + + useEffect(() => { + if (onSelectedValueChange) { + onSelectedValueChange(selectedValue); + } + }, [selectedValue, onSelectedValueChange]); + + const handleOnClick = (event: React.MouseEvent, index: number) => { + const clickX = event.nativeEvent.clientX; // ํด๋ฆญํ•œ ์œ„์น˜์˜ X ์ขŒํ‘œ + + // IconStar... ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ํด๋ฆญํ•œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํŒ๋ณ„ + const containerRect = event.currentTarget.getBoundingClientRect(); + const containerCenterX = (containerRect.left + containerRect.right) / 2; + + if (clickX < containerCenterX) { + setSelectedValue(index + 0.5); + } else { + setSelectedValue(index + 1); + } + }; + + const calculateScore = useCallback((currentX: number) => { + const container = containerRef.current; + if (container) { + const unitSize = container.getBoundingClientRect().width / 10; + const relativeX = currentX - container.getBoundingClientRect().x; + if (relativeX <= 0) setSelectedValue(0.5); + else { + const score = (Math.floor(relativeX / unitSize) + 1) * 0.5; + score > 5 ? setSelectedValue(5) : setSelectedValue(score); + } + } + }, []); + + const handleOnMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = true; + }, []); + + const handleOnMouseLeave = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = false; + }, []); + + const handleOnMouseMove = useCallback( + (event: React.MouseEvent) => { + if (isMouseDown.current) calculateScore(event.clientX); + }, + [calculateScore] + ); + + const handleOnMouseUp = useCallback((event: React.MouseEvent) => { + isMouseDown.current = false; + }, []); + + // For mobile view + const handleOnTouchMove = useCallback( + (event: React.TouchEvent) => { + calculateScore(event.changedTouches[0].clientX); + }, + [calculateScore] + ); + + return ( + <EmotionWrapper isInput={isInput} {...props}> + <div + className="star-container" + onMouseDown={handleOnMouseDown} + onMouseUp={handleOnMouseUp} + onMouseMove={handleOnMouseMove} + onMouseLeave={handleOnMouseLeave} + onTouchMove={handleOnTouchMove} + ref={containerRef} + > + {Array.from({ length: filledStarCount }, (_, index) => + isInput ? ( + <IconStarFilled + key={index} + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, index)} + /> + ) : ( + <IconStarFilled key={index} /> + ) + )} + {hasHalfStar && + (isInput ? ( + <IconStarHalf + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, filledStarCount)} + /> + ) : ( + <IconStarHalf /> + ))} + {Array.from({ length: emptyStarCount }, (_, index) => + isInput ? ( + <IconStarOutlined + key={index} + size={40} + onClick={(event: React.MouseEvent) => + handleOnClick(event, filledStarCount + index + (hasHalfStar ? 1 : 0)) + } + /> + ) : ( + <IconStarOutlined key={index} /> + ) + )} + </div> + {isInput ? ( + <div> + <span className="rating-value-selected">{selectedValue}</span> + <span className="rating-full-marks"> / 5</span> + </div> + ) : ( + <p className="rating-value">{value}</p> + )} + </EmotionWrapper> + ); +}; + +export default Rating; + +const EmotionWrapper = styled.div<{ isInput: boolean }>` + display: flex; + align-items: center; + ${({ isInput }) => (isInput ? "flex-direction: column; gap: 20px;" : "column-gap: 4px;")} + + .star-container { + display: flex; + column-gap: 2px; + } + + color: ${({ theme }) => theme.color.gray400}; + + .rating-full-marks { + font-size: 16px; + font-weight: 300; + } + + .rating-value-selected { + font-size: 32px; + font-weight: 500; + color: ${({ theme }) => theme.color.gray700}; + } + + .rating-value { + font-size: 12px; + } +`;
Unknown
์˜ค... ๋›ฐ์–ด๋‚œ ์‚ฌ์šฉ์„ฑ์ผ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜† ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,120 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Rating from "components/rating/Rating"; +import IconEditFilledWhite from "components/icons/IconEditFilledWhite"; +import Link from "next/link"; +import dayjs from "dayjs"; + +interface Props { + restaurantId: string; + reviewId: number; + userId: number; + score: number; + content: string; + createdAt: Date; +} + +const ReviewItem: React.FC<Props> = ({ + restaurantId, + reviewId, + userId, + score, + content, + createdAt, +}) => { + const [isExpanded, setIsExpanded] = useState(false); + + const toggleExpansion = () => { + setIsExpanded((isExpanded) => !isExpanded); + }; + + const editLink = `/restaurants/${restaurantId}/review/${reviewId}/edit`; + const displayContent = + content.length > 100 && !isExpanded ? content.slice(0, 100) + "..." : content; + + /** + * TODO 1: userId๋กœ userInfo ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userName = "ํ™๊ธธ๋™"; + const ImgSrc = "/images/profile-image-default-1.png"; + + /** + * TODO 2: ํ˜„์žฌ ๋กœ๊ทธ์ธ๋œ ์œ ์ € ์•„์ด๋”” ๊ฐ€์ ธ์˜ค๊ธฐ (๋ฆฌ๋ทฐ ์ˆ˜์ • ๊ถŒํ•œ ํ™•์ธ์šฉ) + */ + const currentUserId = 1; + + return ( + <EmotionWrapper> + <div className="user-info-score-div"> + <div className="user-info-div"> + <Image src={ImgSrc} alt={"์œ ์ € ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"} width={30} height={30} /> + <span className="user-name">{userName}</span> + <span className="date">{dayjs(createdAt).format("YY/MM/DD")}</span> + {currentUserId === userId && ( + <Link href={editLink}> + <IconEditFilledWhite /> + </Link> + )} + </div> + <Rating value={score} /> + </div> + <div className="content-div"> + <span>{displayContent}</span> + {content.length > 100 && ( + <button onClick={toggleExpansion}>{isExpanded ? "์ ‘๊ธฐ" : "๋” ๋ณด๊ธฐ"}</button> + )} + </div> + </EmotionWrapper> + ); +}; + +export default ReviewItem; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + min-height: 90px; + width: 100%; + background-color: ${({ theme }) => theme.color.white}; + border-radius: 6px; + + padding: 10px; + + .user-info-score-div { + display: flex; + justify-content: space-between; + align-items: center; + + .user-info-div { + display: flex; + gap: 8px; + justify-content: center; + align-items: center; + + span.user-name { + font-size: 16px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + span.date { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray300}; + } + } + } + + .content-div { + span { + line-height: 1.5; + color: ${({ theme }) => theme.color.gray400}; + flex-grow: 1; + margin-right: 8px; + } + + button { + color: ${({ theme }) => theme.color.gray300}; + } + } +`;
Unknown
์˜ค..! ์ €ํฌ๊ฐ€ `dayjs` ๋„ ์“ฐ๊ณ  ์žˆ์–ด์„œ ํ™œ์šฉํ•ด๋ณด์‹œ๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ์ด๋Ÿฐ ๊ฒฝ์šฐ ```tsx import dayjs from 'dayjs'; const formattedDate= dayjs(date).format("YY/MM/DD") ``` ์ด๋ ‡๊ฒŒ ํ™œ์šฉํ•ด๋ณผ ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~
@@ -0,0 +1,120 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Rating from "components/rating/Rating"; +import IconEditFilledWhite from "components/icons/IconEditFilledWhite"; +import Link from "next/link"; +import dayjs from "dayjs"; + +interface Props { + restaurantId: string; + reviewId: number; + userId: number; + score: number; + content: string; + createdAt: Date; +} + +const ReviewItem: React.FC<Props> = ({ + restaurantId, + reviewId, + userId, + score, + content, + createdAt, +}) => { + const [isExpanded, setIsExpanded] = useState(false); + + const toggleExpansion = () => { + setIsExpanded((isExpanded) => !isExpanded); + }; + + const editLink = `/restaurants/${restaurantId}/review/${reviewId}/edit`; + const displayContent = + content.length > 100 && !isExpanded ? content.slice(0, 100) + "..." : content; + + /** + * TODO 1: userId๋กœ userInfo ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userName = "ํ™๊ธธ๋™"; + const ImgSrc = "/images/profile-image-default-1.png"; + + /** + * TODO 2: ํ˜„์žฌ ๋กœ๊ทธ์ธ๋œ ์œ ์ € ์•„์ด๋”” ๊ฐ€์ ธ์˜ค๊ธฐ (๋ฆฌ๋ทฐ ์ˆ˜์ • ๊ถŒํ•œ ํ™•์ธ์šฉ) + */ + const currentUserId = 1; + + return ( + <EmotionWrapper> + <div className="user-info-score-div"> + <div className="user-info-div"> + <Image src={ImgSrc} alt={"์œ ์ € ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"} width={30} height={30} /> + <span className="user-name">{userName}</span> + <span className="date">{dayjs(createdAt).format("YY/MM/DD")}</span> + {currentUserId === userId && ( + <Link href={editLink}> + <IconEditFilledWhite /> + </Link> + )} + </div> + <Rating value={score} /> + </div> + <div className="content-div"> + <span>{displayContent}</span> + {content.length > 100 && ( + <button onClick={toggleExpansion}>{isExpanded ? "์ ‘๊ธฐ" : "๋” ๋ณด๊ธฐ"}</button> + )} + </div> + </EmotionWrapper> + ); +}; + +export default ReviewItem; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + min-height: 90px; + width: 100%; + background-color: ${({ theme }) => theme.color.white}; + border-radius: 6px; + + padding: 10px; + + .user-info-score-div { + display: flex; + justify-content: space-between; + align-items: center; + + .user-info-div { + display: flex; + gap: 8px; + justify-content: center; + align-items: center; + + span.user-name { + font-size: 16px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + span.date { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray300}; + } + } + } + + .content-div { + span { + line-height: 1.5; + color: ${({ theme }) => theme.color.gray400}; + flex-grow: 1; + margin-right: 8px; + } + + button { + color: ${({ theme }) => theme.color.gray300}; + } + } +`;
Unknown
`className` ์€ ๋”ฐ๋กœ ์ปจ๋ฒค์…˜์ด ์žˆ๋Š” ๊ฒƒ์€ ์•„๋‹ˆ์ง€๋งŒ ๋Œ€๋ถ€๋ถ„ kebab case ๋ฅผ ์ ์šฉํ•˜๊ณ  ์žˆ์–ด `user-info-score-div` ์ด๋Ÿฐ ์‹์€ ์–ด๋–จ๊นŒ์š”~?
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
์ด `restaurantId` ๊ฐ€ `string[]` ๋„ ๋ฐ›๊ฒŒ ํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”~?
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
์•— ์—ฌ๊ธฐ๋„ `over-title-div` ์ด๋ ‡๊ฒŒ ๊ฐ€ ์–ด๋–จ๊นŒ์š” !
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
์—ฌ๊ธฐ๋Š” ์ด ํŽ˜์ด์ง€์—์„œ ๊ฑฐ์˜ ๋ฉ”์ธ ๊ธ‰ ์ œ๋ชฉ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ `<h1 />` ํƒœ๊ทธ ์ •๋„๋กœ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋–จ๊นŒ์š”~? ์•„๋ž˜๋Š” ๋ ˆํผ๋Ÿฐ์Šค์šฉ [ํŽ˜์ด์Šค๋ถ] ์˜ ๋ฉค๋ฒ„ ์ƒ์„ธ ํŽ˜์ด์ง€์ธ๋ฐ ์„œ๋น„์Šค ์ œ๋ชฉ (์ €ํฌ๋กœ ์น˜๋ฉด '์ฉ์ฉ๋Œ€ํ•™') ์€ `<h2/>` ํƒœ๊ทธ, ์œ ์ € ์ด๋ฆ„์€ `<h1/>` ์œผ๋กœ ์‚ฌ์šฉํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €ํฌ๋„ ์˜คํžˆ๋ ค ์ƒ๋‹จ navbar ์—์„œ [์ฉ์ฉ๋Œ€ํ•™] ์„ `<h2 />` ๋กœ ๋ฐ”๊พธ๊ณ  ๋ง›์ง‘์ด๋‚˜ ๋‹จ์ฒด ์ƒ์„ธ ํŽ˜์ด์ง€์—์„œ ๋ง›์ง‘์ด๋ฆ„, ๋‹จ์ฒด์ด๋ฆ„์€ `<h1/>` ์— ๋„ฃ์œผ๋ฉด semantic tagging ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ SEO ์—๋„ ๋„์›€์ด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! cc. @hoon5083 ![image](https://github.com/SystemConsultantGroup/foodhub-frontend/assets/86560973/31909b28-e965-4157-9662-f9cc6f8ddd4c) ![image](https://github.com/SystemConsultantGroup/foodhub-frontend/assets/86560973/9ba5c818-272f-4814-afe4-7d66dd4ed369)
@@ -0,0 +1,85 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Button from "components/button/Button"; + +interface Props { + imgSrcList: string[]; +} + +const RestaurantDetailImgSection: React.FC<Props> = ({ imgSrcList }) => { + const [currentImgIndex, setCurrentImgIndex] = useState(0); + + const handleOnClickRight = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == imgSrcList.length - 1 ? 0 : currentImgIndex + 1 + ); + }; + + const handleOnClickLeft = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == 0 ? imgSrcList.length - 1 : currentImgIndex - 1 + ); + }; + + return ( + <EmotionWrapper> + {imgSrcList.length === 0 ? ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ๊ธฐ๋ณธ ์ด๋ฏธ์ง€" + src={"/images/defaults/default-restaurant-image.png"} + fill + /> + ) : ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ์ด๋ฏธ์ง€" + src={imgSrcList[currentImgIndex]} + fill + /> + )} + <Button + onClick={handleOnClickLeft} + variant="text" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + left: "0px", + }} + > + &lt; + </Button> + <Button + onClick={handleOnClickRight} + variant="text" + className="right-button" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + right: "0px", + }} + > + &gt; + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailImgSection; + +const EmotionWrapper = styled.div` + position: relative; + width: 100%; + height: 120px; + overflow: hidden; + margin-bottom: 10px; + + .restaurant-img { + z-index: 1; + object-fit: cover; + position: absolute; + } +`;
Unknown
ํ˜น์‹œ ์ด ๋ฒ„ํŠผ์€ ํ™”๋ฉด์ƒ์˜ ์–ด๋А ๋ถ€๋ถ„์ธ๊ฐ€์šฉ~? ๋กœ์ปฌ์—์„œ ๋Œ๋ ธ์„ ๋•Œ ๋…ธ์ถœ๋˜์ง€ ์•Š๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ![image](https://github.com/SystemConsultantGroup/foodhub-frontend/assets/86560973/c705c6dd-3624-40d6-8639-8764bd45609d)
@@ -0,0 +1,70 @@ +import styled from "@emotion/styled"; +import RestaurantDetailImgSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailImgSection"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import RestaurantDetailInfoSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailInfoSection"; +import RestaurantDetailReviewSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailReviewSection"; +import Divider from "components/divider/Divider"; +import { restaurant } from "feature/restaurants/restaurantsDetail/mockups/restaurant"; +import { reviewPage1 } from "feature/restaurants/restaurantsDetail/mockups/reviews"; + +interface Props { + restaurantId: string; +} + +const ViewRestaurantDetail: React.FC<Props> = ({ restaurantId }) => { + /** + * TODO 1: ์‚ฌ์šฉ์ž ๊ถŒํ•œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userAuth = 0; + + /** + * TODO 2: ๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + /** + * TODO3: ๋ง›์ง‘์˜ ๋ชจ๋“  ๋ฆฌ๋ทฐ ์กฐํšŒํ•˜๊ธฐ + * - totalScore, totalPages ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ Read Reviews API ํ˜ธ์ถœ + * - ๋ฆฌ๋ทฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ 404 ์—๋Ÿฌ ๋ฐ˜ํ™˜? + */ + const { totalScore, totalCount, totalPages, scoreStatistics } = reviewPage1; + + return ( + <EmotionWrapper> + <RestaurantDetailImgSection imgSrcList={restaurant.imgSrcList} /> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + userAuth={userAuth} + restaurantName={restaurant.name} + restaurantAddress={restaurant.address} + organizationName={restaurant.organizationName} + link={restaurant.link} + /> + <RestaurantDetailInfoSection + restaurantId={restaurantId} + comment={restaurant.comment} + orderTip={restaurant.orderTip} + capacity={restaurant.capacity} + recommendedMenus={restaurant.recommnededMenus} + category={restaurant.category} + delivery={restaurant.delivery} + openingHour={restaurant.openingHour} + tags={restaurant.tags} + totalScore={totalScore} + totalCount={totalCount} + /> + <Divider /> + <RestaurantDetailReviewSection + restaurantId={restaurantId} + userAuth={userAuth} + totalScore={totalScore} + totalCount={totalCount} + totalPages={totalPages} + scoreStatistics={scoreStatistics} + /> + </EmotionWrapper> + ); +}; + +export default ViewRestaurantDetail; + +const EmotionWrapper = styled.div``;
Unknown
์ž„์‹œ ์ฝ”๋“œ์ธ๊ฐ€์š”!? ๊ฐ์ฒด๊ตฌ์กฐ ๋ถ„ํ•ด๋กœ ๋ฐ›์•„์˜ค๋Š” ๊ฒƒ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ```tsx const { totalScore, totalCount, totalPages, scoreStatistics } = reviewPage1 ```
@@ -0,0 +1,137 @@ +import styled from "@emotion/styled"; +import Rating from "components/rating/Rating"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import Button from "components/button/Button"; +import TextInput from "components/inputs/TextInput/TextInput"; +import { useState, useCallback } from "react"; +import Checkbox from "components/checkbox/Checkbox"; +import { REVIEW_CONTENT_MAX_VALUE, REVIEW_CONTENT_MIN_VALUE } from "constant/limit"; + +interface Props { + restaurantId: string; + isEditMode: boolean; + reviewId?: string | number | string[]; + score?: number; + content?: string; +} + +const RestaurantsReviewForm: React.FC<Props> = ({ restaurantId, score = 0, content = "" }) => { + const [selectedScroe, setSelectedScore] = useState<number>(score); + const [enteredContent, setEnteredContent] = useState<string>(content); + const [isPublic, setIsPublic] = useState<boolean>(true); + + /** + * TODO: restaurantId๋กœ ๋ง›์ง‘ ์ƒ์„ธ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + const contentMaxLengthCheck = { + condition: (content: string) => { + return content.length <= REVIEW_CONTENT_MAX_VALUE; + }, + messageOnError: "500์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const contentMinLengthCheck = { + condition: (content: string) => { + return content.length >= REVIEW_CONTENT_MIN_VALUE; + }, + messageOnError: "20์ž ์ด์ƒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const handleScoreChange = useCallback((value: number) => { + setSelectedScore(value); + }, []); + + const handleContentChange = useCallback((value: string) => { + setEnteredContent(value); + }, []); + + const handleSetIsPublic = useCallback((value: string) => { + if (value === "true") setIsPublic(true); + else setIsPublic(false); + }, []); + + const handleOnSubmit = () => { + console.log("์ ์ˆ˜ : ", selectedScroe); + console.log("๋ฆฌ๋ทฐ ๋‚ด์šฉ : ", enteredContent); + console.log("๊ณต๊ฐœ ์—ฌ๋ถ€ : ", isPublic); + }; + + return ( + <EmotionWrapper> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + restaurantName="๋ด‰์ˆ˜์œก" + restaurantAddress="๊ฒฝ๊ธฐ๋„ ์ˆ˜์›์‹œ ์ฒœ์ฒœ๋™" + organizationName="์‹œ์Šคํ…œ ์ปจ์„คํ„ดํŠธ ๊ทธ๋ฃน" + isMain={false} + /> + <Rating value={score} isInput onSelectedValueChange={handleScoreChange} /> + <TextInput + label="๋ฆฌ๋ทฐ ๋‚ด์šฉ" + placeholder="๋ง›์ง‘์— ๋Œ€ํ•œ ์†”์งํ•œ ํ‰์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!" + multiline + value={content} + onTextChange={handleContentChange} + conditionCheckList={[contentMaxLengthCheck, contentMinLengthCheck]} + height="150px" + /> + <div className="right-alignment"> + <p className="label">๋ฆฌ๋ทฐ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.</p> + <Checkbox.Group + checkedList={[String(isPublic)]} + setCheckedItem={(value) => handleSetIsPublic(value)} + > + <Checkbox.Item value="true">๊ณต๊ฐœ</Checkbox.Item> + <Checkbox.Item value="false">๋น„๊ณต๊ฐœ</Checkbox.Item> + </Checkbox.Group> + {!isPublic && ( + <p className="description">๋น„๊ณต๊ฐœ๋กœ ์„ค์ •์‹œ, ๋‹จ์ฒด ์™ธ๋ถ€์ธ์—๊ฒŒ๋Š” ๋ฆฌ๋ทฐ๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</p> + )} + </div> + <Button onClick={handleOnSubmit} fullWidth> + ์ž‘์„ฑ ์™„๋ฃŒ + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantsReviewForm; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 30px; + + textarea { + font-size: 16px; + } + + button { + font-size: 16px; + } + + .right-alignment { + margin-top: -15px; + width: 100%; + } + + .label { + margin-top: 20px; + margin-bottom: 10px; + margin-left: 2px; + font-weight: 500; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + .description { + margin-top: 5px; + margin-left: 2px; + font-size: 14px; + font-weight: 200; + color: ${({ theme }) => theme.color.gray600}; + } +`;
Unknown
์˜คํƒ€๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,137 @@ +import styled from "@emotion/styled"; +import Rating from "components/rating/Rating"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import Button from "components/button/Button"; +import TextInput from "components/inputs/TextInput/TextInput"; +import { useState, useCallback } from "react"; +import Checkbox from "components/checkbox/Checkbox"; +import { REVIEW_CONTENT_MAX_VALUE, REVIEW_CONTENT_MIN_VALUE } from "constant/limit"; + +interface Props { + restaurantId: string; + isEditMode: boolean; + reviewId?: string | number | string[]; + score?: number; + content?: string; +} + +const RestaurantsReviewForm: React.FC<Props> = ({ restaurantId, score = 0, content = "" }) => { + const [selectedScroe, setSelectedScore] = useState<number>(score); + const [enteredContent, setEnteredContent] = useState<string>(content); + const [isPublic, setIsPublic] = useState<boolean>(true); + + /** + * TODO: restaurantId๋กœ ๋ง›์ง‘ ์ƒ์„ธ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + const contentMaxLengthCheck = { + condition: (content: string) => { + return content.length <= REVIEW_CONTENT_MAX_VALUE; + }, + messageOnError: "500์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const contentMinLengthCheck = { + condition: (content: string) => { + return content.length >= REVIEW_CONTENT_MIN_VALUE; + }, + messageOnError: "20์ž ์ด์ƒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const handleScoreChange = useCallback((value: number) => { + setSelectedScore(value); + }, []); + + const handleContentChange = useCallback((value: string) => { + setEnteredContent(value); + }, []); + + const handleSetIsPublic = useCallback((value: string) => { + if (value === "true") setIsPublic(true); + else setIsPublic(false); + }, []); + + const handleOnSubmit = () => { + console.log("์ ์ˆ˜ : ", selectedScroe); + console.log("๋ฆฌ๋ทฐ ๋‚ด์šฉ : ", enteredContent); + console.log("๊ณต๊ฐœ ์—ฌ๋ถ€ : ", isPublic); + }; + + return ( + <EmotionWrapper> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + restaurantName="๋ด‰์ˆ˜์œก" + restaurantAddress="๊ฒฝ๊ธฐ๋„ ์ˆ˜์›์‹œ ์ฒœ์ฒœ๋™" + organizationName="์‹œ์Šคํ…œ ์ปจ์„คํ„ดํŠธ ๊ทธ๋ฃน" + isMain={false} + /> + <Rating value={score} isInput onSelectedValueChange={handleScoreChange} /> + <TextInput + label="๋ฆฌ๋ทฐ ๋‚ด์šฉ" + placeholder="๋ง›์ง‘์— ๋Œ€ํ•œ ์†”์งํ•œ ํ‰์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!" + multiline + value={content} + onTextChange={handleContentChange} + conditionCheckList={[contentMaxLengthCheck, contentMinLengthCheck]} + height="150px" + /> + <div className="right-alignment"> + <p className="label">๋ฆฌ๋ทฐ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.</p> + <Checkbox.Group + checkedList={[String(isPublic)]} + setCheckedItem={(value) => handleSetIsPublic(value)} + > + <Checkbox.Item value="true">๊ณต๊ฐœ</Checkbox.Item> + <Checkbox.Item value="false">๋น„๊ณต๊ฐœ</Checkbox.Item> + </Checkbox.Group> + {!isPublic && ( + <p className="description">๋น„๊ณต๊ฐœ๋กœ ์„ค์ •์‹œ, ๋‹จ์ฒด ์™ธ๋ถ€์ธ์—๊ฒŒ๋Š” ๋ฆฌ๋ทฐ๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</p> + )} + </div> + <Button onClick={handleOnSubmit} fullWidth> + ์ž‘์„ฑ ์™„๋ฃŒ + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantsReviewForm; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 30px; + + textarea { + font-size: 16px; + } + + button { + font-size: 16px; + } + + .right-alignment { + margin-top: -15px; + width: 100%; + } + + .label { + margin-top: 20px; + margin-bottom: 10px; + margin-left: 2px; + font-weight: 500; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + .description { + margin-top: 5px; + margin-left: 2px; + font-size: 14px; + font-weight: 200; + color: ${({ theme }) => theme.color.gray600}; + } +`;
Unknown
์š” ๊ฐ’์„ `src/constant/limit.ts` ์—์„œ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์š”~? ํ•˜๋‚˜์˜ ํŒŒ์ผ์—์„œ ๊ฐ ์ตœ๋Œ€๊ธธ์ด๋‚˜ ์ตœ์†Œ๊ธธ์ด ์กฐ๊ฑด ๋“ฑ์„ ๊ด€๋ฆฌํ•ด์ฃผ๋ฉด ๋‚˜์ค‘์— ์ด๋ฅผ ์ฆ๊ฐ€ ๋˜๋Š” ๊ฐ์†Œ์‹œํ‚ฌ ์ผ์ด ์žˆ์„ ๋•Œ ๋Œ€์‘ํ•˜๊ธฐ ์šฉ์ดํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,18 @@ +import styled from "@emotion/styled"; +import RestaurantsReviewForm from "feature/restaurants/restaurantsReview/components/form/RestaurantsReviewForm"; + +interface Props { + restaurantId: string; +} + +const ViewRestaurantReviewCreate: React.FC<Props> = ({ restaurantId }) => { + return ( + <EmotionWrapper> + <RestaurantsReviewForm restaurantId={restaurantId} isEditMode={false} /> + </EmotionWrapper> + ); +}; + +export default ViewRestaurantReviewCreate; + +const EmotionWrapper = styled.div``;
Unknown
์—ฌ๊ธฐ์„œ๋„ `string []` ์„ ํŠน๋ณ„ํžˆ ์ถ”๊ฐ€ํ•ด์ฃผ์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”~?
@@ -0,0 +1,170 @@ +import styled from "@emotion/styled"; +import IconStarFilled from "components/rating/icons/IconStarFilled"; +import IconStarHalf from "components/rating/icons/IconStarHalf"; +import IconStarOutlined from "components/rating/icons/IconStarOutlined"; +import { HTMLAttributes, useEffect, useState, useRef, useCallback } from "react"; + +interface Props extends HTMLAttributes<HTMLDivElement> { + value: number; // 0 ~ 5 ์‚ฌ์ด์˜ ์ˆซ์ž, ๋ณ„ ๊ฐœ์ˆ˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด 0.5 ๋‹จ์œ„๋กœ ๋ฐ˜์˜ฌ๋ฆผ + isInput?: boolean; // input ๊ธฐ๋Šฅ์„ ํ•˜๋„๋ก ํ•  ์ง€ ์„ค์ • + onSelectedValueChange?: (value: number) => void; +} + +const Rating = ({ value, isInput = false, onSelectedValueChange, ...props }: Props) => { + const [selectedValue, setSelectedValue] = useState<number>(value); + const isMouseDown = useRef<boolean>(false); + const containerRef = useRef<HTMLDivElement>(null); + + // round value to the nearest 0.5 + const startCount = Math.round(selectedValue * 2) / 2; + + const filledStarCount = Math.floor(startCount); + const hasHalfStar = startCount % 1 !== 0; + const emptyStarCount = 5 - filledStarCount - (hasHalfStar ? 1 : 0); + + useEffect(() => { + if (onSelectedValueChange) { + onSelectedValueChange(selectedValue); + } + }, [selectedValue, onSelectedValueChange]); + + const handleOnClick = (event: React.MouseEvent, index: number) => { + const clickX = event.nativeEvent.clientX; // ํด๋ฆญํ•œ ์œ„์น˜์˜ X ์ขŒํ‘œ + + // IconStar... ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ํด๋ฆญํ•œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํŒ๋ณ„ + const containerRect = event.currentTarget.getBoundingClientRect(); + const containerCenterX = (containerRect.left + containerRect.right) / 2; + + if (clickX < containerCenterX) { + setSelectedValue(index + 0.5); + } else { + setSelectedValue(index + 1); + } + }; + + const calculateScore = useCallback((currentX: number) => { + const container = containerRef.current; + if (container) { + const unitSize = container.getBoundingClientRect().width / 10; + const relativeX = currentX - container.getBoundingClientRect().x; + if (relativeX <= 0) setSelectedValue(0.5); + else { + const score = (Math.floor(relativeX / unitSize) + 1) * 0.5; + score > 5 ? setSelectedValue(5) : setSelectedValue(score); + } + } + }, []); + + const handleOnMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = true; + }, []); + + const handleOnMouseLeave = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = false; + }, []); + + const handleOnMouseMove = useCallback( + (event: React.MouseEvent) => { + if (isMouseDown.current) calculateScore(event.clientX); + }, + [calculateScore] + ); + + const handleOnMouseUp = useCallback((event: React.MouseEvent) => { + isMouseDown.current = false; + }, []); + + // For mobile view + const handleOnTouchMove = useCallback( + (event: React.TouchEvent) => { + calculateScore(event.changedTouches[0].clientX); + }, + [calculateScore] + ); + + return ( + <EmotionWrapper isInput={isInput} {...props}> + <div + className="star-container" + onMouseDown={handleOnMouseDown} + onMouseUp={handleOnMouseUp} + onMouseMove={handleOnMouseMove} + onMouseLeave={handleOnMouseLeave} + onTouchMove={handleOnTouchMove} + ref={containerRef} + > + {Array.from({ length: filledStarCount }, (_, index) => + isInput ? ( + <IconStarFilled + key={index} + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, index)} + /> + ) : ( + <IconStarFilled key={index} /> + ) + )} + {hasHalfStar && + (isInput ? ( + <IconStarHalf + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, filledStarCount)} + /> + ) : ( + <IconStarHalf /> + ))} + {Array.from({ length: emptyStarCount }, (_, index) => + isInput ? ( + <IconStarOutlined + key={index} + size={40} + onClick={(event: React.MouseEvent) => + handleOnClick(event, filledStarCount + index + (hasHalfStar ? 1 : 0)) + } + /> + ) : ( + <IconStarOutlined key={index} /> + ) + )} + </div> + {isInput ? ( + <div> + <span className="rating-value-selected">{selectedValue}</span> + <span className="rating-full-marks"> / 5</span> + </div> + ) : ( + <p className="rating-value">{value}</p> + )} + </EmotionWrapper> + ); +}; + +export default Rating; + +const EmotionWrapper = styled.div<{ isInput: boolean }>` + display: flex; + align-items: center; + ${({ isInput }) => (isInput ? "flex-direction: column; gap: 20px;" : "column-gap: 4px;")} + + .star-container { + display: flex; + column-gap: 2px; + } + + color: ${({ theme }) => theme.color.gray400}; + + .rating-full-marks { + font-size: 16px; + font-weight: 300; + } + + .rating-value-selected { + font-size: 32px; + font-weight: 500; + color: ${({ theme }) => theme.color.gray700}; + } + + .rating-value { + font-size: 12px; + } +`;
Unknown
๋„ต ๋งž์Šต๋‹ˆ๋‹ค..!
@@ -0,0 +1,85 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Button from "components/button/Button"; + +interface Props { + imgSrcList: string[]; +} + +const RestaurantDetailImgSection: React.FC<Props> = ({ imgSrcList }) => { + const [currentImgIndex, setCurrentImgIndex] = useState(0); + + const handleOnClickRight = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == imgSrcList.length - 1 ? 0 : currentImgIndex + 1 + ); + }; + + const handleOnClickLeft = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == 0 ? imgSrcList.length - 1 : currentImgIndex - 1 + ); + }; + + return ( + <EmotionWrapper> + {imgSrcList.length === 0 ? ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ๊ธฐ๋ณธ ์ด๋ฏธ์ง€" + src={"/images/defaults/default-restaurant-image.png"} + fill + /> + ) : ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ์ด๋ฏธ์ง€" + src={imgSrcList[currentImgIndex]} + fill + /> + )} + <Button + onClick={handleOnClickLeft} + variant="text" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + left: "0px", + }} + > + &lt; + </Button> + <Button + onClick={handleOnClickRight} + variant="text" + className="right-button" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + right: "0px", + }} + > + &gt; + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailImgSection; + +const EmotionWrapper = styled.div` + position: relative; + width: 100%; + height: 120px; + overflow: hidden; + margin-bottom: 10px; + + .restaurant-img { + z-index: 1; + object-fit: cover; + position: absolute; + } +`;
Unknown
์•— ์ด๋ฏธ์ง€ ์Šฌ๋ผ์ด๋”๋ฅผ ๊ตฌํ˜„ํ•˜๋ ค๋‹ค๊ฐ€ ์ผ๋‹จ PR๋ถ€ํ„ฐ ์˜ฌ๋ ธ๋Š”๋ฐ, ํ•ด๋‹น ๋ฒ„ํŠผ์€ ๊ทธ ๊ณผ์ •์—์„œ ์ƒ๊ธด ๋ณ„ ์˜๋ฏธ ์—†๋Š” ๋ฒ„ํŠผ์ž…๋‹ˆ๋‹ค.. ์‚ญ์ œํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,70 @@ +import styled from "@emotion/styled"; +import RestaurantDetailImgSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailImgSection"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import RestaurantDetailInfoSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailInfoSection"; +import RestaurantDetailReviewSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailReviewSection"; +import Divider from "components/divider/Divider"; +import { restaurant } from "feature/restaurants/restaurantsDetail/mockups/restaurant"; +import { reviewPage1 } from "feature/restaurants/restaurantsDetail/mockups/reviews"; + +interface Props { + restaurantId: string; +} + +const ViewRestaurantDetail: React.FC<Props> = ({ restaurantId }) => { + /** + * TODO 1: ์‚ฌ์šฉ์ž ๊ถŒํ•œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userAuth = 0; + + /** + * TODO 2: ๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + /** + * TODO3: ๋ง›์ง‘์˜ ๋ชจ๋“  ๋ฆฌ๋ทฐ ์กฐํšŒํ•˜๊ธฐ + * - totalScore, totalPages ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ Read Reviews API ํ˜ธ์ถœ + * - ๋ฆฌ๋ทฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ 404 ์—๋Ÿฌ ๋ฐ˜ํ™˜? + */ + const { totalScore, totalCount, totalPages, scoreStatistics } = reviewPage1; + + return ( + <EmotionWrapper> + <RestaurantDetailImgSection imgSrcList={restaurant.imgSrcList} /> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + userAuth={userAuth} + restaurantName={restaurant.name} + restaurantAddress={restaurant.address} + organizationName={restaurant.organizationName} + link={restaurant.link} + /> + <RestaurantDetailInfoSection + restaurantId={restaurantId} + comment={restaurant.comment} + orderTip={restaurant.orderTip} + capacity={restaurant.capacity} + recommendedMenus={restaurant.recommnededMenus} + category={restaurant.category} + delivery={restaurant.delivery} + openingHour={restaurant.openingHour} + tags={restaurant.tags} + totalScore={totalScore} + totalCount={totalCount} + /> + <Divider /> + <RestaurantDetailReviewSection + restaurantId={restaurantId} + userAuth={userAuth} + totalScore={totalScore} + totalCount={totalCount} + totalPages={totalPages} + scoreStatistics={scoreStatistics} + /> + </EmotionWrapper> + ); +}; + +export default ViewRestaurantDetail; + +const EmotionWrapper = styled.div``;
Unknown
ํ™•์ธ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,137 @@ +import styled from "@emotion/styled"; +import Rating from "components/rating/Rating"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import Button from "components/button/Button"; +import TextInput from "components/inputs/TextInput/TextInput"; +import { useState, useCallback } from "react"; +import Checkbox from "components/checkbox/Checkbox"; +import { REVIEW_CONTENT_MAX_VALUE, REVIEW_CONTENT_MIN_VALUE } from "constant/limit"; + +interface Props { + restaurantId: string; + isEditMode: boolean; + reviewId?: string | number | string[]; + score?: number; + content?: string; +} + +const RestaurantsReviewForm: React.FC<Props> = ({ restaurantId, score = 0, content = "" }) => { + const [selectedScroe, setSelectedScore] = useState<number>(score); + const [enteredContent, setEnteredContent] = useState<string>(content); + const [isPublic, setIsPublic] = useState<boolean>(true); + + /** + * TODO: restaurantId๋กœ ๋ง›์ง‘ ์ƒ์„ธ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + const contentMaxLengthCheck = { + condition: (content: string) => { + return content.length <= REVIEW_CONTENT_MAX_VALUE; + }, + messageOnError: "500์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const contentMinLengthCheck = { + condition: (content: string) => { + return content.length >= REVIEW_CONTENT_MIN_VALUE; + }, + messageOnError: "20์ž ์ด์ƒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const handleScoreChange = useCallback((value: number) => { + setSelectedScore(value); + }, []); + + const handleContentChange = useCallback((value: string) => { + setEnteredContent(value); + }, []); + + const handleSetIsPublic = useCallback((value: string) => { + if (value === "true") setIsPublic(true); + else setIsPublic(false); + }, []); + + const handleOnSubmit = () => { + console.log("์ ์ˆ˜ : ", selectedScroe); + console.log("๋ฆฌ๋ทฐ ๋‚ด์šฉ : ", enteredContent); + console.log("๊ณต๊ฐœ ์—ฌ๋ถ€ : ", isPublic); + }; + + return ( + <EmotionWrapper> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + restaurantName="๋ด‰์ˆ˜์œก" + restaurantAddress="๊ฒฝ๊ธฐ๋„ ์ˆ˜์›์‹œ ์ฒœ์ฒœ๋™" + organizationName="์‹œ์Šคํ…œ ์ปจ์„คํ„ดํŠธ ๊ทธ๋ฃน" + isMain={false} + /> + <Rating value={score} isInput onSelectedValueChange={handleScoreChange} /> + <TextInput + label="๋ฆฌ๋ทฐ ๋‚ด์šฉ" + placeholder="๋ง›์ง‘์— ๋Œ€ํ•œ ์†”์งํ•œ ํ‰์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!" + multiline + value={content} + onTextChange={handleContentChange} + conditionCheckList={[contentMaxLengthCheck, contentMinLengthCheck]} + height="150px" + /> + <div className="right-alignment"> + <p className="label">๋ฆฌ๋ทฐ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.</p> + <Checkbox.Group + checkedList={[String(isPublic)]} + setCheckedItem={(value) => handleSetIsPublic(value)} + > + <Checkbox.Item value="true">๊ณต๊ฐœ</Checkbox.Item> + <Checkbox.Item value="false">๋น„๊ณต๊ฐœ</Checkbox.Item> + </Checkbox.Group> + {!isPublic && ( + <p className="description">๋น„๊ณต๊ฐœ๋กœ ์„ค์ •์‹œ, ๋‹จ์ฒด ์™ธ๋ถ€์ธ์—๊ฒŒ๋Š” ๋ฆฌ๋ทฐ๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</p> + )} + </div> + <Button onClick={handleOnSubmit} fullWidth> + ์ž‘์„ฑ ์™„๋ฃŒ + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantsReviewForm; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 30px; + + textarea { + font-size: 16px; + } + + button { + font-size: 16px; + } + + .right-alignment { + margin-top: -15px; + width: 100%; + } + + .label { + margin-top: 20px; + margin-bottom: 10px; + margin-left: 2px; + font-weight: 500; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + .description { + margin-top: 5px; + margin-left: 2px; + font-size: 14px; + font-weight: 200; + color: ${({ theme }) => theme.color.gray600}; + } +`;
Unknown
๋ฐœ๊ฒฌ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,137 @@ +import styled from "@emotion/styled"; +import Rating from "components/rating/Rating"; +import RestaurantDetailHeaderSection from "feature/restaurants/restaurantsDetail/components/section/RestaurantDetailHeaderSection"; +import Button from "components/button/Button"; +import TextInput from "components/inputs/TextInput/TextInput"; +import { useState, useCallback } from "react"; +import Checkbox from "components/checkbox/Checkbox"; +import { REVIEW_CONTENT_MAX_VALUE, REVIEW_CONTENT_MIN_VALUE } from "constant/limit"; + +interface Props { + restaurantId: string; + isEditMode: boolean; + reviewId?: string | number | string[]; + score?: number; + content?: string; +} + +const RestaurantsReviewForm: React.FC<Props> = ({ restaurantId, score = 0, content = "" }) => { + const [selectedScroe, setSelectedScore] = useState<number>(score); + const [enteredContent, setEnteredContent] = useState<string>(content); + const [isPublic, setIsPublic] = useState<boolean>(true); + + /** + * TODO: restaurantId๋กœ ๋ง›์ง‘ ์ƒ์„ธ์ •๋ณด ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + + const contentMaxLengthCheck = { + condition: (content: string) => { + return content.length <= REVIEW_CONTENT_MAX_VALUE; + }, + messageOnError: "500์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const contentMinLengthCheck = { + condition: (content: string) => { + return content.length >= REVIEW_CONTENT_MIN_VALUE; + }, + messageOnError: "20์ž ์ด์ƒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.", + }; + + const handleScoreChange = useCallback((value: number) => { + setSelectedScore(value); + }, []); + + const handleContentChange = useCallback((value: string) => { + setEnteredContent(value); + }, []); + + const handleSetIsPublic = useCallback((value: string) => { + if (value === "true") setIsPublic(true); + else setIsPublic(false); + }, []); + + const handleOnSubmit = () => { + console.log("์ ์ˆ˜ : ", selectedScroe); + console.log("๋ฆฌ๋ทฐ ๋‚ด์šฉ : ", enteredContent); + console.log("๊ณต๊ฐœ ์—ฌ๋ถ€ : ", isPublic); + }; + + return ( + <EmotionWrapper> + <RestaurantDetailHeaderSection + restaurantId={restaurantId} + restaurantName="๋ด‰์ˆ˜์œก" + restaurantAddress="๊ฒฝ๊ธฐ๋„ ์ˆ˜์›์‹œ ์ฒœ์ฒœ๋™" + organizationName="์‹œ์Šคํ…œ ์ปจ์„คํ„ดํŠธ ๊ทธ๋ฃน" + isMain={false} + /> + <Rating value={score} isInput onSelectedValueChange={handleScoreChange} /> + <TextInput + label="๋ฆฌ๋ทฐ ๋‚ด์šฉ" + placeholder="๋ง›์ง‘์— ๋Œ€ํ•œ ์†”์งํ•œ ํ‰์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!" + multiline + value={content} + onTextChange={handleContentChange} + conditionCheckList={[contentMaxLengthCheck, contentMinLengthCheck]} + height="150px" + /> + <div className="right-alignment"> + <p className="label">๋ฆฌ๋ทฐ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.</p> + <Checkbox.Group + checkedList={[String(isPublic)]} + setCheckedItem={(value) => handleSetIsPublic(value)} + > + <Checkbox.Item value="true">๊ณต๊ฐœ</Checkbox.Item> + <Checkbox.Item value="false">๋น„๊ณต๊ฐœ</Checkbox.Item> + </Checkbox.Group> + {!isPublic && ( + <p className="description">๋น„๊ณต๊ฐœ๋กœ ์„ค์ •์‹œ, ๋‹จ์ฒด ์™ธ๋ถ€์ธ์—๊ฒŒ๋Š” ๋ฆฌ๋ทฐ๊ฐ€ ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</p> + )} + </div> + <Button onClick={handleOnSubmit} fullWidth> + ์ž‘์„ฑ ์™„๋ฃŒ + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantsReviewForm; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 30px; + + textarea { + font-size: 16px; + } + + button { + font-size: 16px; + } + + .right-alignment { + margin-top: -15px; + width: 100%; + } + + .label { + margin-top: 20px; + margin-bottom: 10px; + margin-left: 2px; + font-weight: 500; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + .description { + margin-top: 5px; + margin-left: 2px; + font-size: 14px; + font-weight: 200; + color: ${({ theme }) => theme.color.gray600}; + } +`;
Unknown
๋„ต ์ข‹์Šต๋‹ˆ๋‹ค! ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,85 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Button from "components/button/Button"; + +interface Props { + imgSrcList: string[]; +} + +const RestaurantDetailImgSection: React.FC<Props> = ({ imgSrcList }) => { + const [currentImgIndex, setCurrentImgIndex] = useState(0); + + const handleOnClickRight = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == imgSrcList.length - 1 ? 0 : currentImgIndex + 1 + ); + }; + + const handleOnClickLeft = () => { + setCurrentImgIndex((currentImgIndex) => + currentImgIndex == 0 ? imgSrcList.length - 1 : currentImgIndex - 1 + ); + }; + + return ( + <EmotionWrapper> + {imgSrcList.length === 0 ? ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ๊ธฐ๋ณธ ์ด๋ฏธ์ง€" + src={"/images/defaults/default-restaurant-image.png"} + fill + /> + ) : ( + <Image + className="restaurant-img" + alt="๋ง›์ง‘ ์ด๋ฏธ์ง€" + src={imgSrcList[currentImgIndex]} + fill + /> + )} + <Button + onClick={handleOnClickLeft} + variant="text" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + left: "0px", + }} + > + &lt; + </Button> + <Button + onClick={handleOnClickRight} + variant="text" + className="right-button" + style={{ + backgroundColor: "transparent", + zIndex: "10", + position: "absolute", + right: "0px", + }} + > + &gt; + </Button> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailImgSection; + +const EmotionWrapper = styled.div` + position: relative; + width: 100%; + height: 120px; + overflow: hidden; + margin-bottom: 10px; + + .restaurant-img { + z-index: 1; + object-fit: cover; + position: absolute; + } +`;
Unknown
์ด๋ฏธ์ง€ ์Šฌ๋ผ์ด๋”๋Š” ์•„์ง ๊ตฌํ˜„ํ•˜์ง€ ์•Š์•˜์ง€๋งŒ, ์ผ๋‹จ ์ด๋ฏธ์ง€ ์ „ํ™˜์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๋ฒ„ํŠผ์€ ๋งŒ๋“ค์–ด๋‘์—ˆ์Šต๋‹ˆ๋‹ค! ์ง€๊ธˆ์€ ๋ฒ„ํŠผ ๋ณด์ผ ๊ฒ๋‹ˆ๋‹ค.
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
์˜ค.. ๋„ต ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋„ ๋ฉ”์ธ์ด ๋˜๋Š” ํ…์ŠคํŠธ(๋ง›์ง‘ ์ด๋ฆ„, ๋‹จ์ฒด ์ด๋ฆ„)์€ `<h1 />`์„ ์‚ฌ์šฉํ•˜๋„๋ก ์ˆ˜์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ผ๋‹จ ๋ง›์ง‘ ์ƒ์„ธ ํŽ˜์ด์ง€์—์„œ๋Š” ๋ง›์ง‘ ์ด๋ฆ„์„ `<h1 />` ํƒœ๊ทธ๋กœ ์ˆ˜์ • ์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
className์„ ๋ชจ๋‘ kebab case๋กœ ์ˆ˜์ •์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,120 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Rating from "components/rating/Rating"; +import IconEditFilledWhite from "components/icons/IconEditFilledWhite"; +import Link from "next/link"; +import dayjs from "dayjs"; + +interface Props { + restaurantId: string; + reviewId: number; + userId: number; + score: number; + content: string; + createdAt: Date; +} + +const ReviewItem: React.FC<Props> = ({ + restaurantId, + reviewId, + userId, + score, + content, + createdAt, +}) => { + const [isExpanded, setIsExpanded] = useState(false); + + const toggleExpansion = () => { + setIsExpanded((isExpanded) => !isExpanded); + }; + + const editLink = `/restaurants/${restaurantId}/review/${reviewId}/edit`; + const displayContent = + content.length > 100 && !isExpanded ? content.slice(0, 100) + "..." : content; + + /** + * TODO 1: userId๋กœ userInfo ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userName = "ํ™๊ธธ๋™"; + const ImgSrc = "/images/profile-image-default-1.png"; + + /** + * TODO 2: ํ˜„์žฌ ๋กœ๊ทธ์ธ๋œ ์œ ์ € ์•„์ด๋”” ๊ฐ€์ ธ์˜ค๊ธฐ (๋ฆฌ๋ทฐ ์ˆ˜์ • ๊ถŒํ•œ ํ™•์ธ์šฉ) + */ + const currentUserId = 1; + + return ( + <EmotionWrapper> + <div className="user-info-score-div"> + <div className="user-info-div"> + <Image src={ImgSrc} alt={"์œ ์ € ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"} width={30} height={30} /> + <span className="user-name">{userName}</span> + <span className="date">{dayjs(createdAt).format("YY/MM/DD")}</span> + {currentUserId === userId && ( + <Link href={editLink}> + <IconEditFilledWhite /> + </Link> + )} + </div> + <Rating value={score} /> + </div> + <div className="content-div"> + <span>{displayContent}</span> + {content.length > 100 && ( + <button onClick={toggleExpansion}>{isExpanded ? "์ ‘๊ธฐ" : "๋” ๋ณด๊ธฐ"}</button> + )} + </div> + </EmotionWrapper> + ); +}; + +export default ReviewItem; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + min-height: 90px; + width: 100%; + background-color: ${({ theme }) => theme.color.white}; + border-radius: 6px; + + padding: 10px; + + .user-info-score-div { + display: flex; + justify-content: space-between; + align-items: center; + + .user-info-div { + display: flex; + gap: 8px; + justify-content: center; + align-items: center; + + span.user-name { + font-size: 16px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + span.date { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray300}; + } + } + } + + .content-div { + span { + line-height: 1.5; + color: ${({ theme }) => theme.color.gray400}; + flex-grow: 1; + margin-right: 8px; + } + + button { + color: ${({ theme }) => theme.color.gray300}; + } + } +`;
Unknown
className์„ ๋ชจ๋‘ kebab case๋กœ ์ˆ˜์ •์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,120 @@ +import styled from "@emotion/styled"; +import Image from "next/image"; +import { useState } from "react"; +import Rating from "components/rating/Rating"; +import IconEditFilledWhite from "components/icons/IconEditFilledWhite"; +import Link from "next/link"; +import dayjs from "dayjs"; + +interface Props { + restaurantId: string; + reviewId: number; + userId: number; + score: number; + content: string; + createdAt: Date; +} + +const ReviewItem: React.FC<Props> = ({ + restaurantId, + reviewId, + userId, + score, + content, + createdAt, +}) => { + const [isExpanded, setIsExpanded] = useState(false); + + const toggleExpansion = () => { + setIsExpanded((isExpanded) => !isExpanded); + }; + + const editLink = `/restaurants/${restaurantId}/review/${reviewId}/edit`; + const displayContent = + content.length > 100 && !isExpanded ? content.slice(0, 100) + "..." : content; + + /** + * TODO 1: userId๋กœ userInfo ๋ถˆ๋Ÿฌ์˜ค๊ธฐ + */ + const userName = "ํ™๊ธธ๋™"; + const ImgSrc = "/images/profile-image-default-1.png"; + + /** + * TODO 2: ํ˜„์žฌ ๋กœ๊ทธ์ธ๋œ ์œ ์ € ์•„์ด๋”” ๊ฐ€์ ธ์˜ค๊ธฐ (๋ฆฌ๋ทฐ ์ˆ˜์ • ๊ถŒํ•œ ํ™•์ธ์šฉ) + */ + const currentUserId = 1; + + return ( + <EmotionWrapper> + <div className="user-info-score-div"> + <div className="user-info-div"> + <Image src={ImgSrc} alt={"์œ ์ € ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"} width={30} height={30} /> + <span className="user-name">{userName}</span> + <span className="date">{dayjs(createdAt).format("YY/MM/DD")}</span> + {currentUserId === userId && ( + <Link href={editLink}> + <IconEditFilledWhite /> + </Link> + )} + </div> + <Rating value={score} /> + </div> + <div className="content-div"> + <span>{displayContent}</span> + {content.length > 100 && ( + <button onClick={toggleExpansion}>{isExpanded ? "์ ‘๊ธฐ" : "๋” ๋ณด๊ธฐ"}</button> + )} + </div> + </EmotionWrapper> + ); +}; + +export default ReviewItem; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + min-height: 90px; + width: 100%; + background-color: ${({ theme }) => theme.color.white}; + border-radius: 6px; + + padding: 10px; + + .user-info-score-div { + display: flex; + justify-content: space-between; + align-items: center; + + .user-info-div { + display: flex; + gap: 8px; + justify-content: center; + align-items: center; + + span.user-name { + font-size: 16px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + span.date { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray300}; + } + } + } + + .content-div { + span { + line-height: 1.5; + color: ${({ theme }) => theme.color.gray400}; + flex-grow: 1; + margin-right: 8px; + } + + button { + color: ${({ theme }) => theme.color.gray300}; + } + } +`;
Unknown
์˜ค ๋„ต ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ๋ฐฉ์‹์œผ๋กœ ์ˆ˜์ • ์™„๋ฃŒํ•˜์˜€์Šต๋‹ˆ๋‹ค!
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react"; import styled from "@emotion/styled"; import { css, Theme } from "@emotion/react"; import CheckIcon from "components/inputs/TextInput/CheckIcon"; -import { TConditionCheck } from "./types/TConditionCheck"; +import { TConditionCheck } from "components/inputs/TextInput/types/TConditionCheck"; interface Props { name?: string; @@ -12,6 +12,7 @@ interface Props { conditionList?: string[]; conditionCheckList?: TConditionCheck[]; multiline?: boolean; + height?: string; onTextChange?: (value: string, isValid: boolean) => void; } @@ -23,6 +24,7 @@ const TextInput: React.FC<Props> = ({ conditionList, conditionCheckList, multiline = false, + height, onTextChange, }) => { const [status, setStatus] = useState(value === "" ? "default" : "success"); // default / success / invalid / focus @@ -76,7 +78,7 @@ const TextInput: React.FC<Props> = ({ }, [enteredValue, status, onTextChange]); return ( - <EmotionWrapper> + <EmotionWrapper height={height}> {label && <span className="label">{label}</span>} {conditionList && ( <div className="spanList"> @@ -179,6 +181,7 @@ const EmotionWrapper = styled.div<Props>` ${({ theme }) => commonStyles(theme)}; position: relative; resize: none; + height: ${({ height }) => height ?? "auto"}; } `;
Unknown
๋„ต ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,105 @@ +import styled from "@emotion/styled"; +import RestaurantExternalLinkIcon from "feature/restaurants/restaurantsDetail/components/icons/RestaurantExternalLinkIcon"; +import Link from "next/link"; + +interface Props { + restaurantId: string; + userAuth?: number; + restaurantName: string; + restaurantAddress: string; + organizationName: string; + link?: string; + isMain?: boolean; +} + +const RestaurantDetailHeaderSection: React.FC<Props> = ({ + restaurantId, + userAuth, + restaurantName, + restaurantAddress, + organizationName, + link, + isMain = true, +}) => { + return ( + <EmotionWrapper> + <div className="over-title-div"> + <span className="subtitle">{organizationName}</span> + {isMain && + (userAuth === 0 || userAuth === 1 ? ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/edit"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ) : ( + <Link className="link-div" href={"/restaurants/" + restaurantId + "/copy"}> + ๋ง›์ง‘ ์ˆ˜์ • + </Link> + ))} + </div> + <h1 className="title">{restaurantName}</h1> + <div className="under-title-div"> + <span className="subtitle">{restaurantAddress}</span> + {link && ( + <Link className="link-div" href={link}> + <RestaurantExternalLinkIcon /> + <span className="link-span">๋ง›์ง‘ ์ƒ์„ธ ์ •๋ณด &gt;</span> + </Link> + )} + </div> + </EmotionWrapper> + ); +}; + +export default RestaurantDetailHeaderSection; + +const EmotionWrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: left; + gap: 8px; + + span { + font-weight: 300; + margin-left: 2px; + font-size: 16px; + color: ${({ theme }) => theme.color.gray600}; + } + + span.subtitle { + font-size: 12px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray300}; + } + + .title { + font-size: 30px; + font-weight: 600; + color: ${({ theme }) => theme.color.gray700}; + } + + .under-title-div, + .over-title-div { + display: flex; + justify-content: space-between; + align-items: center; + } + + .link-div { + display: flex; + justify-content: right; + align-items: center; + text-decoration-line: none; + + font-size: 14px; + font-weight: 400; + color: ${({ theme }) => theme.color.gray700}; + } + + .link-span { + font-size: 12px; + font-weight: 300; + color: ${({ theme }) => theme.color.gray500}; + } +`;
Unknown
restaurantId๋ฅผ ๋ฐ›์•„์˜ฌ ๋•Œ `const restaurantId = query.restaurantId ?? 0;` ์ด๋ ‡๊ฒŒ๋งŒ ํ–ˆ๋”๋‹ˆ props๋กœ ๋„˜๊ฒจ์ค„ ๋•Œ ํƒ€์ž… ์—๋Ÿฌ๊ฐ€ ๋– ์„œ ์ €๋ ‡๊ฒŒ ์„ค์ •ํ•œ๊ฑด๋ฐ, ํ˜„์žฌ๋Š” `const restaurantId = (query.restaurantId ?? 0) as string;` ์•„์˜ˆ ์ด๋Ÿฐ ์‹์œผ๋กœ ํƒ€์ž…์„ ๋ช…์‹œํ•ด์ฃผ์–ด์„œ props๋กœ ๋ฐ›์•„์˜ฌ ๋•Œ์—๋„ string์œผ๋กœ๋งŒ ๋ฐ›์•„์˜ค๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,18 @@ +import styled from "@emotion/styled"; +import RestaurantsReviewForm from "feature/restaurants/restaurantsReview/components/form/RestaurantsReviewForm"; + +interface Props { + restaurantId: string; +} + +const ViewRestaurantReviewCreate: React.FC<Props> = ({ restaurantId }) => { + return ( + <EmotionWrapper> + <RestaurantsReviewForm restaurantId={restaurantId} isEditMode={false} /> + </EmotionWrapper> + ); +}; + +export default ViewRestaurantReviewCreate; + +const EmotionWrapper = styled.div``;
Unknown
[์—ฌ๊ธฐ](https://github.com/SystemConsultantGroup/foodhub-frontend/pull/27#discussion_r1373127345)์—์„œ ์ด์œ ๋ฅผ ์„ค๋ช…ํ•˜์˜€๊ณ , ํ•ด๋‹น ๋ถ€๋ถ„ string์œผ๋กœ๋งŒ ๋ฐ›์•„์˜ค๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,170 @@ +import styled from "@emotion/styled"; +import IconStarFilled from "components/rating/icons/IconStarFilled"; +import IconStarHalf from "components/rating/icons/IconStarHalf"; +import IconStarOutlined from "components/rating/icons/IconStarOutlined"; +import { HTMLAttributes, useEffect, useState, useRef, useCallback } from "react"; + +interface Props extends HTMLAttributes<HTMLDivElement> { + value: number; // 0 ~ 5 ์‚ฌ์ด์˜ ์ˆซ์ž, ๋ณ„ ๊ฐœ์ˆ˜๋Š” ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด 0.5 ๋‹จ์œ„๋กœ ๋ฐ˜์˜ฌ๋ฆผ + isInput?: boolean; // input ๊ธฐ๋Šฅ์„ ํ•˜๋„๋ก ํ•  ์ง€ ์„ค์ • + onSelectedValueChange?: (value: number) => void; +} + +const Rating = ({ value, isInput = false, onSelectedValueChange, ...props }: Props) => { + const [selectedValue, setSelectedValue] = useState<number>(value); + const isMouseDown = useRef<boolean>(false); + const containerRef = useRef<HTMLDivElement>(null); + + // round value to the nearest 0.5 + const startCount = Math.round(selectedValue * 2) / 2; + + const filledStarCount = Math.floor(startCount); + const hasHalfStar = startCount % 1 !== 0; + const emptyStarCount = 5 - filledStarCount - (hasHalfStar ? 1 : 0); + + useEffect(() => { + if (onSelectedValueChange) { + onSelectedValueChange(selectedValue); + } + }, [selectedValue, onSelectedValueChange]); + + const handleOnClick = (event: React.MouseEvent, index: number) => { + const clickX = event.nativeEvent.clientX; // ํด๋ฆญํ•œ ์œ„์น˜์˜ X ์ขŒํ‘œ + + // IconStar... ์ปดํฌ๋„ŒํŠธ ๋‚ด์—์„œ ํด๋ฆญํ•œ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์™ผ์ชฝ ๋˜๋Š” ์˜ค๋ฅธ์ชฝ ํŒ๋ณ„ + const containerRect = event.currentTarget.getBoundingClientRect(); + const containerCenterX = (containerRect.left + containerRect.right) / 2; + + if (clickX < containerCenterX) { + setSelectedValue(index + 0.5); + } else { + setSelectedValue(index + 1); + } + }; + + const calculateScore = useCallback((currentX: number) => { + const container = containerRef.current; + if (container) { + const unitSize = container.getBoundingClientRect().width / 10; + const relativeX = currentX - container.getBoundingClientRect().x; + if (relativeX <= 0) setSelectedValue(0.5); + else { + const score = (Math.floor(relativeX / unitSize) + 1) * 0.5; + score > 5 ? setSelectedValue(5) : setSelectedValue(score); + } + } + }, []); + + const handleOnMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = true; + }, []); + + const handleOnMouseLeave = useCallback((event: React.MouseEvent<HTMLDivElement>) => { + isMouseDown.current = false; + }, []); + + const handleOnMouseMove = useCallback( + (event: React.MouseEvent) => { + if (isMouseDown.current) calculateScore(event.clientX); + }, + [calculateScore] + ); + + const handleOnMouseUp = useCallback((event: React.MouseEvent) => { + isMouseDown.current = false; + }, []); + + // For mobile view + const handleOnTouchMove = useCallback( + (event: React.TouchEvent) => { + calculateScore(event.changedTouches[0].clientX); + }, + [calculateScore] + ); + + return ( + <EmotionWrapper isInput={isInput} {...props}> + <div + className="star-container" + onMouseDown={handleOnMouseDown} + onMouseUp={handleOnMouseUp} + onMouseMove={handleOnMouseMove} + onMouseLeave={handleOnMouseLeave} + onTouchMove={handleOnTouchMove} + ref={containerRef} + > + {Array.from({ length: filledStarCount }, (_, index) => + isInput ? ( + <IconStarFilled + key={index} + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, index)} + /> + ) : ( + <IconStarFilled key={index} /> + ) + )} + {hasHalfStar && + (isInput ? ( + <IconStarHalf + size={40} + onClick={(event: React.MouseEvent) => handleOnClick(event, filledStarCount)} + /> + ) : ( + <IconStarHalf /> + ))} + {Array.from({ length: emptyStarCount }, (_, index) => + isInput ? ( + <IconStarOutlined + key={index} + size={40} + onClick={(event: React.MouseEvent) => + handleOnClick(event, filledStarCount + index + (hasHalfStar ? 1 : 0)) + } + /> + ) : ( + <IconStarOutlined key={index} /> + ) + )} + </div> + {isInput ? ( + <div> + <span className="rating-value-selected">{selectedValue}</span> + <span className="rating-full-marks"> / 5</span> + </div> + ) : ( + <p className="rating-value">{value}</p> + )} + </EmotionWrapper> + ); +}; + +export default Rating; + +const EmotionWrapper = styled.div<{ isInput: boolean }>` + display: flex; + align-items: center; + ${({ isInput }) => (isInput ? "flex-direction: column; gap: 20px;" : "column-gap: 4px;")} + + .star-container { + display: flex; + column-gap: 2px; + } + + color: ${({ theme }) => theme.color.gray400}; + + .rating-full-marks { + font-size: 16px; + font-weight: 300; + } + + .rating-value-selected { + font-size: 32px; + font-weight: 500; + color: ${({ theme }) => theme.color.gray700}; + } + + .rating-value { + font-size: 12px; + } +`;
Unknown
๋ณ„์ ์„ dragํ•˜์—ฌ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋„๋ก ์ถ”๊ฐ€์ ์œผ๋กœ ๊ตฌํ˜„ํ•˜์˜€๋Š”๋ฐ, ๋ฐ์Šคํฌํ†ฑ์—์„œ๋Š” ์ž˜ ๋˜๋Š”๋ฐ ๋ชจ๋ฐ”์ผ์—์„œ๋Š” touchMove ์ด๋ฒคํŠธ๊ฐ€ ์ค‘๊ฐ„์— ๋Š๊ธฐ๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ •ํ™•ํžˆ๋Š” touchMove ๋„์ค‘์— state๋ฅผ ์„ธํŒ…ํ•˜๋ฉด, ํ„ฐ์น˜๋Š” ์ด์–ด์ง€๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์ธ๋ฐ๋„ touchMove๊ฐ€ ์ธ์‹๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. selectedValue๊ฐ€ ๋ฐ”๋€Œ๋ฉด์„œ star๋“ค์ด ๋‹ค์‹œ ๋ Œ๋”๋ง๋˜๋Š” ๊ฒƒ ๋•Œ๋ฌธ์ธ ๊ฒƒ ๊ฐ™์ง€๋งŒ ์ •ํ™•ํžˆ ๋ญ ๋•Œ๋ฌธ์ธ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ˜„์žฌ ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์„ ์ฐพ๋Š” ์ค‘์ด๊ธด ํ•œ๋ฐ, ํ•˜๋‹ค๊ฐ€ ์•ˆ๋˜๋ฉด ์ด์Šˆ๋กœ ์˜ฌ๋ฆฌ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.. @jaychang99 @hoon5083
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
๋ฆฌ์•กํŠธ ๊ด€๋ จ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ import๊ฐ€ ๋” ์šฐ์„ ์ˆœ์œ„์— ์œ„์น˜ํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
import './Login.scss'; ์œ„๋กœ ๊ฐ€์•ผ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!! ๐Ÿ˜Ž
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
์ˆ˜์ •์™„๋ฃŒ ๐Ÿ˜Š
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
- variable.scss ๋Š” scss ํŒŒ์ผ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— js ์—์„œ import ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด ์˜๋ฏธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. - scss ํŒŒ์ผ์—์„œ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ์— import ํ•ด์ฃผ์„ธ์š”!
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
- ๋‘ ํ•จ์ˆ˜๋Š” ํ•˜๋Š” ์—ญํ• ์ด ๋น„์Šทํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ถฉ๋ถ„ํžˆ ํ•˜๋‚˜์˜ ํ•จ์ˆ˜๋กœ ํ•ฉ์ณ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. - Refactoring CheckList ์ฐธ๊ณ ํ•ด์„œ ์ˆ˜์ •ํ•ด ๋ณด์„ธ์š”!
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
- isActive ๋Š” id ์™€ pw ๋กœ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ’์ด์ด๊ธฐ ๋•Œ๋ฌธ์— state ๋กœ ๊ด€๋ฆฌํ•  ํ•„์š”๊ฐ€ ์—†์–ด ๋ณด์ž…๋‹ˆ๋‹ค! - ์•„๋ž˜ ๊ณต์‹ ๋ฌธ์„œ ์ฐธ๊ณ ํ•˜์…”์„œ ์–ด๋–ค ๊ฐ’๋“ค์ด state ๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€์ง€ ํŒŒ์•…ํ•ด๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค! https://www.notion.so/wecode/Westagram-React-Refactoring-Checklist-aea297cf88ed4601b769e4b2c2cfd4e1#089493d6bfca438aa328226e327cff92
@@ -1,8 +1,100 @@ import React from 'react'; +import { withRouter } from 'react-router-dom'; +import './Login.scss'; + +class Login extends React.Component { + constructor() { + super(); + this.state = { + id: '', + pw: '', + }; + } + + handleInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + goToMain = e => { + fetch('http://10.58.0.100:8000/users/signin', { + method: 'POST', + body: JSON.stringify({ + email: this.state.id, + password: this.state.pw, + nick_name: '์ด์˜์—ฐ', + phonenumber: '01012345678', + }), + }) + .then(response => response.json()) + .then(result => { + if (result.message === 'SUCCESS') { + this.props.history.push('/MainEuiyeon'); + } else { + alert('์•„์ด๋”” ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!'); + } + }); + }; -class LoginEuiyeon extends React.Component { render() { - return <div>11</div>; + return ( + <div class="Login"> + <section className="loginBox"> + <div className="logo"> + <div className="logoFont">Westagram</div> + </div> + + <form className="loginForm"> + <div className="inputWrap"> + <div className="inputId"> + <input + className="input" + id="idInput" + type="text" + name="id" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + <div className="inputPassword"> + <input + className="input" + id="pwInput" + type="password" + name="pw" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ (6์ž๋ฆฌ ์ด์ƒ)" + onKeyUp={this.checkValid} + onChange={this.handleInput} + /> + </div> + </div> + + <div className="buttonWrap"> + <button + className={ + this.state.id.includes('@') && this.state.pw.length >= 6 + ? 'loginBtn' + : 'loginBtn_disabled' + } + type="button" + onClick={this.goToMain} + > + {' '} + ๋กœ๊ทธ์ธ{' '} + </button> + </div> + </form> + + <div className="forgotText"> + <a className="forgotPassword">๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”?</a> + </div> + </section> + </div> + ); } } -export default LoginEuiyeon; + +export default withRouter(Login);
JavaScript
- isActive ๋ฅผ state ๋กœ ๊ด€๋ฆฌํ•  ํ•„์š” ์—†์ด, ์—ฌ๊ธฐ์„œ ๋ฐ”๋กœ true / false ๋ฅผ ๊ณ„์‚ฐํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -1,3 +1,106 @@ -*{ - margin: 0; -} \ No newline at end of file +@import '../../../styles/variable.scss'; + +.Login { + @include flexCenter; + flex-direction: column; + align-items: center; + height: 100vh; + + .loginBox { + display: flex; + flex-direction: column; + justify-content: space-between; + border: $default-border; + width: 430px; + + .logo { + @include flexCenter; + align-items: center; + margin-top: 60px; + + .logoFont { + font-size: 50px; + font-family: 'Lobster'; + } + } + + .loginForm { + display: flex; + flex-direction: column; + justify-content: space-around; + align-items: center; + margin-top: 80px; + + .inputWrap { + display: flex; + flex-direction: column; + justify-content: space-evenly; + align-items: center; + height: 50%; + width: 80%; + + .inputId, + .inputPassword { + width: 100%; + } + + input { + width: 100%; + height: 45px; + margin-bottom: 15px; + padding: 2px 10px; + border-radius: 5px; + background-color: #eeeeef; + border: $default-border; + font-size: inherit; + } + } + + .buttonWrap { + @include flexCenter; + flex-direction: column; + align-items: center; + width: 100%; + height: 40%; + margin-top: 25px; + + .loginBtn { + width: 80%; + height: 45px; + border-radius: 5px; + border: transparent; + background-color: $btn-color-active; + /* background-color: #b2dffc; */ + color: white; + font-size: 20px; + padding-top: 4px; + } + + .loginBtn_disabled { + width: 80%; + height: 45px; + border-radius: 5px; + border: transparent; + background-color: $btn-color-disable; + color: white; + font-size: 20px; + padding-top: 4px; + } + } + } + + .forgotText { + display: flex; + flex-direction: column; + justify-content: flex-end; + align-items: center; + margin: 80px 0 30px 0; + + .forgotPassword { + text-align: end; + margin-bottom: 20px; + color: #2c5581; + } + } + } +}
Unknown
- css ์ž‘์—…์„ ํ•˜์‹ค๋•Œ ๋ฐ”๊นฅ ์š”์†Œ์— ํŠน์ •ํ•œ width / height ๊ฐ’์„ ๋ถ€์—ฌํ•˜์‹œ๋Š” ๊ฒƒ ๋ณด๋‹ค, ๋ฐ”๊นฅ ์š”์†Œ์˜ ํฌ๊ธฐ๋Š” ๋‚ด์šฉ๋ฌผ์˜ ํฌ๊ธฐ + margin / padding ๋“ค์˜ ํ•ฉ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํฌ๊ธฐ๊ฐ€ ๊ฒฐ์ •๋˜๋„๋ก ํ•˜์‹œ๋Š” ๊ฒŒ ๋” ์ข‹์Šต๋‹ˆ๋‹ค. - ํ•ญ์ƒ bottom up ๋ฐฉ์‹์œผ๋กœ ์Šคํƒ€์ผ๋ง ํ•˜๋Š” ์Šต๊ด€์„ ๋“ค์—ฌ์ฃผ์„ธ์š”!
@@ -0,0 +1,26 @@ +import React from 'react'; +import './Aside.scss'; + +import ProfileWrap from './ProfileWrap/ProfileWrap'; +import StoryBox from './StoryBox/StoryBox'; +import RecommendBox from './RecommendBox/RecommendBox'; +import WestaInfoBox from './WestaInfoBox/WestaInfoBox'; + +class Aside extends React.Component { + render() { + return ( + <aside className="sideWrapper"> + <div className="sidebar"> + <div className="profile_bar"> + <ProfileWrap /> + <StoryBox /> + <RecommendBox /> + <WestaInfoBox /> + </div> + </div> + </aside> + ); + } +} + +export default Aside;
JavaScript
- Import ์ˆœ์„œ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”! ์ผ๋ฐ˜์ ์ธ convention์„ ๋”ฐ๋ฅด๋Š” ์ด์œ ๋„ ์žˆ์ง€๋งŒ ์ˆœ์„œ๋งŒ ์ž˜ ์ง€์ผœ์ฃผ์…”๋„ ๊ฐ€๋…์„ฑ์ด ์ข‹์•„์ง‘๋‹ˆ๋‹ค. ์•„๋ž˜ ์ˆœ์„œ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”. - React โ†’ Library(Package) โ†’ Component โ†’ ๋ณ€์ˆ˜ / ์ด๋ฏธ์ง€ โ†’ css ํŒŒ์ผ(scss ํŒŒ์ผ) ```suggestion import React from 'react'; import ProfileWrap from './ProfileWrap/ProfileWrap'; import StoryBox from './StoryBox/StoryBox'; import RecommendBox from './RecommendBox/RecommendBox'; import WestaInfoBox from './WestaInfoBox/WestaInfoBox'; import './Aside.scss'; ```
@@ -0,0 +1,56 @@ +import React from 'react'; +import './Content.scss'; + +import Feed from './Feed/Feed'; +import Aside from './Aside/Aside'; + +class Content extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + + render() { + return ( + <div class="Main"> + <main> + <div className="container"> + <section className="articleWrapper"> + {this.state.feeds.map(e => ( + <Feed + feed_id={e.feed_id} + profile_img={e.profile_img} + profile_id={e.profile_id} + feed_img={e.feed_img} + like_click={e.like_click} + like_user_profile_img={e.like_user_profile_img} + like_user_profile_id={e.like_user_profile_id} + like_num={e.like_num} + post_user_mension={e.post_user_mension} + comments={e.comments} + /> + ))} + </section> + <Aside /> + </div> + </main> + </div> + ); + } +} + +export default Content;
JavaScript
- `http://localhost:3000` ์€ ์ƒ๋žต ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ํฌํŠธ ๋ฒˆํ˜ธ๊ฐ€ ๋‹ฌ๋ผ์ง€๋ฉด(ex. `localhost:3001`) fetch ํ•จ์ˆ˜๋ฅผ ์ผ์ผ์ด ์ˆ˜์ •ํ•ด์ฃผ์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์–ด๋ ค์›Œ์ง‘๋‹ˆ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ ์ฐธ๊ณ ํ•ด์„œ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”! ```jsx const foo = () => { // fetch("http://localhost:3000/images/1") fetch("/images/1") } ``` - fetchํ•จ์ˆ˜์˜ `get method`๋Š” method์˜ default ๊ฐ’์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ƒ๋žต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ```jsx const foo = () => { fetch(`${cartAPI}/quantity`) .then((res) => res.json()) ```
@@ -0,0 +1,56 @@ +import React from 'react'; +import './Content.scss'; + +import Feed from './Feed/Feed'; +import Aside from './Aside/Aside'; + +class Content extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('http://localhost:3000/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + + render() { + return ( + <div class="Main"> + <main> + <div className="container"> + <section className="articleWrapper"> + {this.state.feeds.map(e => ( + <Feed + feed_id={e.feed_id} + profile_img={e.profile_img} + profile_id={e.profile_id} + feed_img={e.feed_img} + like_click={e.like_click} + like_user_profile_img={e.like_user_profile_img} + like_user_profile_id={e.like_user_profile_id} + like_num={e.like_num} + post_user_mension={e.post_user_mension} + comments={e.comments} + /> + ))} + </section> + <Aside /> + </div> + </main> + </div> + ); + } +} + +export default Content;
JavaScript
- mock up ๋ฐ์ดํ„ฐ์˜ ํ‚ค ๊ฐ’์€ ์Šค๋„ค์ดํฌ ์ผ€์ด์Šค๋กœ ์‚ฌ์šฉํ•ด์ฃผ์…”๋„ ๋˜์ง€๋งŒ (๋ฐฑ์—”๋“œ์—์„œ๋Š” ๋ณดํ†ต ์Šค๋„ค์ดํฌ ์ผ€์ด์Šค๋ฅผ ์“ฐ๊ธฐ ๋•Œ๋ฌธ์—) props ์˜ ์ด๋ฆ„์€ ์นด๋ฉœ ์ผ€์ด์Šค๋กœ ํ†ต์ผํ•ด ์ฃผ์„ธ์š”!
@@ -0,0 +1,210 @@ +import 'package:flutter/material.dart'; + +class ReviewView extends StatelessWidget { + const ReviewView({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: _appBar(context), + floatingActionButtonLocation: FloatingActionButtonLocation.endFloat, + body: SingleChildScrollView( + child: Column(children: [ + _button(), + ...List.generate( + 30, + (index) => Padding( + padding: const EdgeInsets.only(bottom: 20), + child: _review(), + )), + ])), + ); + } + + AppBar _appBar(BuildContext context) => AppBar( + backgroundColor: + Theme.of(context).colorScheme.tertiary.withOpacity(0.0), + foregroundColor: Theme.of(context).colorScheme.onSecondary, + leading: GestureDetector( + onTap: () => Navigator.of(context).pop(), + ), + elevation: 0.0, + title: Text( + "๋ ˆ์‹œํ”ผ ๋“ฑ๋ก", + style: Theme.of(context).textTheme.headlineLarge, + ), + ); + + Widget _button() => Builder(builder: (context) { + return Padding( + padding: + const EdgeInsets.only(top: 20, right: 10, left: 300, bottom: 20), + child: Container( + width: 75, + height: 34, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + color: Theme.of(context).colorScheme.secondary), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(left: 8), + child: Text( + "์ตœ์‹ ์ˆœ", + style: Theme.of(context).textTheme.bodySmall, + ), + ), + Icon( + Icons.arrow_drop_down_sharp, + color: Colors.white, + ) + ], + ), + ), + ); + }); + + Widget _review() => Builder(builder: (context) { + return Container( + width: 350, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.onPrimaryContainer, + borderRadius: BorderRadius.circular(12.0), + ), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + /// ์‚ฌ์šฉ์ž ์ •๋ณด ํ‘œ์‹œ + Padding( + padding: const EdgeInsets.only(left: 10), + child: Container( + width: 48, + height: 48, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.tertiary, + borderRadius: BorderRadius.circular(12), + ), + ), + ), + + Padding( + padding: const EdgeInsets.only(top: 10, left: 10), + child: Text( + "๋‹‰๋„ค์ž„", + style: Theme.of(context).textTheme.bodyMedium, + ), + ) + ], + ), + + /// ํ‚ค์›Œ๋“œ ํ‘œ์‹œ + Padding( + padding: const EdgeInsets.only( + top: 15, bottom: 15, left: 10, right: 5), + child: Row( + children: [ + Container( + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.tertiary, + borderRadius: BorderRadius.circular(10.0), + ), + padding: + EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: Text( + "ํ˜ผ์ž ๋จน๊ธฐ ์ข‹์•„์š”", + style: Theme.of(context).textTheme.labelMedium, + ), + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 5), + child: Container( + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.tertiary, + borderRadius: BorderRadius.circular(10.0), + ), + padding: + EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: Text( + "๋“ ๋“ ํ•ด์š”", + style: Theme.of(context).textTheme.labelMedium, + ), + ), + ), + Container( + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.tertiary, + borderRadius: BorderRadius.circular(10.0), + ), + padding: + EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: Text( + "์ €๋ ดํ•ด์š”", + style: Theme.of(context).textTheme.labelMedium, + ), + ), + ], + ), + ), + + /// ์‚ฌ์ง„ + Padding( + padding: + const EdgeInsets.symmetric(vertical: 10, horizontal: 10), + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: [ + Container( + width: 160, + height: 160, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.tertiary, + borderRadius: BorderRadius.circular(12), + ), + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Container( + width: 160, + height: 160, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.tertiary, + borderRadius: BorderRadius.circular(12), + ), + ), + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Container( + width: 160, + height: 160, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.tertiary, + borderRadius: BorderRadius.circular(12), + ), + ), + ), + ], + ), + ), + ), + + /// ๋‚ด์šฉ ์ž…๋ ฅ + Padding( + padding: const EdgeInsets.only(top: 20), + child: Text( + "์˜ค๋Š˜์€ ์ƒํ† ๋งˆํ† ๊ฐ€ ์—†์–ด์„œ ํ™€ํ† ๋งˆํ† ๋ฅผ ์‚ฌ์šฉํ–ˆ์–ด์š”.^^ ์š”๊ฑฐ ํ•œ ํ†ต ๋‹ค ๋“ค์–ด๊ฐ”๋„ค์š”. ์ „์ฒด ์Šคํ”„์˜ ์–‘์€ 8์ธ๋ถ„ ์ •๋„??", + style: Theme.of(context).textTheme.bodyMedium, + ), + ), + ], + ), + ), + ); + }); +}
Unknown
ํ”Œ๋กœํŒ… ๋ฒ„ํŠผ ์ œ๊ฑฐํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค. ์ด์ „ PR ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.
@@ -5,13 +5,15 @@ import com.somemore.domains.review.dto.response.ReviewDetailResponseDto; import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto; import com.somemore.domains.review.usecase.ReviewQueryUseCase; +import com.somemore.global.auth.annotation.RoleId; import com.somemore.global.common.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; +import org.springframework.security.access.annotation.Secured; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -41,7 +43,7 @@ public ApiResponse<ReviewDetailResponseDto> getById(@PathVariable Long id) { ); } - @Operation(summary = "๊ธฐ๊ด€๋ณ„ ๋ฆฌ๋ทฐ ์กฐํšŒ", description = "๊ธฐ๊ด€ ID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ๋ทฐ ์กฐํšŒ") + @Operation(summary = "ํŠน์ • ๊ธฐ๊ด€ ๋ฆฌ๋ทฐ ์กฐํšŒ", description = "๊ธฐ๊ด€ ID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ๋ทฐ ์กฐํšŒ") @GetMapping("/reviews/center/{centerId}") public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getReviewsByCenterId( @PathVariable UUID centerId, @@ -53,14 +55,34 @@ public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getReviewsByCenter .pageable(pageable) .build(); + return ApiResponse.ok( + 200, + reviewQueryUseCase.getDetailsWithNicknameByCenterId(centerId, condition), + "ํŠน์ • ๊ธฐ๊ด€ ๋ฆฌ๋ทฐ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ ์„ฑ๊ณต" + ); + } + + @Secured("ROLE_CENTER") + @Operation(summary = "๊ธฐ๊ด€ ๋ฆฌ๋ทฐ ์กฐํšŒ", description = "๊ธฐ๊ด€ ์ž์‹ ์˜ ๋ฆฌ๋ทฐ ์กฐํšŒ") + @GetMapping("/reviews/center/me") + public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getMyCenterReviews( + @RoleId UUID centerId, + @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable, + @RequestParam(required = false) VolunteerCategory category + ) { + ReviewSearchCondition condition = ReviewSearchCondition.builder() + .category(category) + .pageable(pageable) + .build(); + return ApiResponse.ok( 200, reviewQueryUseCase.getDetailsWithNicknameByCenterId(centerId, condition), "๊ธฐ๊ด€ ๋ฆฌ๋ทฐ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ ์„ฑ๊ณต" ); } - @Operation(summary = "๋ด‰์‚ฌ์ž ๋ฆฌ๋ทฐ ์กฐํšŒ", description = "๋ด‰์‚ฌ์ž ID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ๋ทฐ ์กฐํšŒ") + @Operation(summary = "ํŠน์ • ๋ด‰์‚ฌ์ž ๋ฆฌ๋ทฐ ์กฐํšŒ", description = "๋ด‰์‚ฌ์ž ID๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ๋ทฐ ์กฐํšŒ") @GetMapping("/reviews/volunteer/{volunteerId}") public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getReviewsByVolunteerId( @PathVariable UUID volunteerId, @@ -75,7 +97,27 @@ public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getReviewsByVolunt return ApiResponse.ok( 200, reviewQueryUseCase.getDetailsWithNicknameByVolunteerId(volunteerId, condition), - "์œ ์ € ๋ฆฌ๋ทฐ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ ์„ฑ๊ณต" + "ํŠน์ • ๋ด‰์‚ฌ์ž ๋ฆฌ๋ทฐ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ ์„ฑ๊ณต" + ); + } + + @Secured("ROLE_VOLUNTEER") + @Operation(summary = "๋ด‰์‚ฌ์ž ๋ฆฌ๋ทฐ ์กฐํšŒ", description = "๋ด‰์‚ฌ์ž ์ž์‹ ์˜ ๋ฆฌ๋ทฐ ์กฐํšŒ") + @GetMapping("/reviews/volunteer/me") + public ApiResponse<Page<ReviewDetailWithNicknameResponseDto>> getMyVolunteerReviews( + @RoleId UUID volunteerId, + @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable, + @RequestParam(required = false) VolunteerCategory category + ) { + ReviewSearchCondition condition = ReviewSearchCondition.builder() + .category(category) + .pageable(pageable) + .build(); + + return ApiResponse.ok( + 200, + reviewQueryUseCase.getDetailsWithNicknameByVolunteerId(volunteerId, condition), + "๋ด‰์‚ฌ์ž ๋ฆฌ๋ทฐ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ ์„ฑ๊ณต" ); }
Java
๋นŒ๋” ๋กœ์ง์„ ์ปจ๋””์…˜ ํด๋ž˜์Šค์˜ of ์ •์  ๋ฉ”์„œ๋“œ์—์„œ ์ง„ํ–‰ํ•˜๋ฉด ๋” ๊น”๋”ํ•  ๊ฒƒ ๊ฐ™์•„์š”~ ๊ตณ์ด ์ˆ˜์ •ํ•  ํ•„์š”๋Š” ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค!
@@ -1,35 +1,34 @@ package com.somemore.domains.review.service; -import com.somemore.domains.center.usecase.query.CenterQueryUseCase; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW; + import com.somemore.domains.review.domain.Review; import com.somemore.domains.review.dto.condition.ReviewSearchCondition; import com.somemore.domains.review.dto.response.ReviewDetailResponseDto; import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto; import com.somemore.domains.review.repository.ReviewRepository; import com.somemore.domains.review.usecase.ReviewQueryUseCase; -import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; +import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; import com.somemore.global.exception.NoSuchElementException; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; +import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW; - @RequiredArgsConstructor @Transactional(readOnly = true) @Service public class ReviewQueryService implements ReviewQueryUseCase { private final ReviewRepository reviewRepository; - private final VolunteerQueryUseCase volunteerQueryUseCase; - private final CenterQueryUseCase centerQueryUseCase; + private final NEWVolunteerQueryUseCase volunteerQueryUseCase; + private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase; @Override public boolean existsByVolunteerApplyId(Long volunteerApplyId) { @@ -45,7 +44,9 @@ public Review getById(Long id) { @Override public ReviewDetailResponseDto getDetailById(Long id) { Review review = getById(id); - return ReviewDetailResponseDto.from(review); + Long recruitBoardId = volunteerApplyQueryUseCase.getRecruitBoardIdById( + review.getVolunteerApplyId()); + return ReviewDetailResponseDto.of(review, recruitBoardId); } @Override @@ -54,10 +55,11 @@ public Page<ReviewDetailWithNicknameResponseDto> getDetailsWithNicknameByVolunte ReviewSearchCondition condition ) { String nickname = volunteerQueryUseCase.getNicknameById(volunteerId); - Page<Review> reviews = reviewRepository.findAllByVolunteerIdAndSearch(volunteerId, condition); + Page<Review> reviews = reviewRepository.findAllByVolunteerIdAndSearch(volunteerId, + condition); return reviews.map( - review -> ReviewDetailWithNicknameResponseDto.from(review, nickname) + review -> ReviewDetailWithNicknameResponseDto.of(review, nickname) ); } @@ -66,28 +68,20 @@ public Page<ReviewDetailWithNicknameResponseDto> getDetailsWithNicknameByCenterI UUID centerId, ReviewSearchCondition condition ) { - centerQueryUseCase.validateCenterExists(centerId); - Page<Review> reviews = reviewRepository.findAllByCenterIdAndSearch(centerId, condition); List<UUID> volunteerIds = reviews.get().map(Review::getVolunteerId).toList(); - Map<UUID, String> volunteerNicknames = getVolunteerNicknames(volunteerIds); + Map<UUID, String> volunteerNicknames = mapVolunteerIdsToNicknames(volunteerIds); - return reviews.map( - review -> { - String nickname = volunteerNicknames.getOrDefault(review.getVolunteerId(), - "์‚ญ์ œ๋œ ์•„์ด๋””"); - return ReviewDetailWithNicknameResponseDto.from(review, nickname); - }); + return reviews.map(review -> + ReviewDetailWithNicknameResponseDto.of(review, + volunteerNicknames.get(review.getVolunteerId())) + ); } - private Map<UUID, String> getVolunteerNicknames(List<UUID> volunteerIds) { - List<Volunteer> volunteers = volunteerQueryUseCase.getAllByIds(volunteerIds); - - Map<UUID, String> volunteerNicknames = new HashMap<>(); - for (Volunteer volunteer : volunteers) { - volunteerNicknames.put(volunteer.getId(), volunteer.getNickname()); - } - - return volunteerNicknames; + private Map<UUID, String> mapVolunteerIdsToNicknames(List<UUID> volunteerIds) { + return volunteerQueryUseCase.getVolunteerNicknameAndIdsByIds(volunteerIds) + .stream() + .collect(Collectors.toMap(VolunteerNicknameAndId::id, + VolunteerNicknameAndId::nickname)); } }
Java
๋ฉ”์„œ๋“œ๋กœ ์ฝ”๋“œ๋ฅผ ํฌ์žฅํ•˜๋ฉด ๊ฐ€๋…์„ฑ์ด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”~
@@ -1,35 +1,34 @@ package com.somemore.domains.review.service; -import com.somemore.domains.center.usecase.query.CenterQueryUseCase; +import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW; + import com.somemore.domains.review.domain.Review; import com.somemore.domains.review.dto.condition.ReviewSearchCondition; import com.somemore.domains.review.dto.response.ReviewDetailResponseDto; import com.somemore.domains.review.dto.response.ReviewDetailWithNicknameResponseDto; import com.somemore.domains.review.repository.ReviewRepository; import com.somemore.domains.review.usecase.ReviewQueryUseCase; -import com.somemore.domains.volunteer.domain.Volunteer; -import com.somemore.domains.volunteer.usecase.VolunteerQueryUseCase; +import com.somemore.domains.volunteerapply.usecase.VolunteerApplyQueryUseCase; import com.somemore.global.exception.NoSuchElementException; +import com.somemore.volunteer.repository.record.VolunteerNicknameAndId; +import com.somemore.volunteer.usecase.NEWVolunteerQueryUseCase; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_REVIEW; - @RequiredArgsConstructor @Transactional(readOnly = true) @Service public class ReviewQueryService implements ReviewQueryUseCase { private final ReviewRepository reviewRepository; - private final VolunteerQueryUseCase volunteerQueryUseCase; - private final CenterQueryUseCase centerQueryUseCase; + private final NEWVolunteerQueryUseCase volunteerQueryUseCase; + private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase; @Override public boolean existsByVolunteerApplyId(Long volunteerApplyId) { @@ -45,7 +44,9 @@ public Review getById(Long id) { @Override public ReviewDetailResponseDto getDetailById(Long id) { Review review = getById(id); - return ReviewDetailResponseDto.from(review); + Long recruitBoardId = volunteerApplyQueryUseCase.getRecruitBoardIdById( + review.getVolunteerApplyId()); + return ReviewDetailResponseDto.of(review, recruitBoardId); } @Override @@ -54,10 +55,11 @@ public Page<ReviewDetailWithNicknameResponseDto> getDetailsWithNicknameByVolunte ReviewSearchCondition condition ) { String nickname = volunteerQueryUseCase.getNicknameById(volunteerId); - Page<Review> reviews = reviewRepository.findAllByVolunteerIdAndSearch(volunteerId, condition); + Page<Review> reviews = reviewRepository.findAllByVolunteerIdAndSearch(volunteerId, + condition); return reviews.map( - review -> ReviewDetailWithNicknameResponseDto.from(review, nickname) + review -> ReviewDetailWithNicknameResponseDto.of(review, nickname) ); } @@ -66,28 +68,20 @@ public Page<ReviewDetailWithNicknameResponseDto> getDetailsWithNicknameByCenterI UUID centerId, ReviewSearchCondition condition ) { - centerQueryUseCase.validateCenterExists(centerId); - Page<Review> reviews = reviewRepository.findAllByCenterIdAndSearch(centerId, condition); List<UUID> volunteerIds = reviews.get().map(Review::getVolunteerId).toList(); - Map<UUID, String> volunteerNicknames = getVolunteerNicknames(volunteerIds); + Map<UUID, String> volunteerNicknames = mapVolunteerIdsToNicknames(volunteerIds); - return reviews.map( - review -> { - String nickname = volunteerNicknames.getOrDefault(review.getVolunteerId(), - "์‚ญ์ œ๋œ ์•„์ด๋””"); - return ReviewDetailWithNicknameResponseDto.from(review, nickname); - }); + return reviews.map(review -> + ReviewDetailWithNicknameResponseDto.of(review, + volunteerNicknames.get(review.getVolunteerId())) + ); } - private Map<UUID, String> getVolunteerNicknames(List<UUID> volunteerIds) { - List<Volunteer> volunteers = volunteerQueryUseCase.getAllByIds(volunteerIds); - - Map<UUID, String> volunteerNicknames = new HashMap<>(); - for (Volunteer volunteer : volunteers) { - volunteerNicknames.put(volunteer.getId(), volunteer.getNickname()); - } - - return volunteerNicknames; + private Map<UUID, String> mapVolunteerIdsToNicknames(List<UUID> volunteerIds) { + return volunteerQueryUseCase.getVolunteerNicknameAndIdsByIds(volunteerIds) + .stream() + .collect(Collectors.toMap(VolunteerNicknameAndId::id, + VolunteerNicknameAndId::nickname)); } }
Java
๋ณต์ˆ˜ํ˜• ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
๊ตฌ์กฐ๋ถ„ํ•ดํ• ๋‹น์„ ์ž˜ ์“ฐ์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
comment๊ด€๋ จ ํ•จ์ˆ˜๋ฅผ ๊น”๋”ํ•˜๊ฒŒ ์ž˜ ์ •๋ฆฌํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
์ปค๋ฉ˜ํŠธ ์ปดํฌ๋„ŒํŠธ์— ํ”„๋กญ์Šค ์ „๋‹ฌ์„ ๊น”๋”ํ•˜๊ฒŒ ์ž˜ ํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
์‚ผํ•ญ์—ฐ์‚ฐ์ž ์‚ฌ์šฉ์„ ์ž˜ ํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
Lifecycle Method๋ฅผ ์ž˜ ์‚ฌ์šฉํ•˜์‹ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
์ €๋„ ์ ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!๐Ÿ‘
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
๋ฒ„ํŠผ์ด ํ™œ์„ฑํ™”๋  ๋•Œ ์ƒ‰์ƒ ๋ณ€๊ฒฝ๊ณผ ๋น„ํ™œ์„ฑํ™” ๊ธฐ๋Šฅ๊นŒ์ง€ ๊ตฌํ˜„ํ•˜์‹  ์  ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค:)
@@ -0,0 +1,74 @@ +[ + { + "id": 1, + "userName": "bbangho", + "alt": "wecode", + "img": "/images/youngho/hanRiver.jpeg", + "comment": [ + { + "id": 1, + "userName": "bbangho", + "content": "ํ•œ๊ฐ• ๋‹ค๋…€๊ฐ~ โœŒ๏ธ", + "isLiked": true + }, + { + "id": 2, + "userName": "manja", + "content": "ํ•œ๊ฐ• ๊ฐฑ~ ๐Ÿ”ซ ๐Ÿ”ซ", + "isLiked": true + } + ] + }, + { + "id": 2, + "userName": "joonsikyang", + "alt": "wecode", + "img": "/images/youngho/we.jpeg", + "comment": [ + { + "id": 1, + "userName": "joonsikyang", + "content": "Work hard ๐Ÿคฏ", + "isLiked": true + }, + { + "id": 2, + "userName": "bbangho", + "content": "Go for it ๐Ÿคฃ", + "isLiked": false + }, + { + "id": 3, + "userName": "manja", + "content": "๐Ÿ”ฅ๐Ÿ”ฅ", + "isLiked": false + } + ] + }, + { + "id": 3, + "userName": "jayPark", + "alt": "wecode", + "img": "/images/youngho/we.jpeg", + "comment": [ + { + "id": 1, + "userName": "jayPark", + "content": "Let's get it", + "isLiked": true + }, + { + "id": 2, + "userName": "bbanho", + "content": "Skrt~ ๐Ÿ˜Ž", + "isLiked": false + }, + { + "id": 3, + "userName": "gildong", + "content": "Yo~ ๐ŸŒž", + "isLiked": true + } + ] + } +]
Unknown
๋ชฉ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ ๋„ˆ๋ฌด ์ข‹์Šต๋‹ˆ๋‹ค! :)
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
```suggestion <button onClick={this.handleLogin} className={condition ? 'buttonActivate' : 'buttonDisabled'} id="loginButton" disabled={ condition ? false : true} > ๋กœ๊ทธ์ธ </button> ``` ํ•ด๋‹น ์กฐ๊ฑด์„ condition์ด๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด์•„์„œ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๊ฐ€๋…์„ฑ์ด ๋” ์ข‹์•„์ง€๊ฒ ๋„ค์š”! ex) ``` const condition = loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); ```
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
์ฐธ๊ณ ๋กœ ์œ„์˜ ๋ณ€์ˆ˜๋Š” render ํ•จ์ˆ˜ ๋‚ด์—์„œ ์„ ์–ธํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค!!
@@ -0,0 +1,78 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +body { + background-color: #fafafa; +} + +.container { + text-align: center; + width: 600px; + height: 600px; + margin: 50px auto 0 auto; + border: 1px solid #e6e6e6; + background-color: white; +} + +.header { + padding: 30px; + font-family: 'Lobster', cursive; + font-size: 70px; + font-weight: 1px; +} + +.loginForm { + width: 425px; + margin: 0 auto; +} + +#id { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#password { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#loginButton { + display: block; + width: 459px; + margin: 20px 0px auto; + padding: 15px; + border: 0px; + border-radius: 5px; + color: white; + font-size: 20px; +} + +.findPassword { + display: block; + height: 50px; + margin-top: 180px; + font-size: 18px; + text-decoration: none; +} + +.buttonDisabled { + background-color: #c5e1fc; +} + +.buttonActivate { + background-color: #0095f6; +} + +a { + text-decoration: none; +}
Unknown
```suggestion body { background-color: #fafafa; } .container { text-align: center; border: 1px solid #e6e6e6; background-color: white; width: 600px; height: 600px; margin: 50px auto 0 auto; } .header { font-family: 'Lobster', cursive; font-size: 70px; font-weight: 1px; padding: 30px; } ``` ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ์…€๋Ÿญํ„ฐ ์‹œ์ž‘ํ•  ๋•Œ๋Š” ํ•œ ์ค„ ๋„์›Œ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
@@ -0,0 +1,78 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +body { + background-color: #fafafa; +} + +.container { + text-align: center; + width: 600px; + height: 600px; + margin: 50px auto 0 auto; + border: 1px solid #e6e6e6; + background-color: white; +} + +.header { + padding: 30px; + font-family: 'Lobster', cursive; + font-size: 70px; + font-weight: 1px; +} + +.loginForm { + width: 425px; + margin: 0 auto; +} + +#id { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#password { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#loginButton { + display: block; + width: 459px; + margin: 20px 0px auto; + padding: 15px; + border: 0px; + border-radius: 5px; + color: white; + font-size: 20px; +} + +.findPassword { + display: block; + height: 50px; + margin-top: 180px; + font-size: 18px; + text-decoration: none; +} + +.buttonDisabled { + background-color: #c5e1fc; +} + +.buttonActivate { + background-color: #0095f6; +} + +a { + text-decoration: none; +}
Unknown
์˜ํ˜ธ๋‹˜! ์ „์ฒด์ ์œผ๋กœ CSS ์†์„ฑ ์ˆœ์„œ ํ™•์ธํ•ด์„œ ์ ์šฉํ•ด์ฃผ์„ธ์š”~ - ํ•˜๋‚˜์˜ ์š”์†Œ์— ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์†์„ฑ์„ ๋ถ€์—ฌํ•˜๋Š” ๊ฒฝ์šฐ ์ค‘์š”๋„, ๊ด€๋ จ๋„์— ๋”ฐ๋ผ์„œ ๋‚˜๋ฆ„์˜ convention์„ ์ง€์ผœ์„œ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. - ์ผ๋ฐ˜์ ์ธ convention ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆœ์„œ ์ ์šฉํ•ด์ฃผ์„ธ์š”. [CSS property ์ˆœ์„œ] - Layout Properties (position, float, clear, display) - Box Model Properties (width, height, margin, padding) - Visual Properties (color, background, border, box-shadow) - Typography Properties (font-size, font-family, text-align, text-transform) - Misc Properties (cursor, overflow, z-index)
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
import ์ˆœ์„œ๋Š” ์ž˜ ๋งž์ถฐ์ฃผ์…จ๊ณ , ํ•ด๋‹น ๋ถ€๋ถ„์—์„œ๋Š” ์ค„๋ฐ”๊ฟˆ ์—†์ด ์ง„ํ–‰ํ•ด์ฃผ์„ธ์š”~
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
fetchํ•จ์ˆ˜์˜ `get method๋Š” method์˜ default` ๊ฐ’์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ `์ƒ๋žต์ด ๊ฐ€๋Šฅ`ํ•ฉ๋‹ˆ๋‹ค. ๊ณ ๋กœ get method ์š”์ฒญ์‹œ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ๋‘๋ฒˆ์งธ ์ธ์ž๊ฐ€ ์ƒ๋žต ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ```jsx const foo = () => { fetch(`${cartAPI}/quantity`) .then((res) => res.json()) ```
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
story ๋ถ€๋ถ„์ด ์—ฌ๋Ÿฌ๋ฒˆ ๋ฐ˜๋ณต๋˜๊ณ  ์žˆ๋„ค์š”! ์ƒ์ˆ˜ ๋ฐ์ดํ„ฐ์™€ map์„ ์‚ฌ์šฉํ•ด์„œ ์ค‘๋ณต๋œ ๋ถ€๋ถ„์„ ์ค„์—ฌ์ฃผ์„ธ์š”! ``` const STORIES = [ {img: "//", name: "wecorder1"}, {img: "//", name: "wecorder2"}, {img: "//", name: "wecorder3"} ]; STORIES.map(); ```
@@ -0,0 +1,285 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +@media screen and (max-width: 1200px) { + .mainRight { + display: none; + } + + .article { + width: 100%; + } +} + +body { + margin: 0; + padding: 0; + border-collapse: collapse; +} + +article { + width: 800px; + background-color: white; +} + +nav { + display: flex; + justify-content: space-around; + align-items: center; + margin: 0px 170px; + height: 60px; +} + +.logo { + width: 30px; + height: 30px; + padding-right: 15px; + border-right: 1px solid black; +} + +.rightIcon { + width: 30px; + height: 30px; + margin-right: 30px; +} + +.instagram { + margin-left: 15px; + font-family: 'Lobster', cursive; + font-size: 33px; + font-weight: 1; +} + +.search { + outline: none; +} + +.writeComment { + width: 100%; + height: 40px; + padding-left: 10px; + border: 1px solid #efefef; + outline: none; +} + +.search-box { + > input { + width: 200px; + height: 20px; + border: 1px solid #dbdbdb; + text-align: center; + } + + position: relative; + > img { + position: absolute; + width: 11px; + height: 11px; + left: 75px; + top: 7px; + } +} + +main { + padding: 60px 0px; + background-color: #fafafa; +} + +.content { + display: flex; + justify-content: space-around; + flex-direction: row; + margin: 0px 350px; +} + +.mainRight { + width: 330px; + margin-left: 10px; +} + +.feedTop { + display: flex; + justify-content: space-between; + align-items: center; + width: 780px; + padding: 10px 10px; + border: 1px solid #e6e6e6; +} + +.feedUser { + display: flex; + align-items: center; +} + +.feedPicture { + height: 800px; + border: 1px solid #e6e6e6; +} + +.feedId { + margin-left: 10px; +} + +.feedMore { + width: 15px; + height: 15px; +} + +.smallUserPicture { + width: 40px; + height: 40px; + border: 1px solid #e6e6e6; + border-radius: 50px; +} + +.feedIcons { + > img { + width: 27px; + height: 27px; + } + + > div { + > img { + width: 27px; + height: 27px; + } + } + display: flex; + justify-content: space-between; + flex-direction: row; + margin: 0px; +} + +.feedBottom { + padding: 10px 10px; + border-left: 1px solid #efefef; + border-right: 1px solid #efefef; + border-bottom: 1px solid #efefef; +} + +.FeedBottomLeftIcon { + > img { + padding-right: 10px; + } +} + +.like { + > img { + width: 15px; + height: 15px; + margin-right: 5px; + border: 1px solid #e6e6e6; + border-radius: 7px; + } + display: flex; + align-items: center; +} + +.comment { + > div { + > div { + color: #a4a4a4; + } + } +} + +.commentIcons { + float: right; + display: inline; + width: 15px; + height: 15px; + margin-left: 5px; +} + +.boldFont { + font-weight: bolder; +} + +.addCommentFrom { + position: relative; + width: 786px; +} + +.postingButton { + position: absolute; + color: #cde6fc; + background-color: white; + top: 14px; + right: 10px; + border: 0; + outline: 0; +} + +.rightTop { + display: flex; + align-items: center; + width: 300px; +} + +.wecodeLogo { + width: 60px; + height: 60px; + margin-right: 20px; + border-radius: 50px; +} + +.lightFont { + color: #9e9e9e; +} + +.followFont { + color: #3797f0; +} + +.rightMiddle { + height: 200px; + margin: 20px 0px; + padding: 12px; + background: white; + border: 3px solid #e6e6e6; + border-radius: 7px; + overflow: scroll; +} + +.seeAllStory { + display: flex; + align-items: center; + justify-content: space-between; +} + +.friendsRecommendContainer { + display: flex; + align-items: center; + justify-content: space-between; +} + +.story { + display: flex; + align-items: center; + margin: 10px; + + > img { + width: 40px; + height: 40px; + margin-right: 10px; + border-radius: 50px; + border: 2px solid #d93081; + } +} + +.friendsRecommend { + display: flex; + align-items: center; + margin: 10px; + > img { + width: 40px; + height: 40px; + border-radius: 50px; + margin-right: 10px; + } +} + +footer { + margin-top: 20px; + > .boldFont { + margin-top: 10px; + } +}
Unknown
๋ฐ˜์‘ํ˜• ์•„์ฃผ ์ข‹๋„ค์š”!! ๋ธŒ๋ ˆ์ดํฌ ํฌ์ธํŠธ๋Š” ๊ธฐํš๋งˆ๋‹ค ๋‹ฌ๋ผ์ง€์ง€๋งŒ ๋ณดํ†ต ํƒœ๋ธ”๋ฆฟ๊ณผ ๋ฐ์Šคํฌํƒ‘์˜ ๊ตฌ๋ถ„์ ์€ 1078px์ด๋ผ๋Š” ์  ์•Œ์•„๋‘์„ธ์š”! ๋ชจ๋ฐ”์ผ๊ณผ ํƒœ๋ธ”๋ฆฟ์€ 768px์ž…๋‹ˆ๋‹ค!
@@ -0,0 +1,285 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +@media screen and (max-width: 1200px) { + .mainRight { + display: none; + } + + .article { + width: 100%; + } +} + +body { + margin: 0; + padding: 0; + border-collapse: collapse; +} + +article { + width: 800px; + background-color: white; +} + +nav { + display: flex; + justify-content: space-around; + align-items: center; + margin: 0px 170px; + height: 60px; +} + +.logo { + width: 30px; + height: 30px; + padding-right: 15px; + border-right: 1px solid black; +} + +.rightIcon { + width: 30px; + height: 30px; + margin-right: 30px; +} + +.instagram { + margin-left: 15px; + font-family: 'Lobster', cursive; + font-size: 33px; + font-weight: 1; +} + +.search { + outline: none; +} + +.writeComment { + width: 100%; + height: 40px; + padding-left: 10px; + border: 1px solid #efefef; + outline: none; +} + +.search-box { + > input { + width: 200px; + height: 20px; + border: 1px solid #dbdbdb; + text-align: center; + } + + position: relative; + > img { + position: absolute; + width: 11px; + height: 11px; + left: 75px; + top: 7px; + } +} + +main { + padding: 60px 0px; + background-color: #fafafa; +} + +.content { + display: flex; + justify-content: space-around; + flex-direction: row; + margin: 0px 350px; +} + +.mainRight { + width: 330px; + margin-left: 10px; +} + +.feedTop { + display: flex; + justify-content: space-between; + align-items: center; + width: 780px; + padding: 10px 10px; + border: 1px solid #e6e6e6; +} + +.feedUser { + display: flex; + align-items: center; +} + +.feedPicture { + height: 800px; + border: 1px solid #e6e6e6; +} + +.feedId { + margin-left: 10px; +} + +.feedMore { + width: 15px; + height: 15px; +} + +.smallUserPicture { + width: 40px; + height: 40px; + border: 1px solid #e6e6e6; + border-radius: 50px; +} + +.feedIcons { + > img { + width: 27px; + height: 27px; + } + + > div { + > img { + width: 27px; + height: 27px; + } + } + display: flex; + justify-content: space-between; + flex-direction: row; + margin: 0px; +} + +.feedBottom { + padding: 10px 10px; + border-left: 1px solid #efefef; + border-right: 1px solid #efefef; + border-bottom: 1px solid #efefef; +} + +.FeedBottomLeftIcon { + > img { + padding-right: 10px; + } +} + +.like { + > img { + width: 15px; + height: 15px; + margin-right: 5px; + border: 1px solid #e6e6e6; + border-radius: 7px; + } + display: flex; + align-items: center; +} + +.comment { + > div { + > div { + color: #a4a4a4; + } + } +} + +.commentIcons { + float: right; + display: inline; + width: 15px; + height: 15px; + margin-left: 5px; +} + +.boldFont { + font-weight: bolder; +} + +.addCommentFrom { + position: relative; + width: 786px; +} + +.postingButton { + position: absolute; + color: #cde6fc; + background-color: white; + top: 14px; + right: 10px; + border: 0; + outline: 0; +} + +.rightTop { + display: flex; + align-items: center; + width: 300px; +} + +.wecodeLogo { + width: 60px; + height: 60px; + margin-right: 20px; + border-radius: 50px; +} + +.lightFont { + color: #9e9e9e; +} + +.followFont { + color: #3797f0; +} + +.rightMiddle { + height: 200px; + margin: 20px 0px; + padding: 12px; + background: white; + border: 3px solid #e6e6e6; + border-radius: 7px; + overflow: scroll; +} + +.seeAllStory { + display: flex; + align-items: center; + justify-content: space-between; +} + +.friendsRecommendContainer { + display: flex; + align-items: center; + justify-content: space-between; +} + +.story { + display: flex; + align-items: center; + margin: 10px; + + > img { + width: 40px; + height: 40px; + margin-right: 10px; + border-radius: 50px; + border: 2px solid #d93081; + } +} + +.friendsRecommend { + display: flex; + align-items: center; + margin: 10px; + > img { + width: 40px; + height: 40px; + border-radius: 50px; + margin-right: 10px; + } +} + +footer { + margin-top: 20px; + > .boldFont { + margin-top: 10px; + } +}
Unknown
๊ฐ™์€ ์Šคํƒ€์ผ์˜ ๊ฒฝ์šฐ์—๋Š” ์ค‘๋ณตํ•˜์—ฌ ์ฃผ์‹œ์ง€ ๋ง๊ณ  ๊ฐ™์€ ํด๋ž˜์Šค๋ช…์„ ์‚ฌ์šฉํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
import ๊ตฌ๋ถ„์€ ๋„ˆ๋ฌด ์ข‹์ง€๋งŒ ์ค„๋ฐ”๊ฟˆ์€ ์•ˆํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค!!!
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
์ด๋ ‡๊ฒŒ ๊ตฌ์กฐ๋ถ„ํ•ดํ• ๋‹น ๋„ˆ๋ฌด ์ข‹๋„ค์š”!!
@@ -0,0 +1,74 @@ +[ + { + "id": 1, + "userName": "bbangho", + "alt": "wecode", + "img": "/images/youngho/hanRiver.jpeg", + "comment": [ + { + "id": 1, + "userName": "bbangho", + "content": "ํ•œ๊ฐ• ๋‹ค๋…€๊ฐ~ โœŒ๏ธ", + "isLiked": true + }, + { + "id": 2, + "userName": "manja", + "content": "ํ•œ๊ฐ• ๊ฐฑ~ ๐Ÿ”ซ ๐Ÿ”ซ", + "isLiked": true + } + ] + }, + { + "id": 2, + "userName": "joonsikyang", + "alt": "wecode", + "img": "/images/youngho/we.jpeg", + "comment": [ + { + "id": 1, + "userName": "joonsikyang", + "content": "Work hard ๐Ÿคฏ", + "isLiked": true + }, + { + "id": 2, + "userName": "bbangho", + "content": "Go for it ๐Ÿคฃ", + "isLiked": false + }, + { + "id": 3, + "userName": "manja", + "content": "๐Ÿ”ฅ๐Ÿ”ฅ", + "isLiked": false + } + ] + }, + { + "id": 3, + "userName": "jayPark", + "alt": "wecode", + "img": "/images/youngho/we.jpeg", + "comment": [ + { + "id": 1, + "userName": "jayPark", + "content": "Let's get it", + "isLiked": true + }, + { + "id": 2, + "userName": "bbanho", + "content": "Skrt~ ๐Ÿ˜Ž", + "isLiked": false + }, + { + "id": 3, + "userName": "gildong", + "content": "Yo~ ๐ŸŒž", + "isLiked": true + } + ] + } +]
Unknown
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
@@ -1,10 +1,94 @@ import React from 'react'; +import { Link } from 'react-router-dom'; + +import './Login.scss'; class Login extends React.Component { + constructor() { + super(); + this.state = { + loginId: '', + loginPassword: '', + }; + } + + handleLoginInput = e => { + const { value, name } = e.target; + this.setState({ + [name]: value, + }); + }; + + handleLogin = () => { + fetch('http://10.58.0.84:8000/users/login', { + method: 'POST', + body: JSON.stringify({ + email: this.state.loginId, + password: this.state.loginPassword, + }), + }) + .then(response => response.json()) + .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + }; + + // handleLogin = () => { + // fetch('http://10.58.0.84:8000/users/signup', { + // method: 'POST', + // body: JSON.stringify({ + // name: '๊น€์˜ํ˜ธ', + // email: this.state.loginId, + // password: this.state.loginPassword, + // phone_number: '01012345678', + // date_of_birth: '1995-07-07', + // gender: 'M', + // address: 'Seoul', + // }), + // }) + // .then(response => response.json()) + // .then(result => console.log('๊ฒฐ๊ณผ: ', result)); + // }; + render() { + const { checkIdPassword, handleLoginInput } = this; + const { loginId, loginPassword } = this.state; + + const condition = + loginId.length >= 5 && loginPassword.length >= 5 && loginId.includes('@'); + return ( <div> - <h3>๋กœ๊ทธ์ธ</h3> + <div className="container"> + <header className="header">Westagram</header> + <form className="loginForm" onKeyUp={checkIdPassword}> + <input + id="id" + name="loginId" + type="text" + placeholder="์ „ํ™”๋ฒˆํ˜ธ, ์‚ฌ์šฉ์ž ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ" + onChange={handleLoginInput} + /> + <input + id="password" + name="loginPassword" + type="password" + placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ" + onChange={handleLoginInput} + /> + <Link to="/main"> + <button + onClick={this.handleLogin} + className={condition ? 'buttonActivate' : 'buttonDisabled'} + id="loginButton" + disabled={condition ? false : true} + > + ๋กœ๊ทธ์ธ + </button> + </Link> + </form> + <a href="#!" className="findPassword"> + ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์žŠ์œผ์…จ๋‚˜์š”? + </a> + </div> </div> ); }
JavaScript
๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,78 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +body { + background-color: #fafafa; +} + +.container { + text-align: center; + width: 600px; + height: 600px; + margin: 50px auto 0 auto; + border: 1px solid #e6e6e6; + background-color: white; +} + +.header { + padding: 30px; + font-family: 'Lobster', cursive; + font-size: 70px; + font-weight: 1px; +} + +.loginForm { + width: 425px; + margin: 0 auto; +} + +#id { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#password { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#loginButton { + display: block; + width: 459px; + margin: 20px 0px auto; + padding: 15px; + border: 0px; + border-radius: 5px; + color: white; + font-size: 20px; +} + +.findPassword { + display: block; + height: 50px; + margin-top: 180px; + font-size: 18px; + text-decoration: none; +} + +.buttonDisabled { + background-color: #c5e1fc; +} + +.buttonActivate { + background-color: #0095f6; +} + +a { + text-decoration: none; +}
Unknown
๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,78 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +body { + background-color: #fafafa; +} + +.container { + text-align: center; + width: 600px; + height: 600px; + margin: 50px auto 0 auto; + border: 1px solid #e6e6e6; + background-color: white; +} + +.header { + padding: 30px; + font-family: 'Lobster', cursive; + font-size: 70px; + font-weight: 1px; +} + +.loginForm { + width: 425px; + margin: 0 auto; +} + +#id { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#password { + display: block; + width: 100%; + margin: 20px 0px auto; + padding: 15px; + border: 1px solid #efefef; + background-color: #fafafa; + border-radius: 5px; + font-size: 20px; +} + +#loginButton { + display: block; + width: 459px; + margin: 20px 0px auto; + padding: 15px; + border: 0px; + border-radius: 5px; + color: white; + font-size: 20px; +} + +.findPassword { + display: block; + height: 50px; + margin-top: 180px; + font-size: 18px; + text-decoration: none; +} + +.buttonDisabled { + background-color: #c5e1fc; +} + +.buttonActivate { + background-color: #0095f6; +} + +a { + text-decoration: none; +}
Unknown
๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -1,10 +1,178 @@ import React from 'react'; +import Nav from '../../../components/Nav/Nav'; +import Feed from '../../../components/Feed/Feed'; +import './Main.scss'; + class Main extends React.Component { + constructor() { + super(); + this.state = { + feeds: [], + }; + } + + componentDidMount() { + fetch('/data/feedData.json', { + method: 'GET', + }) + .then(res => res.json()) + .then(data => { + this.setState({ + feeds: data, + }); + }); + } + render() { + const { feeds } = this.state; + + const STORIES = [ + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder1', + time: 43, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder2', + time: 3, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder3', + time: 23, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder4', + time: 27, + }, + { + alt: '์Šคํ† ๋ฆฌ ํ”„๋กœํ•„ ์‚ฌ์ง„', + img: '/images/youngho/wecode.png', + name: 'wecorder5', + time: 13, + }, + ]; + + const Stories = STORIES.map(store => { + return ( + <div className="story"> + <img alt={store.alt} src={store.img} /> + <div> + <div className="boldFont">{store.name}</div> + <div className="lightFont">{store.time}๋ถ„ ์ „</div> + </div> + </div> + ); + }); return ( <div> - <h3>๋ฉ”์ธ</h3> + <Nav /> + <main> + <div className="content"> + <div> + {feeds.map(feed => { + return <Feed key={`feed${feed.id}`} data={feed} />; + })} + </div> + <div className="mainRight"> + <div className="rightTop"> + <img + className="wecodeLogo" + alt="์œ„์ฝ”๋“œ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">wecode_bootcamp</div> + <div className="lightFont">WeCode | ์œ„์ฝ”๋“œ</div> + </div> + </div> + <div className="rightMiddle"> + <div className="seeAllStory"> + <div className="lightFont">์Šคํ† ๋ฆฌ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="seeStory">{Stories}</div> + </div> + <div className="rightMiddle"> + <div className="friendsRecommendContainer"> + <div className="lightFont">ํšŒ์›๋‹˜์„ ์œ„ํ•œ ์ถ”์ฒœ</div> + <div className="boldFont">๋ชจ๋‘ ๋ณด๊ธฐ</div> + </div> + <div className="friendsRecommendList"> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">ํ™๊ธธ๋™</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์•„๋ฌด๊ฐœ</div> + <div className="lightFont">์‹œ๋Œ์‹œ๋Œ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์–ด์ฉŒ๊ตฌ</div> + <div className="lightFont">์–„๋ผ์–„๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ €์ฉŒ๊ตฌ</div> + <div className="lightFont">์šœ๋กœ์šœ๋กœ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + <div className="friendsRecommend"> + <img + alt="์นœ๊ตฌ์ถ”์ฒœ ํ”„๋กœํ•„ ์‚ฌ์ง„" + src="/images/youngho/wecode.png" + /> + <div> + <div className="boldFont">์ผ๋ผ์ผ๋ผ</div> + <div className="lightFont">๋ธ”๋ผ๋ธ”๋ผ๋‹˜ ์™ธ 2๋ช…์ด ...</div> + </div> + <div className="followFont boldFont">ํŒ”๋กœ์šฐ</div> + </div> + </div> + </div> + <footer> + <div className="lightFont"> + Westagram ์ •๋ณด . ์ง€์› . ํ™๋ณด ์„ผํ„ฐ . API . ์ฑ„์šฉ์ •๋ณด . + ๊ฐœ์ธ์ •๋ณด์ฒ˜๋ฆฌ๋ฐฉ์นจ . ์•ฝ๊ด€ . ๋””๋ ‰ํ„ฐ๋ฆฌ . ํ”„๋กœํ•„ . ํ•ด์‹œํƒœ๊ทธ . ์–ธ์–ด + </div> + <div className="lightFont boldFont">ยฉ 2021 WESTAGRAM</div> + </footer> + </div> + </div> + </main> </div> ); }
JavaScript
๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,285 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +@media screen and (max-width: 1200px) { + .mainRight { + display: none; + } + + .article { + width: 100%; + } +} + +body { + margin: 0; + padding: 0; + border-collapse: collapse; +} + +article { + width: 800px; + background-color: white; +} + +nav { + display: flex; + justify-content: space-around; + align-items: center; + margin: 0px 170px; + height: 60px; +} + +.logo { + width: 30px; + height: 30px; + padding-right: 15px; + border-right: 1px solid black; +} + +.rightIcon { + width: 30px; + height: 30px; + margin-right: 30px; +} + +.instagram { + margin-left: 15px; + font-family: 'Lobster', cursive; + font-size: 33px; + font-weight: 1; +} + +.search { + outline: none; +} + +.writeComment { + width: 100%; + height: 40px; + padding-left: 10px; + border: 1px solid #efefef; + outline: none; +} + +.search-box { + > input { + width: 200px; + height: 20px; + border: 1px solid #dbdbdb; + text-align: center; + } + + position: relative; + > img { + position: absolute; + width: 11px; + height: 11px; + left: 75px; + top: 7px; + } +} + +main { + padding: 60px 0px; + background-color: #fafafa; +} + +.content { + display: flex; + justify-content: space-around; + flex-direction: row; + margin: 0px 350px; +} + +.mainRight { + width: 330px; + margin-left: 10px; +} + +.feedTop { + display: flex; + justify-content: space-between; + align-items: center; + width: 780px; + padding: 10px 10px; + border: 1px solid #e6e6e6; +} + +.feedUser { + display: flex; + align-items: center; +} + +.feedPicture { + height: 800px; + border: 1px solid #e6e6e6; +} + +.feedId { + margin-left: 10px; +} + +.feedMore { + width: 15px; + height: 15px; +} + +.smallUserPicture { + width: 40px; + height: 40px; + border: 1px solid #e6e6e6; + border-radius: 50px; +} + +.feedIcons { + > img { + width: 27px; + height: 27px; + } + + > div { + > img { + width: 27px; + height: 27px; + } + } + display: flex; + justify-content: space-between; + flex-direction: row; + margin: 0px; +} + +.feedBottom { + padding: 10px 10px; + border-left: 1px solid #efefef; + border-right: 1px solid #efefef; + border-bottom: 1px solid #efefef; +} + +.FeedBottomLeftIcon { + > img { + padding-right: 10px; + } +} + +.like { + > img { + width: 15px; + height: 15px; + margin-right: 5px; + border: 1px solid #e6e6e6; + border-radius: 7px; + } + display: flex; + align-items: center; +} + +.comment { + > div { + > div { + color: #a4a4a4; + } + } +} + +.commentIcons { + float: right; + display: inline; + width: 15px; + height: 15px; + margin-left: 5px; +} + +.boldFont { + font-weight: bolder; +} + +.addCommentFrom { + position: relative; + width: 786px; +} + +.postingButton { + position: absolute; + color: #cde6fc; + background-color: white; + top: 14px; + right: 10px; + border: 0; + outline: 0; +} + +.rightTop { + display: flex; + align-items: center; + width: 300px; +} + +.wecodeLogo { + width: 60px; + height: 60px; + margin-right: 20px; + border-radius: 50px; +} + +.lightFont { + color: #9e9e9e; +} + +.followFont { + color: #3797f0; +} + +.rightMiddle { + height: 200px; + margin: 20px 0px; + padding: 12px; + background: white; + border: 3px solid #e6e6e6; + border-radius: 7px; + overflow: scroll; +} + +.seeAllStory { + display: flex; + align-items: center; + justify-content: space-between; +} + +.friendsRecommendContainer { + display: flex; + align-items: center; + justify-content: space-between; +} + +.story { + display: flex; + align-items: center; + margin: 10px; + + > img { + width: 40px; + height: 40px; + margin-right: 10px; + border-radius: 50px; + border: 2px solid #d93081; + } +} + +.friendsRecommend { + display: flex; + align-items: center; + margin: 10px; + > img { + width: 40px; + height: 40px; + border-radius: 50px; + margin-right: 10px; + } +} + +footer { + margin-top: 20px; + > .boldFont { + margin-top: 10px; + } +}
Unknown
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
@@ -0,0 +1,285 @@ +@import 'https://fonts.googleapis.com/css2?family=Lobster&display=swap'; +@media screen and (max-width: 1200px) { + .mainRight { + display: none; + } + + .article { + width: 100%; + } +} + +body { + margin: 0; + padding: 0; + border-collapse: collapse; +} + +article { + width: 800px; + background-color: white; +} + +nav { + display: flex; + justify-content: space-around; + align-items: center; + margin: 0px 170px; + height: 60px; +} + +.logo { + width: 30px; + height: 30px; + padding-right: 15px; + border-right: 1px solid black; +} + +.rightIcon { + width: 30px; + height: 30px; + margin-right: 30px; +} + +.instagram { + margin-left: 15px; + font-family: 'Lobster', cursive; + font-size: 33px; + font-weight: 1; +} + +.search { + outline: none; +} + +.writeComment { + width: 100%; + height: 40px; + padding-left: 10px; + border: 1px solid #efefef; + outline: none; +} + +.search-box { + > input { + width: 200px; + height: 20px; + border: 1px solid #dbdbdb; + text-align: center; + } + + position: relative; + > img { + position: absolute; + width: 11px; + height: 11px; + left: 75px; + top: 7px; + } +} + +main { + padding: 60px 0px; + background-color: #fafafa; +} + +.content { + display: flex; + justify-content: space-around; + flex-direction: row; + margin: 0px 350px; +} + +.mainRight { + width: 330px; + margin-left: 10px; +} + +.feedTop { + display: flex; + justify-content: space-between; + align-items: center; + width: 780px; + padding: 10px 10px; + border: 1px solid #e6e6e6; +} + +.feedUser { + display: flex; + align-items: center; +} + +.feedPicture { + height: 800px; + border: 1px solid #e6e6e6; +} + +.feedId { + margin-left: 10px; +} + +.feedMore { + width: 15px; + height: 15px; +} + +.smallUserPicture { + width: 40px; + height: 40px; + border: 1px solid #e6e6e6; + border-radius: 50px; +} + +.feedIcons { + > img { + width: 27px; + height: 27px; + } + + > div { + > img { + width: 27px; + height: 27px; + } + } + display: flex; + justify-content: space-between; + flex-direction: row; + margin: 0px; +} + +.feedBottom { + padding: 10px 10px; + border-left: 1px solid #efefef; + border-right: 1px solid #efefef; + border-bottom: 1px solid #efefef; +} + +.FeedBottomLeftIcon { + > img { + padding-right: 10px; + } +} + +.like { + > img { + width: 15px; + height: 15px; + margin-right: 5px; + border: 1px solid #e6e6e6; + border-radius: 7px; + } + display: flex; + align-items: center; +} + +.comment { + > div { + > div { + color: #a4a4a4; + } + } +} + +.commentIcons { + float: right; + display: inline; + width: 15px; + height: 15px; + margin-left: 5px; +} + +.boldFont { + font-weight: bolder; +} + +.addCommentFrom { + position: relative; + width: 786px; +} + +.postingButton { + position: absolute; + color: #cde6fc; + background-color: white; + top: 14px; + right: 10px; + border: 0; + outline: 0; +} + +.rightTop { + display: flex; + align-items: center; + width: 300px; +} + +.wecodeLogo { + width: 60px; + height: 60px; + margin-right: 20px; + border-radius: 50px; +} + +.lightFont { + color: #9e9e9e; +} + +.followFont { + color: #3797f0; +} + +.rightMiddle { + height: 200px; + margin: 20px 0px; + padding: 12px; + background: white; + border: 3px solid #e6e6e6; + border-radius: 7px; + overflow: scroll; +} + +.seeAllStory { + display: flex; + align-items: center; + justify-content: space-between; +} + +.friendsRecommendContainer { + display: flex; + align-items: center; + justify-content: space-between; +} + +.story { + display: flex; + align-items: center; + margin: 10px; + + > img { + width: 40px; + height: 40px; + margin-right: 10px; + border-radius: 50px; + border: 2px solid #d93081; + } +} + +.friendsRecommend { + display: flex; + align-items: center; + margin: 10px; + > img { + width: 40px; + height: 40px; + border-radius: 50px; + margin-right: 10px; + } +} + +footer { + margin-top: 20px; + > .boldFont { + margin-top: 10px; + } +}
Unknown
๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,125 @@ +import React from 'react'; +import Comment from '../Comment/Comment'; +import './Feed.scss'; + +class Feed extends React.Component { + constructor(props) { + super(props); + const { comment } = this.props.data; + this.state = { + comment: comment, + commentInputValue: '', + }; + } + + addComment = () => { + const { comment, commentInputValue } = this.state; + if (commentInputValue.length >= 1) { + const newComment = { + id: comment.length + 1, + content: commentInputValue, + isLiked: false, + }; + this.setState({ + comment: [...comment, newComment], + commentInputValue: '', + }); + } + }; + + deleteComment = e => { + const { comment } = this.state; + const deleteCommentId = Number(e.target.id); + const result = comment.filter(comment => comment.id !== deleteCommentId); + this.setState({ + comment: result, + }); + }; + + inputEnterPress = e => { + if (e.key === 'Enter') { + e.preventDefault(); + this.addComment(); + } + }; + + onChange = e => { + const { value } = e.target; + this.setState({ + commentInputValue: value, + }); + }; + + render() { + const { inputEnterPress, onChange, addComment, deleteComment } = this; + const { commentInputValue, comment } = this.state; + const { alt, img, userName } = this.props.data; + + return ( + <div className="feed"> + <article> + <div className="feedTop"> + <div className="feedUser"> + <img className="smallUserPicture" alt={alt} src={img} /> + <div className="feedId boldFont">{userName}</div> + </div> + <img + className="feedMore" + alt="๋”๋ณด๊ธฐ" + src="/images/youngho/more.png" + /> + </div> + <img className="feedPicture" alt="ํ”ผ๋“œ์‚ฌ์ง„" src={img} /> + <div className="feedBottom"> + <div className="feedIcons"> + <div className="FeedBottomLeftIcon"> + <img alt="๋นจ๊ฐ„์ƒ‰ํ•˜ํŠธ" src="/images/youngho/redHeart.png" /> + <img alt="๋ฉ”์„ธ์ง€" src="/images/youngho/speech-bubble.png" /> + <img alt="์—…๋กœ๋“œ" src="/images/youngho/upload.png" /> + </div> + <img alt="์ €์žฅ" src="/images/youngho/ribbon.png" /> + </div> + <div className="like"> + <img alt="์ข‹์•„์š”๋ฅผ ๋ˆ„๋ฅธ ์‚ฌ๋žŒ ์‚ฌ์ง„" src={img} /> + <span className="boldFont">manja</span>๋‹˜ + <span className="boldFont">์™ธ 7๋ช…</span>์ด ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค + </div> + {comment.map(comment => { + return ( + <Comment + key={comment.id} + id={comment.id} + userName={comment.userName} + comment={comment.content} + isLiked={comment.isLiked} + deleteComment={deleteComment} + /> + ); + })} + </div> + <form className="addCommentFrom"> + <input + className="writeComment" + type="text" + placeholder="๋Œ“๊ธ€ ๋‹ฌ๊ธฐ..." + onKeyPress={inputEnterPress} + onChange={onChange} + value={commentInputValue} + /> + <input + className={`postingButton ${ + commentInputValue.length ? 'activeButton' : '' + }`} + type="button" + defaultValue="๊ฒŒ์‹œ" + onClick={addComment} + disabled={commentInputValue.length ? false : true} + /> + </form> + </article> + </div> + ); + } +} + +export default Feed;
JavaScript
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐ŸŒ
@@ -0,0 +1,17 @@ +from django.db import models + +class User(models.Model): + email = models.EmailField(max_length=50, unique=True) + password = models.CharField(max_length=100) + relation = models.ManyToManyField('self', through='Follow', symmetrical=False) + + class Meta: + db_table = "users" + + +class Follow(models.Model): + following = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "following") + follower = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "follower") + + class Meta: + db_table = "follows" \ No newline at end of file
Python
๋‹ค๋ฏผ๋‹˜! ์ž˜ ์ž‘์„ฑํ•ด์ฃผ์…จ๋Š”๋ฐ `email` ์€ ๊ฒน์น  ์ˆ˜ ์—†๋Š” ์ •๋ณด์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹นํ•˜๋Š” ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ด์ฃผ์‹œ๋Š”๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค! ์•Œ์•„๋ณด์‹œ๊ณ  ์•Œ๋งž์€ ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”~
@@ -0,0 +1,10 @@ +from django.urls import path +from .views import SignupView, LoginView, FollowView + +urlpatterns = [ + path('/user', SignupView.as_view()), + path('/login', LoginView.as_view()), + path('/follow', FollowView.as_view()), + +] +'''Error๊ฐ€ ์•„๋‹ˆ๋ผ django์˜ ๊ถŒ์žฅ์‚ฌํ•ญ. ํ•˜์ง€๋งŒ ํŒจํ„ด ์ปจ๋ฒค์…˜์—๋Š” ์œ„ ์‚ฌํ•ญ์ด ๋งž๋‹ค.'''
Python
import ํ•˜์‹ค ๋•Œ `*` ์‚ฌ์šฉํ•˜์ง€ ๋งˆ์‹œ๊ณ  ๋ช…ํ™•ํ•˜๊ฒŒ ๊ฐ€์ ธ์˜ค๊ณ  ์‹ถ์€ class ๋ฅผ ์ ์–ด์ฃผ์„ธ์š”!
@@ -0,0 +1,10 @@ +from django.urls import path +from .views import SignupView, LoginView, FollowView + +urlpatterns = [ + path('/user', SignupView.as_view()), + path('/login', LoginView.as_view()), + path('/follow', FollowView.as_view()), + +] +'''Error๊ฐ€ ์•„๋‹ˆ๋ผ django์˜ ๊ถŒ์žฅ์‚ฌํ•ญ. ํ•˜์ง€๋งŒ ํŒจํ„ด ์ปจ๋ฒค์…˜์—๋Š” ์œ„ ์‚ฌํ•ญ์ด ๋งž๋‹ค.'''
Python
์ด ๋ถ€๋ถ„ ์„ธ์…˜ ์ค‘ ํ•œ๋ฒˆ ์„ค๋ช… ๋“œ๋ ธ๋Š”๋ฐ, ์™œ `/` ๊ด€๋ จ warning ์ด ๋œฌ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”!?
@@ -0,0 +1,21 @@ +"""westagram URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.urls import path, include + +urlpatterns = [ + path('account', include('account.urls')), + path('posting', include('posting.urls')), +]
Python
์ด ๋ถ€๋ถ„์€ ์œ„์ฝ”๋“œ url ํŒจํ„ด ์ปจ๋ฒค์…˜์— ๋งž์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์œ„์— ๋ฆฌ๋ทฐ๋“œ๋ฆฐ ๋‚ด์šฉ ์ค‘ `/` ๊ด€๋ จ ์งˆ๋ฌธ ๋‚จ๊ฒจ๋“œ๋ ธ์œผ๋‹ˆ ํ™•์ธํ•ด์ฃผ์„ธ์š”.
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
๊น”๋”ํ•˜๋„ค์š”~! ๐Ÿ’ฏ
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
`json.loads()` ๋„ ํ•ธ๋“คํ•ด์ฃผ์…”์•ผํ•˜๋Š” exception ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ™•์ธํ•ด๋ณด์‹œ๊ณ  ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
๋‹ค๋ฏผ๋‹˜์ด ์ž‘์„ฑํ•˜์‹  ์ฝ”๋“œ ๋กœ์ง์„ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ฆฌํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 1. `client` ์—์„œ ๋“ค์–ด์˜จ `email`, `password` ๊ฐ’์„ ์ด์šฉํ•˜์—ฌ ์ผ์น˜ํ•˜๋Š” user ๋ฅผ filter ํ•˜๋Š” ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ ค user ๋ณ€์ˆ˜์— ์ €์žฅํ•ด์ค€๋‹ค. 2. `email` ๋กœ filter ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ ค ์กด์žฌํ•˜๋Š” user ์ธ์ง€ ํ™•์ธํ•œ๋‹ค. 3. `password` ๋กœ filter ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ ค ์กด์žฌํ•˜๋Š” user ์ธ์ง€ ํ™•์ธํ•œ๋‹ค. 4. client ์—์„œ ๋“ค์–ด์˜จ `email`, `password` ๊ฐ€ ์œ ํšจํ•œ ํฌ๋งท์ธ์ง€ ๊ฒ€์‚ฌํ•˜์—ฌ ์œ ํšจํ•˜๋‹ค๋ฉด CREATE ๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ๋ง๋กœ ์ •๋ฆฌํ•ด๋ณด๋‹ˆ ํ๋ฆ„์ด ์ข€ ์–ด์ƒ‰ํ•˜์ง€ ์•Š๋‚˜์š”? ์ด ๋ถ€๋ถ„์„ ์–ด๋–ค ์ˆœ์„œ๋Œ€๋กœ ์ž‘์„ฑํ•˜๋ฉด ์ข‹์„์ง€ ์ œ๊ฐ€ ํ•œ๊ฒƒ์ฒ˜๋Ÿผ ๊ธ€๋กœ ์ •๋ฆฌํ•ด์„œ comment ๋‚จ๊ฒจ์ฃผ์„ธ์š”.
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
์—ฌ๊ธฐ์„œ ์ž ๊น ์งˆ๋ฌธ! `KeyError` ์–ด๋–ค ์—๋Ÿฌ์ด๋ฉฐ, ์–ธ์ œ ๋ฐœ์ƒํ• ๊นŒ์š”?
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
SignupView ์™€ ๋น„์Šทํ•œ ๋กœ์ง ํ๋ฆ„์ด๋„ค์š”. ์œ„์ชฝ ๋‚จ๊ฒจ๋“œ๋ฆฐ ์งˆ๋ฌธ ๋จผ์ € ํ™•์ธํ•ด์ฃผ์„ธ์š”!
@@ -0,0 +1,17 @@ +from django.db import models + +class User(models.Model): + email = models.EmailField(max_length=50, unique=True) + password = models.CharField(max_length=100) + relation = models.ManyToManyField('self', through='Follow', symmetrical=False) + + class Meta: + db_table = "users" + + +class Follow(models.Model): + following = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "following") + follower = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "follower") + + class Meta: + db_table = "follows" \ No newline at end of file
Python
`from django.db import models class User(models.Model): email = models.EmailField(max_length=50, unique=True)` ๋กœ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,10 @@ +from django.urls import path +from .views import SignupView, LoginView, FollowView + +urlpatterns = [ + path('/user', SignupView.as_view()), + path('/login', LoginView.as_view()), + path('/follow', FollowView.as_view()), + +] +'''Error๊ฐ€ ์•„๋‹ˆ๋ผ django์˜ ๊ถŒ์žฅ์‚ฌํ•ญ. ํ•˜์ง€๋งŒ ํŒจํ„ด ์ปจ๋ฒค์…˜์—๋Š” ์œ„ ์‚ฌํ•ญ์ด ๋งž๋‹ค.'''
Python
`from django.urls import path from .views import SignupView, LoginView` ๋กœ ํ•„์š”ํ•œ ๋ทฐ ํด๋ž˜์Šค ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ์œผ๋กœ ์ˆ˜์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,10 @@ +from django.urls import path +from .views import SignupView, LoginView, FollowView + +urlpatterns = [ + path('/user', SignupView.as_view()), + path('/login', LoginView.as_view()), + path('/follow', FollowView.as_view()), + +] +'''Error๊ฐ€ ์•„๋‹ˆ๋ผ django์˜ ๊ถŒ์žฅ์‚ฌํ•ญ. ํ•˜์ง€๋งŒ ํŒจํ„ด ์ปจ๋ฒค์…˜์—๋Š” ์œ„ ์‚ฌํ•ญ์ด ๋งž๋‹ค.'''
Python
Error๊ฐ€ ์•„๋‹ˆ๋ผ django์˜ ๊ถŒ์žฅ์‚ฌํ•ญ์ด์–ด์„œ ๊ทธ๋ ‡์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํŒจํ„ด ์ปจ๋ฒค์…˜์—๋Š” ๊ณ ์ณ์„œ ์“ฐ๋Š” ๊ฒƒ์ด ๋งž๊ธฐ ๋•Œ๋ฌธ์— ๊ณ ์ณค์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,21 @@ +"""westagram URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.1/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.urls import path, include + +urlpatterns = [ + path('account', include('account.urls')), + path('posting', include('posting.urls')), +]
Python
์ˆ˜์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
`class SignupView(View): def post(self, request): try: data = json.loads(request.body) user = User.objects.filter(email=data['email'],password=data['password'])` ์•„๋ž˜ ๋กœ๊ทธ์ธ๋ทฐ๋„ ๋˜‘๊ฐ™์€ ํ˜•ํƒœ๋กœ ๋ฐ”๊ฟจ์Šต๋‹ˆ๋‹ค. ์ด์œ  : ์‚ฌ์šฉ์ž์—๊ฒŒ ํ˜•์‹์„ ๋ฐ›์„ ๋•Œ ๊ผญ ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ํ˜•ํƒœ๋กœ json์ด ์˜ค์ง€ ์•Š์„ ์ˆ˜ ์žˆ๊ธฐ์— Key-error ์ƒํ™ฉ์„ ์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ.
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
์ด๊ฑฐ ํƒํ–ฅ๋‹˜ํ•˜๊ณ  ์ด์•ผ๊ธฐํ•˜๋‹ค๊ฐ€ ์•ˆ ๊ฒƒ์ธ๋ฐ, ํ‚ค ์—๋Ÿฌ๋ž€ ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ์—์„œ ์ž์ฃผ ๋ฐœ์ƒํ•˜๋ฉฐ ๋”•์…”๋„ˆ๋ฆฌ ๋‚ด๋ถ€์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ํ‚ค๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ’์„ ๋‚ด๋ ค๊ณ  ํ•  ๋•Œ ๋‚˜๋Š” ์—๋Ÿฌ์ž…๋‹ˆ๋‹ค. ์ด๋ฒˆ ์˜ˆ์‹œ๋กœ๋Š” ๋งŒ์ผ ๋ฐ์ดํ„ฐ๊ฐ€ email=~~~ password=~~~ ๋กœ ์˜ค๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ emailadkfj=~~~ apsdkfjsa=~~~์ฒ˜๋Ÿผ ํ‚ค ๋‚ด์šฉ์ด ์ž˜๋ชป ์™€๋ฒ„๋ฆฌ๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋กœ ํ‚ค ์—๋Ÿฌ๋ฅผ ๋‚ด๊ธฐ ์œ„ํ•ด ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์˜๋„ํ•˜๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
๋จผ์ € ๋‘ ํด๋ž˜์Šค ๋ชจ๋‘ ๊ณตํ†ต์ ์œผ๋กœ user๋ผ๋Š” ๋ณ€์ˆ˜๊ฐ€ ๋ถˆํ•„์š”ํ•ด์„œ ์ง€์› ์Šต๋‹ˆ๋‹ค. - ์ด์œ  : ์ด๋ฏธ User.~๋ฅผ ํ†ตํ•ด ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ ค ๋ฐ์ดํ„ฐ์—์„œ ํ•„์š”ํ•œ ์ž๋ฃŒ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค. ๋ถˆํ•„์š”ํ•œ ๋ณ€์ˆ˜์˜€๋‹ค. - comment : 1. client์—์„œ ๋“ค์–ด์˜จ ๊ฐ’ ์ค‘ ์ด๋ฉ”์ผ ํ•„ํ„ฐ ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ ค ์กด์žฌํ•˜๋Š” ์ด๋ฉ”์ผ์ผ ๊ฒฝ์šฐ์ธ์ง€ ํ™•์ธ. 2. (๋งˆ์ฐฌ๊ฐ€์ง€๋กœ) ๋น„๋ฐ€๋ฒˆํ˜ธ ํ•„ํ„ฐ ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ ค ์กด์žฌํ•˜๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ์ธ์ง€ ํ™•์ธ. 3. ์ด๋ฉ”์ผ๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์œ ํšจํ•œ ํฌ๋งท์ธ์ง€ ๊ฒ€์‚ฌํ•˜์—ฌ ์œ ํšจํ•˜๋ฉด ๊ฐ’ ๋งŒ๋“ค๊ธฐ ์ง„ํ–‰. - ์•„์ง ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ฆฐ๋‹ค๋Š” ๊ฐœ๋…์ด ํ™•์‹คํžˆ ์„œ์ง€ ์•Š์•„ ํ‘œํ˜„์ด ๋งž๋Š”๊ฑด์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฌธ๋ฒ•์ ์ธ ์ ์€ ๊ฒ€ํ† ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค..!
@@ -0,0 +1,17 @@ +from django.db import models + +class User(models.Model): + email = models.EmailField(max_length=50, unique=True) + password = models.CharField(max_length=100) + relation = models.ManyToManyField('self', through='Follow', symmetrical=False) + + class Meta: + db_table = "users" + + +class Follow(models.Model): + following = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "following") + follower = models.ForeignKey(User, on_delete = models.SET_NULL, null=True, related_name = "follower") + + class Meta: + db_table = "follows" \ No newline at end of file
Python
`unique=True` ๊ตณ์ž…๋‹ˆ๋‹ค!!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
@damin0320 ์ •ํ™•ํ•ฉ๋‹ˆ๋‹ค ๋‹ค๋ฏผ๋‹˜!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ๋กœ์ง๋ณ„๋กœ ๋ถ„๋ฆฌํ•ด์„œ ๋„์–ด์“ฐ๊ธฐ๋กœ ๊ตฌ๋ถ„ํ•ด์ฃผ์„ธ์š”! ์ง€๊ธˆ์€ ๋„ˆ๋ฌด ๋‹ค ๋ถ™์–ด์žˆ์–ด์„œ ์ฝ๊ธฐ๊ฐ€ ์ข‹์€ ์ฝ”๋“œ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค ๋‹ค๋ฏผ๋‹˜!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
exists() ํ™œ์šฉ gooood ๐Ÿ‘
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
์ด ๋ถ€๋ถ„์€ ๋กœ์ง์ด ์กฐ๊ธˆ ์ด์ƒํ•œ๋ฐ์š”. password ๋Š” ๊ณ ์œ ๊ฐ’์ด ์•„๋‹ˆ๊ณ , ๊ฐ™์€ password ๋ฅผ ๊ฐ€์ง„ ์œ ์ €์ •๋ณด๋“ค์ด ์ถฉ๋ถ„ํžˆ ์กด์žฌํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ password ๋กœ ํ•„ํ„ฐ๋ฅผ ๊ฑธ์–ด์ค„ ํ•„์š”๋Š” ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค~
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
์•”ํ˜ธํ™” ๊ณผ์ • ์ ์šฉ ์ •๋ง ์ž˜ํ•˜์…จ์Šต๋‹ˆ๋‹ค!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
create() ๋’ค์— save() ๋Š” ๋ถˆํ•„์š”ํ•ฉ๋‹ˆ๋‹ค ๋‹ค๋ฏผ๋‹˜. ์—†์• ์ฃผ์„ธ์š”!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
get() ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๊ผญ ์žก์•„์ฃผ์…”์•ผํ•˜๋Š” exception ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์•Œ์•„๋ณด์‹œ๊ณ  exception handling ๋กœ์ง์— ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
์—ฌ๊ธฐ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ๋กœ์ง์„ ๋ธ”๋ก์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•œ์ค„์”ฉ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”!
@@ -0,0 +1,103 @@ +import json +import bcrypt +import jwt + +from django.views import View +from django.http import JsonResponse + +from .models import User, Follow +from my_settings import SECRET_KEY + +class SignupView(View): + def post(self, request): + try: + data = json.loads(request.body) + if User.objects.filter(email=data['email']).exists(): + return JsonResponse({"message": "EMAIL_ERROR"}, status=400) + + if not '@' in data['email'] or not '.' in data['email']: + return JsonResponse({"message":"EMAIL_FAIL"}, status=400) + if len(data['password']) < 8: + return JsonResponse({"message":"PASSWORD_TOO_SHORT"}, status=400) + + byted_password = data['password'].encode('utf-8') + hash_password = bcrypt.hashpw(byted_password, bcrypt.gensalt()).decode() + password = hash_password + user = User.objects.create( + email = data['email'], + password = password + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + except KeyError: + return JsonResponse({"message": "KEY_ERROR"}, status=400) + + +class LoginView(View): + def post(self, request): + try: + data = json.loads(request.body) + try: + user = User.objects.get(email=data['email']) + # user๋Š” ๊ฐ์ฒด๋‹ค + user_id = user.id + # ๊ฐ์ฒด์— .~ํ•˜๋ฉด ๋ฐ”๋กœ ๋‚ด์šฉ์„ ๊บผ๋‚ผ ์ˆ˜ ์žˆ๋‹ค. + except User.DoesNotExist: + return JsonResponse({"message":"USER_DOES_NOT_EXIST"}, status=400) + + if bcrypt.checkpw(data['password'].encode('utf-8'), user.password.encode('utf-8')): + token = jwt.encode({'user_id' : user_id}, SECRET_KEY, algorithm="HS256") + # ์œ ์ € id๋ฅผ ํ† ํฐ ๋‚ด์šฉ๋ฌผ์„ ๋„ฃ๋Š”๋‹ค. ์ด๋–„ ์ด๋ฏธ ์ˆซ์ž๊ฐ€ ๋‚˜์™”์œผ๋ฏ€๋กœ data๋กœ ํ•  ํ•„์š” ์—†์Œ + return JsonResponse({'token' : token, "message":"SUCCESS"}, status=200) + + return JsonResponse({"message":"INVALID_USER"}, status=401) + + except KeyError: + return JsonResponse({"message":"KEY_ERROR"}, status=400) + +class TokenCheckView(View): + def post(self,request): + data = json.loads(request.body) + + user_token_info = jwt.decode(data['token'], SECRET_KEY, algorithms='HS256') + + if User.objects.filter(email=user_token_info['email']).exists(): + return JsonResponse({"message": "SUCCESS"}, status=200) + return JsonResponse({"message":"INVALID_USER"}, status=401) + +class FollowView(View): + def post(self, request): + data = json.loads(request.body) + following = User.objects.get(email=data['following']) + follower = User.objects.get(email=data['follower']) + if following == follower: + return JsonResponse({"message":"SAME_PERSON!"}) + follow = Follow.objects.create( + following = following, + follower = follower + ) + return JsonResponse({"message": "SUCCESS"}, status=200) + +def TokenCheck(func): + def wrapper(self, request, *args, **kwargs): + # ๋ฆฌํ€˜์ŠคํŠธํ•ด์„œ ํ† ํฐ ๊นŒ๋Š” ์•  + # ํ† ํฐ์˜ ํ•ต์‹ฌ์€ ๊ณต๊ฐœ๊ฐ€ ๋˜์–ด๋„ ๋œ๋‹ค -> ๊ทธ๋ž˜์„œ ์˜ˆ์ œ๊ฐ€ user_id์˜€๋˜ ๊ฒƒ. + try: + token = request.headers.get('Authorization') + if token: + payload = jwt.decode(token, SECRET_KEY, algorithms="HS256") + user_id = payload['user_id'] + user = User.objects.get(id=user_id) + # user_id ๊ฐ€์ ธ์˜จ ๊ฒƒ์„ user๋ผ๋Š” ๋ณ€์ˆ˜์— ๋‹ด๊ณ  + + request.user = user + # ๋ณ€์ˆ˜์— ๋‹ด์€ ๊ฒƒ์„ ๋’ค์—์„œ ๋ถ€๋ฅผ request.user์— ๋˜ ๋‹ด์•„์ค€๋‹ค. + return func(self, request, *args, **kwargs) + # ์–˜๋Š” returnํ•˜๋ฉด์„œ request๋ฅผ posting์—์„œ ์‚ฌ์šฉํ•  ์˜ˆ์ •(.user ๋งŒ ๋ถ™์ด๋ฉด ์ด์ œ ์ž๋™ ์™„์„ฑ) + return JsonResponse({"message":"GIVE_ME_TOKEN"}, status=400) + except jwt.InvalidTokenError: + return JsonResponse({"message":"YOUR_TOKEN_ERROR"}, status=400) + + # ์ง€๊ธˆ์€ ์ˆซ์ž๋งŒ ํ™•์ธ ์ƒํ™ฉ(id๊ฐ’๋งŒ ๋ฐ›์•„์„œ ํ™•์ธํ•œ ์ƒํ™ฉ) + # ์ถ”๊ฐ€ : ํ† ํฐ์„ ๋‹ค์‹œ ์•ˆ ๊ฐ–๋‹ค์ค€ ์ƒํ™ฉ(๋ฆฌํ€˜์ŠคํŠธ์— ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€๋‹ค.) ; ๋ฆฌํ€˜์ŠคํŠธ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด์ค€๋‹ค.(์•„์ด๋””๊ฐ’์„ ๋„ฃ์–ด์ค€๋‹ค.->์ด๊ฑธ ๊บผ๋‚ด ์“ด๋‹ค.) + + return wrapper \ No newline at end of file
Python
์ด์•ผ~ jwt ์ƒ์„ฑ ๋กœ์ง๊นŒ์ง€ ๋„ˆ๋ฌด ์ž˜ ์ ์šฉํ•˜์…จ๋„ค์š”! ํ•˜์ง€๋งŒ ์ƒ์„ฑ์„ ์™„๋ฃŒํ–ˆ๋Š”๋ฐ ์ƒ์„ฑ๋งŒํ•˜๊ณ  ์‚ฌ์šฉ์„ ์•ˆํ•˜๊ณ  ๊ณ„์‹œ๋„ค์š”. ๋‹ค์Œ ์Šคํ…์€ ๋ฌด์—‡์ผ๊นŒ์š”?