Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ECE651_Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chris Li
ECE651_Backend
Compare revisions
87229152be648a480b9e4f4896a38ea8484739f1 to 7a191d0f6de1b722f2b11e3c3332a2f39e00525b
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
c58li/ece651_backend
Select target project
No results found
7a191d0f6de1b722f2b11e3c3332a2f39e00525b
Select Git revision
Swap
Target
c58li/ece651_backend
Select target project
c58li/ece651_backend
1 result
87229152be648a480b9e4f4896a38ea8484739f1
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (7)
Merge branch 'yrq/feature/bill-api'
· 774060e0
Yirou Qiu
authored
2 years ago
774060e0
Merge branch 'yrq/feature/bill-api'
· b2db7fe2
Yirou Qiu
authored
2 years ago
b2db7fe2
Added an api for searching the sum of price in different categories
· f1eb239a
Yirou Qiu
authored
2 years ago
f1eb239a
delete useless code
· c8a84d71
Yirou Qiu
authored
2 years ago
c8a84d71
add date search
· ec5af473
Yirou Qiu
authored
2 years ago
ec5af473
change search
· 85799954
Yirou Qiu
authored
2 years ago
85799954
Merge branch 'yrq/feature/billSumPrice' into 'main'
· 7a191d0f
Yirou QIU
authored
1 year ago
Yrq/feature/bill sum price See merge request
!8
7a191d0f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
core/api/billPriceSum.py
+48
-0
48 additions, 0 deletions
core/api/billPriceSum.py
core/api/billSearch.py
+0
-1
0 additions, 1 deletion
core/api/billSearch.py
core/models/bill.py
+0
-13
0 additions, 13 deletions
core/models/bill.py
core/urls.py
+5
-1
5 additions, 1 deletion
core/urls.py
with
53 additions
and
15 deletions
core/api/billPriceSum.py
0 → 100644
View file @
7a191d0f
from
rest_framework
import
generics
,
response
from
core.models.bill
import
Bill
,
BillSearchQuerySet
from
core.serializers.bill
import
BillSerializer
from
rest_framework
import
authentication
from
django.db.models
import
Sum
class
BillSumPriceListView
(
generics
.
ListAPIView
):
queryset
=
Bill
.
objects
.
all
()
serializer_class
=
BillSerializer
authentication_classes
=
[
authentication
.
SessionAuthentication
,
authentication
.
TokenAuthentication
]
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
item
=
request
.
GET
.
get
(
'
item
'
)
categorieModel
=
{
1
:
"
Food
"
,
2
:
"
Groceries
"
,
3
:
"
Transportation
"
,
4
:
"
clothing
"
,
5
:
"
Entertainment
"
,
6
:
"
Bill
"
,
7
:
"
Sports
"
,
8
:
"
Electronics
"
,
9
:
"
Travel
"
,
10
:
"
House & Car
"
,
11
:
"
Others
"
,
}
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
user
=
None
if
self
.
request
.
user
.
is_authenticated
:
user
=
self
.
request
.
user
data
=
{}
for
i
in
range
(
1
,
12
):
qs
=
BillSearchQuerySet
(
Bill
).
searchCategories
(
query
=
i
,
user
=
user
)
if
item
==
'
today
'
:
qs
=
qs
.
searchToday
(
user
=
user
)
elif
item
==
'
month
'
:
qs
=
qs
.
searchThisMonth
(
user
=
user
)
total_price
=
qs
.
aggregate
(
Sum
(
'
price
'
))
data
[
categorieModel
[
i
]]
=
total_price
[
'
price__sum
'
]
return
response
.
Response
(
data
)
BillSumPriceListViewAPI
=
BillSumPriceListView
.
as_view
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
core/api/billSearch.py
View file @
7a191d0f
...
@@ -35,5 +35,4 @@ class SearchBillListView(generics.ListAPIView):
...
@@ -35,5 +35,4 @@ class SearchBillListView(generics.ListAPIView):
result
=
qs
.
searchToday
(
user
=
user
)
result
=
qs
.
searchToday
(
user
=
user
)
elif
item
==
"
title
"
:
elif
item
==
"
title
"
:
result
=
qs
.
searchTitle
(
keyword
,
user
=
user
)
result
=
qs
.
searchTitle
(
keyword
,
user
=
user
)
print
(
result
)
return
result
return
result
\ No newline at end of file
This diff is collapsed.
Click to expand it.
core/models/bill.py
View file @
7a191d0f
...
@@ -41,20 +41,7 @@ class BillSearchQuerySet(models.QuerySet):
...
@@ -41,20 +41,7 @@ class BillSearchQuerySet(models.QuerySet):
if
user
is
not
None
:
if
user
is
not
None
:
qs
=
self
.
filter
(
user
=
user
).
filter
(
lookup
)
qs
=
self
.
filter
(
user
=
user
).
filter
(
lookup
)
return
qs
return
qs
# def searchTitle(self, keyword, user=None):
# lookup = Q(title__contains = keyword)
# qs = self.filter(lookup)
# if user is not None:
# qs = self.filter(user=user).filter(lookup)
# return qs
# def categorieAmount(self, date, categories, user=None):
# if date == "day":
# qs = self.searchCategories(categories, user=user).searchToday(user=user)
# elif date == "month":
# qs = self.searchCategories(categories, user=user).searchThisMonth(user=user)
class
BillManager
(
models
.
Manager
):
class
BillManager
(
models
.
Manager
):
...
...
This diff is collapsed.
Click to expand it.
core/urls.py
View file @
7a191d0f
...
@@ -8,6 +8,7 @@ from core.api.profile import ProfileViewSet
...
@@ -8,6 +8,7 @@ from core.api.profile import ProfileViewSet
from
core.api.coupon
import
CouponViewSet
from
core.api.coupon
import
CouponViewSet
from
core.api.bill
import
*
from
core.api.bill
import
*
from
core.api.billSearch
import
SearchBillListView
from
core.api.billSearch
import
SearchBillListView
from
core.api.billPriceSum
import
BillSumPriceListViewAPI
router
=
routers
.
DefaultRouter
()
router
=
routers
.
DefaultRouter
()
...
@@ -36,7 +37,10 @@ urlpatterns += [
...
@@ -36,7 +37,10 @@ urlpatterns += [
path
(
'
api/bill/<uuid:pk>/
'
,
bill_detail_api
,
name
=
"
bill-detail
"
),
path
(
'
api/bill/<uuid:pk>/
'
,
bill_detail_api
,
name
=
"
bill-detail
"
),
# bill search
# bill search
path
(
'
api/bill/search/
'
,
SearchBillListView
.
as_view
(),
name
=
"
bill-search
"
)
path
(
'
api/bill/search/
'
,
SearchBillListView
.
as_view
(),
name
=
"
bill-search
"
),
# bill price list searched by categories
path
(
'
api/bill/price-sum/
'
,
BillSumPriceListViewAPI
,
name
=
"
bill-price-sum
"
)
]
]
...
...
This diff is collapsed.
Click to expand it.