sungjin

Fix cpp, add level when making post.

1 -<p align="center"> 1 +<div id="top"></div>
2 - <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a> 2 +<!--
3 -</p> 3 +*** Thanks for checking out the Best-README-Template. If you have a suggestion
4 +*** that would make this better, please fork the repo and create a pull request
5 +*** or simply open an issue with the tag "enhancement".
6 +*** Don't forget to give the project a star!
7 +*** Thanks again! Now go create something AMAZING! :D
8 +-->
4 9
5 -[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6 -[circleci-url]: https://circleci.com/gh/nestjs/nest
7 10
8 - <p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p> 11 +
12 +<!-- PROJECT SHIELDS -->
13 +<!--
14 +*** I'm using markdown "reference style" links for readability.
15 +*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
16 +*** See the bottom of this document for the declaration of the reference variables
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
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 +
29 +<!-- PROJECT LOGO -->
30 +<br />
31 +
32 +<div align="center">
33 + <a href="https://github.com/github_username/repo_name">
34 + <img src="images/logo.png" alt="Logo" width="80" height="80">
35 + </a>
36 +<h3 align="center">Learn In Web(Backend)</h3>
37 +
9 <p align="center"> 38 <p align="center">
10 -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> 39 + NestJS Backend for
11 -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> 40 + <a href="http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend"><strong>Learn In Web</strong></a>
12 -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a> 41 + <br />
13 -<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a> 42 + <a href="https://code.sungjin.dev"><strong>View Demo »</strong></a>
14 -<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a> 43 + <br />
15 -<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a> 44 + <br />
16 -<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> 45 + <a href="http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend/issues">Report Bug</a>
17 -<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> 46 + ·
18 - <a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a> 47 + <a href="http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend/issues">Request Feature</a>
19 - <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a> 48 + </p>
20 - <a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a> 49 +
21 -</p> 50 +</div>
22 - <!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer) 51 +
23 - [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)--> 52 +
53 +
54 +<!-- TABLE OF CONTENTS -->
55 +
56 +<details>
57 + <summary>Table of Contents</summary>
58 + <ol>
59 + <li>
60 + <a href="#about-the-project">About The Project</a>
61 + <ul>
62 + <li><a href="#built-with">Built With</a></li>
63 + </ul>
64 + </li>
65 + <li>
66 + <a href="#getting-started">Getting Started</a>
67 + <ul>
68 + <li><a href="#prerequisites">Prerequisites</a></li>
69 + <li><a href="#installation">Installation</a></li>
70 + </ul>
71 + </li>
72 + <li><a href="#usage">Usage</a></li>
73 + <li><a href="#roadmap">Roadmap</a></li>
74 + <li><a href="#contributing">Contributing</a></li>
75 + <li><a href="#license">License</a></li>
76 + <li><a href="#contact">Contact</a></li>
77 + <li><a href="#acknowledgments">Acknowledgments</a></li>
78 + </ol>
79 +</details>
80 +
81 +
82 +
83 +<!-- ABOUT THE PROJECT -->
84 +## About The Project
85 +
86 +[![Product Name Screen Shot][product-screenshot]](https://example.com)
87 +
88 +This project allows users to run codes and study without any IDE. This project focusd on schools, and students for study.
89 +
90 +Why we need this project? :
91 +
92 +In Korea, learning programming is essential in school. So students wants to learn programming in school; however it is difficult for students to study programming without computer.
93 +
94 +So run this project in school server, and allow students to access this page. So they can study, and run code only with phone, or tablet.
95 +
96 +<p align="right">(<a href="#top">back to top</a>)</p>
97 +
98 +
99 +
100 +### Built With
101 +
102 +* [Nest.js](https://nestjs.com/)
103 +
104 +<p align="right">(<a href="#top">back to top</a>)</p>
105 +
106 +
107 +
108 +<!-- GETTING STARTED -->
109 +## Getting Started
110 +
111 +This is an example of how you may give instructions on setting up your project locally.
112 +To get a local copy up and running follow these simple example steps.
113 +
114 +### Prerequisites
115 +
116 +This is an example of how to list things you need to use the software and how to install them.
117 +* npm
118 +
119 + ```sh
120 + npm install npm@latest ts-node -g
121 + ```
122 +
123 +* Compiler for languages
124 +
125 + ```sh
126 + #For typescript
127 + npm install -g ts-node
128 + #Ubuntu, Debian Based
129 + sudo apt update && sudo apt install golang build-essential
130 + #RedHat Based
131 + sudo yum update && sudo yum install golang build-essential
132 + #Other
133 + #install golang, cpp, c++ manually.
134 + ```
135 +
136 +* Docker, postgreSQL Database
137 +
138 + (You can manually change port, name, etc if you want.)
24 139
25 -## Description 140 + ```sh
141 + #Install docker for your OS. ex) sudo apt install docker
142 + 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
144 + ```
26 145
27 -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
28 146
29 -## Installation
30 147
31 -```bash 148 +* Installation
32 -$ npm install
33 -```
34 149
35 -## Running the app 150 +1. Clone the repo
151 + ```sh
152 + git clone http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend
153 + ```
36 154
37 -```bash 155 +2. Install NPM packages
38 -# development 156 + ```sh
39 -$ npm run start 157 + npm install
158 + ```
40 159
41 -# watch mode 160 +3. Enter your DB URL in `.env`
42 -$ npm run start:dev 161 + ```js
162 + DATABASE_URL="postgresql://_User:_Password@localhost:5432/postgres""
163 + ```
43 164
44 -# production mode 165 +4. Migrate DB
45 -$ npm run start:prod
46 -```
47 166
48 -## Test 167 + ```sh
168 + npx prisma migrate dev
169 + ```
49 170
50 -```bash 171 +5. Start Server.
51 -# unit tests
52 -$ npm run test
53 172
54 -# e2e tests 173 + ```sh
55 -$ npm run test:e2e 174 + nest start
175 + ```
56 176
57 -# test coverage
58 -$ npm run test:cov
59 -```
60 177
61 -## Support
62 178
63 -Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). 179 +<p align="right">(<a href="#top">back to top</a>)</p>
64 180
65 -## Stay in touch
66 181
67 -- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
68 -- Website - [https://nestjs.com](https://nestjs.com/)
69 -- Twitter - [@nestframework](https://twitter.com/nestframework)
70 182
183 +<!-- USAGE EXAMPLES -->
184 +
185 +## Usage
186 +
187 +To Use Learn In Web, you need to use this backend; this project communicate via RESTful API.
188 +
189 +_For More Useage, please see frontend [Demo](http://khuhub.khu.ac.kr/2021105619/learn_in_web)_
190 +
191 +<p align="right">(<a href="#top">back to top</a>)</p>
192 +
193 +
194 +
195 +<!-- ROADMAP -->
196 +## Roadmap
197 +
198 +- [x] Add README
199 +- [ ] Add How to Use for new user
200 +- [ ] Add Saving with DB
201 +- [ ] Multi-language Support
202 + - [ ] English
203 + - [ ] Japanese
204 +
205 +- [ ] View code run time
206 +- [ ] Add competition between users with runtime.
207 +
208 +See the [open issues](http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend/issues) for a full list of proposed features (and known issues).
209 +
210 +<p align="right">(<a href="#top">back to top</a>)</p>
211 +
212 +
213 +
214 +<!-- CONTRIBUTING -->
215 +## Contributing
216 +
217 +Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
218 +
219 +If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
220 +Don't forget to give the project a star! Thanks again!
221 +
222 +1. Fork the Project
223 +2. Create your Feature Branch (`git checkout -b feature/newFeature`)
224 +3. Commit your Changes (`git commit -m 'Add some newFeature'`)
225 +4. Push to the Branch (`git push origin feature/newFeature`)
226 +5. Open a Pull Request
227 +
228 +<p align="right">(<a href="#top">back to top</a>)</p>
229 +
230 +
231 +
232 +<!-- LICENSE -->
71 ## License 233 ## License
72 234
73 -Nest is [MIT licensed](LICENSE). 235 +Distributed under the MIT License. See `LICENSE.txt` for more information.
236 +
237 +<p align="right">(<a href="#top">back to top</a>)</p>
238 +
239 +
240 +
241 +<!-- CONTACT -->
242 +## Contact
243 +
244 +Your Name - [@taintlesscupcake](https://instagram.com/taintless_cupcake) - [email](mailto:me@sungjin.dev)
245 +
246 +Project Link: [http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend](http://khuhub.khu.ac.kr/2021105619/learn-in-web-backend)
247 +
248 +<p align="right">(<a href="#top">back to top</a>)</p>
249 +
250 +
251 +
252 +<!-- ACKNOWLEDGMENTS -->
253 +## Acknowledgments
254 +
255 +* []()
256 +* []()
257 +* []()
258 +
259 +<p align="right">(<a href="#top">back to top</a>)</p>
260 +
261 +
262 +
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
......
...@@ -18,12 +18,21 @@ export class PostService { ...@@ -18,12 +18,21 @@ export class PostService {
18 example: string, 18 example: string,
19 testinput: string[], 19 testinput: string[],
20 testoutput: string[], 20 testoutput: string[],
21 + difficulty: number,
21 ) { 22 ) {
22 const user = await this.auth.validateUser( 23 const user = await this.auth.validateUser(
23 ( 24 (
24 await this.auth.getUserFromToken(token) 25 await this.auth.getUserFromToken(token)
25 ).id, 26 ).id,
26 ); 27 );
28 + let level: Level;
29 + if (difficulty == 1) {
30 + level = 'LOW';
31 + } else if (difficulty == 2) {
32 + level = 'MEDIUM';
33 + } else {
34 + level = 'HIGH';
35 + }
27 const post = await this.prisma.post.create({ 36 const post = await this.prisma.post.create({
28 data: { 37 data: {
29 author: { 38 author: {
...@@ -37,6 +46,7 @@ export class PostService { ...@@ -37,6 +46,7 @@ export class PostService {
37 example: example, 46 example: example,
38 testinput: testinput, 47 testinput: testinput,
39 testoutput: testoutput, 48 testoutput: testoutput,
49 + level: level,
40 }, 50 },
41 }); 51 });
42 return post; 52 return post;
......
...@@ -85,7 +85,7 @@ export class RunnerService { ...@@ -85,7 +85,7 @@ export class RunnerService {
85 cpp(body: any, location: string) { 85 cpp(body: any, location: string) {
86 const output: Array<string> = []; 86 const output: Array<string> = [];
87 if (body.input == []) { 87 if (body.input == []) {
88 - const test = child_process.spawnSync('gcc', [location, '-o', 'tmp'], { 88 + const test = child_process.spawnSync('g++', [location, '-o', 'tmp'], {
89 encoding: 'utf8', 89 encoding: 'utf8',
90 shell: true, 90 shell: true,
91 }); 91 });
...@@ -101,7 +101,7 @@ export class RunnerService { ...@@ -101,7 +101,7 @@ export class RunnerService {
101 output.push(result.stdout as string); 101 output.push(result.stdout as string);
102 } 102 }
103 for (const ip of body.input) { 103 for (const ip of body.input) {
104 - const test = child_process.spawnSync('gcc', [location, '-o', 'tmp'], { 104 + const test = child_process.spawnSync('g++', [location, '-o', 'tmp'], {
105 encoding: 'utf8', 105 encoding: 'utf8',
106 shell: true, 106 shell: true,
107 }); 107 });
...@@ -176,7 +176,7 @@ export class RunnerService { ...@@ -176,7 +176,7 @@ export class RunnerService {
176 output.push(result.stdout as string); 176 output.push(result.stdout as string);
177 } 177 }
178 for (const ip of body.input) { 178 for (const ip of body.input) {
179 - const result = child_process.spawnSync('go', ['run', location], { 179 + const result = child_process.spawnSync('ts-node', ['run', location], {
180 encoding: 'utf8', 180 encoding: 'utf8',
181 shell: true, 181 shell: true,
182 input: ip, 182 input: ip,
......