Skip to content

Commit

Permalink
Merge pull request #55 from CMU-17313Q/career-implem
Browse files Browse the repository at this point in the history
Career feature integration with microservice
  • Loading branch information
Malika1109 authored Nov 11, 2023
2 parents 0257cb6 + e09954d commit 469cfc7
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 26 deletions.
2 changes: 2 additions & 0 deletions public/openapi/write.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,5 @@ paths:
$ref: "write/files.yaml"
/files/folder:
$ref: "write/files/folder.yaml"
/career/register:
$ref: 'write/career/register.yaml'
68 changes: 68 additions & 0 deletions public/openapi/write/career/register.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
post:
tags:
- career
summary: Sign up with the student information
description: This operation registers career-related data of a user
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
student_id:
type: string
example: student1
major:
type: string
example: Computer Science
age:
type: number
example: 20
gender:
type: string
example: M
gpa:
type: number
example: 4.0
extra_curricular:
type: string
example: Men's Basketball
num_programming_languages:
type: number
example: 1
num_past_internships:
type: number
example: 2
required:
- student_id
- major
- age
- gender
- gpa
- extra_curricular
- num_programming_languages
- num_past_internships
responses:
'200':
description: Career data is successfully registered
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../components/schemas/Status.yaml#/Status
response:
type: object
properties: {}
'400':
$ref: ../../components/responses/400.yaml#/400
'401':
$ref: ../../components/responses/401.yaml#/401
'403':
$ref: ../../components/responses/403.yaml#/403
'426':
$ref: ../../components/responses/426.yaml#/426
'500':
$ref: ../../components/responses/500.yaml#/500
35 changes: 18 additions & 17 deletions public/src/client/chats/recent.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
'use strict';
// 'use strict';


define('forum/chats/recent', ['alerts'], function (alerts) {
const recent = {};

recent.init = function () {
require(['forum/chats'], function (Chats) {
$('[component="chat/recent"]').on('click', '[component="chat/recent/room"]', function () {
Chats.switchChat($(this).attr('data-roomid'));
});

$('[component="chat/recent"]').on('scroll', function () {
const $this = $(this);
const bottom = ($this[0].scrollHeight - $this.height()) * 0.9;
if ($this.scrollTop() > bottom) {
loadMoreRecentChats();
}
});
});
};

function loadMoreRecentChats() {
const recentChats = $('[component="chat/recent"]');
if (recentChats.attr('loading')) {
Expand All @@ -44,6 +28,23 @@ define('forum/chats/recent', ['alerts'], function (alerts) {
}
});
}
recent.init = function () {
require(['forum/chats'], function (Chats) {
$('[component="chat/recent"]').on('click', '[component="chat/recent/room"]', function () {
Chats.switchChat($(this).attr('data-roomid'));
});

$('[component="chat/recent"]').on('scroll', function () {
const $this = $(this);
const bottom = ($this[0].scrollHeight - $this.height()) * 0.9;
if ($this.scrollTop() > bottom) {
loadMoreRecentChats();
}
});
});
};



function onRecentChatsLoaded(data, callback) {
if (!data.rooms.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ helpers.formatApiResponse = async (statusCode, res, payload) => {
returnPayload.response = response;

if (global.env === 'development') {
returnPayload.stack = payload.stack;
// returnPayload.stack = payload.stack;
process.stdout.write(`[${chalk.yellow('api')}] Exception caught, error with stack trace follows:\n`);
process.stdout.write(payload.stack);
}
Expand Down
32 changes: 24 additions & 8 deletions src/controllers/write/career.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
/* eslint-disable quotes */
/* eslint-disable max-len */

"use strict";
'use strict';

const helpers = require('../helpers');
const user = require('../../user');
const db = require('../../database');

/* https://career-service-kev265hxta-de.a.run.app/api?data=
{"Student ID":"123","Gender":"M","Age":20,"Major":"Computer Science","GPA":3.5,"Extra Curricular":"Sorority","Num Programming Languages":2,"Num Past Internships":1} */

const helpers = require("../helpers");
const user = require("../../user");
const db = require("../../database");

const Career = module.exports;


Career.register = async (req, res) => {
const userData = req.body;
const URL = `https://career-service-kev265hxta-de.a.run.app/api?data={"Student%20ID":"${userData.student_id}","Gender":"${userData.gender}","Age":${userData.age},"Major":"${encodeURIComponent(userData.major)}","GPA":${encodeURIComponent(userData.gpa)},"Extra%20Curricular":"${encodeURIComponent(userData.extra_curricular)}","Num%20Programming%20Languages":${userData.num_programming_languages},"Num%20Past%20Internships":${userData.num_past_internships}}`;
let response;
try {
const userCareerData = {
student_id: userData.student_id,
Expand All @@ -22,14 +29,23 @@ Career.register = async (req, res) => {
num_programming_languages: userData.num_programming_languages,
num_past_internships: userData.num_past_internships,
};
// userCareerData.prediction = Math.round(Math.random());
// TODO: Change this line to do call and retrieve actual candidate success prediction from the model instead of using a random number

userCareerData.prediction = Math.round(Math.random()); // TODO: Change this line to do call and retrieve actual candidate success prediction from the model instead of using a random number
response = await fetch(URL, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
response = await response.json();

userCareerData.prediction = response.result;
await user.setCareerData(req.uid, userCareerData);
db.sortedSetAdd("users:career", req.uid, req.uid);
res.json({});
db.sortedSetAdd('users:career', req.uid, req.uid);
helpers.formatApiResponse(200, res);
} catch (err) {
console.log(err);
console.error(response.status);
helpers.noScriptErrors(req, res, err.message, 400);
}
};
1 change: 1 addition & 0 deletions src/controllers/write/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Write = module.exports;

Write.users = require('./users');
Write.career = require('./career');
Write.groups = require('./groups');
Write.categories = require('./categories');
Write.topics = require('./topics');
Expand Down
13 changes: 13 additions & 0 deletions src/routes/write/career.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });
const express = require('express');
const controllers = require('../../controllers');
const routeHelpers = require('../helpers');

const router = express.Router();
const { setupApiRoute } = routeHelpers;
module.exports = function () {
setupApiRoute(router, 'post', '/register', [], controllers.write.career.register);
return router;
};
1 change: 1 addition & 0 deletions src/routes/write/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Write.reload = async (params) => {

router.use('/api/v3/users', require('./users')());
router.use('/api/v3/groups', require('./groups')());
router.use('/api/v3/career', require('./career')());
router.use('/api/v3/categories', require('./categories')());
router.use('/api/v3/topics', require('./topics')());
router.use('/api/v3/posts', require('./posts')());
Expand Down

0 comments on commit 469cfc7

Please sign in to comment.