Skip to content

Commit

Permalink
Merge pull request #300 from boostcampwm-2024/dev
Browse files Browse the repository at this point in the history
[Deploy] 6주차 1차 배포
  • Loading branch information
ShipFriend0516 authored Dec 2, 2024
2 parents 314cfaa + b963cc1 commit 2ccc3d3
Show file tree
Hide file tree
Showing 131 changed files with 2,868 additions and 1,696 deletions.
141 changes: 59 additions & 82 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"dotenv": "^16.4.5",
"ioredis": "^5.4.1",
"mysql2": "^3.11.4",
"nestjs-paginate": "^10.0.0",
"nestjs-redis-om": "^0.1.2",
"passport": "^0.7.0",
"passport-custom": "^1.1.1",
Expand Down
2 changes: 2 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createDataSource, typeOrmConfig } from "./config/typeorm.config";
import { QuestionListModule } from "./question-list/question-list.module";
import { RedisOmModule } from "@moozeh/nestjs-redis-om";
import { SigServerModule } from "@/signaling-server/sig-server.module";
import { QuestionModule } from './question/question.module';

@Module({
imports: [
Expand All @@ -29,6 +30,7 @@ import { SigServerModule } from "@/signaling-server/sig-server.module";
UserModule,
QuestionListModule,
SigServerModule,
QuestionModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
6 changes: 3 additions & 3 deletions backend/src/config/typeorm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SnakeNamingStrategy } from "typeorm-naming-strategies";
import { User } from "@/user/user.entity";
import "dotenv/config";
import { addTransactionalDataSource } from "typeorm-transactional";
import { QuestionList } from "@/question-list/question-list.entity";
import { Question } from "@/question-list/question.entity";
import { Category } from "@/question-list/category.entity";
import { QuestionList } from "@/question-list/entity/question-list.entity";
import { Question } from "@/question-list/entity/question.entity";
import { Category } from "@/question-list/entity/category.entity";

export const typeOrmConfig: DataSourceOptions = {
type: "mysql",
Expand Down
24 changes: 24 additions & 0 deletions backend/src/question-list/dto/paginate-meta.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { IsInt, IsNumberString, IsString } from "class-validator";
import { Expose } from "class-transformer";

export class PaginateMetaDto {
@Expose()
@IsInt()
itemsPerPage: number;

@Expose()
@IsInt()
totalItems: number;

@Expose()
@IsNumberString()
currentPage: string;

@Expose()
@IsInt()
totalPages: number;

@Expose()
@IsString()
sortBy: string;
}
29 changes: 29 additions & 0 deletions backend/src/question-list/dto/paginate-query.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IsInt, IsOptional, IsString, Min } from "class-validator";
import { Expose, Transform } from "class-transformer";

export class PaginateQueryDto {
@Expose()
@IsOptional()
@IsInt()
@Min(1)
@Transform(({ value }) => (value ? parseInt(value) : 1))
page?: number;

@Expose()
@IsOptional()
@IsInt()
@Min(1)
@Transform(({ value }) => (value ? parseInt(value) : 4))
limit?: number;

@Expose()
@IsOptional()
@IsString()
@Transform(({ value }) => value || "usage:DESC")
sortBy?: string;

@Expose()
@IsOptional()
@IsString()
category?: string;
}
9 changes: 9 additions & 0 deletions backend/src/question-list/dto/paginate.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { SelectQueryBuilder } from "typeorm";

export class PaginateDto {
queryBuilder: SelectQueryBuilder<any>;
skip: number;
take: number;
field: string;
direction: "ASC" | "DESC";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Question } from "../question.entity";
import { Question } from "../entity/question.entity";

export interface QuestionListContentsDto {
id: number;
Expand Down
81 changes: 44 additions & 37 deletions backend/src/question-list/question-list.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
Query,
Req,
UseGuards,
UsePipes,
ValidationPipe,
} from "@nestjs/common";
import { QuestionListService } from "./question-list.service";
import { CreateQuestionListDto } from "./dto/create-question-list.dto";
Expand All @@ -19,14 +21,15 @@ import { IJwtPayload } from "@/auth/jwt/jwt.model";
import { UpdateQuestionListDto } from "@/question-list/dto/update-question-list.dto";
import { QuestionDto } from "@/question-list/dto/question.dto";
import { DeleteQuestionDto } from "@/question-list/dto/delete-question.dto";
import { PaginateQuery } from "nestjs-paginate";
import { PaginateQueryDto } from "@/question-list/dto/paginate-query.dto";

@Controller("question-list")
export class QuestionListController {
constructor(private readonly questionListService: QuestionListService) {}

@Get()
async getAllQuestionLists(@Query() query: PaginateQuery) {
@UsePipes(new ValidationPipe({ transform: true }))
async getAllQuestionLists(@Query() query: PaginateQueryDto) {
try {
const { allQuestionLists, meta } =
await this.questionListService.getAllQuestionLists(query);
Expand All @@ -47,6 +50,37 @@ export class QuestionListController {
}
}

@Post("category")
@UsePipes(new ValidationPipe({ transform: true }))
async getAllQuestionListsByCategoryName(
@Query() query: PaginateQueryDto,
@Body()
body: {
categoryName: string;
}
) {
try {
const { categoryName } = body;
query.category = categoryName;
const { allQuestionLists, meta } =
await this.questionListService.getAllQuestionLists(query);
return {
success: true,
message: "All question lists received successfully.",
data: {
allQuestionLists,
meta,
},
};
} catch (error) {
return {
success: false,
message: "Failed to get all question lists.",
error: error.message,
};
}
}

@Post()
@UseGuards(AuthGuard("jwt"))
async createQuestionList(
Expand Down Expand Up @@ -92,49 +126,20 @@ export class QuestionListController {
}
}

@Post("category")
async getAllQuestionListsByCategoryName(
@Query() query: PaginateQuery,
@Body()
body: {
categoryName: string;
}
) {
try {
const { categoryName } = body;
const { allQuestionLists, meta } =
await this.questionListService.getAllQuestionListsByCategoryName(
categoryName,
query
);
return {
success: true,
message: "All question lists received successfully.",
data: {
allQuestionLists,
meta,
},
};
} catch (error) {
return {
success: false,
message: "Failed to get all question lists.",
error: error.message,
};
}
}

@Post("contents")
@UseGuards(AuthGuard("jwt"))
async getQuestionListContents(
@JwtPayload() token: IJwtPayload,
@Body()
body: {
questionListId: number;
}
) {
try {
const userId = token.userId;
const { questionListId } = body;
const questionListContents: QuestionListContentsDto =
await this.questionListService.getQuestionListContents(questionListId);
await this.questionListService.getQuestionListContents(questionListId, userId);
return {
success: true,
message: "Question list contents received successfully.",
Expand All @@ -153,7 +158,8 @@ export class QuestionListController {

@Get("my")
@UseGuards(AuthGuard("jwt"))
async getMyQuestionLists(@Query() query: PaginateQuery, @JwtPayload() token: IJwtPayload) {
@UsePipes(new ValidationPipe({ transform: true }))
async getMyQuestionLists(@Query() query: PaginateQueryDto, @JwtPayload() token: IJwtPayload) {
try {
const userId = token.userId;
const { myQuestionLists, meta } = await this.questionListService.getMyQuestionLists(
Expand Down Expand Up @@ -353,8 +359,9 @@ export class QuestionListController {

@Get("scrap")
@UseGuards(AuthGuard("jwt"))
@UsePipes(new ValidationPipe({ transform: true }))
async getScrappedQuestionLists(
@Query() query: PaginateQuery,
@Query() query: PaginateQueryDto,
@JwtPayload() token: IJwtPayload
) {
try {
Expand Down
14 changes: 11 additions & 3 deletions backend/src/question-list/question-list.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Module } from "@nestjs/common";
import { QuestionListController } from "./question-list.controller";
import { QuestionListService } from "./question-list.service";
import { QuestionListRepository } from "./question-list.repository";
import { QuestionListRepository } from "./repository/question-list.repository";
import { UserRepository } from "@/user/user.repository";
import { QuestionRepository } from "@/question-list/repository/question.respository";
import { CategoryRepository } from "@/question-list/repository/category.repository";

@Module({
controllers: [QuestionListController],
providers: [QuestionListService, QuestionListRepository, UserRepository],
exports: [QuestionListRepository],
providers: [
QuestionListService,
QuestionListRepository,
QuestionRepository,
UserRepository,
CategoryRepository,
],
exports: [QuestionListRepository, QuestionRepository],
})
export class QuestionListModule {}
Loading

0 comments on commit 2ccc3d3

Please sign in to comment.