Skip to content

Commit

Permalink
[Release] 3차 배포 (11/29)
Browse files Browse the repository at this point in the history
[Release] 3차 배포 (11/29)
  • Loading branch information
seoko97 authored Nov 28, 2024
2 parents 7052826 + 0495edc commit 3d258b6
Show file tree
Hide file tree
Showing 65 changed files with 1,253 additions and 417 deletions.
39 changes: 26 additions & 13 deletions apps/api/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Post, Res, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Post, Query, Res, UseGuards } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ThrottlerGuard } from '@nestjs/throttler';
Expand Down Expand Up @@ -43,17 +43,21 @@ export class AuthController {
@ApiResponse({ status: 302, description: '홈으로 리다이렉션' })
@ApiResponse({ status: 401 })
@UseGuards(LocalAuthGuard)
localLogin(@GetUserId() userId: number, @Res() response: Response) {
this.loginProcess(response, userId);
localLogin(
@GetUserId() userId: number,
@Query('redirect') redirect: string,
@Res() response: Response
) {
this.loginProcess(response, userId, redirect);
}

@Get('guest/login')
@ApiOperation({ summary: '게스트 로그인' })
@ApiResponse({ status: 302, description: '홈으로 리다이렉션' })
@UseGuards(ThrottlerGuard)
async guestLogin(@Res() response: Response) {
async guestLogin(@Query('redirect') redirect: string, @Res() response: Response) {
const guestUser = await this.authService.createGuestUser();
this.loginProcess(response, guestUser.id);
this.loginProcess(response, guestUser.id, redirect);
}

@Get('google/login')
Expand All @@ -65,8 +69,12 @@ export class AuthController {

@Get('google/callback')
@UseGuards(GoogleAuthGuard)
googleAuthCallback(@GetUserId() userId: number, @Res() response: Response) {
this.loginProcess(response, userId);
googleAuthCallback(
@GetUserId() userId: number,
@Query('state') state: string,
@Res() response: Response
) {
this.loginProcess(response, userId, state);
}

@Get('github/login')
Expand All @@ -78,8 +86,12 @@ export class AuthController {

@Get('github/callback')
@UseGuards(GitHubAuthGuard)
githubAuthCallback(@GetUserId() userId: number, @Res() response: Response) {
this.loginProcess(response, userId);
githubAuthCallback(
@GetUserId() userId: number,
@Query('state') state: string,
@Res() response: Response
) {
this.loginProcess(response, userId, state);
}

@Get('logout')
Expand All @@ -90,13 +102,14 @@ export class AuthController {
this.redirectToHome(response);
}

private loginProcess(response: Response, userId: number) {
private loginProcess(response: Response, userId: number, path?: string) {
const { accessToken } = this.authService.createJWT(userId);
response.cookie('accessToken', accessToken, this.cookieConfig.getAuthCookieOptions());
this.redirectToHome(response);
this.redirectToHome(response, path);
}

private redirectToHome(response: Response) {
response.redirect(this.redirectUrl);
private redirectToHome(response: Response, path?: string) {
const redirectUrl = `${this.redirectUrl}${path || ''}`;
response.redirect(redirectUrl);
}
}
10 changes: 9 additions & 1 deletion apps/api/src/auth/github/github.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { Profile, Strategy } from 'passport-github2';
import { Request } from 'express';
import { Profile, Strategy, StrategyOption } from 'passport-github2';
import { Provider } from '@repo/types';

import { AuthService } from '../auth.service';
Expand All @@ -19,6 +20,13 @@ export class GitHubStrategy extends PassportStrategy(Strategy, Provider.github)
scope: ['user:email'],
});
}
authenticate(req: Request, options: StrategyOption) {
const returnUrl = req.query.redirect as string;
if (returnUrl) {
options.state = returnUrl;
}
return super.authenticate(req, options);
}

async validate(accessToken: string, refreshToken: string, profile: Profile) {
const { id, username, emails, photos } = profile;
Expand Down
10 changes: 10 additions & 0 deletions apps/api/src/auth/google/google.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { Request } from 'express';
import { StrategyOption } from 'passport-github2';
import { Profile, Strategy } from 'passport-google-oauth20';
import { Provider } from '@repo/types';

Expand All @@ -20,6 +22,14 @@ export class GoogleStrategy extends PassportStrategy(Strategy, Provider.google)
});
}

authenticate(req: Request, options: StrategyOption) {
const returnUrl = req.query.redirect as string;
if (returnUrl) {
options.state = returnUrl;
}
return super.authenticate(req, options);
}

async validate(accessToken: string, refreshToken: string, profile: Profile): Promise<any> {
const { id, displayName, emails, photos } = profile;

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/entity/applicant.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Applicant {
@PrimaryGeneratedColumn({ type: 'bigint' })
id: number;

@ManyToOne(() => Ticle, (ticle) => ticle.applicants)
@ManyToOne(() => Ticle, (ticle) => ticle.applicants, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'ticle_id' })
ticle: Ticle;

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/entity/summary.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Summary {
@CreateDateColumn({ type: 'timestamp', name: 'created_at' })
createdAt: Date;

@OneToOne(() => Ticle, (ticle) => ticle.summary)
@OneToOne(() => Ticle, (ticle) => ticle.summary, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'ticle_id' })
ticle: Ticle;
}
8 changes: 7 additions & 1 deletion apps/api/src/ticle/ticle.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
import { CreateTicleSchema } from '@repo/types';

import { JwtAuthGuard } from '@/auth/jwt/jwt-auth.guard';
Expand Down Expand Up @@ -50,4 +50,10 @@ export class TicleController {
applyToTicle(@GetUserId() userId: number, @Param('ticleId') ticleId: number) {
return this.ticleService.applyTicle(ticleId, userId);
}

@Delete(':ticleId')
@UseGuards(JwtAuthGuard)
deleteTicle(@GetUserId() userId: number, @Param('ticleId') ticleId: number) {
return this.ticleService.deleteTicle(userId, ticleId);
}
}
23 changes: 21 additions & 2 deletions apps/api/src/ticle/ticle.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ export class TicleService {
.leftJoinAndSelect('ticle.tags', 'tags')
.leftJoinAndSelect('ticle.speaker', 'speaker')
.leftJoinAndSelect('ticle.applicants', 'applicants')
.select(['ticle', 'tags', 'speaker.id', 'speaker.profileImageUrl', 'applicants'])
.leftJoinAndSelect('applicants.user', 'user')
.select(['ticle', 'tags', 'speaker.id', 'speaker.profileImageUrl', 'applicants', 'user.id'])
.where('ticle.id = :id', { id: ticleId })
.getOne();

Expand All @@ -143,7 +144,7 @@ export class TicleService {
}
const { tags, speaker, ...ticleData } = ticle;

const alreadyApplied = ticle.applicants.some((applicnat) => applicnat.id === userId);
const alreadyApplied = ticle.applicants.some((applicant) => applicant.user.id === userId);

return {
...ticleData,
Expand Down Expand Up @@ -226,4 +227,22 @@ export class TicleService {
},
};
}

async deleteTicle(userId: number, ticleId: number) {
const ticle = await this.ticleRepository.findOne({
where: { id: ticleId },
relations: ['speaker'],
});

if (!ticle) {
throw new NotFoundException(ErrorMessage.TICLE_NOT_FOUND);
}

if (ticle.speaker.id !== userId) {
throw new BadRequestException(ErrorMessage.CANNOT_DELETE_OTHERS_TICLE);
}

await this.ticleRepository.remove(ticle);
return;
}
}
1 change: 1 addition & 0 deletions apps/media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.4.7",
"@nestjs/websockets": "^10.4.7",
"@repo/lint": "workspace:*",
"@repo/tsconfig": "workspace:*",
"@repo/mediasoup": "workspace:*",
"@repo/types": "workspace:*",
Expand Down
Loading

0 comments on commit 3d258b6

Please sign in to comment.