Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
warpinfra
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
infrastruktur
warpinfra
Commits
a816c30e
Commit
a816c30e
authored
8 years ago
by
Christian Dresen
Browse files
Options
Downloads
Patches
Plain Diff
[WarpPay] Backend API modifications
parent
f64c3970
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
www/web/warppay/admin.py
+4
-0
4 additions, 0 deletions
www/web/warppay/admin.py
www/web/warppay/models.py
+4
-1
4 additions, 1 deletion
www/web/warppay/models.py
www/web/warppay/urls.py
+1
-1
1 addition, 1 deletion
www/web/warppay/urls.py
www/web/warppay/views.py
+22
-10
22 additions, 10 deletions
www/web/warppay/views.py
with
31 additions
and
12 deletions
www/web/warppay/admin.py
+
4
−
0
View file @
a816c30e
...
@@ -13,4 +13,8 @@ class ProductAdmin(admin.ModelAdmin):
...
@@ -13,4 +13,8 @@ class ProductAdmin(admin.ModelAdmin):
@admin.register
(
UserCredit
)
@admin.register
(
UserCredit
)
class
UserCreditAdmin
(
admin
.
ModelAdmin
):
class
UserCreditAdmin
(
admin
.
ModelAdmin
):
pass
@admin.register
(
Transaction
)
class
TransactionAdmin
(
admin
.
ModelAdmin
):
pass
pass
\ No newline at end of file
This diff is collapsed.
Click to expand it.
www/web/warppay/models.py
+
4
−
1
View file @
a816c30e
...
@@ -26,7 +26,7 @@ class ProductSerializer(serializers.ModelSerializer):
...
@@ -26,7 +26,7 @@ class ProductSerializer(serializers.ModelSerializer):
category
=
serializers
.
StringRelatedField
()
category
=
serializers
.
StringRelatedField
()
class
Meta
:
class
Meta
:
model
=
Product
model
=
Product
fields
=
[
'
id
'
,
'
name
'
,
'
price
'
,
'
category
'
,
'
count
'
]
fields
=
[
'
id
'
,
'
name
'
,
'
price
_vk
'
,
'
category
'
,
'
stock_
count
'
]
class
Transaction
(
models
.
Model
):
class
Transaction
(
models
.
Model
):
...
@@ -36,6 +36,9 @@ class Transaction(models.Model):
...
@@ -36,6 +36,9 @@ class Transaction(models.Model):
amount
=
models
.
FloatField
()
amount
=
models
.
FloatField
()
cash_paid
=
models
.
BooleanField
(
default
=
False
)
cash_paid
=
models
.
BooleanField
(
default
=
False
)
def
__str__
(
self
):
return
str
(
self
.
amount
)
#self.product.name+" - "+self.amount
class
TransactionLog
(
models
.
Model
):
class
TransactionLog
(
models
.
Model
):
uid
=
models
.
CharField
(
max_length
=
100
)
uid
=
models
.
CharField
(
max_length
=
100
)
...
...
This diff is collapsed.
Click to expand it.
www/web/warppay/urls.py
+
1
−
1
View file @
a816c30e
...
@@ -7,6 +7,6 @@ urlpatterns = [
...
@@ -7,6 +7,6 @@ urlpatterns = [
url
(
r
'
^api/users/(?P<user_id>\w+)/$
'
,
views
.
user_list
),
url
(
r
'
^api/users/(?P<user_id>\w+)/$
'
,
views
.
user_list
),
url
(
r
'
^api/products/$
'
,
views
.
product_list
),
url
(
r
'
^api/products/$
'
,
views
.
product_list
),
url
(
r
'
^api/gen_token/$
'
,
views
.
gen_token
),
url
(
r
'
^api/gen_token/$
'
,
views
.
gen_token
),
url
(
r
'
^api/transaction/$
'
,
views
.
transaction
),
url
(
r
'
^api/transaction/
(?P<user_id>\w+)/
$
'
,
views
.
transaction
),
]
]
This diff is collapsed.
Click to expand it.
www/web/warppay/views.py
+
22
−
10
View file @
a816c30e
...
@@ -50,6 +50,7 @@ def user_list(request, user_id = 0):
...
@@ -50,6 +50,7 @@ def user_list(request, user_id = 0):
if
not
user_id
:
if
not
user_id
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
try
:
try
:
print
(
request
.
data
)
user
=
UserCredit
.
objects
.
get
(
uid
=
user_id
)
user
=
UserCredit
.
objects
.
get
(
uid
=
user_id
)
if
"
card_id
"
in
request
.
data
:
if
"
card_id
"
in
request
.
data
:
try
:
try
:
...
@@ -90,27 +91,38 @@ def user_list(request, user_id = 0):
...
@@ -90,27 +91,38 @@ def user_list(request, user_id = 0):
@api_view
([
'
PUT
'
])
@api_view
([
'
PUT
'
])
#@authentication_classes((TokenAuthentication,))
#@authentication_classes((TokenAuthentication,))
#@permission_classes((IsAuthenticated,))
#@permission_classes((IsAuthenticated,))
def
transaction
(
request
):
def
transaction
(
request
,
user_id
=
None
):
if
request
.
method
==
'
PUT
'
:
if
request
.
method
==
'
PUT
'
:
if
'
t
ype
'
not
in
request
.
data
or
'
amount
'
not
in
request
.
data
or
'
uid
'
not
in
request
.
data
or
(
'
amount
'
in
request
.
data
and
int
(
request
.
data
[
'
amount
'
]
<
0
))
:
if
'
t
rans_type
'
not
in
request
.
data
or
not
user_id
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
try
:
try
:
u
=
UserCredit
.
objects
.
get
(
uid
=
str
(
request
.
data
[
'
uid
'
]
))
u
=
UserCredit
.
objects
.
get
(
uid
=
str
(
user_id
))
except
ObjectDoesNotExist
:
except
ObjectDoesNotExist
:
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
return
Response
(
status
=
status
.
HTTP_404_NOT_FOUND
)
t
=
Transaction
()
t
=
Transaction
()
t
.
type
=
request
.
data
[
'
type
'
]
t
.
type
=
int
(
request
.
data
[
'
trans_type
'
])
t
.
amount
=
float
(
request
.
data
[
'
amount
'
])
if
request
.
data
[
'
type
'
]
==
1
:
if
t
.
type
==
1
:
u
.
credit
+=
t
.
amount
if
'
amount
'
not
in
request
.
data
or
(
'
amount
'
in
request
.
data
and
float
(
request
.
data
[
'
amount
'
]
<
0
)):
elif
request
.
data
[
'
type
'
]
==
2
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
#product = models.ForeignKey(Product, on_delete=models.CASCADE, null=True)
if
'
cash_paid
'
in
request
.
data
:
if
'
cash_paid
'
in
request
.
data
:
t
.
cash_paid
=
bool
(
request
.
data
[
'
cash_paid
'
])
t
.
cash_paid
=
bool
(
request
.
data
[
'
cash_paid
'
])
u
.
credit
-=
t
.
amount
else
:
t
.
cash_paid
=
True
t
.
amount
=
float
(
request
.
data
[
'
amount
'
])
u
.
credit
+=
t
.
amount
elif
t
.
type
==
2
:
try
:
product
=
Product
.
objects
.
get
(
id
=
request
.
data
[
'
product
'
][
'
id
'
])
t
.
product
=
product
if
'
cash_paid
'
in
request
.
data
:
t
.
cash_paid
=
bool
(
request
.
data
[
'
cash_paid
'
])
t
.
amount
=
product
.
price_vk
u
.
credit
-=
t
.
amount
except
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
else
:
else
:
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
return
Response
(
status
=
status
.
HTTP_406_NOT_ACCEPTABLE
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment