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
57dfa249
Commit
57dfa249
authored
Nov 30, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
直播间名称更新相关接口
parent
a7e14536
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
329 additions
and
72 deletions
+329
-72
live_info.go
models/live_info.go
+8
-0
live_title_record.go
models/live_title_record.go
+97
-0
errno.go
pkg/errno/errno.go
+8
-0
live_info.go
routers/api/backend/live_info.go
+3
-72
live_title_record.go
routers/api/backend/live_title_record.go
+106
-0
router.go
routers/router.go
+2
-0
live_info.go
service/live_info_service/live_info.go
+10
-0
live_title_record.go
service/live_title_record_service/live_title_record.go
+82
-0
live_title_record.go
validate_service/live_title_record.go
+13
-0
No files found.
models/live_info.go
View file @
57dfa249
...
...
@@ -104,6 +104,14 @@ func EditLiveInfo(id int, data interface{}) error {
return
nil
}
func
TitleUpdate
(
id
int
,
data
interface
{})
error
{
if
err
:=
db
.
Model
(
&
LiveInfo
{})
.
Where
(
"id = ?"
,
id
)
.
Updates
(
data
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
func
DeleteLiveInfo
(
id
int
)
error
{
if
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
Delete
(
LiveInfo
{})
.
Error
;
err
!=
nil
{
return
err
...
...
models/live_title_record.go
0 → 100644
View file @
57dfa249
package
models
import
(
"bwallet/pkg/setting"
"github.com/jinzhu/gorm"
)
type
LiveTitleRecord
struct
{
Model
LiveId
int
`json:"live_id"`
CurrentTitle
string
`json:"current_title"`
NewTitle
string
`json:"new_title"`
Status
uint8
`json:"status"`
PlatformId
int64
`gorm:"not null;default:0" json:"platform_id"`
LiveInfo
*
LiveInfo
`gorm:"foreignkey:LiveId" json:"live"`
}
func
(
w
LiveTitleRecord
)
TableName
()
string
{
return
setting
.
DatabaseSetting
.
Name_Sources
+
".wallet_live_title_record"
}
func
GetOneLiveTitleRecord
(
id
int
)
(
*
LiveTitleRecord
,
error
)
{
var
live
LiveTitleRecord
err
:=
db
.
Where
(
"id = ?"
,
id
)
.
First
(
&
live
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
err
=
db
.
Model
(
&
live
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
&
live
,
nil
}
func
ExistLiveTitleRecordById
(
id
int
)
(
bool
,
error
)
{
var
live
LiveTitleRecord
err
:=
db
.
Select
(
"id"
)
.
Where
(
"id = ?"
,
id
)
.
First
(
&
live
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
false
,
err
}
if
live
.
ID
>
0
{
return
true
,
nil
}
return
false
,
nil
}
func
GetLiveTitleRecordTotal
(
maps
interface
{})
(
int
,
error
)
{
var
count
int
if
err
:=
db
.
Model
(
&
LiveTitleRecord
{})
.
Where
(
maps
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
return
count
,
nil
}
func
GetLiveTitleRecord
(
pageNum
,
pageSize
int
,
maps
interface
{})
([]
*
LiveTitleRecord
,
error
)
{
var
live
[]
*
LiveTitleRecord
err
:=
db
.
Where
(
maps
)
.
Preload
(
"LiveInfo"
)
.
Order
(
"create_time desc"
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
live
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
return
live
,
nil
}
func
AddLiveTitleRecord
(
data
map
[
string
]
interface
{})
(
error
)
{
live
:=
LiveTitleRecord
{
LiveId
:
data
[
"live_id"
]
.
(
int
),
CurrentTitle
:
data
[
"current_title"
]
.
(
string
),
NewTitle
:
data
[
"new_title"
]
.
(
string
),
Status
:
data
[
"sort"
]
.
(
uint8
),
PlatformId
:
data
[
"platform_id"
]
.
(
int64
),
}
if
err
:=
db
.
Create
(
&
live
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
func
EditLiveTitleRecord
(
id
int
,
data
interface
{})
error
{
if
err
:=
db
.
Model
(
&
LiveTitleRecord
{})
.
Where
(
"id = ?"
,
id
)
.
Updates
(
data
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
}
\ No newline at end of file
pkg/errno/errno.go
View file @
57dfa249
...
...
@@ -163,4 +163,12 @@ var (
ErrUpdateLiveInfo
=
&
Errno
{
Code
:
20102
,
Message
:
"The live info update error."
}
ErrDeleteLiveInfo
=
&
Errno
{
Code
:
20102
,
Message
:
"The live info delete error."
}
ErrExistLiveInfo
=
&
Errno
{
Code
:
20103
,
Message
:
"The live info already exists."
}
// live title record errors
ErrLiveTitleRecordNotFound
=
&
Errno
{
Code
:
20101
,
Message
:
"The live title record was not found."
}
ErrCountLiveTitleRecord
=
&
Errno
{
Code
:
20102
,
Message
:
"The live title record statistic error."
}
ErrAddLiveTitleRecord
=
&
Errno
{
Code
:
20101
,
Message
:
"The live title record add error."
}
ErrUpdateLiveTitleRecord
=
&
Errno
{
Code
:
20102
,
Message
:
"The live title record update error."
}
ErrDeleteLiveTitleRecord
=
&
Errno
{
Code
:
20102
,
Message
:
"The live title record delete error."
}
ErrExistLiveTitleRecord
=
&
Errno
{
Code
:
20103
,
Message
:
"The live title record already exists."
}
)
routers/api/backend/live_info.go
View file @
57dfa249
...
...
@@ -24,7 +24,10 @@ func GetLiveInfo(c *gin.Context) {
}
}
status
:=
com
.
StrTo
(
c
.
DefaultQuery
(
"status"
,
"0"
))
.
MustUint8
()
infoService
:=
live_info_service
.
LiveInfo
{
Status
:
status
,
PlatformId
:
int64
(
platform_id
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
...
...
@@ -100,75 +103,3 @@ func VerifyLiveInfo(c *gin.Context) {
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
func
EditLiveInfo
(
c
*
gin
.
Context
)
{
info
:=
validate_service
.
EditLiveInfo
{}
c
.
ShouldBindJSON
(
&
info
)
//方法一
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
info
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
}
}
infoService
:=
live_info_service
.
LiveInfo
{
Id
:
info
.
Id
,
Title
:
info
.
Title
,
Cover
:
info
.
Cover
,
CategoryId
:
info
.
CategoryId
,
Duration
:
info
.
Duration
,
Attendance
:
info
.
Attendance
,
Mode
:
info
.
Mode
,
ApplyId
:
info
.
ApplyId
,
Sort
:
info
.
Sort
,
}
if
err
:=
infoService
.
Edit
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrUpdateLiveInfo
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
func
DeleteLiveInfo
(
c
*
gin
.
Context
)
{
//id := com.StrTo(c.DefaultQuery("id", "0")).MustInt()
//valid := validation.Validation{}
//valid.Min(id, 1, "id").Message("Id必须大于0")
//if valid.HasErrors() {
// handler.SendResponse(c, valid.Errors[0], nil)
// return
//}
//
//infoService := live_info_service.LiveInfo{Id: id}
//exists, err := infoService.ExistById()
//if err != nil {
// handler.SendResponse(c, errno.ErrLiveInfoNotFound, nil)
// return
//}
//
//if !exists {
// handler.SendResponse(c, errno.ErrLiveInfoNotFound, nil)
// return
//}
//
//token := c.Request.Header.Get("Token")
//user, _ := util.ParseToken(token)
//group := user.UserInfo.Group
//if ("administrator" != group) {
// info, _ := infoService.GetOneLiveInfo()
// if info.PlatformId != int64(user.UserInfo.PlatformId) {
// handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
// return
// }
//}
//err = infoService.Delete()
//if err != nil {
// handler.SendResponse(c, errno.ErrDeleteLiveInfo, nil)
// return
//}
//
//handler.SendResponse(c, nil, nil)
}
routers/api/backend/live_title_record.go
0 → 100644
View file @
57dfa249
package
backend
import
(
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/live_info_service"
"bwallet/service/live_title_record_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
"github.com/gin-gonic/gin"
"strings"
)
func
GetLiveTitleRecord
(
c
*
gin
.
Context
)
{
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
user
,
_
:=
util
.
ParseToken
(
token
)
group
:=
user
.
UserInfo
.
Group
var
platform_id
int
platform_id
=
user
.
UserInfo
.
PlatformId
if
(
"administrator"
==
group
)
{
if
arg
:=
c
.
Query
(
"platform_id"
);
arg
!=
""
{
platform_id
=
com
.
StrTo
(
c
.
Query
(
"platform_id"
))
.
MustInt
()
}
}
status
:=
com
.
StrTo
(
c
.
DefaultQuery
(
"status"
,
"0"
))
.
MustUint8
()
recordService
:=
live_title_record_service
.
LiveTitleRecord
{
Status
:
status
,
PlatformId
:
int64
(
platform_id
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
total
,
err
:=
recordService
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountLiveTitleRecord
,
nil
)
return
}
record
,
err
:=
recordService
.
GetAll
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
record
data
[
"total"
]
=
total
handler
.
SendResponse
(
c
,
nil
,
data
)
}
func
VerifyLiveTitleRecord
(
c
*
gin
.
Context
)
{
record
:=
validate_service
.
VerifyLiveTitleRecord
{}
c
.
ShouldBindJSON
(
&
record
)
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
record
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
}
}
recordService
:=
live_title_record_service
.
LiveTitleRecord
{
Id
:
record
.
Id
,
Status
:
record
.
Status
,
}
if
err
:=
recordService
.
Verify
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrUpdateLiveTitleRecord
,
nil
)
return
}
if
1
==
record
.
Status
{
recordService
:=
live_title_record_service
.
LiveTitleRecord
{
Id
:
record
.
Id
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
_
,
err
:=
recordService
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountLiveTitleRecord
,
nil
)
return
}
record
,
err
:=
recordService
.
GetAll
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
}
infoService
:=
live_info_service
.
LiveInfo
{
Id
:
record
[
0
]
.
LiveId
,
Title
:
record
[
0
]
.
NewTitle
,
}
if
err
:=
infoService
.
TitleUpdate
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrUpdateLiveInfo
,
nil
)
return
}
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
routers/router.go
View file @
57dfa249
...
...
@@ -118,6 +118,8 @@ func InitRouter() *gin.Engine {
api
.
POST
(
"/live"
,
backend
.
AddLiveInfo
)
api
.
GET
(
"/live-info"
,
backend
.
GetLiveInfo
)
api
.
PUT
(
"/live-info"
,
backend
.
VerifyLiveInfo
)
api
.
GET
(
"/live-title-record"
,
backend
.
GetLiveTitleRecord
)
api
.
PUT
(
"/live-title-record"
,
backend
.
VerifyLiveTitleRecord
)
}
return
r
...
...
service/live_info_service/live_info.go
View file @
57dfa249
...
...
@@ -82,6 +82,12 @@ func (l *LiveInfo) Edit() error {
})
}
func
(
l
*
LiveInfo
)
TitleUpdate
()
error
{
return
models
.
TitleUpdate
(
l
.
Id
,
map
[
string
]
interface
{}{
"title"
:
l
.
Title
,
})
}
func
(
l
*
LiveInfo
)
ExistById
()
(
bool
,
error
)
{
return
models
.
ExistLiveInfoById
(
l
.
Id
)
}
...
...
@@ -109,6 +115,10 @@ func (l *LiveInfo) getMaps() (map[string]interface{}) {
maps
[
"category_id"
]
=
l
.
CategoryId
}
if
l
.
Status
!=
0
{
maps
[
"status"
]
=
l
.
Status
}
if
l
.
PlatformId
!=
0
{
maps
[
"platform_id"
]
=
l
.
PlatformId
}
...
...
service/live_title_record_service/live_title_record.go
0 → 100644
View file @
57dfa249
package
live_title_record_service
import
(
"bwallet/models"
)
type
LiveTitleRecord
struct
{
Id
int
LiveId
int
CurrentTitle
string
NewTitle
string
Status
uint8
PlatformId
int64
PageNum
int
PageSize
int
}
func
(
l
*
LiveTitleRecord
)
GetAll
()
([]
*
models
.
LiveTitleRecord
,
error
)
{
var
live
[]
*
models
.
LiveTitleRecord
live
,
err
:=
models
.
GetLiveTitleRecord
(
l
.
PageNum
,
l
.
PageSize
,
l
.
getMaps
())
if
err
!=
nil
{
return
nil
,
err
}
return
live
,
nil
}
func
(
l
*
LiveTitleRecord
)
Add
()
error
{
live
:=
map
[
string
]
interface
{}{
"live_id"
:
l
.
LiveId
,
"current_title"
:
l
.
CurrentTitle
,
"new_title"
:
l
.
NewTitle
,
"platform_id"
:
l
.
PlatformId
,
}
if
err
:=
models
.
AddLiveTitleRecord
(
live
);
err
!=
nil
{
return
err
}
return
nil
}
func
(
l
*
LiveTitleRecord
)
Verify
()
error
{
return
models
.
EditLiveTitleRecord
(
l
.
Id
,
map
[
string
]
interface
{}{
"status"
:
l
.
Status
,
})
}
func
(
l
*
LiveTitleRecord
)
Edit
()
error
{
return
models
.
EditLiveTitleRecord
(
l
.
Id
,
map
[
string
]
interface
{}{
"new_title"
:
l
.
NewTitle
,
})
}
func
(
l
*
LiveTitleRecord
)
ExistById
()
(
bool
,
error
)
{
return
models
.
ExistLiveTitleRecordById
(
l
.
Id
)
}
func
(
l
*
LiveTitleRecord
)
Count
()
(
int
,
error
)
{
return
models
.
GetLiveTitleRecordTotal
(
l
.
getMaps
())
}
func
(
l
*
LiveTitleRecord
)
getMaps
()
(
map
[
string
]
interface
{})
{
maps
:=
make
(
map
[
string
]
interface
{})
if
l
.
Id
!=
0
{
maps
[
"id"
]
=
l
.
Id
}
if
l
.
Status
!=
0
{
maps
[
"status"
]
=
l
.
Status
}
if
l
.
PlatformId
!=
0
{
maps
[
"platform_id"
]
=
l
.
PlatformId
}
return
maps
}
validate_service/live_title_record.go
0 → 100644
View file @
57dfa249
package
validate_service
type
LiveTitleRecord
struct
{
LiveId
int
`json:"live_id" validate:"required"`
CurrentTitle
string
`json:"current_title" validate:"required"`
NewTitle
string
`json:"new_title" validate:"required"`
PlatformId
int64
`json:"platform_id" validate:"required"`
}
type
VerifyLiveTitleRecord
struct
{
Id
int
`json:"id" validate:"required"`
Status
uint8
`json:"status" validate:"min=1,max=2"`
}
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