Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
650b22e
frontend/static changes
nilajean Jan 25, 2025
0544ebb
registration and route config
nilajean Jan 25, 2025
aeeff06
API endpoints
nilajean Jan 25, 2025
67e4ad1
CarModel and CarMake
nilajean Jan 26, 2025
4e01a46
django proxy services/ backend
nilajean Jan 26, 2025
3b6a6d3
unfinished module 4
nilajean Jan 26, 2025
8d5315b
module 4
nilajean Jan 26, 2025
6f7c30d
module 4- dynamic pages
nilajean Jan 27, 2025
2dd3231
Create main.yml
nilajean Jan 28, 2025
2d3a645
Create mainn.yml
nilajean Jan 28, 2025
f371388
Update models.py
nilajean Jan 28, 2025
d162b1e
Update populate.py
nilajean Jan 28, 2025
99dfbcd
Update restapis.py
nilajean Jan 28, 2025
3320166
Update urls.py
nilajean Jan 28, 2025
9754436
Update views.py
nilajean Jan 28, 2025
531eedd
Update settings.py
nilajean Jan 28, 2025
9a0c5b0
Update urls.py
nilajean Jan 28, 2025
21fdd2e
Update review.js
nilajean Jan 28, 2025
a1e791e
Update dealership.js
nilajean Jan 28, 2025
64c77af
Update inventory.js
nilajean Jan 28, 2025
916111f
Update app.js
nilajean Jan 28, 2025
64e4768
Delete .github/workflows/main.yml
nilajean Jan 28, 2025
22a550d
Delete .github/workflows/mainn.yml
nilajean Jan 28, 2025
a357ff7
Create main.yml
nilajean Jan 28, 2025
9a55eaa
Delete .github/workflows directory
nilajean Jan 28, 2025
707c72f
final application
nilajean Jan 28, 2025
c93cfb5
Create main.yml
nilajean Jan 28, 2025
69b0eb0
Update models.py
nilajean Jan 28, 2025
39036ee
Update populate.py
nilajean Jan 28, 2025
b1202d7
Update restapis.py
nilajean Jan 28, 2025
a5476b4
Update urls.py
nilajean Jan 28, 2025
65f0c6b
Update views.py
nilajean Jan 28, 2025
53f6875
Update settings.py
nilajean Jan 28, 2025
6b34c4f
Update urls.py
nilajean Jan 28, 2025
13f6bff
Update populate.py
nilajean Jan 28, 2025
b02ae2d
Update views.py
nilajean Jan 28, 2025
55855e9
Update settings.py
nilajean Jan 28, 2025
aad8c9e
Update urls.py
nilajean Jan 28, 2025
2a9046f
Update populate.py
nilajean Jan 28, 2025
6adeb2a
Update populate.py
nilajean Jan 28, 2025
44206ea
Update populate.py
nilajean Jan 28, 2025
0ab60d7
Delete .github/workflows directory
nilajean Jan 28, 2025
dd0fe16
Create main.yml
nilajean Jan 28, 2025
d5153a2
Update populate.py
nilajean Jan 28, 2025
3328e02
Update views.py
nilajean Jan 28, 2025
cae68e5
Update views.py
nilajean Jan 28, 2025
c27849f
Update settings.py
nilajean Jan 28, 2025
e7dcea6
Delete .github/workflows directory
nilajean Jan 28, 2025
3b833d4
Create main.yml
nilajean Jan 28, 2025
ad0dfae
Update populate.py
nilajean Jan 28, 2025
848cfab
Update views.py
nilajean Jan 28, 2025
b64a0dc
Update views.py
nilajean Jan 28, 2025
8c666b1
Update settings.py
nilajean Jan 28, 2025
0a0329a
Update populate.py
nilajean Jan 28, 2025
3eecf24
Delete .github/workflows directory
nilajean Jan 28, 2025
52261b6
Create main.yml
nilajean Jan 28, 2025
d8591ef
Update settings.py
nilajean Jan 28, 2025
8345b1b
Update settings.py
nilajean Jan 28, 2025
d8d58fe
Delete .github/workflows directory
nilajean Jan 28, 2025
b2eebed
Create main.yml
nilajean Jan 28, 2025
15afb72
Update app.js
nilajean Jan 28, 2025
eea994a
Update app.js
nilajean Jan 28, 2025
441f4c7
Update app.js
nilajean Jan 28, 2025
a582023
Delete .github/workflows directory
nilajean Jan 28, 2025
67b07fd
Create main.yml
nilajean Jan 28, 2025
53bde49
Update app.js
nilajean Jan 28, 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"
25 changes: 25 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM python:3.12.0-slim-bookworm

ENV PYTHONBUFFERED 1
ENV PYTHONWRITEBYTECODE 1

ENV APP=/app

# Change the workdir.
WORKDIR $APP

# Install the requirements
COPY requirements.txt $APP

RUN pip3 install -r requirements.txt

# Copy the rest of the files
COPY . $APP

EXPOSE 8000

RUN chmod +x /app/entrypoint.sh

ENTRYPOINT ["/bin/bash","/app/entrypoint.sh"]

CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "djangoproj.wsgi"]
114 changes: 67 additions & 47 deletions server/database/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

/*jshint esversion: 8 */

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'));
Expand All @@ -20,10 +23,10 @@ const Dealerships = require('./dealership');

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

} catch (error) {
Expand All @@ -33,7 +36,7 @@ try {

// 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 @@ -57,47 +60,64 @@ app.get('/fetchReviews/dealer/:id', async (req, res) => {
});

// Express route to fetch all dealerships
app.get('/fetchDealers', async (req, res) => {
//Write your code here
});

// 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
});

//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' });
}
});

app.get("/fetchDealers", async (req, res) => {
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) => {
try {
let stateValue = req.params.state;
stateValue = stateValue.charAt(0).toUpperCase() + stateValue.slice(1);
const documents = await Dealerships.find({ state: stateValue });
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) => {
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
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" });
}
});

// Start the Express server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
Expand Down
3 changes: 3 additions & 0 deletions server/database/dealership.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

/*jshint esversion: 8 */

const mongoose = require('mongoose');

const Schema = mongoose.Schema;
Expand Down
3 changes: 3 additions & 0 deletions server/database/inventory.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

/*jshint esversion: 8 */

const { Int32 } = require('mongodb');
const mongoose = require('mongoose');

Expand Down
2 changes: 2 additions & 0 deletions server/database/review.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*jshint esversion: 8 */

const mongoose = require('mongoose');

const Schema = mongoose.Schema;
Expand Down
29 changes: 29 additions & 0 deletions server/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: dealership
name: dealership
spec:
replicas: 1
selector:
matchLabels:
run: dealership
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
run: dealership
spec:
containers:
- image: us.icr.io/sn-labs-intenilajean/dealership:latest
imagePullPolicy: Always
name: dealership
ports:
- containerPort: 8000
protocol: TCP
restartPolicy: Always
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://intenilajean-3030.theiadockernext-1-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai
sentiment_analyzer_url= https://sentianalyzer.1r4luekfxyrf.us-south.codeengine.appdomain.cloud
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
58 changes: 37 additions & 21 deletions server/djangoapp/models.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
# 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

# Car Make model
class CarMake(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()

def __str__(self):
return self.name # Return the name as the string representation


# Car Model model
class CarModel(models.Model):
car_make = models.ForeignKey(
CarMake, on_delete=models.CASCADE
) # Many-to-One relationship
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
Loading