sungjin

Release 1.0 version

......@@ -4,4 +4,4 @@
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server and MongoDB (Preview).
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="postgresql://postgres:12345@localhost:5432/postgres"
\ No newline at end of file
DATABASE_URL="YOUR_DATABASE_URL"
\ No newline at end of file
......
......@@ -17,24 +17,17 @@
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
-->
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]
[![LinkedIn][linkedin-shield]][linkedin-url]
<!-- PROJECT LOGO -->
<br />
<div align="center">
<a href="https://github.com/github_username/repo_name">
<img src="images/logo.png" alt="Logo" width="80" height="80">
<a href="http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend">
<img src="logo.svg" alt="Logo" width="80" height="80">
</a>
<h3 align="center">Learn In Web(Backend)</h3>
<p align="center">
NestJS Backend for
<a href="http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend"><strong>Learn In Web</strong></a>
......@@ -74,7 +67,6 @@
<li><a href="#contributing">Contributing</a></li>
<li><a href="#license">License</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#acknowledgments">Acknowledgments</a></li>
</ol>
</details>
......@@ -83,7 +75,7 @@
<!-- ABOUT THE PROJECT -->
## About The Project
[![Product Name Screen Shot][product-screenshot]](https://example.com)
[![Product Name Screen Shot][product-screenshot]](https://code.sungjin.dev)
This project allows users to run codes and study without any IDE. This project focusd on schools, and students for study.
......@@ -121,7 +113,7 @@ This is an example of how to list things you need to use the software and how to
```
* Compiler for languages
```sh
#For typescript
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
sudo yum update && sudo yum install golang build-essential
#Other
#install golang, cpp, c++ manually.
```
```
* Docker, postgreSQL Database
(You can manually change port, name, etc if you want.)
```sh
......@@ -142,9 +134,9 @@ This is an example of how to list things you need to use the software and how to
docker pull postgres
docker run -d -p 5432:5432 --name postgres-container -e POSTGRES_PASSWORD=Your_Password -v ~/pgdata:/Location_to_save_data/ postgres
```
* Installation
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
3. Enter your DB URL in `.env`
```js
DATABASE_URL="postgresql://_User:_Password@localhost:5432/postgres""
DATABASE_URL="postgresql://_User:_Password@localhost:5432/postgres"
```
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
To Use Learn In Web, you need to use this backend; this project communicate via RESTful API.
_For More Useage, please see frontend [Demo](http://khuhub.khu.ac.kr/2021105619/learn_in_web)_
-API-
```json
POST /auth/signup
{
"name" : "name",
"email" : "email",
"password" : "password"
}
```
```json
POST /auth/signin
{
"email" : "email",
"password" : "password"
}
```
```json
POST /auth/refresh
{
"token" : "token_madeby_signup_or_signin"
}
```
```json
POST /auth/validate
{
"token" : "token_madeby_signup_or_signin"
}
```
```json
POST /post
{
"token" : "token",
"title" : "title",
"privat" : true,
"explain" : "explain of problem",
"testinput" : ["1", "2"],
"testoutput" : ["3", "4"],
"difficulty" : 1
}
```
```json
PUT /post
{
"token" : "token",
"title" : "title",
"privat" : true,
"explain" : "explain of problem",
"testinput" : ["1", "2"],
"testoutput" : ["3", "4"],
"difficulty" : 1
}
```
```json
GET /post
```
```json
GET /post/some
{
"take" : 20
}
```
```
GET /post/id/:id
use integer param for :id
```
```
GET /post/difficulty/:level
use integer param for :level
```
```json
POST /post/like/:id
use integer param for :id
{
"token" : "token"
}
```
```json
DELETE /post
```
```json
POST /comment/:id
use integer param for :id
{
"token" : "token",
"content" : "content of comment"
}
```
```json
DELETE /comment/:id
use integer param for :id
{
"token" : "token"
}
```
```json
GET /comment/:id
use integer param for :id
```
```json
POST /search
{
"search" : "search item divided by black"
}
```
```json
POST /runner
{
"token" : "token",
"input" : ["input", "data", "array", "does not working now"],
"type" : "cpp",
"code" : "//example code\n#include <iostream> ~~~~"
}
```
_For Real Useage, please see frontend [Frontend_URL](http://khuhub.khu.ac.kr/2021105619/learn_in_web)_
<p align="right">(<a href="#top">back to top</a>)</p>
......@@ -232,7 +356,7 @@ Don't forget to give the project a star! Thanks again!
<!-- LICENSE -->
## License
Distributed under the MIT License. See `LICENSE.txt` for more information.
Distributed under the MIT License.
<p align="right">(<a href="#top">back to top</a>)</p>
......@@ -241,37 +365,13 @@ Distributed under the MIT License. See `LICENSE.txt` for more information.
<!-- CONTACT -->
## Contact
Your Name - [@taintlesscupcake](https://instagram.com/taintless_cupcake) - [email](mailto:me@sungjin.dev)
SungJin - [@taintlesscupcake](https://instagram.com/taintless_cupcake) - [email](mailto:me@sungjin.dev)
Project Link: [http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend](http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend)
<p align="right">(<a href="#top">back to top</a>)</p>
<!-- ACKNOWLEDGMENTS -->
## Acknowledgments
* []()
* []()
* []()
<p align="right">(<a href="#top">back to top</a>)</p>
<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
[contributors-shield]: https://img.shields.io/github/contributors/github_username/repo_name.svg?style=for-the-badge
[contributors-url]: https://github.com/github_username/repo_name/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/github_username/repo_name.svg?style=for-the-badge
[forks-url]: https://github.com/github_username/repo_name/network/members
[stars-shield]: https://img.shields.io/github/stars/github_username/repo_name.svg?style=for-the-badge
[stars-url]: https://github.com/github_username/repo_name/stargazers
[issues-shield]: https://img.shields.io/github/issues/github_username/repo_name.svg?style=for-the-badge
[issues-url]: https://github.com/github_username/repo_name/issues
[license-shield]: https://img.shields.io/github/license/github_username/repo_name.svg?style=for-the-badge
[license-url]: https://github.com/github_username/repo_name/blob/master/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/linkedin_username
[product-screenshot]: images/screenshot.png
[product-screenshot]: screenshot.png
......
<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
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);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
describe('AuthController', () => {
let controller: AuthController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
}).compile();
controller = module.get<AuthController>(AuthController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
......@@ -3,25 +3,25 @@ import { AuthService } from './auth.service';
@Controller('auth')
export class AuthController {
constructor(private readonly AuthService: AuthService) {}
constructor(private readonly authService: AuthService) {}
@Post('signup')
signUp(@Body() body) {
return this.AuthService.createUser(body.name, body.email, body.password);
return this.authService.createUser(body.name, body.email, body.password);
}
@Post('signin')
signIn(@Body() body) {
return this.AuthService.login(body.email, body.password);
return this.authService.login(body.email, body.password);
}
@Post('refresh')
refresh(@Body() body) {
return this.AuthService.refreshTokens(body.token);
return this.authService.refreshTokens(body.token);
}
@Post('validate')
validate(@Body() body) {
return this.AuthService.getUserFromToken(body.token);
return this.authService.getUserFromToken(body.token);
}
}
......
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';
describe('AuthService', () => {
let service: AuthService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService],
}).compile();
service = module.get<AuthService>(AuthService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Test, TestingModule } from '@nestjs/testing';
import { PostController } from './post.controller';
describe('PostController', () => {
let controller: PostController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [PostController],
}).compile();
controller = module.get<PostController>(PostController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
import { Test, TestingModule } from '@nestjs/testing';
import { PostService } from './post.service';
describe('PostService', () => {
let service: PostService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [PostService],
}).compile();
service = module.get<PostService>(PostService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
......@@ -70,7 +70,7 @@ export class PostService {
}
async getPostsByUser(token: string, userId: string, take: number) {
const user = await this.auth.getUserFromToken(token);
await this.auth.getUserFromToken(token);
const posts = await this.prisma.post.findMany({
where: {
authorId: userId,
......@@ -142,7 +142,7 @@ export class PostService {
testoutput: string[],
difficulty: number,
) {
const user = await this.auth.getUserFromToken(token);
await this.auth.getUserFromToken(token);
let level: Level;
if (difficulty == 1) {
level = 'LOW';
......@@ -169,7 +169,7 @@ export class PostService {
}
async deletePost(token: string, id: number) {
const user = await this.auth.getUserFromToken(token);
await this.auth.getUserFromToken(token);
const post = await this.prisma.post.delete({
where: {
id: id,
......@@ -190,7 +190,7 @@ export class PostService {
})
)
return this.getPost(id);
const post = await this.prisma.postLike.create({
await this.prisma.postLike.create({
data: {
post: {
connect: {
......@@ -229,7 +229,7 @@ export class PostService {
}
async deleteComment(token: string, id: string) {
const user = await this.auth.getUserFromToken(token);
await this.auth.getUserFromToken(token);
const comment = await this.prisma.comment.delete({
where: {
id: id,
......
import {
INestApplication,
Injectable,
OnModuleInit,
OnModuleDestroy,
} from '@nestjs/common';
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
......
import { Test, TestingModule } from '@nestjs/testing';
import { RunnerController } from './runner.controller';
describe('RunnerController', () => {
let controller: RunnerController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [RunnerController],
}).compile();
controller = module.get<RunnerController>(RunnerController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
import { Test, TestingModule } from '@nestjs/testing';
import { RunnerService } from './runner.service';
describe('RunnerService', () => {
let service: RunnerService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [RunnerService],
}).compile();
service = module.get<RunnerService>(RunnerService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Body, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import * as child_process from 'child_process';
import { AuthService } from 'src/auth/auth.service';
import * as fs from 'fs';
......@@ -54,7 +54,7 @@ export class RunnerService {
c(body: any, location: string) {
const output: Array<string> = [];
if (body.input == '' || body.input == undefined) {
const test = child_process.spawnSync('gcc', [location, '-o', 'tmp'], {
child_process.spawnSync('gcc', [location, '-o', 'tmp'], {
encoding: 'utf8',
shell: true,
});
......
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}