Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
ea2fd3f1
Commit
ea2fd3f1
authored
Dec 29, 2021
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/optimize' into develop
parents
9f66803a
3716c745
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
20 deletions
+45
-20
coin_gas.go
models/coin_gas.go
+19
-5
coin_gas.go
routers/api/backend/coin_gas.go
+13
-5
coin_gas.go
service/coin_gas_service/coin_gas.go
+13
-9
coin_gas.go
validate_service/coin_gas.go
+0
-1
No files found.
models/coin_gas.go
View file @
ea2fd3f1
...
...
@@ -6,11 +6,12 @@ import (
)
type
CoinGas
struct
{
Model
CoinName
string
`json:"coin_name"`
Low
string
`json:"low"`
Average
string
`json:"average"`
High
string
`json:"high"`
Switch
int8
`json:"switch"`
}
func
(
c
CoinGas
)
TableName
()
string
{
...
...
@@ -33,9 +34,8 @@ func AddCoinGas(data map[string]interface{}) (error) {
Low
:
data
[
"low"
]
.
(
string
),
Average
:
data
[
"average"
]
.
(
string
),
High
:
data
[
"high"
]
.
(
string
),
Switch
:
data
[
"switch"
]
.
(
int8
),
}
if
err
:=
db
.
Debug
()
.
Create
(
&
CoinGas
)
.
Error
;
err
!=
nil
{
if
err
:=
db
.
Create
(
&
CoinGas
)
.
Error
;
err
!=
nil
{
return
err
}
...
...
@@ -60,7 +60,7 @@ func DeleteCoinGas(id int) error {
func
GetCoinGas
(
coin_name
string
)
(
*
CoinGas
,
error
)
{
var
gas
CoinGas
err
:=
db
.
Where
(
"coin_name = ?
and switch = ?"
,
coin_name
,
1
)
.
First
(
&
gas
)
.
Error
err
:=
db
.
Where
(
"coin_name = ?
"
,
coin_name
)
.
First
(
&
gas
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
...
...
@@ -73,7 +73,7 @@ func GetCoinGas(coin_name string) (*CoinGas, error) {
return
&
gas
,
nil
}
func
Exist
(
coin_name
string
)
(
bool
,
error
)
{
func
Exist
CoinGasByName
(
coin_name
string
)
(
bool
,
error
)
{
var
coinGas
CoinGas
err
:=
db
.
Where
(
"coin_name = ?"
,
coin_name
)
.
First
(
&
coinGas
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
...
...
@@ -86,3 +86,17 @@ func Exist(coin_name string) (bool, error) {
return
false
,
nil
}
func
ExistCoinGasById
(
id
int
)
(
bool
,
error
)
{
var
coinGas
CoinGas
err
:=
db
.
Select
(
"id"
)
.
Where
(
"id = ?"
,
id
)
.
First
(
&
coinGas
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
false
,
err
}
if
coinGas
.
ID
>
0
{
return
true
,
nil
}
return
false
,
nil
}
routers/api/backend/coin_gas.go
View file @
ea2fd3f1
...
...
@@ -52,12 +52,21 @@ func AddCoinGas(c *gin.Context) {
}
}
CoinGasValidateService
:=
coin_gas_service
.
CoinGas
{
CoinName
:
coin_gas
.
CoinName
,
}
exist
,
_
:=
CoinGasValidateService
.
ExistCoinGasByName
()
if
exist
{
handler
.
SendResponse
(
c
,
errno
.
ErrExistCoinGas
,
nil
)
return
}
CoinGasService
:=
coin_gas_service
.
CoinGas
{
CoinName
:
coin_gas
.
CoinName
,
Low
:
coin_gas
.
Low
,
Average
:
coin_gas
.
Average
,
High
:
coin_gas
.
High
,
Switch
:
coin_gas
.
Switch
,
}
if
err
:=
CoinGasService
.
Add
();
err
!=
nil
{
...
...
@@ -92,7 +101,7 @@ func UpdateCoinGas(c *gin.Context) {
CoinName
:
coin_gas
.
CoinName
,
}
exist
,
_
:=
CoinGasValidateService
.
Exist
()
exist
,
_
:=
CoinGasValidateService
.
Exist
CoinGasByName
()
if
!
exist
{
handler
.
SendResponse
(
c
,
errno
.
ErrCoinGasNotFound
,
nil
)
return
...
...
@@ -102,7 +111,6 @@ func UpdateCoinGas(c *gin.Context) {
Low
:
coin_gas
.
Low
,
Average
:
coin_gas
.
Average
,
High
:
coin_gas
.
High
,
Switch
:
coin_gas
.
Switch
,
}
if
err
:=
CoinGasService
.
Edit
();
err
!=
nil
{
...
...
@@ -132,9 +140,9 @@ func DeleteCoinGas(c *gin.Context) {
}
CoinGasService
:=
coin_gas_service
.
CoinGas
{
Id
:
id
,
Id
:
id
,
}
exists
,
err
:=
CoinGasService
.
Exist
()
exists
,
err
:=
CoinGasService
.
Exist
CoinGasById
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
...
...
service/coin_gas_service/coin_gas.go
View file @
ea2fd3f1
...
...
@@ -6,7 +6,6 @@ import (
"bwallet/pkg/gredis"
"bwallet/pkg/util"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
...
...
@@ -258,7 +257,6 @@ type CoinGas struct {
Low
string
Average
string
High
string
Switch
int8
}
func
(
g
*
CoinGas
)
GetAll
()
([]
*
models
.
CoinGas
,
error
)
{
...
...
@@ -271,15 +269,14 @@ func (g *CoinGas) GetAll() ([]*models.CoinGas, error) {
}
func
(
g
*
CoinGas
)
Add
()
error
{
C
oinGas
:=
map
[
string
]
interface
{}{
c
oinGas
:=
map
[
string
]
interface
{}{
"coin_name"
:
g
.
CoinName
,
"low"
:
g
.
Low
,
"average"
:
g
.
Average
,
"high"
:
g
.
High
,
"switch"
:
g
.
Switch
,
}
fmt
.
Println
(
CoinGas
)
if
err
:=
models
.
AddCoinGas
(
C
oinGas
);
err
!=
nil
{
if
err
:=
models
.
AddCoinGas
(
c
oinGas
);
err
!=
nil
{
return
err
}
...
...
@@ -291,7 +288,6 @@ func (g *CoinGas) Edit() error {
"low"
:
g
.
Low
,
"average"
:
g
.
Average
,
"high"
:
g
.
High
,
"switch"
:
g
.
Switch
,
})
}
...
...
@@ -299,8 +295,12 @@ func (g *CoinGas) Delete() error {
return
models
.
DeleteCoinGas
(
g
.
Id
)
}
func
(
g
*
CoinGas
)
Exist
()
(
bool
,
error
)
{
return
models
.
Exist
(
g
.
CoinName
)
func
(
g
*
CoinGas
)
ExistCoinGasByName
()
(
bool
,
error
)
{
return
models
.
ExistCoinGasByName
(
g
.
CoinName
)
}
func
(
g
*
CoinGas
)
ExistCoinGasById
()
(
bool
,
error
)
{
return
models
.
ExistCoinGasById
(
g
.
Id
)
}
func
(
c
*
CoinGas
)
getMaps
()
(
map
[
string
]
interface
{})
{
...
...
@@ -310,5 +310,9 @@ func (c *CoinGas) getMaps() (map[string]interface{}) {
maps
[
"coin_name"
]
=
c
.
CoinName
}
if
c
.
Id
!=
0
{
maps
[
"id"
]
=
c
.
Id
}
return
maps
}
validate_service/coin_gas.go
View file @
ea2fd3f1
...
...
@@ -5,5 +5,4 @@ type CoinGas struct {
Low
string
`json:"low" validate:"required"`
Average
string
`json:"average" validate:"required"`
High
string
`json:"high" validate:"required"`
Switch
int8
`json:"switch" validate:"required"`
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment