Skip to content

PullRequest#2 #213

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

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
293bd2d
Adding temporary changes to Github
iintii Jul 19, 2025
bb7d0a1
m
iintii Jul 19, 2025
50e7b8f
y
iintii Jul 19, 2025
153b231
m
iintii Jul 20, 2025
a7cea5f
m
iintii Jul 20, 2025
1c28ab6
m
iintii Jul 20, 2025
dcbc0e8
m
iintii Jul 22, 2025
f2c59d6
m
iintii Jul 23, 2025
6e08a98
m
iintii Jul 23, 2025
d779e60
Create main.yml
iintii Jul 23, 2025
6d71299
Update urls.py
iintii Jul 23, 2025
7c10ebe
Update main.yml
iintii Jul 23, 2025
46a496d
Update main.yml
iintii Jul 23, 2025
752c652
Update main.yml
iintii Jul 23, 2025
6a8bb30
Update main.yml
iintii Jul 23, 2025
3b5d87c
Create .jshintrc
iintii Jul 23, 2025
51c9c76
Update main.yml
iintii Jul 23, 2025
56b119c
Update app.js
iintii Jul 23, 2025
33316e1
Update settings.py
iintii Jul 23, 2025
0ba605b
Update settings.py
iintii Jul 23, 2025
b3b6776
Update settings.py
iintii Jul 23, 2025
85f0530
formatted
iintii Jul 23, 2025
1bcec65
Update main.yml
iintii Jul 24, 2025
c4cba1b
Update settings.py
iintii Jul 24, 2025
c612177
Update app.js
iintii Jul 24, 2025
1923275
readjusted Line length
iintii Jul 24, 2025
6fc0c6b
Update settings.py
iintii Jul 24, 2025
22eeb7b
Update views.py
iintii Jul 24, 2025
6d891ea
Update settings.py
iintii Jul 24, 2025
2995c0a
Update models.py
iintii Jul 24, 2025
0827034
Update settings.py
iintii Jul 24, 2025
9b48275
Update settings.py
iintii Jul 24, 2025
432c9ee
Update views.py
iintii Jul 24, 2025
7f5df0a
Update settings.py
iintii Jul 24, 2025
bdf3ca0
Update views.py
iintii Jul 24, 2025
e0f74ac
final
iintii Jul 24, 2025
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
59 changes: 59 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: 'Lint Code'

on:
push:
branches: [master, main]
pull_request:
branches: [master, main]

jobs:
lint_python:
name: Lint Python Files
runs-on: ubuntu-latest

steps:

- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8

- name: Print working directory
run: pwd

- name: Run Linter
run: |
pwd
# This command finds all Python files recursively and runs flake8 on them
find . -name "*.py" -exec flake8 {} +
echo "Linted all the python files successfully"

lint_js:
name: Lint JavaScript Files
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14

- name: Install JSHint
run: npm install jshint --global

- name: Run Linter
run: |
# This command finds all JavaScript files recursively and runs JSHint on them
find ./server/database -name "*.js" -exec jshint {} +
echo "Linted all the js files successfully"
3 changes: 3 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esversion": 6
}
122 changes: 64 additions & 58 deletions server/database/app.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,110 @@
/*jshint esversion: 8 */ // This line should already be at the top from previous fixes.

const express = require('express');
const mongoose = require('mongoose');
const fs = require('fs');
const cors = require('cors')
const app = express()
const cors = require('cors'); // Corrected spacing
const app = express(); // Added semicolon
const port = 3030;

app.use(cors())
app.use(require('body-parser').urlencoded({ extended: false }));

const reviews_data = JSON.parse(fs.readFileSync("reviews.json", 'utf8'));
const dealerships_data = JSON.parse(fs.readFileSync("dealerships.json", 'utf8'));
app.use(cors()); // Added semicolon
app.use(require('body-parser').urlencoded({ extended: false })); // Added semicolon

mongoose.connect("mongodb://mongo_db:27017/",{'dbName':'dealershipsDB'});
const reviews_data = JSON.parse(fs.readFileSync("reviews.json", 'utf8')); // Added semicolon
const dealerships_data = JSON.parse(fs.readFileSync("dealerships.json", 'utf8')); // Added semicolon

mongoose.connect("mongodb://mongo_db:27017/", {'dbName': 'dealershipsDB'}); // Added semicolon and fixed spacing

const Reviews = require('./review');
const Reviews = require('./review'); // Added semicolon

const Dealerships = require('./dealership');
const Dealerships = require('./dealership'); // Added semicolon

try {
Reviews.deleteMany({}).then(()=>{
Reviews.insertMany(reviews_data['reviews']);
});
Dealerships.deleteMany({}).then(()=>{
Dealerships.insertMany(dealerships_data['dealerships']);
});
Reviews.deleteMany({}).then(() => {
Reviews.insertMany(reviews_data.reviews); // Fixed to dot notation: reviews_data['reviews'] -> reviews_data.reviews
});
Dealerships.deleteMany({}).then(() => {
Dealerships.insertMany(dealerships_data.dealerships); // Fixed to dot notation: dealerships_data['dealerships'] -> dealerships_data.dealerships
});

} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
res.status(500).json({ error: 'Error fetching documents' });
}


// Express route to home
app.get('/', async (req, res) => {
res.send("Welcome to the Mongoose API")
res.send("Welcome to the Mongoose API"); // Added semicolon
});

