Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
kefu_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
faec1e86
authored
Jan 12, 2020
by
keith
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加删除单个消息api
parent
32d0cb2c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
controllers/message.go
routers/router.go
controllers/message.go
View file @
faec1e86
...
@@ -111,6 +111,54 @@ func (c *MessageController) List() {
...
@@ -111,6 +111,54 @@ func (c *MessageController) List() {
c
.
ServeJSON
()
c
.
ServeJSON
()
}
}
// RemoveRequestData struct
type
RemoveRequestData
struct
{
FromAccount
int64
`json:"from_account"`
ToAccount
int64
`json:"to_account"`
Key
int64
`json:"key"`
}
// Remove one message
func
(
c
*
MessageController
)
Remove
()
{
o
:=
orm
.
NewOrm
()
token
:=
c
.
Ctx
.
Input
.
Header
(
"Authorization"
)
admin
:=
models
.
Admin
{
Token
:
token
}
if
err
:=
o
.
Read
(
&
admin
,
"Token"
);
err
!=
nil
{
c
.
Data
[
"json"
]
=
utils
.
ResponseError
(
c
.
Ctx
,
"无权限操作"
,
err
)
c
.
ServeJSON
()
return
}
// request body
removeRequestData
:=
RemoveRequestData
{}
if
err
:=
json
.
Unmarshal
(
c
.
Ctx
.
Input
.
RequestBody
,
&
removeRequestData
);
err
!=
nil
{
c
.
Data
[
"json"
]
=
utils
.
ResponseError
(
c
.
Ctx
,
"参数错误!"
,
nil
)
c
.
ServeJSON
()
return
}
// validation
valid
:=
validation
.
Validation
{}
valid
.
Required
(
removeRequestData
.
ToAccount
,
"to_account"
)
.
Message
(
"to_account不能为空!"
)
valid
.
Required
(
removeRequestData
.
FromAccount
,
"from_account"
)
.
Message
(
"from_account不能为空!"
)
valid
.
Required
(
removeRequestData
.
Key
,
"key"
)
.
Message
(
"key不能为空!"
)
if
valid
.
HasErrors
()
{
for
_
,
err
:=
range
valid
.
Errors
{
c
.
Data
[
"json"
]
=
utils
.
ResponseError
(
c
.
Ctx
,
err
.
Message
,
nil
)
break
}
c
.
ServeJSON
()
return
}
_
,
err
:=
o
.
Raw
(
"UPDATE message SET `delete` = 1 WHERE from_account = ? AND to_account = ? AND `key` = ?"
,
removeRequestData
.
FromAccount
,
removeRequestData
.
ToAccount
,
removeRequestData
.
Key
)
.
Exec
()
if
err
!=
nil
{
utils
.
ResponseError
(
c
.
Ctx
,
"删除失败!"
,
&
err
)
}
else
{
utils
.
ResponseSuccess
(
c
.
Ctx
,
"删除成功"
,
nil
)
}
c
.
ServeJSON
()
}
// TransferRequestData struct
// TransferRequestData struct
type
TransferRequestData
struct
{
type
TransferRequestData
struct
{
ToAccount
int64
`json:"to_account"`
// 转接给谁
ToAccount
int64
`json:"to_account"`
// 转接给谁
...
...
routers/router.go
View file @
faec1e86
...
@@ -67,6 +67,7 @@ func init() {
...
@@ -67,6 +67,7 @@ func init() {
beego
.
NSBefore
(
filters
.
FilterToken
),
beego
.
NSBefore
(
filters
.
FilterToken
),
beego
.
NSRouter
(
"/list"
,
&
controllers
.
MessageController
{},
"post:List"
),
beego
.
NSRouter
(
"/list"
,
&
controllers
.
MessageController
{},
"post:List"
),
beego
.
NSRouter
(
"/transfer"
,
&
controllers
.
MessageController
{},
"post:Transfer"
),
beego
.
NSRouter
(
"/transfer"
,
&
controllers
.
MessageController
{},
"post:Transfer"
),
beego
.
NSRouter
(
"/remove"
,
&
controllers
.
MessageController
{},
"post:Remove"
),
),
),
// admin
// admin
...
...
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