Skip to content

About us changes #174

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 6 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
19 changes: 19 additions & 0 deletions server/database/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mongoose.connect("mongodb://mongo_db:27017/",{'dbName':'dealershipsDB'});
const Reviews = require('./review');

const Dealerships = require('./dealership');
const dealership = require('./dealership');

try {
Reviews.deleteMany({}).then(()=>{
Expand Down Expand Up @@ -59,16 +60,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
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)
32 changes: 29 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 @@ -12,6 +12,13 @@
# - Description
# - 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()
# Other fields as needed

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


# <HINT> Create a Car Model model `class CarModel(models.Model):`:
Expand All @@ -23,3 +30,22 @@
# - 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_make = models.ForeignKey(CarMake, on_delete=models.CASCADE) # Many-to-One relationship
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
38 changes: 37 additions & 1 deletion server/djangoapp/populate.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
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']))


# Create CarModel instances with the corresponding CarMake instances
car_model_data = [
{"name":"Pathfinder", "type":"SUV", "year": 2023, "car_make":car_make_instances[0]},
{"name":"Qashqai", "type":"SUV", "year": 2023, "car_make":car_make_instances[0]},
{"name":"XTRAIL", "type":"SUV", "year": 2023, "car_make":car_make_instances[0]},
{"name":"A-Class", "type":"SUV", "year": 2023, "car_make":car_make_instances[1]},
{"name":"C-Class", "type":"SUV", "year": 2023, "car_make":car_make_instances[1]},
{"name":"E-Class", "type":"SUV", "year": 2023, "car_make":car_make_instances[1]},
{"name":"A4", "type":"SUV", "year": 2023, "car_make":car_make_instances[2]},
{"name":"A5", "type":"SUV", "year": 2023, "car_make":car_make_instances[2]},
{"name":"A6", "type":"SUV", "year": 2023, "car_make":car_make_instances[2]},
{"name":"Sorrento", "type":"SUV", "year": 2023, "car_make":car_make_instances[3]},
{"name":"Carnival", "type":"SUV", "year": 2023, "car_make":car_make_instances[3]},
{"name":"Cerato", "type":"Sedan", "year": 2023, "car_make":car_make_instances[3]},
{"name":"Corolla", "type":"Sedan", "year": 2023, "car_make":car_make_instances[4]},
{"name":"Camry", "type":"Sedan", "year": 2023, "car_make":car_make_instances[4]},
{"name":"Kluger", "type":"SUV", "year": 2023, "car_make":car_make_instances[4]},
# Add more CarModel instances as needed
]

for data in car_model_data:
CarModel.objects.create(name=data['name'], car_make=data['car_make'], type=data['type'], year=data['year'])
11 changes: 8 additions & 3 deletions server/djangoapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# 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(route='registration', view=views.registration, name='registration'),

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



# path for dealer reviews view

Expand Down
63 changes: 54 additions & 9 deletions server/djangoapp/views.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Uncomment the required imports before adding the code

# from django.shortcuts import render
# from django.http import HttpResponseRedirect, HttpResponse
# from django.contrib.auth.models import User
# from django.shortcuts import get_object_or_404, render, redirect
# from django.contrib.auth import logout
# from django.contrib import messages
# from datetime import datetime
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, render, redirect
from django.contrib.auth import logout
from django.contrib import messages
from datetime import datetime

from django.http import JsonResponse
from django.contrib.auth import login, authenticate
import logging
import json
from django.views.decorators.csrf import csrf_exempt
from .models import CarMake, CarModel
# from .populate import initiate


Expand All @@ -21,6 +22,16 @@


# Create your views here.
def get_cars(request):
count = CarMake.objects.filter().count()
print(count)
if(count == 0):
initiate()
car_models = CarModel.objects.select_related('car_make')
cars = []
for car_model in car_models:
cars.append({"CarModel": car_model.name, "CarMake": car_model.car_make.name})
return JsonResponse({"CarModels":cars})

# Create a `login_request` view to handle sign in request
@csrf_exempt
Expand All @@ -39,13 +50,47 @@ def login_user(request):
return JsonResponse(data)

# Create a `logout_request` view to handle sign out request
# def logout_request(request):
def logout_request(request):
# ...

logout(request)
data = {"userName":""}
return JsonResponse(data)
# Create a `registration` view to handle sign up request
# @csrf_exempt
# def registration(request):
# ...
@csrf_exempt
def registration(request):
context = {}

data = json.loads(request.body)
username = data['userName']
password = data['password']
first_name = data['firstName']
last_name = data['lastName']
email = data['email']
username_exist = False
email_exist = False
try:
# Check if user already exists
User.objects.get(username=username)
username_exist = True
except:
# If not, simply log this is a new user
logger.debug("{} is new user".format(username))

# If it is a new user
if not username_exist:
# Create user in auth_user table
user = User.objects.create_user(username=username, first_name=first_name, last_name=last_name,password=password, email=email)
# Login the user and redirect to list page
login(request, user)
data = {"userName":username,"status":"Authenticated"}
return JsonResponse(data)
else :
data = {"userName":username,"error":"Already Registered"}
return JsonResponse(data)


# # Update the `get_dealerships` view to render the index page with
# a list of dealerships
Expand Down
16 changes: 12 additions & 4 deletions server/djangoproj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
CSRF_TRUSTED_ORIGINS = []
ALLOWED_HOSTS = ['127.0.0.1', 'https://vamsikalapal-8000.theianext-0-labs-prod-misc-tools-us-east-0.proxy.cognitiveclass.ai/']
CSRF_TRUSTED_ORIGINS = ['https://vamsikalapal-8000.theianext-0-labs-prod-misc-tools-us-east-0.proxy.cognitiveclass.ai/']

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [],
Expand Down Expand Up @@ -61,7 +61,11 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
os.path.join(BASE_DIR, 'frontend/static'),
os.path.join(BASE_DIR, 'frontend/build'),
os.path.join(BASE_DIR, 'frontend/build/static'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -134,5 +138,9 @@

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

STATICFILES_DIRS = []
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'frontend/static'),
os.path.join(BASE_DIR, 'frontend/build'),
os.path.join(BASE_DIR, 'frontend/build/static'),
]

4 changes: 4 additions & 0 deletions server/djangoproj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
path('admin/', admin.site.urls),
path('djangoapp/', include('djangoapp.urls')),
path('', TemplateView.as_view(template_name="Home.html")),
path('about/', TemplateView.as_view(template_name="About.html")),
path('contact/', TemplateView.as_view(template_name="Contact.html")),
path('login/', TemplateView.as_view(template_name="index.html")),
path('register/', TemplateView.as_view(template_name="index.html")),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
30 changes: 27 additions & 3 deletions server/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import LoginPanel from "./components/Login/Login"
import { Routes, Route } from "react-router-dom";
import Register from "./components/Register/Register";

function App() {
return (
<Routes>
<Route path="/login" element={<LoginPanel />} />
<Route path="/Register" element={<Register />} />
</Routes>
);
}
Expand Down
Loading