Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE/#497] 리팩토링 #497 #498

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions BE/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';

describe('AppController', () => {
let appController: AppController;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();

appController = app.get<AppController>(AppController);
Expand Down
8 changes: 1 addition & 7 deletions BE/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Controller, Get, Redirect } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

// @Get()
// home(): string {
// return this.appService.getHello();
// }
constructor() {}

@Get('API')
@Redirect(
Expand Down
2 changes: 0 additions & 2 deletions BE/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { WinstonModule } from 'nest-winston';
import * as process from 'process';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { winstonTransportsOption } from './config/winston.config';
import { MysqlConfigProvider } from './config/mysql.config';
import { PostModule } from './post/post.module';
Expand Down Expand Up @@ -44,7 +43,6 @@ import { ReportModule } from './report/report.module';
],
controllers: [AppController],
providers: [
AppService,
Logger,
{
provide: APP_PIPE,
Expand Down
8 changes: 0 additions & 8 deletions BE/src/app.service.ts

This file was deleted.

8 changes: 4 additions & 4 deletions BE/src/chat/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
UseGuards,
} from '@nestjs/common';
import { ChatService } from './chat.service';
import { AuthGuard } from '../utils/auth.guard';
import { UserHash } from '../utils/auth.decorator';
import { CreateRoomDto } from './createRoom.dto';
import { FcmHandler } from '../utils/fcmHandler';
import { AuthGuard } from '../common/guard/auth.guard';
import { UserHash } from '../common/decorator/auth.decorator';
import { CreateRoomDto } from './dto/createRoom.dto';
import { FcmHandler } from '../common/fcmHandler';

@Controller('chat')
export class ChatController {
Expand Down
2 changes: 1 addition & 1 deletion BE/src/chat/chat.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChatsGateway } from './chats.gateway';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ChatRoomEntity } from '../entities/chatRoom.entity';
import { PostEntity } from '../entities/post.entity';
import { FcmHandler } from '../utils/fcmHandler';
import { FcmHandler } from '../common/fcmHandler';
import { RegistrationTokenEntity } from '../entities/registrationToken.entity';
import { ChatEntity } from 'src/entities/chat.entity';
import { UserEntity } from 'src/entities/user.entity';
Expand Down
2 changes: 1 addition & 1 deletion BE/src/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChatRoomEntity } from '../entities/chatRoom.entity';
import { ChatEntity } from 'src/entities/chat.entity';
import { ChatDto } from './dto/chat.dto';
import { UserEntity } from 'src/entities/user.entity';
import { FcmHandler, PushMessage } from '../utils/fcmHandler';
import { FcmHandler, PushMessage } from '../common/fcmHandler';
import * as jwt from 'jsonwebtoken';
import { ConfigService } from '@nestjs/config';
import { JwtPayload } from 'jsonwebtoken';
Expand Down
2 changes: 1 addition & 1 deletion BE/src/chat/dto/chat.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsBoolean, IsNumber, IsString } from 'class-validator';
import { IsNumber, IsString } from 'class-validator';

