diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..1d5c207add --- /dev/null +++ b/.github/workflows/main.yml @@ -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" diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000000..6795963570 --- /dev/null +++ b/server/Dockerfile @@ -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"] \ No newline at end of file diff --git a/server/database/app.js b/server/database/app.js index 00f52b2008..1ecd63400a 100644 --- a/server/database/app.js +++ b/server/database/app.js @@ -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')); @@ -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) { @@ -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 @@ -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 { diff --git a/server/database/dealership.js b/server/database/dealership.js index b10d6b4730..329d6edf1b 100644 --- a/server/database/dealership.js +++ b/server/database/dealership.js @@ -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 }, diff --git a/server/database/inventory.js b/server/database/inventory.js index 2c22fd092c..b14f0847b5 100644 --- a/server/database/inventory.js +++ b/server/database/inventory.js @@ -1,3 +1,4 @@ +/* jshint esversion: 6 */ const { Int32 } = require('mongodb'); const mongoose = require('mongoose'); diff --git a/server/database/review.js b/server/database/review.js index 4759725a3a..c4c780654e 100644 --- a/server/database/review.js +++ b/server/database/review.js @@ -1,3 +1,4 @@ +/* jshint esversion: 6 */ const mongoose = require('mongoose'); const Schema = mongoose.Schema; diff --git a/server/deployment.yaml b/server/deployment.yaml new file mode 100644 index 0000000000..a47add2395 --- /dev/null +++ b/server/deployment.yaml @@ -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 \ No newline at end of file diff --git a/server/djangoapp/.env b/server/djangoapp/.env index 01822e542a..578fdaff30 100644 --- a/server/djangoapp/.env +++ b/server/djangoapp/.env @@ -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/ \ No newline at end of file diff --git a/server/djangoapp/__init__.py b/server/djangoapp/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/server/djangoapp/admin.py b/server/djangoapp/admin.py index 433657fc64..8d58498ac4 100644 --- a/server/djangoapp/admin.py +++ b/server/djangoapp/admin.py @@ -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. @@ -11,3 +11,5 @@ # CarMakeAdmin class with CarModelInline # Register models here +admin.site.register(CarMake) +admin.site.register(CarModel) diff --git a/server/djangoapp/djangoapp/README.md b/server/djangoapp/djangoapp/README.md new file mode 100644 index 0000000000..36dec0639c --- /dev/null +++ b/server/djangoapp/djangoapp/README.md @@ -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). diff --git a/server/djangoapp/djangoapp/bin/2to3-3.8 b/server/djangoapp/djangoapp/bin/2to3-3.8 new file mode 100755 index 0000000000..4d1b3b8508 --- /dev/null +++ b/server/djangoapp/djangoapp/bin/2to3-3.8 @@ -0,0 +1,5 @@ +#! /usr/bin/python3.8 +import sys +from lib2to3.main import main + +sys.exit(main("lib2to3.fixes")) diff --git a/server/djangoapp/djangoapp/bin/FileCheck-17 b/server/djangoapp/djangoapp/bin/FileCheck-17 new file mode 100755 index 0000000000..bbbce270de Binary files /dev/null and b/server/djangoapp/djangoapp/bin/FileCheck-17 differ diff --git a/server/djangoapp/djangoapp/bin/GET b/server/djangoapp/djangoapp/bin/GET new file mode 100755 index 0000000000..355ff3dae9 --- /dev/null +++ b/server/djangoapp/djangoapp/bin/GET @@ -0,0 +1,561 @@ +#!/usr/bin/perl + +# Simple user agent using LWP library. + +=head1 NAME + +lwp-request - Simple command line user agent + +=head1 SYNOPSIS + +B [B<-afPuUsSedvhx>] [B<-m> I] [B<-b> I] [B<-t> I] + [B<-i> I] [B<-c> I] + [B<-C> I] [B<-p> I] [B<-o> I] I... + +=head1 DESCRIPTION + +This program can be used to send requests to WWW servers and your +local file system. The request content for POST and PUT +methods is read from stdin. The content of the response is printed on +stdout. Error messages are printed on stderr. The program returns a +status value indicating the number of URLs that failed. + +The options are: + +=over 4 + +=item -m + +Set which method to use for the request. If this option is not used, +then the method is derived from the name of the program. + +=item -f + +Force request through, even if the program believes that the method is +illegal. The server might reject the request eventually. + +=item -b + +This URI will be used as the base URI for resolving all relative URIs +given as argument. + +=item -t + +Set the timeout value for the requests. The timeout is the amount of +time that the program will wait for a response from the remote server +before it fails. The default unit for the timeout value is seconds. +You might append "m" or "h" to the timeout value to make it minutes or +hours, respectively. The default timeout is '3m', i.e. 3 minutes. + +=item -i