Skip to content

module 1 done #218

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 27 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
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"]
74 changes: 51 additions & 23 deletions server/database/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* jshint esversion: 6 */
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 +21,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 +34,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 @@ -58,35 +59,62 @@ 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 dealerships = await Dealerships.find(); // Fetch all dealerships
res.status(200).json(dealerships); // Send the data as JSON
} catch (error) {
res.status(500).json({ error: 'Error fetching dealerships' }); // Handle errors
}
});

// Express route to fetch Dealers by a particular state
// Express route to fetch dealerships by a particular state
app.get('/fetchDealers/:state', async (req, res) => {
//Write your code here
});
const state = req.params.state;
try {
const dealerships = await Dealerships.find({ state });
if (dealerships.length === 0 ) {
res.status(404).json({ error: 'No dealerships found in state: ${state}'});
} else {
res.json(dealerships);
}
} catch (error) {
res.status(500).json({ error: 'Error fetching dealerships by state' });
}
});

// Express route to fetch dealer by a particular id
// Express route to fetch dealers by ID
// Correcting the query to match the dealership data
app.get('/fetchDealer/:id', async (req, res) => {
//Write your code here
});
const id = parseInt(req.params.id, 10); // Parse the ID as an integer
try {
const dealership = await Dealerships.findOne({ id });
if (!dealership) {
res.status(404).json({ error: 'No dealership found with ID: ${id}'});
} else {
res.json(dealership);
}
} 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'],
"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 {
Expand Down
5 changes: 3 additions & 2 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
1 change: 1 addition & 0 deletions server/database/inventory.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* jshint esversion: 6 */
const { Int32 } = require('mongodb');
const mongoose = require('mongoose');

Expand Down
1 change: 1 addition & 0 deletions server/database/review.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* jshint esversion: 6 */
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-maikoblaukop/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://maikoblaukop-8000.theiadockernext-1-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai
sentiment_analyzer_url=https://sentianalyzer1.1z91a1tkyv48.us-south.codeengine.appdomain.cloud/
Empty file removed server/djangoapp/__init__.py
Empty file.
6 changes: 4 additions & 2 deletions server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# from django.contrib import admin
# from .models import related models
from django.contrib import admin
from .models import CarMake, CarModel


# Register your models here.
Expand All @@ -11,3 +11,5 @@
# CarMakeAdmin class with CarModelInline

# Register models here
admin.site.register(CarMake)
admin.site.register(CarModel)
24 changes: 24 additions & 0 deletions server/djangoapp/djangoapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# OpenShift Clients

The OpenShift client `oc` simplifies working with Kubernetes and OpenShift
clusters, offering a number of advantages over `kubectl` such as easy login,
kube config file management, and access to developer tools. The `kubectl`
binary is included alongside for when strict Kubernetes compliance is necessary.

To learn more about OpenShift, visit [docs.openshift.com](https://docs.openshift.com)
and select the version of OpenShift you are using.

## Installing the tools

After extracting this archive, move the `oc` and `kubectl` binaries
to a location on your PATH such as `/usr/local/bin`. Then run:

oc login [API_URL]

to start a session against an OpenShift cluster. After login, run `oc` and
`oc help` to learn more about how to get started with OpenShift.

## License

OpenShift is licensed under the Apache Public License 2.0. The source code for this
program is [located on github](https://github.com/openshift/oc).
5 changes: 5 additions & 0 deletions server/djangoapp/djangoapp/bin/2to3-3.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /usr/bin/python3.8
import sys
from lib2to3.main import main

sys.exit(main("lib2to3.fixes"))
Binary file added server/djangoapp/djangoapp/bin/FileCheck-17
Binary file not shown.
Loading