export class ChatDto {
@IsString()
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function IsPriceCorrect(
property: string,
validationOptions?: ValidationOptions,
) {
return (object: Object, propertyName: string) => {
return (object, propertyName: string) => {
registerDecorator({
name: 'IsPriceCorrect',
target: object.constructor,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
NestInterceptor,
Injectable,
Logger,
HttpException,
} from '@nestjs/common';
import { Observable, throwError } from 'rxjs';
import { tap, catchError } from 'rxjs/operators';
Expand Down
1 change: 0 additions & 1 deletion BE/src/entities/post.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { UserEntity } from './user.entity';
import { PostImageEntity } from './postImage.entity';
import { BlockPostEntity } from './blockPost.entity';
import { ChatRoomEntity } from './chatRoom.entity';
import { ReportEntity } from './report.entity';

@Entity('post')
Expand Down
3 changes: 2 additions & 1 deletion BE/src/login/login.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
} from '@nestjs/common';
import { LoginService, SocialProperties } from './login.service';
import { AppleLoginDto } from './dto/appleLogin.dto';
import { AuthGuard } from '../utils/auth.guard';
import { AuthGuard } from '../common/guard/auth.guard';


@Controller()
export class LoginController {
Expand Down
4 changes: 2 additions & 2 deletions BE/src/login/login.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { JwtModule } from '@nestjs/jwt';
import { JwtConfig } from '../config/jwt.config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserEntity } from '../entities/user.entity';
import { AuthGuard } from 'src/utils/auth.guard';
import { FcmHandler } from '../utils/fcmHandler';
import { AuthGuard } from 'src/common/guard/auth.guard';
import { FcmHandler } from '../common/fcmHandler';
import { RegistrationTokenEntity } from '../entities/registrationToken.entity';

@Module({
Expand Down
21 changes: 6 additions & 15 deletions BE/src/login/login.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { HttpException, Inject, Injectable, Logger } from '@nestjs/common';
import { HttpException, Inject, Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { InjectRepository } from '@nestjs/typeorm';
import { UserEntity } from '../entities/user.entity';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { hashMaker } from '../utils/hashMaker';
import { hashMaker } from '../common/hashMaker';
import { AppleLoginDto } from './dto/appleLogin.dto';
import * as jwt from 'jsonwebtoken';
import * as jwksClient from 'jwks-rsa';
import { FcmHandler } from '../utils/fcmHandler';
import { FcmHandler } from '../common/fcmHandler';
import { CACHE_MANAGER, CacheStore } from '@nestjs/cache-manager';

export interface SocialProperties {
Expand All @@ -24,7 +24,6 @@ export interface JwtTokens {
@Injectable()
export class LoginService {
private jwksClient: jwksClient.JwksClient;
private readonly logger = new Logger('ChatsGateway');
constructor(
@InjectRepository(UserEntity)
private userRepository: Repository<UserEntity>,
Expand Down Expand Up @@ -87,13 +86,12 @@ export class LoginService {
async verifyUserRegistration(
socialProperties: SocialProperties,
): Promise<UserEntity> {
const user = await this.userRepository.findOne({
return await this.userRepository.findOne({
where: {
OAuth_domain: socialProperties.OAuthDomain,
social_id: socialProperties.socialId,
},
});
return user;
}

generateAccessToken(user: UserEntity): string {
Expand All @@ -119,12 +117,7 @@ export class LoginService {
const identityTokenParts = identityToken.split('.');
const identityTokenPayload = identityTokenParts[1];

const payloadClaims = Buffer.from(
identityTokenPayload,
'base64',
).toString();

return payloadClaims;
return Buffer.from(identityTokenPayload, 'base64').toString();
}

async getApplePublicKey(kid: string) {
Expand All @@ -133,9 +126,7 @@ export class LoginService {
});

const key = await client.getSigningKey(kid);
const signingKey = key.getPublicKey();

return signingKey;
return key.getPublicKey();
}

async appleOAuth(body: AppleLoginDto): Promise<SocialProperties> {
Expand Down
2 changes: 1 addition & 1 deletion BE/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { setupSwagger } from './config/swagger.config';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { winstonLogger } from './config/winston.config';
import { ValidationPipe } from '@nestjs/common';
import { HttpLoggerInterceptor } from './utils/httpLogger.interceptor';
import { HttpLoggerInterceptor } from './common/interceptor/httpLogger.interceptor';
import { WsAdapter } from '@nestjs/platform-ws';

async function bootstrap() {
Expand Down
2 changes: 1 addition & 1 deletion BE/src/post/dto/postCreate.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IsBoolean, IsString, MaxLength } from 'class-validator';
import { IsPriceCorrect } from '../../utils/price.decorator';
import { IsPriceCorrect } from '../../common/decorator/price.decorator';

export class PostCreateDto {
@IsString()
Expand Down
11 changes: 5 additions & 6 deletions BE/src/post/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { UpdatePostDto } from './dto/postUpdate.dto';
import { FilesInterceptor } from '@nestjs/platform-express';
import { PostCreateDto } from './dto/postCreate.dto';
import { MultiPartBody } from '../utils/multiPartBody.decorator';
import { MultiPartBody } from '../common/decorator/multiPartBody.decorator';
import { PostListDto } from './dto/postList.dto';
import { AuthGuard } from 'src/utils/auth.guard';
import { UserHash } from 'src/utils/auth.decorator';
import { FilesSizeValidator } from '../utils/files.validator';
import { AuthGuard } from 'src/common/guard/auth.guard';
import { UserHash } from 'src/common/decorator/auth.decorator';
import { FilesSizeValidator } from '../common/files.validator';

@Controller('posts')
@ApiTags('posts')
Expand All @@ -32,8 +32,7 @@ export class PostController {

@Get()
async postsList(@Query() query: PostListDto, @UserHash() userId: string) {
const posts = await this.postService.findPosts(query, userId);
return posts;
return await this.postService.findPosts(query, userId);
}

@Get('/titles')
Expand Down
4 changes: 2 additions & 2 deletions BE/src/post/post.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { PostController } from './post.controller';
import { PostService } from './post.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PostEntity } from '../entities/post.entity';
import { S3Handler } from '../utils/S3Handler';
import { S3Handler } from '../common/S3Handler';
import { PostImageEntity } from '../entities/postImage.entity';
import { BlockUserEntity } from '../entities/blockUser.entity';
import { BlockPostEntity } from '../entities/blockPost.entity';
import { AuthGuard } from 'src/utils/auth.guard';
import { AuthGuard } from 'src/common/guard/auth.guard';

@Module({
imports: [
Expand Down
24 changes: 1 addition & 23 deletions BE/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PostEntity } from '../entities/post.entity';
import { LessThan, Like, Repository } from 'typeorm';
import { UpdatePostDto } from './dto/postUpdate.dto';
import { PostImageEntity } from 'src/entities/postImage.entity';
import { S3Handler } from '../utils/S3Handler';
import { S3Handler } from '../common/S3Handler';
import { PostListDto } from './dto/postList.dto';
import { BlockUserEntity } from '../entities/blockUser.entity';
import { BlockPostEntity } from '../entities/blockPost.entity';
Expand Down Expand Up @@ -138,28 +138,6 @@ export class PostService {
};
}

async changeImages(postId: number, images: string[]) {
try {
await this.postImageRepository.delete({ post_id: postId });
for (const img of images) {
await this.postImageRepository.save({
post_id: postId,
image_url: img,
});
}
} catch {
throw new HttpException('서버 오류입니다.', 500);
}
}

async changeExceptImages(postId: number, updatePostDto: UpdatePostDto) {
try {
await this.postRepository.update({ id: postId }, updatePostDto);
} catch (e) {
throw new HttpException('서버 오류입니다.', 500);
}
}

Comment on lines -141 to -162
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그냥 지워버린줄 알았는데 안쓰는거라니 다행임다~

async checkAuth(postId, userId) {
const isDataExists = await this.postRepository.findOne({
where: { id: postId },
Expand Down
4 changes: 2 additions & 2 deletions BE/src/posts-block/posts-block.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
UseGuards,
} from '@nestjs/common';
import { PostsBlockService } from './posts-block.service';
import { AuthGuard } from 'src/utils/auth.guard';
import { UserHash } from 'src/utils/auth.decorator';
import { AuthGuard } from 'src/common/guard/auth.guard';
import { UserHash } from 'src/common/decorator/auth.decorator';

@Controller('posts/block')
@UseGuards(AuthGuard)
Expand Down
2 changes: 1 addition & 1 deletion BE/src/posts-block/posts-block.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PostsBlockService } from './posts-block.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BlockPostEntity } from '../entities/blockPost.entity';
import { PostEntity } from '../entities/post.entity';
import { AuthGuard } from 'src/utils/auth.guard';
import { AuthGuard } from 'src/common/guard/auth.guard';

@Module({
imports: [TypeOrmModule.forFeature([BlockPostEntity, PostEntity])],
Expand Down
6 changes: 3 additions & 3 deletions BE/src/report/report.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { CreateReportDto } from './createReport.dto';
import { CreateReportDto } from './dto/createReport.dto';
import { ReportService } from './report.service';
import { AuthGuard } from '../utils/auth.guard';
import { UserHash } from '../utils/auth.decorator';
import { AuthGuard } from '../common/guard/auth.guard';
import { UserHash } from '../common/decorator/auth.decorator';

@Controller('report')
@UseGuards(AuthGuard)
Expand Down
2 changes: 1 addition & 1 deletion BE/src/report/report.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpException, Injectable } from '@nestjs/common';
import { CreateReportDto } from './createReport.dto';
import { CreateReportDto } from './dto/createReport.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ReportEntity } from '../entities/report.entity';
Expand Down
4 changes: 2 additions & 2 deletions BE/src/users-block/users-block.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
UseGuards,
} from '@nestjs/common';
import { UsersBlockService } from './users-block.service';
import { AuthGuard } from 'src/utils/auth.guard';
import { UserHash } from 'src/utils/auth.decorator';
import { AuthGuard } from 'src/common/guard/auth.guard';
import { UserHash } from 'src/common/decorator/auth.decorator';

@Controller('users/block')
@UseGuards(AuthGuard)
Expand Down
2 changes: 1 addition & 1 deletion BE/src/users-block/users-block.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UsersBlockController } from './users-block.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BlockUserEntity } from 'src/entities/blockUser.entity';
import { UserEntity } from 'src/entities/user.entity';
import { AuthGuard } from 'src/utils/auth.guard';
import { AuthGuard } from 'src/common/guard/auth.guard';

@Module({
imports: [TypeOrmModule.forFeature([BlockUserEntity, UserEntity])],
Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 6 additions & 9 deletions BE/src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ import {
HttpException,
UseGuards,
Body,
ParseFilePipe,
MaxFileSizeValidator,
Header,
Headers,
} from '@nestjs/common';
import { UsersService } from './users.service';
import { CreateUserDto } from './createUser.dto';
import { CreateUserDto } from './dto/createUser.dto';
import { FileInterceptor } from '@nestjs/platform-express';
import { MultiPartBody } from 'src/utils/multiPartBody.decorator';
import { UpdateUsersDto } from './usersUpdate.dto';
import { AuthGuard } from 'src/utils/auth.guard';
import { UserHash } from '../utils/auth.decorator';
import { FileSizeValidator } from '../utils/files.validator';
import { MultiPartBody } from 'src/common/decorator/multiPartBody.decorator';
import { UpdateUsersDto } from './dto/usersUpdate.dto';
import { AuthGuard } from 'src/common/guard/auth.guard';
import { UserHash } from '../common/decorator/auth.decorator';
import { FileSizeValidator } from '../common/files.validator';

@Controller('users')
@UseGuards(AuthGuard)
Expand Down
Loading
Loading