Skip to content

Commit

Permalink
feat: Implement APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowtham1729 committed Dec 13, 2023
1 parent 25f5a31 commit da961c5
Show file tree
Hide file tree
Showing 40 changed files with 5,626 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@

STATIC_URL = "api/static/"
STATIC_ROOT = Path(BASE_DIR, "static")
STATICFILES_DIRS = (Path(BASE_DIR, "api", "static"),)

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
Expand Down
10 changes: 10 additions & 0 deletions applications/backend/django_server/news/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import django_filters
from .models import News


class NewsFilter(django_filters.FilterSet):
date = django_filters.DateFilter(field_name="publish_time", lookup_expr="date")

class Meta:
model = News
fields = ["category", "symbol", "src", "need_attention", "date"]
21 changes: 21 additions & 0 deletions applications/backend/django_server/news/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from rest_framework import serializers

from .models import Analysis, News, Ticker


class NewsSerializer(serializers.ModelSerializer):
class Meta:
model = News
fields = "__all__"


class TickerSerializer(serializers.ModelSerializer):
class Meta:
model = Ticker
fields = "__all__"


class AnalysisSerializer(serializers.ModelSerializer):
class Meta:
model = Analysis
fields = "__all__"
11 changes: 9 additions & 2 deletions applications/backend/django_server/news/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from django.urls import path
from django.urls import include, path
from rest_framework.routers import DefaultRouter

from . import views

router = DefaultRouter()
router.register(r"news", views.NewsViewSet)
router.register(r"tickers", views.TickerViewSet)
router.register(r"analysis", views.AnalysisViewSet)

urlpatterns = [
path("", views.index, name="main_index"),
# path("", views.index, name="main_index"),
path("", include(router.urls)),
]
71 changes: 62 additions & 9 deletions applications/backend/django_server/news/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,64 @@
from django.http import JsonResponse
from django.utils import timezone

from rest_framework import viewsets

# Create your views here.
def index(request):
return JsonResponse(
{
"message": "Hello, world!!",
"status": "ok",
}
)
from .models import Analysis, News, Ticker
from .serializers import AnalysisSerializer, NewsSerializer, TickerSerializer


class NewsViewSet(viewsets.ReadOnlyModelViewSet):
queryset = News.objects.all()
serializer_class = NewsSerializer

def get_queryset(self):
queryset = News.objects.all()
category = self.request.query_params.get("category")
symbol = self.request.query_params.get("symbol")
src = self.request.query_params.get("src")
need_attention = self.request.query_params.get("need_attention")
date_param = self.request.query_params.get("date")
if category:
queryset = queryset.filter(category=category)
if symbol:
queryset = queryset.filter(symbol=symbol)
if src:
queryset = queryset.filter(src=src)
if need_attention:
queryset = queryset.filter(need_attention=need_attention)
if date_param:
try:
date = timezone.datetime.strptime(date_param, "%Y-%m-%d").date()
queryset = queryset.filter(publish_time__date=date)
except ValueError:
pass
return queryset


class TickerViewSet(viewsets.ModelViewSet):
queryset = Ticker.objects.all()
serializer_class = TickerSerializer


class AnalysisViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Analysis.objects.all()
serializer_class = AnalysisSerializer

def get_queryset(self):
queryset = Analysis.objects.all()
category = self.request.query_params.get("category")
symbol = self.request.query_params.get("symbol")
need_attention = self.request.query_params.get("need_attention")
date_param = self.request.query_params.get("date")
if category:
queryset = queryset.filter(category=category)
if symbol:
queryset = queryset.filter(symbol=symbol)
if need_attention:
queryset = queryset.filter(need_attention=need_attention)
if date_param:
try:
date = timezone.datetime.strptime(date_param, "%Y-%m-%d").date()
queryset = queryset.filter(date=date)
except ValueError:
pass
return queryset

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/*
This CSS file contains some tweaks specific to the included Bootstrap theme.
It's separate from `style.css` so that it can be easily overridden by replacing
a single block in the template.
*/

.form-actions {
background: transparent;
border-top-color: transparent;
padding-top: 0;
text-align: right;
}

#generic-content-form textarea {
font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
font-size: 80%;
}

.navbar-inverse .brand a {
color: #999999;
}
.navbar-inverse .brand:hover a {
color: white;
text-decoration: none;
}

/* custom navigation styles */
.navbar {
width: 100%;
position: fixed;
left: 0;
top: 0;
}

.navbar {
background: #2C2C2C;
color: white;
border: none;
border-top: 5px solid #A30000;
border-radius: 0px;
}

.navbar .nav li, .navbar .nav li a, .navbar .brand:hover {
color: white;
}

.nav-list > .active > a, .nav-list > .active > a:hover {
background: #2C2C2C;
}

.navbar .dropdown-menu li a, .navbar .dropdown-menu li {
color: #A30000;
}

.navbar .dropdown-menu li a:hover {
background: #EEEEEE;
color: #C20000;
}

ul.breadcrumb {
margin: 70px 0 0 0;
}

.breadcrumb li.active a {
color: #777;
}

.pagination>.disabled>a,
.pagination>.disabled>a:hover,
.pagination>.disabled>a:focus {
cursor: not-allowed;
pointer-events: none;
}

.pager>.disabled>a,
.pager>.disabled>a:hover,
.pager>.disabled>a:focus {
pointer-events: none;
}

.pager .next {
margin-left: 10px;
}

/*=== dabapps bootstrap styles ====*/

html {
width:100%;
background: none;
}

/*body, .navbar .container-fluid {
max-width: 1150px;
margin: 0 auto;
}*/

body {
background: url("../img/grid.png") repeat-x;
background-attachment: fixed;
}

#content {
margin: 0;
padding-bottom: 60px;
}

/* sticky footer and footer */
html, body {
height: 100%;
}

.wrapper {
position: relative;
top: 0;
left: 0;
padding-top: 60px;
margin: -60px 0;
min-height: 100%;
}

.form-switcher {
margin-bottom: 0;
}

.well {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}

.well .form-actions {
padding-bottom: 0;
margin-bottom: 0;
}

.well form {
margin-bottom: 0;
}

.nav-tabs {
border: 0;
}

.nav-tabs > li {
float: right;
}

.nav-tabs li a {
margin-right: 0;
}

.nav-tabs > .active > a {
background: #F5F5F5;
}

.nav-tabs > .active > a:hover {
background: #F5F5F5;
}

.tabbable.first-tab-active .tab-content {
border-top-right-radius: 0;
}

footer {
position: absolute;
bottom: 0;
left: 0;
clear: both;
z-index: 10;
height: 60px;
width: 95%;
margin: 0 2.5%;
}

footer p {
text-align: center;
color: gray;
border-top: 1px solid #DDDDDD;
padding-top: 10px;
}

footer a {
color: gray !important;
font-weight: bold;
}

footer a:hover {
color: gray;
}

.page-header {
border-bottom: none;
padding-bottom: 0px;
margin: 0;
}

/* custom general page styles */
.hero-unit h1, .hero-unit h2 {
color: #A30000;
}

body a {
color: #A30000;
}

body a:hover {
color: #c20000;
}

.request-info {
clear:both;
}

.horizontal-checkbox label {
padding-top: 0;
}

.horizontal-checkbox label {
padding-top: 0 !important;
}

.horizontal-checkbox input {
float: left;
width: 20px;
margin-top: 3px;
}

.modal-footer form {
margin-left: 5px;
margin-right: 5px;
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit da961c5

Please sign in to comment.