Skip to content

Commit

Permalink
Merge pull request #280 from boostcampwm2023/develop
Browse files Browse the repository at this point in the history
[Deploy] week5 금요일 배포
  • Loading branch information
MinboyKim authored Dec 8, 2023
2 parents 1df8b2b + cfaa70f commit 727ff93
Show file tree
Hide file tree
Showing 27 changed files with 517 additions and 290 deletions.
Binary file modified packages/client/src/assets/bgm.mp3
Binary file not shown.
9 changes: 4 additions & 5 deletions packages/client/src/entities/posts/ui/Posts.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import Post from './Post';
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { StarData } from 'shared/lib/types/star';
import { useOwnerStore } from 'shared/store/useOwnerStore';
import { getPostListByNickName } from 'shared/apis/star';
import { useEffect } from 'react';
import { useViewStore } from 'shared/store';
import { getMyPost } from '../apis/getMyPost';

Expand All @@ -28,10 +27,10 @@ export default function Posts() {
const otherPostData = await getPostListByNickName(pageOwnerNickName);
setPostData(otherPostData);
})();
}, [isMyPage, view]);
}, [view, pageOwnerNickName]);

return (
<>
<group>
{postData &&
postData.map((data, index) => (
<Post
Expand All @@ -41,6 +40,6 @@ export default function Posts() {
title={data.title}
/>
))}
</>
</group>
);
}
29 changes: 29 additions & 0 deletions packages/client/src/features/controls/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Camera, useFrame, useThree } from '@react-three/fiber';
import type { OrbitControls as OrbitControlsImpl } from 'three-stdlib';
import { useViewStore } from 'shared/store/useViewStore';
import { useEffect } from 'react';
import { CAMERA_POST_VIEW } from '@constants';
import { useOwnerStore } from 'shared/store/useOwnerStore';

