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

signup #153

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
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"
31 changes: 31 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use the official Python base image
FROM python:3.12.0-slim-bookworm

# Set environment variables
ENV PYTHONBUFFERED 1
ENV PYTHONWRITEBYTECODE 1
ENV APP=/app

# Set the working directory inside the container
WORKDIR $APP

# Copy the requirements.txt file into the container
COPY requirements.txt $APP

# Install the required Python packages
RUN pip3 install --upgrade pip && pip3 install -r requirements.txt

# Copy the rest of the application files into the container
COPY . $APP

# Expose the application port (e.g., 8000)
EXPOSE 8000

# Make sure the entrypoint script is executable
RUN chmod +x /app/entrypoint.sh

# Set the entry point for the application
ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]

# Run the application with Gunicorn server (or any command to start the app)
CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "djangoproj.wsgi"]
76 changes: 50 additions & 26 deletions server/database/app.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
/*jshint esversion: 6 */
/*jshint sub:true*/
/* 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'));
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.deleteMany({}).then(() => {
Reviews.insertMany(reviews_data['reviews']);
});
Dealerships.deleteMany({}).then(()=>{
Dealerships.deleteMany({}).then(() => {
Dealerships.insertMany(dealerships_data['dealerships']);
});

} catch (error) {
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");
});

// Express route to fetch all reviews
Expand All @@ -49,7 +52,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 +61,63 @@ 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(); // Fetch all dealerships
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching dealerships' });
}
});

// Express route to fetch Dealers by a particular state
// Express route to fetch dealers by a particular state
app.get('/fetchDealers/:state', async (req, res) => {
//Write your code here
try {
const state = req.params.state; // Extract state from route parameters
const documents = await Dealerships.find({ state: state }); // Fetch dealerships matching the state
res.json(documents);
} catch (error) {
res.status(500).json({ error: 'Error fetching dealerships by state' });
}
});

// Express route to fetch dealer by a particular id
app.get('/fetchDealer/:id', async (req, res) => {
//Write your code here
try {
const id = req.params.id; // Extract dealer ID from route parameters
const document = await Dealerships.findOne({ id: parseInt(id) }); // Fetch dealership by ID
if (document) {
res.json(document);
} else {
res.status(404).json({ error: 'Dealer not found' });
}
} catch (error) {
res.status(500).json({ error: 'Error fetching dealership by ID' });
}
});

//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 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.log(error);
res.status(500).json({ error: 'Error inserting review' });
}
});
Expand Down
7 changes: 4 additions & 3 deletions server/database/dealership.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*jshint esversion: 6 */
const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const dealerships = new Schema({
id: {
id: {
type: Number,
required: true,
},
city: {
},
city: {
type: String,
required: true
},
Expand Down
15 changes: 8 additions & 7 deletions server/database/inventory.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
/*jshint esversion: 6 */
const { Int32 } = require('mongodb');
const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const cars = new Schema({
dealer_id: {
dealer_id: {
type: Number,
required: true
},
make: {
},
make: {
type: String,
required: true
},
model: {
model: {
type: String,
required: true
},
bodyType: {
bodyType: {
type: String,
required: true
},
year: {
year: {
type: Number,
required: true
},
mileage: {
mileage: {
type: Number,
required: true
}
Expand Down
7 changes: 4 additions & 3 deletions server/database/review.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*jshint esversion: 6 */
const mongoose = require('mongoose');

const Schema = mongoose.Schema;

const reviews = new Schema({
id: {
id: {
type: Number,
required: true,
},
name: {
},
name: {
type: String,
required: true
},
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-bouhalihamza/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://bouhalihamza-3030.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai/
sentiment_analyzer_url=https://sentianalyzer.1qfi4e5z095o.us-south.codeengine.appdomain.cloud/
Empty file removed server/djangoapp/__init__.py
Empty file.
16 changes: 13 additions & 3 deletions server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# from django.contrib import admin
# from .models import related models
from django.contrib import admin
from .models import CarMake, CarModel


# Register your models here.
# Register CarMake
class CarMakeAdmin(admin.ModelAdmin):
list_display = ('name', 'description')


# Register CarModel
class CarModelAdmin(admin.ModelAdmin):
list_display = ('name', 'car_make', 'car_type', 'year')


admin.site.register(CarMake, CarMakeAdmin)
admin.site.register(CarModel, CarModelAdmin)
# CarModelInline class

# CarModelAdmin class
Expand Down
Loading