Skip to content

Adding temporary changes to Github #172

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 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e847b1e
Adding temporary changes to Github
Vegablues Apr 3, 2025
626b8e6
Adding temporary changes to Github
Vegablues Apr 3, 2025
93a2dab
Adding temporary changes to Github
Vegablues Apr 4, 2025
5297ddb
Adding temporary changes to Github
Vegablues Apr 4, 2025
632733a
Adding temporary changes to Github
Vegablues Apr 4, 2025
f3a2535
Adding temporary changes to Github
Vegablues Apr 7, 2025
d35f579
Adding temporary changes to Github
Vegablues Apr 8, 2025
17bfb25
Create main.yml
Vegablues Apr 8, 2025
2916032
Delete .github/workflows directory
Vegablues Apr 8, 2025
6331a84
Adding temporary changes to Github
Vegablues Apr 8, 2025
598d4ef
Create main.yml
Vegablues Apr 8, 2025
93afb65
Adding temporary changes to Github
Vegablues Apr 8, 2025
def8c62
Delete .github/workflows directory
Vegablues Apr 8, 2025
1201c35
Create main.yml
Vegablues Apr 8, 2025
0ab026d
Adding temporary changes to Github
Vegablues Apr 8, 2025
29da9a8
Delete .github/workflows directory
Vegablues Apr 8, 2025
d07cfb7
Create main.yml
Vegablues Apr 8, 2025
cbaea09
Update urls.py
Vegablues Apr 8, 2025
92e696f
Update settings.py
Vegablues Apr 8, 2025
c1d97be
Update views.py
Vegablues Apr 8, 2025
588d232
Update urls.py
Vegablues Apr 8, 2025
7a2ed53
Delete .github/workflows directory
Vegablues Apr 8, 2025
569c104
Create main.yml
Vegablues Apr 8, 2025
9149223
Update urls.py
Vegablues Apr 8, 2025
e330dd8
Update urls.py
Vegablues Apr 8, 2025
c38ff05
Delete .github/workflows directory
Vegablues Apr 8, 2025
499a199
Create main.yml
Vegablues Apr 8, 2025
1b40c1f
Update settings.py
Vegablues Apr 8, 2025
2794886
Update settings.py
Vegablues Apr 8, 2025
24cb899
Update views.py
Vegablues Apr 8, 2025
3c08702
Delete .github/workflows directory
Vegablues Apr 8, 2025
1a5b2a9
Create main.yml
Vegablues Apr 8, 2025
0b4deed
Update views.py
Vegablues Apr 8, 2025
7bb0355
Delete .github/workflows directory
Vegablues Apr 8, 2025
0bd38ea
Create main.yml
Vegablues Apr 8, 2025
08d5839
Update views.py
Vegablues Apr 8, 2025
8ec3718
Delete .github/workflows directory
Vegablues Apr 8, 2025
76ca4fc
Create main.yml
Vegablues Apr 8, 2025
d8b99b0
Update views.py
Vegablues Apr 8, 2025
83a8903
Update app.js
Vegablues Apr 8, 2025
2e094ad
Delete .github/workflows directory
Vegablues Apr 8, 2025
7c9c709
Create main.yml
Vegablues Apr 8, 2025
2595231
Adding temporary changes to Github
Vegablues Apr 17, 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
47 changes: 47 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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"
79 changes: 46 additions & 33 deletions server/database/app.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
/* eslint-env es6 */

const express = require('express');
const mongoose = require('mongoose');
const fs = require('fs');
const cors = require('cors')
const app = express()
const cors = require('cors');
const app = express();
const port = 3030;

app.use(cors())
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'));

mongoose.connect("mongodb://mongo_db:27017/",{'dbName':'dealershipsDB'});

mongoose.connect("mongodb://mongo_db:27017/", { dbName: 'dealershipsDB' });

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

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

