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

Fixed the searchUser API #8

Merged
merged 3 commits into from
Oct 2, 2024
Merged
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
11 changes: 4 additions & 7 deletions .github/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const getUserNameFromCodeBaseFile = (fileName) => {

// function to connect to mongodb using mongoose
const connectMongoDB = () => {
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
mongoose.connect(process.env.MONGODB_URI)
const db = mongoose.connection
db.on('error', console.error.bind(console, 'Connection error:'))
return db
Expand All @@ -58,13 +55,13 @@ const insertDataInMongo = (records) => {
const callGithubCodeBaseAPI = () => {
axios
.get(
`https://api.github.com/repos/TECHOUS/${process.env.CODE_SRC}/contents/CodeBase`
`https://api.github.com/repos/TECHOUS/${process.env.CODE_SRC}/contents/CodeBase`,
)
.then((res) => {
// get all the names from the files
const filePromises = res.data.map((codeObject) => {
return getUserNameFromCodeBaseFile(
`${process.env.CODE_SRC}/${codeObject.path}`
`${process.env.CODE_SRC}/${codeObject.path}`,
)
})

Expand All @@ -77,7 +74,7 @@ const callGithubCodeBaseAPI = () => {
fileObject.value.fileName,
fileObject.value.username,
]
})
}),
)

const dataToInsert = res.data.map((data) => {
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/Vercel Deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
- run: yarn install
- run: yarn run test
env:
Expand All @@ -25,8 +25,8 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: amondnet/vercel-action@v20
- uses: actions/checkout@v4
- uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
vercel-args: '--prod' #Optional
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/Vercel Dev Deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
- run: yarn install
- run: yarn run test
env:
Expand All @@ -25,8 +25,8 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: amondnet/vercel-action@v20
- uses: actions/checkout@v4
- uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
vercel-org-id: ${{ secrets.ORG_ID}} #Required
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codebase-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
init-setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
- run: yarn install
- run: bash .github/job.sh
env:
Expand Down
111 changes: 82 additions & 29 deletions api/public/assets/main.bundle.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions api/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<meta name="description" content="Engine to handle the rating mechanisms for the clean code">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="assets/bootstrap.min.css?v=1697340676180" rel="stylesheet" media="screen">
<link href="assets/prism.css?v=1697340676180" rel="stylesheet" />
<link href="assets/prism-toolbar.css?v=1697340676180" rel="stylesheet" />
<link href="assets/prism-diff-highlight.css?v=1697340676180" rel="stylesheet" />
<link href="assets/main.css?v=1697340676180" rel="stylesheet" media="screen, print">
<link href="assets/favicon.ico?v=1697340676180" rel="icon" type="image/x-icon">
<link href="assets/apple-touch-icon.png?v=1697340676180" rel="apple-touch-icon" sizes="180x180">
<link href="assets/favicon-32x32.png?v=1697340676180" rel="icon" type="image/png" sizes="32x32">
<link href="assets/favicon-16x16.png?v=1697340676180" rel="icon" type="image/png" sizes="16x16">
<link href="assets/bootstrap.min.css?v=1727851422673" rel="stylesheet" media="screen">
<link href="assets/prism.css?v=1727851422673" rel="stylesheet" />
<link href="assets/prism-toolbar.css?v=1727851422673" rel="stylesheet" />
<link href="assets/prism-diff-highlight.css?v=1727851422673" rel="stylesheet" />
<link href="assets/main.css?v=1727851422673" rel="stylesheet" media="screen, print">
<link href="assets/favicon.ico?v=1727851422673" rel="icon" type="image/x-icon">
<link href="assets/apple-touch-icon.png?v=1727851422673" rel="apple-touch-icon" sizes="180x180">
<link href="assets/favicon-32x32.png?v=1727851422673" rel="icon" type="image/png" sizes="32x32">
<link href="assets/favicon-16x16.png?v=1727851422673" rel="icon" type="image/png" sizes="16x16">
</head>

<body class="container-fluid">
Expand Down Expand Up @@ -1042,6 +1042,6 @@ <h2>{{__ "Request Body"}}</h2>
</div>
</div>

<script src="assets/main.bundle.js?v=1697340676180"></script>
<script src="assets/main.bundle.js?v=1727851422673"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions apidoc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Code Rating Engine",
"version": "1.0.0",
"version": "1.20.0",
"description": "Engine to handle the rating mechanisms for the clean code",
"title": "Code Rating Engine",
"url": "https://coderatingengine-techous.vercel.app"
}
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "coderatingengine",
"version": "1.0.0",
"version": "1.20.0",
"engines": {
"node": "18.x",
"node": "20.x",
"yarn": "1.x"
},
"description": "Engine to handle the rating mechanisms for the clean code",
Expand All @@ -17,22 +17,22 @@
"author": "Gaurav Walia",
"license": "ISC",
"dependencies": {
"axios": "^1.5.1",
"axios": "^1.7.7",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-rate-limit": "^7.1.1",
"mongoose": "^7.6.2",
"uuid": "^9.0.1"
"express": "^4.21.0",
"express-rate-limit": "^7.4.0",
"mongoose": "^8.7.0",
"uuid": "^10.0.0"
},
"devDependencies": {
"apidoc": "^1.2.0",
"dotenv": "^16.3.1",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"mocha": "^10.2.0",
"nodemon": "^3.0.1",
"mocha": "^10.7.3",
"nodemon": "^3.1.7",
"prettier": "^3.0.3",
"supertest": "^6.3.3"
"supertest": "^7.0.0"
},
"lint-staged": {
"*.js": "prettier --write"
Expand Down
19 changes: 12 additions & 7 deletions routes/api/v1/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ const {
setSearchUserInCache,
} = require('../../../src/cache')
// import middlewares
const {authenticateAPI} = require('../../../src/auth')
const {authenticatePutAPI, authenticateGetAPI} = require('../../../src/auth')
const {updateValidator, searchValidator} = require('../../../src/validator')

/**
* @api {GET} /api/v1/randomCodes GET: get the random Code files
* @apiName randomCodes
* @apiDescription api to get the Random Code files present in code base
* @apiVersion 1.0.0
* @apiVersion 1.20.0
*
* @apiGroup randomCodes
* @apiSuccess (200 Success Response) {Number} status 200 (Status Code)
Expand Down Expand Up @@ -155,7 +155,7 @@ router.get('/randomCodes', async (req, res, next) => {
* @api {PUT} /api/v1/rateCode PUT: rate the code file
* @apiName rateCode
* @apiDescription api to rate the Random Code files present in code base
* @apiVersion 1.0.0
* @apiVersion 1.20.0
* @apiBody {Number} winner Marked winner 1 or 2
* @apiBody {String} codeId1 code Id for code 1
* @apiBody {String} codeId2 code Id for code 2
Expand Down Expand Up @@ -208,7 +208,7 @@ router.get('/randomCodes', async (req, res, next) => {
**/
router.put(
'/rateCode',
authenticateAPI,
authenticatePutAPI,
updateValidator,
async (req, res, next) => {
try {
Expand Down Expand Up @@ -249,8 +249,13 @@ router.put(
* @api {GET} /api/v1/searchUser GET: searching the user name
* @apiName searchUser
* @apiDescription search and return the code rating for the specific user
* @apiVersion 1.0.0
* @apiBody {String} codeRatingEngineToken Access token received from randomCodes request
* @apiVersion 1.20.0
* @apiHeader {String} Authorization Access token received from randomCodes request
* @apiHeaderExample {json} Request Header example
* {
* "Authorization": "Bearer <ACCESS_TOKEN>"
* }
*
* @apiQuery {String} username Username to search
* @apiQuery {Boolean} sendContent Whether content is needed from the API or not
*
Expand Down Expand Up @@ -300,7 +305,7 @@ router.put(
**/
router.get(
'/searchUser',
authenticateAPI,
authenticateGetAPI,
searchValidator,
async (req, res, next) => {
try {
Expand Down
138 changes: 138 additions & 0 deletions routes/api/v1/_apidoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* @api {GET} /api/v1/randomCodes GET: get the random Code files
* @apiName randomCodes
* @apiDescription api to get the Random Code files present in code base
* @apiVersion 1.0.0
*
* @apiGroup randomCodes
* @apiSuccess (200 Success Response) {Number} status 200 (Status Code)
* @apiSuccess (200 Success Response) {Object} codeObject1 First CodeObject
* @apiSuccess (200 Success Response) {Object} codeObject2 Second CodeObject
* @apiSuccess (200 Success Response) {String} accessToken Access Token for the secured APIs
* @apiSuccess (CodeObject) {String} codeId unique code Id
* @apiSuccess (CodeObject) {Number} codeRating current code rating of the file
* @apiSuccess (CodeObject) {String} codeUrl file URL of the code file
* @apiSuccess (CodeObject) {String} codeName file name of the code file
* @apiSuccess (CodeObject) {String} content content of the code file
*
* @apiSuccessExample {json} Success Response Example
*
* {
* "status": 200,
* "codeObject1": {
* "codeId": "9f6ca40579efdee44097ccf62c93fa192b6efb2b",
* "codeRating": 45,
* "codeUrl": "https://api.github.com/repos/<path>/CodeBase/UnixTimeStampToHumanReadableFormat.cpp",
* "codeName": "UnixTimeStampToHumanReadableFormat.cpp",
* "content": "#include<bits/stdc++.h>\n\nusing namespace std;\n......."
* },
* "codeObject2": {
* "codeId": "55dfc162f8163243c9c7e155e9a9a26b9528be73",
* "codeRating": 2361,
* "codeUrl": "https://api.github.com/repos/<path>/CodeBase/SelectionSort.java",
* "codeName": "SelectionSort.java",
* "content": "public class SelectionSort{public static void main(String[] args){......."
* },
* "accessToken": "96d3371e-9da8-4261-b8a6-ea9b8e68f770"
* }
*
* @apiError (4xx Error Response) {Number} 429 Too many requests, please try again later!!!
* @apiError (4xx Error Response) {Number} 405 Method not Allowed
* @apiError (4xx Error Response) {Number} 404 No results found
* @apiError (4xx Error Response) {Number} 400 Bad Request
* @apiError (500 Error Response) {Number} 500 Internal Server Error
**/
/**
* @api {PUT} /api/v1/rateCode PUT: rate the code file
* @apiName rateCode
* @apiDescription api to rate the Random Code files present in code base
* @apiVersion 1.0.0
* @apiBody {Number} winner Marked winner 1 or 2
* @apiBody {String} codeId1 code Id for code 1
* @apiBody {String} codeId2 code Id for code 2
* @apiBody {String} codeRatingEngineToken Access token received from randomCodes request
*
* @apiGroup rateCode
* @apiSuccess (200 Success Response) {Object} update1 First UpdatedCodeObject
* @apiSuccess (200 Success Response) {Object} update2 Second UpdatedCodeObject
* @apiSuccess (200 Success Response) {Number} status 200 (Status Code)
* @apiSuccess (200 Success Response) {String} message Code Ratings are updated
* @apiSuccess (UpdatedCodeObject) {String} codeId unique code Id
* @apiSuccess (UpdatedCodeObject) {Number} codeRating updated code rating of the file
* @apiSuccess (UpdatedCodeObject) {String} codeUrl file URL of the code file
* @apiSuccess (UpdatedCodeObject) {String} codeName file name of the code file
* @apiSuccess (UpdatedCodeObject) {String} userName user name of the contributed user
*
* @apiSuccessExample {json} Success Response Example
*
* {
* "update1": {
* "codeId": "55dfc162f8163243c9c7e155e9a9a26b9528be73",
* "codeRating": 2369,
* "codeUrl": "https://api.github.com/repos/..../CodeBase/SelectionSort.java",
* "codeName": "SelectionSort.java",
* "userName": "GauravWalia19",
* },
* "update2": {
* "codeId": "489e8fe91b2db73cc0f8f78b831fabb1b927d2b5",
* "codeRating": 2235,
* "codeUrl": "https://api.github.com/repos/..../CodeBase/LinearSearch.c",
* "codeName": "LinearSearch.c",
* "userName": "GauravWalia19",
* },
* "status": 200,
* "message": "Code Ratings are updated"
* }
*
* @apiError (4xx Error Response) {Number} 429 Too many requests, please try again later!!!
* @apiError (4xx Error Response) {Number} 405 Method not Allowed
* @apiError (4xx Error Response) {Number} 401 Invalid Token !! Please send the valid token
* @apiError (4xx Error Response) {Number} 400 Bad Request
* @apiError (500 Error Response) {Number} 500 Internal Server Error
**/
/**
* @api {GET} /api/v1/searchUser GET: searching the user name
* @apiName searchUser
* @apiDescription search and return the code rating for the specific user
* @apiVersion 1.0.0
* @apiBody {String} codeRatingEngineToken Access token received from randomCodes request
* @apiQuery {String} username Username to search
* @apiQuery {Boolean} sendContent Whether content is needed from the API or not
*
* @apiGroup searchUser
* @apiSuccess (200 Success Response) {Number} status 200 (Status Code)
* @apiSuccess (200 Success Response) {Array} userCodeBaseFiles CodeBaseFile
*
* @apiSuccess (CodeBaseFile) {String} _id unique mongo Id
* @apiSuccess (CodeBaseFile) {String} codeId unique code Id
* @apiSuccess (CodeBaseFile) {Number} codeRating current code rating of the file
* @apiSuccess (CodeBaseFile) {String} codeUrl file URL of the code file
* @apiSuccess (CodeBaseFile) {String} codeName file name of the code file
* @apiSuccess (CodeBaseFile) {String} userName user name of the contributed user
* @apiSuccess (CodeBaseFile) {String} content content of the code file
*
* @apiSuccessExample {json} Success Response Example
*
* {
* "status": 200,
* "userCodeBaseFiles": [
* {
* "_id": "60d877a541d44f4a2350d1b1",
* "codeId": "55dfc162f8163243c9c7e155e9a9a26b9528be73",
* "codeRating": 2384,
* "codeUrl": "https://api.github.com/repos/..../CodeBase/SelectionSort.java?ref=master",
* "codeName": "SelectionSort.java",
* "userName": "GauravWalia19",
* "__v": 0,
* "content": "Scanner in = new Scanner(System.in)"
* }
* ]
* }
*
* @apiError (4xx Error Response) {Number} 429 Too many requests, please try again later!!!
* @apiError (4xx Error Response) {Number} 405 Method not Allowed
* @apiError (4xx Error Response) {Number} 404 No Code Base file found for the respective user
* @apiError (4xx Error Response) {Number} 401 Invalid Token !! Please send the valid token
* @apiError (4xx Error Response) {Number} 400 Bad Request
* @apiError (500 Error Response) {Number} 500 Internal Server Error
**/
Loading