Skip to content

Commit

Permalink
Merge branch 'main' into feature-#145-create
Browse files Browse the repository at this point in the history
  • Loading branch information
ATeals authored Nov 26, 2024
2 parents 7f30427 + 5702b89 commit ca227fb
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 91 deletions.
2 changes: 1 addition & 1 deletion apps/backend/src/docker/docker.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class DockerService {
});

stream.on('end', async () => {
// await container.remove({ force: true });
await container.remove({ force: true });
let result = this.filterAnsiCode(output);
if (inputs.length !== 0) {
result = result.split('\n').slice(1).join('\n');
Expand Down
9 changes: 8 additions & 1 deletion apps/backend/src/lotus/dto/lotus.detail.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsArray, IsBoolean, IsDate, IsString, ValidateNested } from 'class-validator';
import { IsArray, IsBoolean, IsDate, IsString, IsUrl, ValidateNested } from 'class-validator';
import { SimpleFileResponseDto } from './simple.file.response.dto';
import { SimpleUserResponseDto } from './simple.user.response.dto';
import { GistApiFileListDto } from '@/gist/dto/gistApiFileList.dto';
Expand Down Expand Up @@ -43,6 +43,12 @@ export class LotusDetailDto {
})
version: string;

@IsUrl()
@ApiProperty({
example: 'https://gist.github.com/gistId~~/commitId~~'
})
gistUrl: string;

@IsBoolean()
@ApiProperty({
example: true
Expand Down Expand Up @@ -73,6 +79,7 @@ export class LotusDetailDto {
id: lotus.lotusId,
title: lotus.title,
language: lotus.language,
gistUrl: `https://gist.github.com/${lotus.gistRepositoryId}/${lotus.commitId}`,
version: lotus.version,
date: lotus.createdAt,
isPublic: lotus.isPublic,
Expand Down
10 changes: 9 additions & 1 deletion apps/backend/src/lotus/dto/lotus.response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsBoolean, IsDate, IsString, ValidateNested } from 'class-validator';
import { IsBoolean, IsDate, IsString, IsUrl, ValidateNested } from 'class-validator';
import { SimpleUserResponseDto } from './simple.user.response.dto';
import { Lotus } from '@/lotus/lotus.entity';

Expand Down Expand Up @@ -29,6 +29,12 @@ export class LotusResponseDto {
})
language: string;

@IsUrl()
@ApiProperty({
example: 'https://gist.github.com/gistId~~/commitId~~'
})
gistUrl: string;

@IsDate()
@ApiProperty({
example: '로투스 생성 일시'
Expand All @@ -54,6 +60,7 @@ export class LotusResponseDto {
author: user,
title: lotus.title,
language: lotus.language,
gistUrl: `https://gist.github.com/${lotus.gistRepositoryId}/${lotus.commitId}`,
isPublic: lotus.isPublic,
date: lotus.createdAt,
tags
Expand All @@ -67,6 +74,7 @@ export class LotusResponseDto {
id: lotus.lotusId,
author: simpleUser,
title: lotus.title,
gistUrl: `https://gist.github.com/${lotus.gistRepositoryId}/${lotus.commitId}`,
language: lotus.language,
isPublic: lotus.isPublic,
date: lotus.createdAt,
Expand Down
9 changes: 8 additions & 1 deletion apps/backend/src/lotus/dto/simple.user.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ export class SimpleUserResponseDto {
})
profile: string;

@IsUrl()
@ApiProperty({
example: 'https://gist.github.com/nickname'
})
gistUrl: string;

static ofUserDto(userData: User) {
return {
id: userData.userId,
nickname: userData.nickname,
profile: userData.profilePath
profile: userData.profilePath,
gistUrl: userData.gistUrl
};
}
}
40 changes: 20 additions & 20 deletions apps/backend/src/lotus/lotus.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,65 +132,65 @@ export class LotusService {
}

async getPublicLotus(page: number, size: number, search: string): Promise<LotusPublicDto> {
const lotusData = await this.getLotusByTags(search);

const totalNum = lotusData.length;
const [lotusData, totalNum] = await this.getLotusByTags(page, size, search);
const maxPage = Math.ceil(totalNum / size);
if (page > maxPage && maxPage !== 0) {
throw new HttpException('page must be lower than max page', HttpStatus.NOT_FOUND);
}
if (page <= 0) {
throw new HttpException('page must be higher than 0', HttpStatus.NOT_FOUND);
}
const firstIdx = size * (page - 1);
const returnLotusData = lotusData.splice(firstIdx, size);

return LotusPublicDto.ofLotusList(returnLotusData, page, maxPage);
return LotusPublicDto.ofLotusList(lotusData, page, maxPage);
}

async getLotusByTags(search: string) {
async getLotusByTags(page: number, size: number, search: string) {
if (!search) {
return await this.lotusRepository.find({
return await this.lotusRepository.findAndCount({
where: {
isPublic: true
},
relations: ['tags', 'user']
skip: (page - 1) * size,
take: size,
relations: ['tags', 'user'],
order: { createdAt: 'DESC' }
});
}
const tags = await this.tagService.searchTag(search);
return await this.lotusRepository.find({
return await this.lotusRepository.findAndCount({
where: {
isPublic: true,
tags: {
tagId: In(tags)
}
},
relations: ['tags', 'user']
skip: (page - 1) * size,
take: size,
relations: ['tags', 'user'],
order: { createdAt: 'DESC' }
});
}

async getUserLotus(userId: string, page: number, size: number) {
const user = this.userService.findOneByUserId(userId);
if (!user) {
throw new HttpException('user data is not found', HttpStatus.NOT_FOUND);
throw new HttpException('user data is not found', HttpStatus.UNAUTHORIZED);
}

const lotusData = await this.lotusRepository.find({
const [lotusData, totalNum] = await this.lotusRepository.findAndCount({
where: { user: { userId } },
relations: ['tags', 'user']
skip: (page - 1) * size,
take: size,
relations: ['tags', 'user'],
order: { createdAt: 'DESC' }
});
const totalNum = lotusData.length;
const maxPage = Math.ceil(totalNum / size);
if (page > maxPage && maxPage !== 0) {
throw new HttpException('page must be lower than max page', HttpStatus.NOT_FOUND);
}
if (page <= 0) {
throw new HttpException('page must be higher than 0', HttpStatus.NOT_FOUND);
}
const firstIdx = size * (page - 1);
const returnLotusData = lotusData.splice(firstIdx, size);

return LotusPublicDto.ofLotusList(returnLotusData, page, maxPage);
return LotusPublicDto.ofLotusList(lotusData, page, maxPage);
}

async checkAlreadyExist(gistUuid: string, commitId: string) {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { INestApplication, ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerCustomOptions, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';
import { typeOrmExceptionFilter } from './filter/\btypeorm.exception.filter';
import { httpExceptionFilter } from './filter/http.exception.filter';
import { typeOrmExceptionFilter } from './filter/typeorm.exception.filter';

async function bootstrap() {
const app: INestApplication = await NestFactory.create(AppModule);
Expand Down
4 changes: 4 additions & 0 deletions apps/backend/src/user/dto/user.create.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class UserCreateDto {
@IsNumber()
gitId: number;

@IsString()
gistUrl: string;

@ValidateNested({ each: true })
@Type(() => Lotus)
lotuses: Lotus[];
Expand All @@ -32,6 +35,7 @@ export class UserCreateDto {
this.profilePath = response.avatar_url;
this.gitToken = accessToken;
this.gitId = response.id;
this.gistUrl = `https://gist.github.com/${response.login}`;
this.lotuses = [];
this.comments = [];
}
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/user/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export class User {
@Column({ name: 'git_token' })
gitToken: string;

@Column({ name: 'gist_url' })
gistUrl: string;

@Column({ name: 'git_id', unique: true })
gitId: number;

Expand Down
64 changes: 32 additions & 32 deletions apps/frontend/src/app/router/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import { Route as LoginErrorIndexImport } from './../../page/login/error/index';
import { Route as mainUserIndexImport } from './../../page/(main)/user/index';
import { Route as mainLotusIndexImport } from './../../page/(main)/lotus/index';
import { Route as mainLotusCreateIndexImport } from './../../page/(main)/lotus/create/index';
import { Route as mainLotusLotusIdIndexImport } from './../../page/(main)/lotus/$lotusId/index';

// Create Virtual Routes

const mainRouteLazyImport = createFileRoute('/(main)')();
const IndexLazyImport = createFileRoute('/')();
const mainLotusLotusIdIndexLazyImport = createFileRoute('/(main)/lotus/$lotusId/')();

// Create/Update Routes

Expand Down Expand Up @@ -69,14 +69,6 @@ const mainLotusIndexRoute = mainLotusIndexImport
} as any)
.lazy(() => import('./../../page/(main)/lotus/index.lazy').then((d) => d.Route));

const mainLotusLotusIdIndexLazyRoute = mainLotusLotusIdIndexLazyImport
.update({
id: '/lotus/$lotusId/',
path: '/lotus/$lotusId/',
getParentRoute: () => mainRouteLazyRoute
} as any)
.lazy(() => import('./../../page/(main)/lotus/$lotusId/index.lazy').then((d) => d.Route));

const mainLotusCreateIndexRoute = mainLotusCreateIndexImport
.update({
id: '/lotus/create/',
Expand All @@ -85,6 +77,14 @@ const mainLotusCreateIndexRoute = mainLotusCreateIndexImport
} as any)
.lazy(() => import('./../../page/(main)/lotus/create/index.lazy').then((d) => d.Route));

const mainLotusLotusIdIndexRoute = mainLotusLotusIdIndexImport
.update({
id: '/lotus/$lotusId/',
path: '/lotus/$lotusId/',
getParentRoute: () => mainRouteLazyRoute
} as any)
.lazy(() => import('./../../page/(main)/lotus/$lotusId/index.lazy').then((d) => d.Route));

// Populate the FileRoutesByPath interface

declare module '@tanstack/react-router' {
Expand Down Expand Up @@ -131,20 +131,20 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof LoginSuccessIndexImport;
parentRoute: typeof rootRoute;
};
'/(main)/lotus/$lotusId/': {
id: '/(main)/lotus/$lotusId/';
path: '/lotus/$lotusId';
fullPath: '/lotus/$lotusId';
preLoaderRoute: typeof mainLotusLotusIdIndexImport;
parentRoute: typeof mainRouteLazyImport;
};
'/(main)/lotus/create/': {
id: '/(main)/lotus/create/';
path: '/lotus/create';
fullPath: '/lotus/create';
preLoaderRoute: typeof mainLotusCreateIndexImport;
parentRoute: typeof mainRouteLazyImport;
};
'/(main)/lotus/$lotusId/': {
id: '/(main)/lotus/$lotusId/';
path: '/lotus/$lotusId';
fullPath: '/lotus/$lotusId';
preLoaderRoute: typeof mainLotusLotusIdIndexLazyImport;
parentRoute: typeof mainRouteLazyImport;
};
}
}

Expand All @@ -153,15 +153,15 @@ declare module '@tanstack/react-router' {
interface mainRouteLazyRouteChildren {
mainLotusIndexRoute: typeof mainLotusIndexRoute;
mainUserIndexRoute: typeof mainUserIndexRoute;
mainLotusLotusIdIndexRoute: typeof mainLotusLotusIdIndexRoute;
mainLotusCreateIndexRoute: typeof mainLotusCreateIndexRoute;
mainLotusLotusIdIndexLazyRoute: typeof mainLotusLotusIdIndexLazyRoute;
}

const mainRouteLazyRouteChildren: mainRouteLazyRouteChildren = {
mainLotusIndexRoute: mainLotusIndexRoute,
mainUserIndexRoute: mainUserIndexRoute,
mainLotusCreateIndexRoute: mainLotusCreateIndexRoute,
mainLotusLotusIdIndexLazyRoute: mainLotusLotusIdIndexLazyRoute
mainLotusLotusIdIndexRoute: mainLotusLotusIdIndexRoute,
mainLotusCreateIndexRoute: mainLotusCreateIndexRoute
};

const mainRouteLazyRouteWithChildren = mainRouteLazyRoute._addFileChildren(mainRouteLazyRouteChildren);
Expand All @@ -172,8 +172,8 @@ export interface FileRoutesByFullPath {
'/user': typeof mainUserIndexRoute;
'/login/error': typeof LoginErrorIndexRoute;
'/login/success': typeof LoginSuccessIndexRoute;
'/lotus/$lotusId': typeof mainLotusLotusIdIndexRoute;
'/lotus/create': typeof mainLotusCreateIndexRoute;
'/lotus/$lotusId': typeof mainLotusLotusIdIndexLazyRoute;
}

export interface FileRoutesByTo {
Expand All @@ -182,8 +182,8 @@ export interface FileRoutesByTo {
'/user': typeof mainUserIndexRoute;
'/login/error': typeof LoginErrorIndexRoute;
'/login/success': typeof LoginSuccessIndexRoute;
'/lotus/$lotusId': typeof mainLotusLotusIdIndexRoute;
'/lotus/create': typeof mainLotusCreateIndexRoute;
'/lotus/$lotusId': typeof mainLotusLotusIdIndexLazyRoute;
}

export interface FileRoutesById {
Expand All @@ -194,15 +194,15 @@ export interface FileRoutesById {
'/(main)/user/': typeof mainUserIndexRoute;
'/login/error/': typeof LoginErrorIndexRoute;
'/login/success/': typeof LoginSuccessIndexRoute;
'/(main)/lotus/$lotusId/': typeof mainLotusLotusIdIndexRoute;
'/(main)/lotus/create/': typeof mainLotusCreateIndexRoute;
'/(main)/lotus/$lotusId/': typeof mainLotusLotusIdIndexLazyRoute;
}

export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath;
fullPaths: '/' | '/lotus' | '/user' | '/login/error' | '/login/success' | '/lotus/create' | '/lotus/$lotusId';
fullPaths: '/' | '/lotus' | '/user' | '/login/error' | '/login/success' | '/lotus/$lotusId' | '/lotus/create';
fileRoutesByTo: FileRoutesByTo;
to: '/' | '/lotus' | '/user' | '/login/error' | '/login/success' | '/lotus/create' | '/lotus/$lotusId';
to: '/' | '/lotus' | '/user' | '/login/error' | '/login/success' | '/lotus/$lotusId' | '/lotus/create';
id:
| '__root__'
| '/'
Expand All @@ -211,8 +211,8 @@ export interface FileRouteTypes {
| '/(main)/user/'
| '/login/error/'
| '/login/success/'
| '/(main)/lotus/create/'
| '/(main)/lotus/$lotusId/';
| '/(main)/lotus/$lotusId/'
| '/(main)/lotus/create/';
fileRoutesById: FileRoutesById;
}

Expand Down Expand Up @@ -252,8 +252,8 @@ export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileT
"children": [
"/(main)/lotus/",
"/(main)/user/",
"/(main)/lotus/create/",
"/(main)/lotus/$lotusId/"
"/(main)/lotus/$lotusId/",
"/(main)/lotus/create/"
]
},
"/(main)/lotus/": {
Expand All @@ -270,12 +270,12 @@ export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileT
"/login/success/": {
"filePath": "login/success/index.tsx"
},
"/(main)/lotus/create/": {
"filePath": "(main)/lotus/create/index.tsx",
"/(main)/lotus/$lotusId/": {
"filePath": "(main)/lotus/$lotusId/index.tsx",
"parent": "/(main)"
},
"/(main)/lotus/$lotusId/": {
"filePath": "(main)/lotus/$lotusId/index.lazy.tsx",
"/(main)/lotus/create/": {
"filePath": "(main)/lotus/create/index.tsx",
"parent": "/(main)"
}
}
Expand Down
Loading

0 comments on commit ca227fb

Please sign in to comment.