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
meskio
cicer
Commits
cb50f841
Commit
cb50f841
authored
4 years ago
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
Add suppliers
parent
8fee840e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
api/api.go
+3
-0
3 additions, 0 deletions
api/api.go
api/db/db.go
+1
-1
1 addition, 1 deletion
api/db/db.go
api/db/inventary.go
+15
-0
15 additions, 0 deletions
api/db/inventary.go
api/inventary.go
+51
-0
51 additions, 0 deletions
api/inventary.go
api/inventary_test.go
+38
-0
38 additions, 0 deletions
api/inventary_test.go
with
108 additions
and
1 deletion
api/api.go
+
3
−
0
View file @
cb50f841
...
@@ -48,6 +48,9 @@ func Init(dbPath string, signKey string, mail *Mail, r *mux.Router) error {
...
@@ -48,6 +48,9 @@ func Init(dbPath string, signKey string, mail *Mail, r *mux.Router) error {
r
.
HandleFunc
(
"/product/{code:[0-9]+}"
,
a
.
authAdmin
(
a
.
UpdateProduct
))
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/product/{code:[0-9]+}"
,
a
.
authAdmin
(
a
.
UpdateProduct
))
.
Methods
(
"PUT"
)
r
.
HandleFunc
(
"/product/{code:[0-9]+}"
,
a
.
authAdmin
(
a
.
DeleteProduct
))
.
Methods
(
"DELETE"
)
r
.
HandleFunc
(
"/product/{code:[0-9]+}"
,
a
.
authAdmin
(
a
.
DeleteProduct
))
.
Methods
(
"DELETE"
)
r
.
HandleFunc
(
"/supplier"
,
a
.
auth
(
a
.
ListSuppliers
))
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/supplier"
,
a
.
authAdmin
(
a
.
AddSupplier
))
.
Methods
(
"POST"
)
r
.
HandleFunc
(
"/transaction"
,
a
.
authAdmin
(
a
.
ListTransactions
))
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/transaction"
,
a
.
authAdmin
(
a
.
ListTransactions
))
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/transaction/{id:[0-9]+}"
,
a
.
authNumRole
(
a
.
GetTransaction
))
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/transaction/{id:[0-9]+}"
,
a
.
authNumRole
(
a
.
GetTransaction
))
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/transaction/mine"
,
a
.
authNum
(
a
.
getTransactionsByMember
))
.
Methods
(
"GET"
)
r
.
HandleFunc
(
"/transaction/mine"
,
a
.
authNum
(
a
.
getTransactionsByMember
))
.
Methods
(
"GET"
)
...
...
This diff is collapsed.
Click to expand it.
api/db/db.go
+
1
−
1
View file @
cb50f841
...
@@ -16,6 +16,6 @@ func Init(dbPath string) (*DB, error) {
...
@@ -16,6 +16,6 @@ func Init(dbPath string) (*DB, error) {
}
}
db
.
AutoMigrate
(
&
Member
{},
&
Product
{},
&
Purchase
{},
&
Topup
{},
&
Transaction
{},
db
.
AutoMigrate
(
&
Member
{},
&
Product
{},
&
Purchase
{},
&
Topup
{},
&
Transaction
{},
&
OrderPurchase
{},
&
Order
{},
&
PasswordReset
{})
&
OrderPurchase
{},
&
Order
{},
&
PasswordReset
{}
,
&
Supplier
{}
)
return
&
DB
{
db
},
err
return
&
DB
{
db
},
err
}
}
This diff is collapsed.
Click to expand it.
api/db/inventary.go
0 → 100644
+
15
−
0
View file @
cb50f841
package
db
type
Supplier
struct
{
gorm
.
Model
Name
string
`json:"name"`
}
func
(
d
*
DB
)
AddSupplier
(
supplier
Supplier
)
error
{
return
d
.
db
.
Create
(
&
supplier
)
.
Error
}
func
(
d
*
DB
)
ListSuppliers
()
(
suppliers
[]
Supplier
,
err
error
)
{
err
=
d
.
db
.
Find
(
&
suppliers
)
.
Error
return
}
This diff is collapsed.
Click to expand it.
api/inventary.go
0 → 100644
+
51
−
0
View file @
cb50f841
package
api
import
(
"encoding/json"
"log"
"net/http"
"0xacab.org/meskio/cicer/api/db"
)
func
(
a
*
api
)
AddSupplier
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
var
supplier
db
.
Supplier
err
:=
json
.
NewDecoder
(
req
.
Body
)
.
Decode
(
&
supplier
)
if
err
!=
nil
{
log
.
Printf
(
"Can't decode supplier: %v"
,
err
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
err
=
a
.
db
.
AddSupplier
(
supplier
)
if
err
!=
nil
{
log
.
Printf
(
"Can't create supplier: %v
\n
%v"
,
err
,
supplier
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
WriteHeader
(
http
.
StatusCreated
)
err
=
json
.
NewEncoder
(
w
)
.
Encode
(
supplier
)
if
err
!=
nil
{
log
.
Printf
(
"Can't encode added supplier: %v"
,
err
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
}
func
(
a
*
api
)
ListSuppliers
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
suppliers
,
err
:=
a
.
db
.
ListSuppliers
()
if
err
!=
nil
{
log
.
Printf
(
"Can't list suppliers: %v"
,
err
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
WriteHeader
(
http
.
StatusOK
)
err
=
json
.
NewEncoder
(
w
)
.
Encode
(
suppliers
)
if
err
!=
nil
{
log
.
Printf
(
"Can't encode suppliers: %v"
,
err
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
return
}
}
This diff is collapsed.
Click to expand it.
api/inventary_test.go
0 → 100644
+
38
−
0
View file @
cb50f841
package
api
import
(
"net/http"
"testing"
"0xacab.org/meskio/cicer/api/db"
)
var
testSupplier
=
db
.
Supplier
{
Name
:
"Aceites Geronimo"
,
}
func
TestSupplierAddList
(
t
*
testing
.
T
)
{
tapi
:=
newTestAPI
(
t
)
defer
tapi
.
close
()
tapi
.
addTestSuppliers
()
var
suppliers
[]
db
.
Supplier
resp
:=
tapi
.
do
(
"GET"
,
"/supplier"
,
nil
,
&
suppliers
)
if
resp
.
StatusCode
!=
http
.
StatusOK
{
t
.
Fatal
(
"Can't get suppliers:"
,
resp
.
Status
)
}
if
len
(
suppliers
)
!=
1
{
t
.
Fatal
(
"Wrong number of suppliers"
,
len
(
suppliers
),
suppliers
)
}
if
suppliers
[
0
]
.
Name
!=
testSupplier
.
Name
{
t
.
Error
(
"Wrong name:"
,
suppliers
[
0
]
.
Name
)
}
}
func
(
tapi
*
testAPI
)
addTestSuppliers
()
{
resp
:=
tapi
.
doAdmin
(
"POST"
,
"/supplier"
,
testSupplier
,
nil
)
if
resp
.
StatusCode
!=
http
.
StatusCreated
{
tapi
.
t
.
Fatal
(
"Can't create supplier:"
,
resp
.
Status
)
}
}
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