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

Feature #4 gist api module PR 재등록 #50

Merged
merged 1 commit into from
Nov 13, 2024
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
4 changes: 3 additions & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppController } from './app.controller';
import { AppService } from './app.service';
import { typeORMConfig } from './config/typeorm.config';
import { DockerModule } from './docker/docker.module';
import { GistModule } from './gist/gist.module';

@Module({
imports: [
Expand All @@ -13,7 +14,8 @@ import { DockerModule } from './docker/docker.module';
envFilePath: '.env'
}),
TypeOrmModule.forRoot(typeORMConfig),
DockerModule
DockerModule,
GistModule
],
controllers: [AppController],
providers: [AppService]
Expand Down
15 changes: 15 additions & 0 deletions apps/backend/src/gist/dto/comment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { UserDto } from './user.dto';

export class CommentDto {
id: string;
created_at: string;
body: string;
owner: UserDto;

constructor(id: string, created_at: string, body: string, owner: UserDto) {
this.id = id;
this.created_at = created_at;
this.body = body;
this.owner = owner;
}
}
9 changes: 9 additions & 0 deletions apps/backend/src/gist/dto/commit.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class CommitDto {
committed_at: string;
url: string;

constructor(committed_at: string, url: string) {
this.committed_at = committed_at;
this.url = url;
}
}
17 changes: 17 additions & 0 deletions apps/backend/src/gist/dto/gistApiFile.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export class GistApiFileDto {
file_name?: string;
raw_url?: string;
type?: string;
language?: string;
size?: number;
content?: string;

constructor(file_name: string, raw_url: string, type: string, language: string, size: number, content: string) {
this.file_name = file_name;
this.raw_url = raw_url;
this.type = type;
this.language = language;
this.size = size;
this.content = content;
}
}
18 changes: 18 additions & 0 deletions apps/backend/src/gist/dto/gistApiFileList.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { GistApiFileDto } from './gistApiFile.dto';
import { UserDto } from './user.dto';

export class GistApiFileListDto {
id: string;
description: string;
files: GistApiFileDto[];
owner: UserDto;
public: boolean;

constructor(id: string, description: string, files: GistApiFileDto[], owner: UserDto, isPublic: boolean) {
this.id = id;
this.description = description;
this.files = files;
this.owner = owner;
this.public = isPublic;
}
}
11 changes: 11 additions & 0 deletions apps/backend/src/gist/dto/user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class UserDto {
login: string;
id: number;
avatar_url: string;

constructor(login: string, id: number, avatar_url) {
this.login = login;
this.id = id;
this.avatar_url = avatar_url;
}
}
20 changes: 20 additions & 0 deletions apps/backend/src/gist/gist.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { GistController } from './gist.controller';
import { GistService } from './gist.service';

describe('GistController', () => {
let controller: GistController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [GistController],
providers: [GistService]
}).compile();

controller = module.get<GistController>(GistController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
61 changes: 61 additions & 0 deletions apps/backend/src/gist/gist.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { GistService } from './gist.service';

@Controller('gist')
export class GistController {
constructor(private readonly gistService: GistService) {}

@Get()
findAll() {
return this.gistService.getAllGists();
}

@Get('/Last')
findLast() {
return this.gistService.getMostRecentGistInUser();
}

@Get('/user')
findUser() {
return this.gistService.getUserData();
}

@Get('/:gist_id/comments')
findComments(@Param('gist_id') gist_id: string) {
return this.gistService.getComments(gist_id);
}

@Get(['/:id/commits', '/:id/commits/:pageIdx'])
findCommits(@Param('id') id: string, @Param('pageIdx') pageIdx: number) {
return this.gistService.getCommitsForAGist(id, pageIdx ? pageIdx : 1);
}

@Get(['/:id'])
findOne(@Param('id') id: string) {
return this.gistService.getGistById(id);
}

@Patch('/:gist_id/comment/:comment_id')
patchComment(
@Param('gist_id') gist_id: string,
@Param('comment_id') comment_id: string,
@Body('comment') comment: string
) {
return this.gistService.updateComment(gist_id, comment_id, comment);
}

@Post('/:gist_id/comment')
postComment(@Param('gist_id') gist_id: string, @Body('comment') comment: string) {
return this.gistService.createComments(gist_id, comment);
}

@Delete('/:gist_id/comment/:comment_id')
deleteComment(@Param('gist_id') gist_id: string, @Param('comment_id') comment_id: string) {
return this.gistService.deleteComment(gist_id, comment_id);
}

@Get(':gist_id/commit/:id')
getCommitFile(@Param('gist_id') gist_id: string, @Param('id') commit_id: number) {
return this.gistService.getCommit(gist_id, commit_id);
}
}
9 changes: 9 additions & 0 deletions apps/backend/src/gist/gist.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { GistController } from './gist.controller';
import { GistService } from './gist.service';

@Module({
controllers: [GistController],
providers: [GistService]
})
export class GistModule {}
18 changes: 18 additions & 0 deletions apps/backend/src/gist/gist.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { GistService } from './gist.service';

describe('GistService', () => {
let service: GistService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [GistService]
}).compile();

service = module.get<GistService>(GistService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
Loading
Loading