sungjin

Release 1.0 version

...@@ -4,4 +4,4 @@ ...@@ -4,4 +4,4 @@
4 # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server and MongoDB (Preview). 4 # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server and MongoDB (Preview).
5 # See the documentation for all the connection string options: https://pris.ly/d/connection-strings 5 # See the documentation for all the connection string options: https://pris.ly/d/connection-strings
6 6
7 -DATABASE_URL="postgresql://postgres:12345@localhost:5432/postgres"
...\ No newline at end of file ...\ No newline at end of file
7 +DATABASE_URL="YOUR_DATABASE_URL"
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -17,24 +17,17 @@ ...@@ -17,24 +17,17 @@
17 *** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use. 17 *** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
18 *** https://www.markdownguide.org/basic-syntax/#reference-style-links 18 *** https://www.markdownguide.org/basic-syntax/#reference-style-links
19 --> 19 -->
20 -[![Contributors][contributors-shield]][contributors-url]
21 -[![Forks][forks-shield]][forks-url]
22 -[![Stargazers][stars-shield]][stars-url]
23 -[![Issues][issues-shield]][issues-url]
24 -[![MIT License][license-shield]][license-url]
25 -[![LinkedIn][linkedin-shield]][linkedin-url]
26 -
27 -
28 20
29 <!-- PROJECT LOGO --> 21 <!-- PROJECT LOGO -->
30 <br /> 22 <br />
31 23
32 <div align="center"> 24 <div align="center">
33 - <a href="https://github.com/github_username/repo_name"> 25 + <a href="http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend">
34 - <img src="images/logo.png" alt="Logo" width="80" height="80"> 26 + <img src="logo.svg" alt="Logo" width="80" height="80">
35 </a> 27 </a>
36 <h3 align="center">Learn In Web(Backend)</h3> 28 <h3 align="center">Learn In Web(Backend)</h3>
37 29
30 +
38 <p align="center"> 31 <p align="center">
39 NestJS Backend for 32 NestJS Backend for
40 <a href="http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend"><strong>Learn In Web</strong></a> 33 <a href="http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend"><strong>Learn In Web</strong></a>
...@@ -74,7 +67,6 @@ ...@@ -74,7 +67,6 @@
74 <li><a href="#contributing">Contributing</a></li> 67 <li><a href="#contributing">Contributing</a></li>
75 <li><a href="#license">License</a></li> 68 <li><a href="#license">License</a></li>
76 <li><a href="#contact">Contact</a></li> 69 <li><a href="#contact">Contact</a></li>
77 - <li><a href="#acknowledgments">Acknowledgments</a></li>
78 </ol> 70 </ol>
79 </details> 71 </details>
80 72
...@@ -83,7 +75,7 @@ ...@@ -83,7 +75,7 @@
83 <!-- ABOUT THE PROJECT --> 75 <!-- ABOUT THE PROJECT -->
84 ## About The Project 76 ## About The Project
85 77
86 -[![Product Name Screen Shot][product-screenshot]](https://example.com) 78 +[![Product Name Screen Shot][product-screenshot]](https://code.sungjin.dev)
87 79
88 This project allows users to run codes and study without any IDE. This project focusd on schools, and students for study. 80 This project allows users to run codes and study without any IDE. This project focusd on schools, and students for study.
89 81
...@@ -121,7 +113,7 @@ This is an example of how to list things you need to use the software and how to ...@@ -121,7 +113,7 @@ This is an example of how to list things you need to use the software and how to
121 ``` 113 ```
122 114
123 * Compiler for languages 115 * Compiler for languages
124 - 116 +
125 ```sh 117 ```sh
126 #For typescript 118 #For typescript
127 npm install -g ts-node 119 npm install -g ts-node
...@@ -131,10 +123,10 @@ This is an example of how to list things you need to use the software and how to ...@@ -131,10 +123,10 @@ This is an example of how to list things you need to use the software and how to
131 sudo yum update && sudo yum install golang build-essential 123 sudo yum update && sudo yum install golang build-essential
132 #Other 124 #Other
133 #install golang, cpp, c++ manually. 125 #install golang, cpp, c++ manually.
134 - ``` 126 + ```
135 - 127 +
136 * Docker, postgreSQL Database 128 * Docker, postgreSQL Database
137 - 129 +
138 (You can manually change port, name, etc if you want.) 130 (You can manually change port, name, etc if you want.)
139 131
140 ```sh 132 ```sh
...@@ -142,9 +134,9 @@ This is an example of how to list things you need to use the software and how to ...@@ -142,9 +134,9 @@ This is an example of how to list things you need to use the software and how to
142 docker pull postgres 134 docker pull postgres
143 docker run -d -p 5432:5432 --name postgres-container -e POSTGRES_PASSWORD=Your_Password -v ~/pgdata:/Location_to_save_data/ postgres 135 docker run -d -p 5432:5432 --name postgres-container -e POSTGRES_PASSWORD=Your_Password -v ~/pgdata:/Location_to_save_data/ postgres
144 ``` 136 ```
137 +
145 138
146 - 139 +
147 -
148 * Installation 140 * Installation
149 141
150 1. Clone the repo 142 1. Clone the repo
...@@ -159,7 +151,7 @@ This is an example of how to list things you need to use the software and how to ...@@ -159,7 +151,7 @@ This is an example of how to list things you need to use the software and how to
159 151
160 3. Enter your DB URL in `.env` 152 3. Enter your DB URL in `.env`
161 ```js 153 ```js
162 - DATABASE_URL="postgresql://_User:_Password@localhost:5432/postgres"" 154 + DATABASE_URL="postgresql://_User:_Password@localhost:5432/postgres"
163 ``` 155 ```
164 156
165 4. Migrate DB 157 4. Migrate DB
...@@ -186,7 +178,139 @@ This is an example of how to list things you need to use the software and how to ...@@ -186,7 +178,139 @@ This is an example of how to list things you need to use the software and how to
186 178
187 To Use Learn In Web, you need to use this backend; this project communicate via RESTful API. 179 To Use Learn In Web, you need to use this backend; this project communicate via RESTful API.
188 180
189 -_For More Useage, please see frontend [Demo](http://khuhub.khu.ac.kr/2021105619/learn_in_web)_ 181 +-API-
182 +
183 +```json
184 +POST /auth/signup
185 +{
186 + "name" : "name",
187 + "email" : "email",
188 + "password" : "password"
189 +}
190 +```
191 +
192 +```json
193 +POST /auth/signin
194 +{
195 + "email" : "email",
196 + "password" : "password"
197 +}
198 +```
199 +
200 +```json
201 +POST /auth/refresh
202 +{
203 + "token" : "token_madeby_signup_or_signin"
204 +}
205 +```
206 +
207 +```json
208 +POST /auth/validate
209 +{
210 + "token" : "token_madeby_signup_or_signin"
211 +}
212 +```
213 +
214 +```json
215 +POST /post
216 +{
217 + "token" : "token",
218 + "title" : "title",
219 + "privat" : true,
220 + "explain" : "explain of problem",
221 + "testinput" : ["1", "2"],
222 + "testoutput" : ["3", "4"],
223 + "difficulty" : 1
224 +}
225 +```
226 +
227 +```json
228 +PUT /post
229 +{
230 + "token" : "token",
231 + "title" : "title",
232 + "privat" : true,
233 + "explain" : "explain of problem",
234 + "testinput" : ["1", "2"],
235 + "testoutput" : ["3", "4"],
236 + "difficulty" : 1
237 +}
238 +```
239 +
240 +```json
241 +GET /post
242 +```
243 +
244 +```json
245 +
246 +GET /post/some
247 +{
248 + "take" : 20
249 +}
250 +```
251 +
252 +```
253 +GET /post/id/:id
254 +use integer param for :id
255 +```
256 +
257 +```
258 +GET /post/difficulty/:level
259 +use integer param for :level
260 +```
261 +
262 +```json
263 +POST /post/like/:id
264 +use integer param for :id
265 +{
266 + "token" : "token"
267 +}
268 +```
269 +
270 +```json
271 +DELETE /post
272 +```
273 +
274 +```json
275 +POST /comment/:id
276 +use integer param for :id
277 +{
278 + "token" : "token",
279 + "content" : "content of comment"
280 +}
281 +```
282 +
283 +```json
284 +DELETE /comment/:id
285 +use integer param for :id
286 +{
287 + "token" : "token"
288 +}
289 +```
290 +
291 +```json
292 +GET /comment/:id
293 +use integer param for :id
294 +```
295 +
296 +```json
297 +POST /search
298 +{
299 + "search" : "search item divided by black"
300 +}
301 +```
302 +
303 +```json
304 +POST /runner
305 +{
306 + "token" : "token",
307 + "input" : ["input", "data", "array", "does not working now"],
308 + "type" : "cpp",
309 + "code" : "//example code\n#include <iostream> ~~~~"
310 +}
311 +```
312 +
313 +_For Real Useage, please see frontend [Frontend_URL](http://khuhub.khu.ac.kr/2021105619/learn_in_web)_
190 314
191 <p align="right">(<a href="#top">back to top</a>)</p> 315 <p align="right">(<a href="#top">back to top</a>)</p>
192 316
...@@ -232,7 +356,7 @@ Don't forget to give the project a star! Thanks again! ...@@ -232,7 +356,7 @@ Don't forget to give the project a star! Thanks again!
232 <!-- LICENSE --> 356 <!-- LICENSE -->
233 ## License 357 ## License
234 358
235 -Distributed under the MIT License. See `LICENSE.txt` for more information. 359 +Distributed under the MIT License.
236 360
237 <p align="right">(<a href="#top">back to top</a>)</p> 361 <p align="right">(<a href="#top">back to top</a>)</p>
238 362
...@@ -241,37 +365,13 @@ Distributed under the MIT License. See `LICENSE.txt` for more information. ...@@ -241,37 +365,13 @@ Distributed under the MIT License. See `LICENSE.txt` for more information.
241 <!-- CONTACT --> 365 <!-- CONTACT -->
242 ## Contact 366 ## Contact
243 367
244 -Your Name - [@taintlesscupcake](https://instagram.com/taintless_cupcake) - [email](mailto:me@sungjin.dev) 368 +SungJin - [@taintlesscupcake](https://instagram.com/taintless_cupcake) - [email](mailto:me@sungjin.dev)
245 369
246 Project Link: [http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend](http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend) 370 Project Link: [http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend](http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend)
247 371
248 <p align="right">(<a href="#top">back to top</a>)</p> 372 <p align="right">(<a href="#top">back to top</a>)</p>
249 373
250 -
251 -
252 -<!-- ACKNOWLEDGMENTS -->
253 -## Acknowledgments
254 -
255 -* []()
256 -* []()
257 -* []()
258 -
259 <p align="right">(<a href="#top">back to top</a>)</p> 374 <p align="right">(<a href="#top">back to top</a>)</p>
260 375
261 376
262 - 377 +[product-screenshot]: screenshot.png
263 -<!-- MARKDOWN LINKS & IMAGES -->
264 -<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
265 -[contributors-shield]: https://img.shields.io/github/contributors/github_username/repo_name.svg?style=for-the-badge
266 -[contributors-url]: https://github.com/github_username/repo_name/graphs/contributors
267 -[forks-shield]: https://img.shields.io/github/forks/github_username/repo_name.svg?style=for-the-badge
268 -[forks-url]: https://github.com/github_username/repo_name/network/members
269 -[stars-shield]: https://img.shields.io/github/stars/github_username/repo_name.svg?style=for-the-badge
270 -[stars-url]: https://github.com/github_username/repo_name/stargazers
271 -[issues-shield]: https://img.shields.io/github/issues/github_username/repo_name.svg?style=for-the-badge
272 -[issues-url]: https://github.com/github_username/repo_name/issues
273 -[license-shield]: https://img.shields.io/github/license/github_username/repo_name.svg?style=for-the-badge
274 -[license-url]: https://github.com/github_username/repo_name/blob/master/LICENSE.txt
275 -[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
276 -[linkedin-url]: https://linkedin.com/in/linkedin_username
277 -[product-screenshot]: images/screenshot.png
......
1 +<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M2 5a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5zm3.293 1.293a1 1 0 0 1 1.414 0l3 3a1 1 0 0 1 0 1.414l-3 3a1 1 0 0 1-1.414-1.414L7.586 10 5.293 7.707a1 1 0 0 1 0-1.414zM11 12a1 1 0 1 0 0 2h3a1 1 0 1 0 0-2h-3z" clip-rule="evenodd"/></svg>
...\ No newline at end of file ...\ No newline at end of file
1 -import { Test, TestingModule } from '@nestjs/testing';
2 -import { AppController } from './app.controller';
3 -import { AppService } from './app.service';
4 -
5 -describe('AppController', () => {
6 - let appController: AppController;
7 -
8 - beforeEach(async () => {
9 - const app: TestingModule = await Test.createTestingModule({
10 - controllers: [AppController],
11 - providers: [AppService],
12 - }).compile();
13 -
14 - appController = app.get<AppController>(AppController);
15 - });
16 -
17 - describe('root', () => {
18 - it('should return "Hello World!"', () => {
19 - expect(appController.getHello()).toBe('Hello World!');
20 - });
21 - });
22 -});
1 -import { Test, TestingModule } from '@nestjs/testing';
2 -import { AuthController } from './auth.controller';
3 -
4 -describe('AuthController', () => {
5 - let controller: AuthController;
6 -
7 - beforeEach(async () => {
8 - const module: TestingModule = await Test.createTestingModule({
9 - controllers: [AuthController],
10 - }).compile();
11 -
12 - controller = module.get<AuthController>(AuthController);
13 - });
14 -
15 - it('should be defined', () => {
16 - expect(controller).toBeDefined();
17 - });
18 -});
...@@ -3,25 +3,25 @@ import { AuthService } from './auth.service'; ...@@ -3,25 +3,25 @@ import { AuthService } from './auth.service';
3 3
4 @Controller('auth') 4 @Controller('auth')
5 export class AuthController { 5 export class AuthController {
6 - constructor(private readonly AuthService: AuthService) {} 6 + constructor(private readonly authService: AuthService) {}
7 7
8 @Post('signup') 8 @Post('signup')
9 signUp(@Body() body) { 9 signUp(@Body() body) {
10 - return this.AuthService.createUser(body.name, body.email, body.password); 10 + return this.authService.createUser(body.name, body.email, body.password);
11 } 11 }
12 12
13 @Post('signin') 13 @Post('signin')
14 signIn(@Body() body) { 14 signIn(@Body() body) {
15 - return this.AuthService.login(body.email, body.password); 15 + return this.authService.login(body.email, body.password);
16 } 16 }
17 17
18 @Post('refresh') 18 @Post('refresh')
19 refresh(@Body() body) { 19 refresh(@Body() body) {
20 - return this.AuthService.refreshTokens(body.token); 20 + return this.authService.refreshTokens(body.token);
21 } 21 }
22 22
23 @Post('validate') 23 @Post('validate')
24 validate(@Body() body) { 24 validate(@Body() body) {
25 - return this.AuthService.getUserFromToken(body.token); 25 + return this.authService.getUserFromToken(body.token);
26 } 26 }
27 } 27 }
......
1 -import { Test, TestingModule } from '@nestjs/testing';
2 -import { AuthService } from './auth.service';
3 -
4 -describe('AuthService', () => {
5 - let service: AuthService;
6 -
7 - beforeEach(async () => {
8 - const module: TestingModule = await Test.createTestingModule({
9 - providers: [AuthService],
10 - }).compile();
11 -
12 - service = module.get<AuthService>(AuthService);
13 - });
14 -
15 - it('should be defined', () => {
16 - expect(service).toBeDefined();
17 - });
18 -});
1 -import { Test, TestingModule } from '@nestjs/testing';
2 -import { PostController } from './post.controller';
3 -
4 -describe('PostController', () => {
5 - let controller: PostController;
6 -
7 - beforeEach(async () => {
8 - const module: TestingModule = await Test.createTestingModule({
9 - controllers: [PostController],
10 - }).compile();
11 -
12 - controller = module.get<PostController>(PostController);
13 - });
14 -
15 - it('should be defined', () => {
16 - expect(controller).toBeDefined();
17 - });
18 -});
1 -import { Test, TestingModule } from '@nestjs/testing';
2 -import { PostService } from './post.service';
3 -
4 -describe('PostService', () => {
5 - let service: PostService;
6 -
7 - beforeEach(async () => {
8 - const module: TestingModule = await Test.createTestingModule({
9 - providers: [PostService],
10 - }).compile();
11 -
12 - service = module.get<PostService>(PostService);
13 - });
14 -
15 - it('should be defined', () => {
16 - expect(service).toBeDefined();
17 - });
18 -});
...@@ -70,7 +70,7 @@ export class PostService { ...@@ -70,7 +70,7 @@ export class PostService {
70 } 70 }
71 71
72 async getPostsByUser(token: string, userId: string, take: number) { 72 async getPostsByUser(token: string, userId: string, take: number) {
73 - const user = await this.auth.getUserFromToken(token); 73 + await this.auth.getUserFromToken(token);
74 const posts = await this.prisma.post.findMany({ 74 const posts = await this.prisma.post.findMany({
75 where: { 75 where: {
76 authorId: userId, 76 authorId: userId,
...@@ -142,7 +142,7 @@ export class PostService { ...@@ -142,7 +142,7 @@ export class PostService {
142 testoutput: string[], 142 testoutput: string[],
143 difficulty: number, 143 difficulty: number,
144 ) { 144 ) {
145 - const user = await this.auth.getUserFromToken(token); 145 + await this.auth.getUserFromToken(token);
146 let level: Level; 146 let level: Level;
147 if (difficulty == 1) { 147 if (difficulty == 1) {
148 level = 'LOW'; 148 level = 'LOW';
...@@ -169,7 +169,7 @@ export class PostService { ...@@ -169,7 +169,7 @@ export class PostService {
169 } 169 }
170 170
171 async deletePost(token: string, id: number) { 171 async deletePost(token: string, id: number) {
172 - const user = await this.auth.getUserFromToken(token); 172 + await this.auth.getUserFromToken(token);
173 const post = await this.prisma.post.delete({ 173 const post = await this.prisma.post.delete({
174 where: { 174 where: {
175 id: id, 175 id: id,
...@@ -190,7 +190,7 @@ export class PostService { ...@@ -190,7 +190,7 @@ export class PostService {
190 }) 190 })
191 ) 191 )
192 return this.getPost(id); 192 return this.getPost(id);
193 - const post = await this.prisma.postLike.create({ 193 + await this.prisma.postLike.create({
194 data: { 194 data: {
195 post: { 195 post: {
196 connect: { 196 connect: {
...@@ -229,7 +229,7 @@ export class PostService { ...@@ -229,7 +229,7 @@ export class PostService {
229 } 229 }
230 230
231 async deleteComment(token: string, id: string) { 231 async deleteComment(token: string, id: string) {
232 - const user = await this.auth.getUserFromToken(token); 232 + await this.auth.getUserFromToken(token);
233 const comment = await this.prisma.comment.delete({ 233 const comment = await this.prisma.comment.delete({
234 where: { 234 where: {
235 id: id, 235 id: id,
......
1 -import { 1 +import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
2 - INestApplication,
3 - Injectable,
4 - OnModuleInit,
5 - OnModuleDestroy,
6 -} from '@nestjs/common';
7 import { PrismaClient } from '@prisma/client'; 2 import { PrismaClient } from '@prisma/client';
8 3
9 @Injectable() 4 @Injectable()
......
1 -import { Test, TestingModule } from '@nestjs/testing';
2 -import { RunnerController } from './runner.controller';
3 -
4 -describe('RunnerController', () => {
5 - let controller: RunnerController;
6 -
7 - beforeEach(async () => {
8 - const module: TestingModule = await Test.createTestingModule({
9 - controllers: [RunnerController],
10 - }).compile();
11 -
12 - controller = module.get<RunnerController>(RunnerController);
13 - });
14 -
15 - it('should be defined', () => {
16 - expect(controller).toBeDefined();
17 - });
18 -});
1 -import { Test, TestingModule } from '@nestjs/testing';
2 -import { RunnerService } from './runner.service';
3 -
4 -describe('RunnerService', () => {
5 - let service: RunnerService;
6 -
7 - beforeEach(async () => {
8 - const module: TestingModule = await Test.createTestingModule({
9 - providers: [RunnerService],
10 - }).compile();
11 -
12 - service = module.get<RunnerService>(RunnerService);
13 - });
14 -
15 - it('should be defined', () => {
16 - expect(service).toBeDefined();
17 - });
18 -});
1 -import { Body, Injectable } from '@nestjs/common'; 1 +import { Injectable } from '@nestjs/common';
2 import * as child_process from 'child_process'; 2 import * as child_process from 'child_process';
3 import { AuthService } from 'src/auth/auth.service'; 3 import { AuthService } from 'src/auth/auth.service';
4 import * as fs from 'fs'; 4 import * as fs from 'fs';
...@@ -54,7 +54,7 @@ export class RunnerService { ...@@ -54,7 +54,7 @@ export class RunnerService {
54 c(body: any, location: string) { 54 c(body: any, location: string) {
55 const output: Array<string> = []; 55 const output: Array<string> = [];
56 if (body.input == '' || body.input == undefined) { 56 if (body.input == '' || body.input == undefined) {
57 - const test = child_process.spawnSync('gcc', [location, '-o', 'tmp'], { 57 + child_process.spawnSync('gcc', [location, '-o', 'tmp'], {
58 encoding: 'utf8', 58 encoding: 'utf8',
59 shell: true, 59 shell: true,
60 }); 60 });
......
1 -import { Test, TestingModule } from '@nestjs/testing';
2 -import { INestApplication } from '@nestjs/common';
3 -import * as request from 'supertest';
4 -import { AppModule } from './../src/app.module';
5 -
6 -describe('AppController (e2e)', () => {
7 - let app: INestApplication;
8 -
9 - beforeEach(async () => {
10 - const moduleFixture: TestingModule = await Test.createTestingModule({
11 - imports: [AppModule],
12 - }).compile();
13 -
14 - app = moduleFixture.createNestApplication();
15 - await app.init();
16 - });
17 -
18 - it('/ (GET)', () => {
19 - return request(app.getHttpServer())
20 - .get('/')
21 - .expect(200)
22 - .expect('Hello World!');
23 - });
24 -});
1 -{
2 - "moduleFileExtensions": ["js", "json", "ts"],
3 - "rootDir": ".",
4 - "testEnvironment": "node",
5 - "testRegex": ".e2e-spec.ts$",
6 - "transform": {
7 - "^.+\\.(t|j)s$": "ts-jest"
8 - }
9 -}