const setCameraPosition = (
camera: Camera,
Expand All @@ -19,6 +21,25 @@ const setCameraPosition = (
camera.position.add(direction);
};

const setPostViewCamera = (
camera: Camera,
currentView: THREE.Vector3,
LENGTH_LIMIT: number,
) => {
const distance = camera.position.distanceTo(currentView);
const direction = currentView.clone().sub(camera.position);

if (distance - CAMERA_POST_VIEW > LENGTH_LIMIT)
direction.setLength(LENGTH_LIMIT);
else if (CAMERA_POST_VIEW - distance > LENGTH_LIMIT)
direction.setLength(-LENGTH_LIMIT);
else
direction.setLength(
camera.position.distanceTo(currentView) - CAMERA_POST_VIEW,
);
camera.position.add(direction);
};

export default function Controls() {
const controlsRef = useRef<OrbitControlsImpl>(null!);
const {
Expand All @@ -27,14 +48,20 @@ export default function Controls() {
currentView,
setCurrentView,
targetView,
setTargetView,
} = useCameraStore();
const { view } = useViewStore();
const state = useThree();
const { pageOwnerNickName } = useOwnerStore();

useEffect(() => {
setCameraToCurrentView(currentView.distanceTo(state.camera.position));
}, []);

useEffect(() => {
setTargetView(null);
}, [pageOwnerNickName]);

useFrame((state, delta) => {
const targetPosition = new THREE.Vector3(0, 0, 0);
const LENGTH_LIMIT = ((cameraToCurrentView + 5000) * delta) / 2;
Expand All @@ -50,6 +77,7 @@ export default function Controls() {
distance.z = 0;
if (distance.length() > LENGTH_LIMIT) distance.setLength(LENGTH_LIMIT);
state.camera.position.add(distance);
setCameraToCurrentView(currentView.distanceTo(state.camera.position));
}

if (targetPosition !== currentView) {
Expand All @@ -60,6 +88,7 @@ export default function Controls() {
setCurrentView(currentView.add(direction));
if (view !== 'POST')
setCameraPosition(state.camera, currentView, cameraToCurrentView);
else setPostViewCamera(state.camera, currentView, LENGTH_LIMIT);

controlsRef.current.target = currentView;
}
Expand Down
19 changes: 16 additions & 3 deletions packages/client/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useScreenSwitchStore } from 'shared/store/useScreenSwitchStore';
import Cookies from 'js-cookie';
import { getSignInInfo } from 'shared/apis';
import { getGalaxy } from 'shared/apis';
import { useGalaxyStore } from 'shared/store';
import { useGalaxyStore, useCustomStore } from 'shared/store';
import { Toast } from 'shared/ui';
import { useToastStore } from 'shared/store';
import { useOwnerStore } from 'shared/store/useOwnerStore';
Expand All @@ -26,15 +26,16 @@ import styled from '@emotion/styled';
import { keyframes } from '@emotion/react';

export default function Home() {
const { view } = useViewStore();
const { view, setView } = useViewStore();
const { isSwitching } = useScreenSwitchStore();
const { text } = useToastStore();
const { pageOwnerNickName } = useOwnerStore();
const { pageOwnerNickName, setPageOwnerNickName } = useOwnerStore();
const [nickname, setNickname] = useState('');
const handleFullScreen = useFullScreenHandle();

const navigate = useNavigate();
const { setSpiral, setStart, setThickness, setZDist } = useGalaxyStore();
const custom = useCustomStore();

useEffect(() => {
(async () => {
Expand All @@ -53,6 +54,17 @@ export default function Home() {
getSignInInfo().then((res) => {
Cookies.set('nickname', res.nickname);
setNickname(res.nickname);
setPageOwnerNickName(nickname);
});
getGalaxy('').then((res) => {
const { setSpiral, setStart, setThickness, setZDist } = custom;
if (res.spiral) setSpiral(res.spiral);

if (res.start) setStart(res.start);

if (res.thickness) setThickness(res.thickness);

if (res.zDist) setZDist(res.zDist);
});
}, []);

Expand All @@ -70,6 +82,7 @@ export default function Home() {
if (!res.zDist) setZDist(ARMS_Z_DIST);
else setZDist(res.zDist);
});
setView('MAIN');
}, [pageOwnerNickName]);

const keyDown = (e: KeyboardEvent) => {
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/shared/lib/constants/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export const CAMERA_POSITION: Vector3 = [5000, 5000, 5000];
export const CAMERA_FAR = 500000;
export const CAMERA_MIN_DISTANCE = 1000;
export const CAMERA_MAX_DISTANCE = 40000;
export const CAMERA_POST_VIEW = 2000;
10 changes: 9 additions & 1 deletion packages/client/src/widgets/galaxy/Galaxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import { useRef, useMemo } from 'react';
import { useFrame } from '@react-three/fiber';
import { Instances } from './lib/modules';
import { STARS_NUM, starTypes } from './lib/constants';
import React from 'react';

interface PropsType {
number?: number;
isCustom?: boolean;
children?: React.ReactNode;
}

export default function Galaxy({
number = STARS_NUM,
isCustom = false,
children,
}: PropsType) {
const galaxyRef = useRef<THREE.Group>(null!);

Expand All @@ -36,5 +39,10 @@ export default function Galaxy({
return starList;
}, []);

return <group ref={galaxyRef}>{stars}</group>;
return (
<group ref={galaxyRef}>
{stars}
{children}
</group>
);
}
2 changes: 1 addition & 1 deletion packages/client/src/widgets/loginModal/ui/LoginContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function LoginContent({
id="userPassword"
label="비밀번호"
type="password"
placeholder="비밀먼호를 입력해주세요."
placeholder="비밀번호를 입력해주세요."
onChange={(e) => {
if (passwordState === false) setPasswordState(true);
setPassword(e.target.value);
Expand Down
5 changes: 3 additions & 2 deletions packages/client/src/widgets/screen/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export default function Screen() {
<ambientLight color="#fff" intensity={1} />
<Controls />
<BackgroundStars />
<Galaxy />
<Posts />
<Galaxy>
<Posts />
</Galaxy>
<CameraLight />
</Canvas>
<LevaWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const STAR_MAX_SIZE = 300;
export const STAR_DEFAULT_SIZE = 200;
export const STAR_SIZE_STEP = 10;

export const STAR_MIN_BRIGHTNESS = -1;
export const STAR_MIN_BRIGHTNESS = -2;
export const STAR_MAX_BRIGHTNESS = 4;
export const STAR_DEFAULT_BRIGHTNESS = 0;
export const STAR_BRIGHTNESS_STEP = 0.2;
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class AuthController {
redirectUrl = `https://accounts.google.com/o/oauth2/v2/auth?client_id=${process.env.OAUTH_GOOGLE_CLIENT_ID}&redirect_uri=${process.env.OAUTH_GOOGLE_REDIRECT_URI}&response_type=code&scope=email%20profile`;
break;
default:
throw new NotFoundException('존재하지 않는 서비스입니다.');
throw new NotFoundException('not supported service');
}
res.redirect(redirectUrl);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ export class AuthController {
try {
resourceServerUsername = req.cookies[`${service}Username`];
} catch (e) {
throw new UnauthorizedException('잘못된 접근입니다.');
throw new UnauthorizedException('login is required');
}

await this.authService.signUpWithOAuth(
Expand All @@ -197,7 +197,7 @@ export class AuthController {
@SearchUserSwaggerDecorator()
searchUser(@Query('nickname') nickname: string) {
if (!nickname) {
throw new BadRequestException('검색할 닉네임을 입력해주세요.');
throw new BadRequestException('nickname is required');
}
return this.authService.searchUser(nickname);
}
Expand Down
20 changes: 9 additions & 11 deletions packages/server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class AuthService {

async oauthCallback(service: string, authorizedCode: string, state?: string) {
if (!authorizedCode) {
throw new BadRequestException('Authorized Code가 존재하지 않습니다.');
throw new BadRequestException('authorized code is required');
}

const resourceServerAccessToken = await getOAuthAccessToken(
Expand Down Expand Up @@ -191,11 +191,11 @@ export class AuthService {
resourceServerAccessToken,
);
} catch (e) {
throw new UnauthorizedException('잘못된 접근입니다.');
throw new UnauthorizedException(`could not get username from ${service}`);
}

if (recivedResourceServerUsername !== resourceServerUsername) {
throw new UnauthorizedException('잘못된 접근입니다.');
throw new UnauthorizedException(`${service} username is uncorrect`);
}

this.redisRepository.del(resourceServerUsername);
Expand Down Expand Up @@ -234,11 +234,11 @@ export class AuthService {
const user = await this.userRepository.findOneBy({ id: userData.userId });

if (!user) {
throw new NotFoundException('해당 유저를 찾을 수 없습니다.');
throw new NotFoundException('user not found');
}

if (user.status === status) {
throw new BadRequestException('이미 해당 상태입니다.');
throw new BadRequestException('user status is already same');
}

user.status = status;
Expand All @@ -250,13 +250,13 @@ export class AuthService {

async getShareLinkByNickname(nickname: string) {
if (!nickname) {
throw new BadRequestException('nickname을 입력해주세요.');
throw new BadRequestException('nickname is required');
}

const user = await this.userRepository.findOneBy({ nickname });

if (!user) {
throw new NotFoundException('해당 유저를 찾을 수 없습니다.');
throw new NotFoundException('user not found');
}

const foundLink = await this.shareLinkRepository.findOneBy({
Expand All @@ -283,17 +283,15 @@ export class AuthService {
});

if (!foundLink) {
throw new NotFoundException('존재하지 않는 링크입니다.');
throw new NotFoundException('link not found');
}

const linkUser = await this.userRepository.findOneBy({
id: foundLink.user,
});

if (!linkUser) {
throw new InternalServerErrorException(
'링크에 대한 사용자가 존재하지 않습니다.',
);
throw new InternalServerErrorException('link user not found');
}

return linkUser.username;
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/auth/cookie-auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CookieAuthGuard extends AuthGuard('jwt') {
const response = context.switchToHttp().getResponse();

if (!request.cookies) {
throw new UnauthorizedException('로그인이 필요합니다.');
throw new UnauthorizedException('login is required');
}

const accessToken = request.cookies['accessToken'];
Expand All @@ -50,7 +50,7 @@ export class CookieAuthGuard extends AuthGuard('jwt') {
JwtEnum.REFRESH_TOKEN_COOKIE_NAME,
cookieOptionsConfig,
);
throw new UnauthorizedException('로그인이 필요합니다.');
throw new UnauthorizedException('login is required');
}

if (
Expand All @@ -67,7 +67,7 @@ export class CookieAuthGuard extends AuthGuard('jwt') {
JwtEnum.REFRESH_TOKEN_COOKIE_NAME,
cookieOptionsConfig,
);
throw new UnauthorizedException('로그인이 필요합니다.');
throw new UnauthorizedException('login is required');
}

const newAccessToken = await createJwt(
Expand Down
4 changes: 1 addition & 3 deletions packages/server/src/auth/decorators/get-user.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export const GetUser = createParamDecorator(

const user = req.user as UserDataDto;
if (!user) {
throw new InternalServerErrorException(
'CookieAuthGuard를 적용해야 @GetUser를 사용할 수 있습니다.',
);
throw new InternalServerErrorException('User not found in request');
}

return req.user;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { applyDecorators } from '@nestjs/common';
import {
ApiNotFoundResponse,
ApiOkResponse,
ApiOperation,
ApiUnauthorizedResponse,
Expand All @@ -20,10 +21,16 @@ const apiUnauthorizedResponse = {
description: '잘못된 유저 정보로 로그인 실패',
};

const apiNotFoundResponse = {
status: 404,
description: '유저 정보를 찾을 수 없음',
};

export const SignInSwaggerDecorator = () => {
return applyDecorators(
ApiOperation(apiOperation),
ApiOkResponse(apiOkResponse),
ApiUnauthorizedResponse(apiUnauthorizedResponse),
ApiNotFoundResponse(apiNotFoundResponse),
);
};
6 changes: 0 additions & 6 deletions packages/server/src/auth/dto/signin-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { UserEnum } from '../enums/user.enum';
import { IsNotEmpty, IsString } from 'class-validator';
import {
IsPassword,
IsUsername,
} from '../decorators/user-constraints.decorator';

export class SignInUserDto {
@ApiProperty({
Expand Down
Loading

0 comments on commit 727ff93

Please sign in to comment.