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

first commit #83

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c716708
first commit
rosaspace Jul 30, 2024
27798fe
add screenshots
rosaspace Jul 30, 2024
9e6cc42
add signup login and logout end-to-end
rosaspace Aug 1, 2024
c64af23
dealer screenshots
rosaspace Aug 1, 2024
b192df7
dealer app endpoints
rosaspace Aug 2, 2024
2f472f0
add carModel and carMake django models
rosaspace Aug 2, 2024
3e75fbf
add carModel and cars screenshots
rosaspace Aug 2, 2024
19d0dca
Create Django Proxy Services of Backend APIs
rosaspace Aug 2, 2024
00e2818
Add Dynamic Pages
rosaspace Aug 3, 2024
9d81088
add main.yml
rosaspace Aug 5, 2024
1aafe04
update main.yml
rosaspace Aug 5, 2024
365a30a
format python files
rosaspace Aug 5, 2024
1ab12bb
format python files
rosaspace Aug 6, 2024
d9035c3
format python files
rosaspace Aug 6, 2024
9b067f4
format pthon files
rosaspace Aug 6, 2024
f468947
format python files
rosaspace Aug 6, 2024
0d6fc38
format js files
rosaspace Aug 6, 2024
4109b8f
format js files
rosaspace Aug 6, 2024
8e94078
format python files
rosaspace Aug 6, 2024
37060d0
format python files
rosaspace Aug 6, 2024
2829177
format python files
rosaspace Aug 6, 2024
60ecb23
format python files
rosaspace Aug 6, 2024
6921e72
format python files
rosaspace Aug 6, 2024
150be2b
Deploy the application
rosaspace Aug 6, 2024
b3a7f36
add finally print
rosaspace Aug 6, 2024
e758c96
modify SN Labs namespace
rosaspace Aug 7, 2024
b85b872
modify url
rosaspace Aug 8, 2024
c71f7f1
format python file
rosaspace Aug 8, 2024
b7d8b6b
fix requests error
rosaspace Aug 8, 2024
f477c32
commit add Dealers Page screenshot
rosaspace Aug 8, 2024
5939d23
fix settings
rosaspace Aug 9, 2024
f39c1f0
fix settings
rosaspace Aug 9, 2024
2aded7e
fix app.js error
rosaspace Aug 9, 2024
b7dea90
fix add_review and format py file
rosaspace Aug 10, 2024
c1292ac
add deployed screenshots
rosaspace Aug 10, 2024
26761d2
Update README.md
rosaspace Nov 18, 2024
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"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ dmypy.json

# Pyre type checker
.pyre/
server/djangoproj/settings.py
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# coding-project-template
# IBM fullstack developer homework

## Folder screanshots

website screanshots

## Folder server

source code
Binary file added screenshots/CICD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/about_us.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/added_review.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/admin_login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/admin_logout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/car models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/cars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/contact_us.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/dealer_details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/dealer_id_reviews.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/dealer_review.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/dealersbystate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/dealership_review_submission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/dealerships.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/deployed_add_review.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/deployed_dealer_detail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/deployed_landingpage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/deployed_loggedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/django_server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/get_dealers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/get_dealers_loggedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/githab-URL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/kansasDealers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/login1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/login2.png
Binary file added screenshots/logout.png
Binary file added screenshots/sentiment_analyzer.png
Binary file added screenshots/sign-up.png
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"]
52 changes: 36 additions & 16 deletions server/database/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* 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 +22,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 +35,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 @@ -59,34 +61,52 @@ 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
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
2 changes: 2 additions & 0 deletions server/database/dealership.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* jshint esversion: 6 */

const mongoose = require('mongoose');

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

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: 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-rosaspace/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://rosaspace-3030.theiadockernext-1-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai
sentiment_analyzer_url=https://sentianalyzer.1kfb1z37z4ju.us-south.codeengine.appdomain.cloud/
9 changes: 7 additions & 2 deletions server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# from django.contrib import admin
# from .models import related models
from django.contrib import admin

# from .models import related models
from .models import CarMake, CarModel

# Register your models here.

Expand All @@ -11,3 +12,7 @@
# CarMakeAdmin class with CarModelInline

# Register models here

# Registering models with their respective admins
admin.site.register(CarMake)
admin.site.register(CarModel)
2 changes: 1 addition & 1 deletion server/djangoapp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class DjangoappConfig(AppConfig):
name = 'djangoapp'
name = "djangoapp"
35 changes: 33 additions & 2 deletions server/djangoapp/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Uncomment the following imports before adding the Model code

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


# Create your models here.
Expand All @@ -23,3 +23,34 @@
# - 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()
# Other fields as needed

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


class CarModel(models.Model):
# Many-to-One relationship
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)])
# Other fields as needed

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