// Express route to fetch all reviews
app.get('/fetchReviews', async (req, res) => {
try {
const documents = await Reviews.find();
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
}
try {
const documents = await Reviews.find();
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
}
});

// Express route to fetch reviews by a particular dealer
app.get('/fetchReviews/dealer/:id', async (req, res) => {
try {
const documents = await Reviews.find({dealership: req.params.id});
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
}
try {
const documents = await Reviews.find({ dealership: req.params.id });
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
}
});

// Express route to fetch all dealerships
app.get('/fetchDealers', async (req, res) => {
//Write your code here
try {
const documents = await Dealerships.find();
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
}
});

// Express route to fetch Dealers by a particular state
app.get('/fetchDealers/:state', async (req, res) => {
//Write your code here

});

// Express route to fetch dealer by a particular id
app.get('/fetchDealer/:id', async (req, res) => {
//Write your code here
//Write your code here
});

//Express route to insert review
app.post('/insert_review', express.raw({ type: '*/*' }), async (req, res) => {
data = JSON.parse(req.body);
const documents = await Reviews.find().sort( { id: -1 } )
let new_id = documents[0]['id']+1

const review = new Reviews({
"id": new_id,
"name": data['name'],
"dealership": data['dealership'],
"review": data['review'],
"purchase": data['purchase'],
"purchase_date": data['purchase_date'],
"car_make": data['car_make'],
"car_model": data['car_model'],
"car_year": data['car_year'],
});

try {
const savedReview = await review.save();
res.json(savedReview);
} catch (error) {
console.log(error);
res.status(500).json({ error: 'Error inserting review' });
}
data = JSON.parse(req.body); // Added semicolon
const documents = await Reviews.find().sort({ id: -1 }); // Added semicolon
let new_id = documents[0].id + 1; // Fixed to dot notation: documents[0]['id'] -> documents[0].id

const review = new Reviews({
"id": new_id,
"name": data.name,
"dealership": data.dealership,
"review": data.review,
"purchase": data.purchase,
"purchase_date": data.purchase_date,
"car_make": data.car_make,
"car_model": data.car_model,
"car_year": data.car_year
});

try {
const savedReview = await review.save();
res.json(savedReview);
} catch (error) {
console.log(error); // Added semicolon
res.status(500).json({ error: 'Error inserting review' });
}
});

// Start the Express server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
console.log(`Server is running on http://localhost:${port}`);
});
3 changes: 2 additions & 1 deletion server/djangoapp/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
backend_url =your backend url
sentiment_analyzer_url=your code engine deployment url
sentiment_analyzer_url=https://sentianalyzer.1y32t94nuhbv.us-south.codeengine.appdomain.cloud/
backend_url = https://brody8991-3030.theiadockernext-1-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai/
6 changes: 4 additions & 2 deletions server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# from django.contrib import admin
# from .models import related models
from django.contrib import admin
from .models import CarMake, CarModel


# Register your models here.
admin.site.register(CarMake)
admin.site.register(CarModel)

# CarModelInline class

Expand Down
2 changes: 1 addition & 1 deletion server/djangoapp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class DjangoappConfig(AppConfig):
name = 'djangoapp'
name = "djangoapp"
15 changes: 8 additions & 7 deletions server/djangoapp/microservices/app.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
from flask import Flask
from nltk.sentiment import SentimentIntensityAnalyzer
import json

app = Flask("Sentiment Analyzer")

sia = SentimentIntensityAnalyzer()


@app.get('/')
@app.get("/")
def home():
return "Welcome to the Sentiment Analyzer. \
Use /analyze/text to get the sentiment"


@app.get('/analyze/<input_txt>')
@app.get("/analyze/<input_txt>")
def analyze_sentiment(input_txt):

scores = sia.polarity_scores(input_txt)
print(scores)
pos = float(scores['pos'])
neg = float(scores['neg'])
neu = float(scores['neu'])
pos = float(scores["pos"])
neg = float(scores["neg"])
neu = float(scores["neu"])
res = "positive"
print("pos neg nue ", pos, neg, neu)
if (neg > pos and neg > neu):
if neg > pos and neg > neu:
res = "negative"
elif (neu > neg and neu > pos):
elif neu > neg and neu > pos:
res = "neutral"
res = json.dumps({"sentiment": res})
print(res)
Expand Down
82 changes: 82 additions & 0 deletions server/djangoapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Generated by Django 5.2.4 on 2025-07-20 16:03

import django.core.validators
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="CarMake",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
("description", models.TextField()),
],
),
migrations.CreateModel(
name="CarModel",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("dealer_id", models.IntegerField(null=True)),
("name", models.CharField(max_length=100)),
(
"type",
models.CharField(
choices=[
("SEDAN", "Sedan"),
("SUV", "SUV"),
("WAGON", "Wagon"),
("TRUCK", "Truck"),
("HATCHBACK", "Hatchback"),
("COUPE", "Coupe"),
("CONVERTIBLE", "Convertible"),
("MINIVAN", "Minivan"),
("PICKUP", "Pickup"),
],
default="SUV",
max_length=15,
),
),
(
"year",
models.IntegerField(
default=2023,
validators=[
django.core.validators.MaxValueValidator(2023),
django.core.validators.MinValueValidator(2015),
],
),
),
(
"car_make",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="djangoapp.carmake",
),
),
],
),
]
Empty file.
Loading