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

Swagger update #100

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
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
100 changes: 51 additions & 49 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
{
"name": "opportunity-calendar-backend",
"version": "1.0.0",
"description": "Opportunity Calendar is the one-stop place to refer important opportunities available in tech-space like newly posted jobs, internships, hackathons, tech-conferences, scholarships etc.",
"main": "index.js",
"type": "module",
"scripts": {
"preinstall": "npx husky-init",
"prepare": "husky install",
"start": "node index.js",
"test": "mocha './tests/*/*'",
"start:dev": "nodemon –experimental-modules index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Manvityagi/Opportunity-Calendar-Backend.git"
},
"author": "ManviTyagi",
"license": "ISC",
"bugs": {
"url": "https://github.com/Manvityagi/Opportunity-Calendar-Backend/issues"
},
"homepage": "https://github.com/Manvityagi/Opportunity-Calendar-Backend#readme",
"dependencies": {
"body-parser": "^1.19.0",
"cluster": "^0.7.7",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"method-override": "^3.0.0",
"mongoose": "^5.12.1",
"mongoose-type-url": "^2.1.0",
"morgan": "^1.10.0",
"nodemon": "^2.0.7",
"passport": "^0.4.1",
"passport-google-oauth20": "^2.0.0",
"swagger-jsdoc": "^6.0.0",
"swagger-ui-express": "^4.1.6"
},
"devDependencies": {
"chai": "^4.3.4",
"faker": "^5.5.2",
"husky": "^6.0.0",
"mocha": "^8.3.2",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"sinon": "^10.0.0"
}
}
"name": "opportunity-calendar-backend",
"version": "1.0.0",
"description": "Opportunity Calendar is the one-stop place to refer important opportunities available in tech-space like newly posted jobs, internships, hackathons, tech-conferences, scholarships etc.",
"main": "index.js",
"type": "module",
"scripts": {
"preinstall": "npx husky-init",
"prepare": "husky install",
"start": "node index.js",
"test": "mocha './tests/*/*'",
"start:dev": "nodemon –experimental-modules index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Manvityagi/Opportunity-Calendar-Backend.git"
},
"author": "ManviTyagi",
"license": "ISC",
"bugs": {
"url": "https://github.com/Manvityagi/Opportunity-Calendar-Backend/issues"
},
"homepage": "https://github.com/Manvityagi/Opportunity-Calendar-Backend#readme",
"dependencies": {
"body-parser": "^1.19.0",
"cluster": "^0.7.7",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"method-override": "^3.0.0",
"mongoose": "^5.12.1",
"mongoose-type-url": "^2.1.0",
"morgan": "^1.10.0",
"nodemon": "^2.0.7",
"passport": "^0.4.1",
"passport-google-oauth20": "^2.0.0",
"swagger-jsdoc": "^6.0.0",
"swagger-ui-express": "^4.1.6"
},
"devDependencies": {
"chai": "^4.3.4",
"faker": "^5.5.2",
"husky": "^6.0.0",
"mocha": "^8.3.2",
"prettier": "^2.2.1",

"pretty-quick": "^3.1.0",
"sinon": "^10.0.0"

}
}
50 changes: 49 additions & 1 deletion routes/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,64 @@ import {User} from '../models/user.js';
import {FRONT_END} from '../config.js';
import authController from '../controllers/auth/AuthController.js';

router.get('/login', (req, res)=>{
/**
* @swagger
* /authenticate/login:
* get:
* summary: Redirect to login with google page
* description: Redirect to login with google page for Oauth2 with Google
* responses:
* 200:
* description: Redirect to google account for authentication
* 404:
* description: Failure to authenticate with google account
*/

router.get('/login', (req, res) => {
res.redirect('/auth/google-authenticate');
});

/**
* @swagger
* /authenticate/google-authenticate:
* get:
* summary: Redirect to login with google page
* description: Redirect to login with google page for Oauth2 with Google
* security:
* OAuth2: [email,profile]
* responses:
* 200:
* description: Successfully authenticated with given scopes
* 401:
* description: User is not authenticated
* 403:
* description: Access token does not have the required scope
*/

router.get(
'/google-authenticate',
passport.authenticate('google',{scope : ['email','profile']}),
(req, res) => {
});


/**
* @swagger
* /authenticate/google-callback:
* get:
* summary: Either redirect to front-end page on successful response or login on failure
* description: Either google calllback URL will be called on success or /login on failure.
* security:
* OAuth2: [email,profile]
* responses:
* 200:
* description: Successfully redirect to front-end with access-token in url
* 401:
* description: Failure redirect to login page
* 400:
* description: Error occur redirect to front-end error page with JSON
*/

router.get(
'/google-callback',
passport.authenticate('google',{failureRedirect : '/auth/login'}),
Expand Down
45 changes: 45 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,65 @@ import {loggedIn} from '../middleware/auth.js'
* 200:
* description: Hello World
*/

/**
* @swagger
* /index:
* get:
* summary: Returns a 'hello world' response
* description: Returns a 'hello world' response
* responses:
* 200:
* description: Hello World
*/

router.get('/', (req, res) => {
return res.send('Hello World');
});

/**
* @swagger
* /index/loggedInChecker:
* get:
* summary: To check wheather user is loggedIn or not.
* description: Returns a 'hello world' response if user is loggedIn.
* responses:
* 200:
* description: Hello World
*/

router.get('/loggedInChecker', loggedIn, (req, res) => {
return res.send('Hello World');
});

/**
* @swagger
* /index/login/:token:
* get:
* summary: if the user is loggedIn will return a token.
* description: Returns a token response if the user is loggedIn.
* responses:
* 200:
* description: A loggedIn token from request parameter.
* content: req.params.token
*/

router.get('/login/:token', (req, res) => {
return res.send(req.params.token);
});

/**
* @swagger
* /index/error/:token:
* get:
* summary: Return an error token.
* description: Returns an error token response.
* responses:
* 200:
* description: An error token from request parameter.
* content: req.params.token
*/

router.get('/error/:token', (req, res) => {
return res.send(req.params.token);
});
Expand Down