Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cicer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
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
Quique
cicer
Commits
3e8f0d81
Commit
3e8f0d81
authored
4 years ago
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
Fix get order
parent
406404a8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/order.go
+15
-12
15 additions, 12 deletions
api/order.go
api/order_test.go
+53
-0
53 additions, 0 deletions
api/order_test.go
with
68 additions
and
12 deletions
api/order.go
+
15
−
12
View file @
3e8f0d81
...
...
@@ -36,6 +36,11 @@ type OrderPurchase struct {
Ammount
int
`json:"ammount"`
}
type
OrderGetResponse
struct
{
Order
Order
`json:"order"`
Transaction
*
Transaction
`json:"transaction"`
}
func
(
a
*
api
)
refundOrders
()
{
const
refundSleeptime
=
10
*
time
.
Minute
for
{
...
...
@@ -133,23 +138,21 @@ func (a *api) GetOrder(num int, w http.ResponseWriter, req *http.Request) {
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
var
body
struct
{
Order
Order
`json:"order"`
Transaction
*
Transaction
`json:"transaction"`
}
var
body
OrderGetResponse
body
.
Order
=
order
var
transaction
Transaction
err
=
a
.
db
.
Joins
(
"OrderPurchase"
)
.
Where
(
"member = ? AND type = 'order' AND order_purchases.order_id = ?"
,
num
,
order
.
ID
)
.
err
=
a
.
db
.
Where
(
"member = ? AND type = 'order' AND id IN (?)"
,
num
,
a
.
db
.
Table
(
"order_purchases"
)
.
Where
(
"order_id = ?"
,
order
.
ID
)
.
Select
(
"transaction_id"
))
.
Find
(
&
transaction
)
.
Error
if
err
!=
nil
{
if
err
.
Error
()
!=
"record not found"
{
log
.
Printf
(
"Can't get order transaction %s: %v"
,
vars
[
"id"
],
err
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
}
else
{
log
.
Printf
(
"Can't get order transaction %s: %v"
,
vars
[
"id"
],
err
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
if
transaction
.
ID
!=
0
{
body
.
Transaction
=
&
transaction
}
...
...
This diff is collapsed.
Click to expand it.
api/order_test.go
+
53
−
0
View file @
3e8f0d81
...
...
@@ -3,6 +3,7 @@ package api
import
(
"net/http"
"path"
"strconv"
"testing"
"time"
)
...
...
@@ -224,6 +225,58 @@ func TestOrderDeactivation(t *testing.T) {
}
}
func
TestGetOrder
(
t
*
testing
.
T
)
{
tapi
:=
newTestAPI
(
t
)
defer
tapi
.
close
()
tapi
.
addTestMember
()
tapi
.
addTestOrder
()
var
orders
[]
Order
resp
:=
tapi
.
do
(
"GET"
,
"/order/active"
,
nil
,
&
orders
)
if
resp
.
StatusCode
!=
http
.
StatusOK
{
t
.
Fatal
(
"Can't get orders:"
,
resp
.
Status
)
}
if
len
(
orders
)
!=
1
{
t
.
Fatal
(
"Didn't find my new order"
)
}
id
:=
strconv
.
Itoa
(
int
(
orders
[
0
]
.
ID
))
var
body
OrderGetResponse
resp
=
tapi
.
do
(
"GET"
,
"/order/"
+
id
,
nil
,
&
body
)
if
resp
.
StatusCode
!=
http
.
StatusOK
{
t
.
Fatal
(
"Can't get order:"
,
resp
.
Status
)
}
if
body
.
Transaction
!=
nil
{
t
.
Error
(
"Unexpected transaction"
,
body
.
Transaction
)
}
if
body
.
Order
.
Name
!=
testOrder
.
Name
{
t
.
Error
(
"Wrong name:"
,
body
.
Order
.
Name
)
}
purchase
:=
[]
OrderPurchase
{
{
ProductCode
:
testProduct
.
Code
,
Ammount
:
3
,
OrderID
:
orders
[
0
]
.
ID
,
},
}
resp
=
tapi
.
do
(
"POST"
,
"/order/purchase"
,
purchase
,
nil
)
if
resp
.
StatusCode
!=
http
.
StatusCreated
{
t
.
Fatal
(
"Can't create order:"
,
resp
.
Status
)
}
resp
=
tapi
.
do
(
"GET"
,
"/order/"
+
id
,
nil
,
&
body
)
if
resp
.
StatusCode
!=
http
.
StatusOK
{
t
.
Fatal
(
"Can't get order:"
,
resp
.
Status
)
}
if
body
.
Transaction
==
nil
{
t
.
Fatal
(
"There is no transaction"
)
}
if
body
.
Transaction
.
Type
!=
"order"
{
t
.
Error
(
"Wrong transaction type"
,
body
.
Transaction
.
Type
)
}
}
func
(
tapi
*
testAPI
)
addTestOrder
()
{
resp
:=
tapi
.
do
(
"POST"
,
"/order"
,
testOrder
,
nil
)
if
resp
.
StatusCode
!=
http
.
StatusCreated
{
...
...
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