Git Product home page Git Product logo

full-stack-assignment's Introduction

Documentation

This code is a simple backend application that provides endpoints for signing up, logging in, fetching and submitting questions, and submitting code for evaluation. The application uses the Express.js framework and handles data in memory.

Endpoints

POST /signup

This endpoint is used to register new users. The endpoint requires the following fields in the request body: email and password. The optional field isAdmin can also be set to true for admin users. Upon successful registration, a 200 status code and a message indicating success is returned. If the request is invalid or a user with the given email already exists, an error is returned.

POST /login

This endpoint is used to log in existing users. The endpoint requires the following fields in the request body: email and password. Upon successful login, a 200 status code, a message indicating success, and a login token is returned. If the request is invalid or the user credentials are incorrect, an error is returned.

GET /questions

This endpoint is used to retrieve the list of questions. The endpoint requires a valid login token in the request body to access. Upon successful retrieval, a 200 status code and the list of questions is returned. If the request is invalid or the user is not logged in, an error is returned.

GET /submissions

This endpoint is used to retrieve the list of code submissions. The endpoint requires a valid login token in the request body to access. Upon successful retrieval, a 200 status code and the list of code submissions is returned. If the request is invalid or the user is not logged in, an error is returned.

POST /submissions

This endpoint is used to submit code for evaluation. The endpoint requires the following field in the request body: code. Upon successful submission, a 200 status code and a message indicating success or failure is returned. Submissions are randomly accepted or rejected for demonstration purposes.

POST /questions

This endpoint is used to submit new questions. The endpoint requires the following fields in the request body: token and question. The token field is a valid login token of an admin user, and the question field is an object that contains the fields title, description, and testCases. Upon successful submission, a 200 status code and a message indicating success is returned. If the request is invalid, the user is not logged in, or the user is not an admin, an error is returned.

Middleware

The application uses two middleware functions, express.json() and express.urlencoded(), to parse incoming requests that have a JSON or URL-encoded body. This middleware is applied to all endpoints.

Data

The application stores three arrays in memory: USERS, SUBMISSIONS, and QUESTIONS. The USERS array contains registered users, the SUBMISSIONS array contains submitted code, and the QUESTIONS array contains submitted questions. The application also stores a map of TOKENS to keep track of login tokens and the associated email of the user.

full-stack-assignment's People

Contributors

abhaykumarvats avatar hkirat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.