Skip to content

Offline work #165

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 10 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"
18 changes: 18 additions & 0 deletions server/database/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,34 @@ 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
Expand Down
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://joeperkinspt-3030.theiadockernext-0-labs-prod-theiak8s-4-tor01.proxy.cognitiveclass.ai/
sentiment_analyzer_url=https://sentianalyzer.1sz97p1eisbw.us-south.codeengine.appdomain.cloud/
26 changes: 24 additions & 2 deletions server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# from django.contrib import admin
# from .models import related models
from django.contrib import admin
from .models import CarMake, CarModel


class CarModelInline(admin.StackedInline):
model = CarModel
extra = 1


class CarModelAdmin(admin.ModelAdmin):
list_display = ['name', 'dealer_id', 'car_make', 'car_type', 'year']
search_fields = ['name', 'car_type']
list_filter = ['car_make', 'car_type', 'year']


class CarMakeAdmin(admin.ModelAdmin):
inlines = [CarModelInline]
list_display = ['name', 'description']
search_fields = ['name']


# Register models with their respective admin classes
admin.site.register(CarMake, CarMakeAdmin)
admin.site.register(CarModel, CarModelAdmin)


# Register your models here.
Expand Down
41 changes: 38 additions & 3 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.utils.timezone import now
# from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.timezone import now
from django.core.validators import MaxValueValidator, MinValueValidator


# Create your models here.
Expand All @@ -13,6 +13,14 @@
# - Any other fields you would like to include in car make model
# - __str__ method to print a car make object

class CarMake(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
return self.name

# <HINT> Create a Car Model model `class CarModel(models.Model):`:
# - Many-To-One relationship to Car Make model (One Car Make has many
Expand All @@ -23,3 +31,30 @@
# - 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 CarModel(models.Model):
CAR_TYPES = [
('SEDAN', 'Sedan'),
('SUV', 'SUV'),
('WAGON', 'Wagon'),
('SPORT', 'Sport'),
('COUPE', 'Coupe'),
('MINIVAN', 'Minivan'),
('PICKUP', 'Pickup'),
]

car_make = models.ForeignKey(CarMake, on_delete=models.CASCADE)
dealer_id = models.IntegerField()
name = models.CharField(max_length=100)
car_type = models.CharField(max_length=10, choices=CAR_TYPES)
year = models.IntegerField(
validators=[
MinValueValidator(2015),
MaxValueValidator(2023)
]
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
return f"{self.car_make.name} {self.name} ({self.year})"
39 changes: 38 additions & 1 deletion server/djangoapp/populate.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
from .models import CarMake, CarModel

def initiate():
print("Populate not implemented. Add data manually")
car_make_data = [
{"name": "NISSAN", "description": "Great cars. Japanese technology"},
{"name": "Mercedes", "description": "Great cars. German technology"},
{"name": "Audi", "description": "Great cars. German technology"},
{"name": "Kia", "description": "Great cars. Korean technology"},
{"name": "Toyota", "description": "Great cars. Japanese technology"},
]
car_make_instances = []
for data in car_make_data:
car_make_instances.append(CarMake.objects.create(name=data['name'], description=data['description']))

car_model_data = [
{"name": "Pathfinder", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[0]},
{"name": "Qashqai", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[0]},
{"name": "XTRAIL", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[0]},
{"name": "A-Class", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[1]},
{"name": "C-Class", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[1]},
{"name": "E-Class", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[1]},
{"name": "A4", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[2]},
{"name": "A5", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[2]},
{"name": "A6", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[2]},
{"name": "Sorrento", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[3]},
{"name": "Carnival", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[3]},
{"name": "Cerato", "car_type": "Sedan", "year": 2023, "car_make": car_make_instances[3]},
{"name": "Corolla", "car_type": "Sedan", "year": 2023, "car_make": car_make_instances[4]},
{"name": "Camry", "car_type": "Sedan", "year": 2023, "car_make": car_make_instances[4]},
{"name": "Kluger", "car_type": "SUV", "year": 2023, "car_make": car_make_instances[4]},
]
for data in car_model_data:
CarModel.objects.create(
name=data['name'],
car_make=data['car_make'],
car_type=data['car_type'],
year=data['year'],
dealer_id=1 # Adding a default dealer_id since it's required
)
37 changes: 35 additions & 2 deletions server/djangoapp/restapis.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Uncomment the imports below before you add the function code
# import requests
import requests
import os
from dotenv import load_dotenv


load_dotenv()

backend_url = os.getenv(
Expand All @@ -12,11 +13,43 @@
default="http://localhost:5050/")

# def get_request(endpoint, **kwargs):
def get_request(endpoint, **kwargs):
params = ""
if(kwargs):
for key,value in kwargs.items():
params=params+key+"="+value+"&"

request_url = backend_url+endpoint+"?"+params

print("GET from {} ".format(request_url))
try:
# Call get method of requests library with URL and parameters
response = requests.get(request_url)
return response.json()
except:
# If any error occurs
print("Network exception occurred")
# Add code for get requests to back end

# def analyze_review_sentiments(text):
def analyze_review_sentiments(text):
request_url = sentiment_analyzer_url+"analyze/"+text
try:
# Call get method of requests library with URL and parameters
response = requests.get(request_url)
return response.json()
except Exception as err:
print(f"Unexpected {err=}, {type(err)=}")
print("Network exception occurred")
# request_url = sentiment_analyzer_url+"analyze/"+text
# Add code for retrieving sentiments

# def post_review(data_dict):
# Add code for posting review
def post_review(data_dict):
request_url = backend_url+"/insert_review"
try:
response = requests.post(request_url,json=data_dict)
print(response.json())
return response.json()
except:
print("Network exception occurred")
28 changes: 20 additions & 8 deletions server/djangoapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# Uncomment the imports before you add the code
# from django.urls import path
from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
# from . import views
from . import views

app_name = 'djangoapp'
urlpatterns = [
# # path for registration

# path for registration
path(route='register', view=views.registration, name='register'),
# path for login
# path(route='login', view=views.login_user, name='login'),

# path for dealer reviews view
path(route='login', view=views.login_user, name='login'),
#logout
path(route='logout', view=views.logout_request, name='logout'),

# path for dealer
path(route='get_dealers/', view=views.get_dealerships, name='get_dealers'),
#
path(route='get_dealers/<str:state>', view=views.get_dealerships, name='get_dealers_by_state'),
# path for add a review view


# dealer id
path(route='dealer/<int:dealer_id>', view=views.get_dealer_details, name='dealer_details'),
# dealer reviews
path(route='reviews/dealer/<int:dealer_id>', view=views.get_dealer_reviews, name='dealer_reviews'),
# add review
path(route='add_review', view=views.add_review, name='add_review'),
# path get cars
path(route='get_cars', view=views.get_cars, name='getcars'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Loading