try {
Reviews.deleteMany({}).then(()=>{
Reviews.insertMany(reviews_data['reviews']);
Reviews.deleteMany({}).then(() => {
Reviews.insertMany(reviews_data.reviews);
});
Dealerships.deleteMany({}).then(()=>{
Dealerships.insertMany(dealerships_data['dealerships']);
Dealerships.deleteMany({}).then(() => {
Dealerships.insertMany(dealerships_data.dealerships);
});

} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
console.error(error); // You can't use res here without a route context
}


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

// Express route to fetch all reviews
Expand All @@ -49,7 +47,7 @@ app.get('/fetchReviews', async (req, res) => {
// 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});
const documents = await Reviews.find({ dealership: req.params.id });
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
Expand All @@ -58,42 +56,57 @@ app.get('/fetchReviews/dealer/:id', async (req, res) => {

// 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
try {
const documents = await Dealerships.find({ state: req.params.state });
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
}
});

// Express route to fetch dealer by a particular id
app.get('/fetchDealer/:id', async (req, res) => {
//Write your code here
try {
const documents = await Dealerships.find({ id: req.params.id });
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching documents' });
}
});

//Express route to insert review
// 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 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'],
});
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);
console.error(error);
res.status(500).json({ error: 'Error inserting review' });
}
});
Expand Down
4 changes: 2 additions & 2 deletions server/djangoapp/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
backend_url =your backend url
sentiment_analyzer_url=your code engine deployment url
backend_url =https://eminyeni-3030.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai
sentiment_analyzer_url=https://sentianalyzer.1ucbiy71o5ho.us-south.codeengine.appdomain.cloud/
Empty file removed server/djangoapp/__init__.py
Empty file.
9 changes: 5 additions & 4 deletions server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# from django.contrib import admin
# from .models import related models
from django.contrib import admin
from .models import CarMake, CarModel


# Register your models here.
# Registering models with their respective admins
admin.site.register(CarMake)
admin.site.register(CarModel)

# CarModelInline class

Expand Down
49 changes: 30 additions & 19 deletions server/djangoapp/models.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
# Uncomment the following imports before adding the Model code

# from django.db import models
# from django.utils.timezone import now
# from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator


# Create your models here.

# <HINT> Create a Car Make model `class CarMake(models.Model)`:
# - Name
# - Description
# - Any other fields you would like to include in car make model
# - __str__ method to print a car make object


# <HINT> Create a Car Model model `class CarModel(models.Model):`:
# - Many-To-One relationship to Car Make model (One Car Make has many
# Car Models, using ForeignKey field)
# - Name
# - Type (CharField with a choices argument to provide limited choices
# such as Sedan, SUV, WAGON, etc.)
# - Year (IntegerField) with min value 2015 and max value 2023
# - Any other fields you would like to include in car model
# - __str__ method to print a car make object
class CarMake(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()

def __str__(self):
return self.name


class CarModel(models.Model):
car_make = models.ForeignKey(CarMake, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
CAR_TYPES = [
('SEDAN', 'Sedan'),
('SUV', 'SUV'),
('WAGON', 'Wagon'),
# Add more choices as required
]
type = models.CharField(max_length=10, choices=CAR_TYPES, default='SUV')
year = models.IntegerField(
default=2023,
validators=[
MaxValueValidator(2023),
MinValueValidator(2015)
]
)

def __str__(self):
return self.name # Return the name as the string representation
123 changes: 122 additions & 1 deletion server/djangoapp/populate.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,123 @@
from .models import CarMake, CarModel


def initiate():
print("Populate not implemented. Add data manually")
car_make_data = [
{"name": "NISSAN", "description": "Great cars. Japanese technology"},
{"name": "Mercedes", "description": "Great cars. German technology"},
{"name": "Audi", "description": "Great cars. German technology"},
{"name": "Kia", "description": "Great cars. Korean technology"},
{"name": "Toyota", "description": "Great cars. Japanese technology"},
]

car_make_instances = []
for data in car_make_data:
car_make_instances.append(
CarMake.objects.create(
name=data['name'],
description=data['description']
)
)

# Create CarModel instances with the corresponding CarMake instances
car_model_data = [
{
"name": "Pathfinder",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[0]
},
{
"name": "Qashqai",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[0]
},
{
"name": "XTRAIL",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[0]
},
{
"name": "A-Class",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[1]
},
{
"name": "C-Class",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[1]
},
{
"name": "E-Class",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[1]
},
{
"name": "A4",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[2]
},
{
"name": "A5",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[2]
},
{
"name": "A6",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[2]
},
{
"name": "Sorrento",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[3]
},
{
"name": "Carnival",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[3]
},
{
"name": "Cerato",
"type": "Sedan",
"year": 2023,
"car_make": car_make_instances[3]
},
{
"name": "Corolla",
"type": "Sedan",
"year": 2023,
"car_make": car_make_instances[4]
},
{
"name": "Camry",
"type": "Sedan",
"year": 2023,
"car_make": car_make_instances[4]
},
{
"name": "Kluger",
"type": "SUV",
"year": 2023,
"car_make": car_make_instances[4]
},
# Add more CarModel instances as needed
]

for data in car_model_data:
CarModel.objects.create(
name=data['name'],
car_make=data['car_make'],
type=data['type'],
year=data['year']
)
Loading