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
92ebe143
Commit
92ebe143
authored
Jul 30, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
23e0bb79
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
216 additions
and
215 deletions
+216
-215
article.go
routers/api/backend/article.go
+214
-214
article.go
service/article_service/article.go
+2
-1
No files found.
routers/api/backend/article.go
View file @
92ebe143
package
backend
package
backend
import
(
import
(
"bwallet/pkg/errno"
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/pkg/util"
"bwallet/service/article_service"
"bwallet/service/article_service"
"bwallet/validate_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"strings"
"strings"
)
)
func
GetOneArticle
(
c
*
gin
.
Context
)
{
func
GetOneArticle
(
c
*
gin
.
Context
)
{
id
:=
com
.
StrTo
(
c
.
DefaultQuery
(
"id"
,
"0"
))
.
MustInt
()
id
:=
com
.
StrTo
(
c
.
DefaultQuery
(
"id"
,
"0"
))
.
MustInt
()
valid
:=
validation
.
Validation
{}
valid
:=
validation
.
Validation
{}
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
if
valid
.
HasErrors
()
{
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
return
}
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
user
,
_
:=
util
.
ParseToken
(
token
)
user
,
_
:=
util
.
ParseToken
(
token
)
group
:=
user
.
UserInfo
.
Group
group
:=
user
.
UserInfo
.
Group
var
platform_id
int
var
platform_id
int
platform_id
=
user
.
UserInfo
.
PlatformId
platform_id
=
user
.
UserInfo
.
PlatformId
articleService
:=
article_service
.
Article
{}
articleService
:=
article_service
.
Article
{}
if
(
"administrator"
==
group
)
{
if
(
"administrator"
==
group
)
{
articleService
=
article_service
.
Article
{
articleService
=
article_service
.
Article
{
Id
:
id
,
Id
:
id
,
PageNum
:
util
.
GetPage
(
c
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
}
}
else
{
}
else
{
articleService
=
article_service
.
Article
{
articleService
=
article_service
.
Article
{
Id
:
id
,
Id
:
id
,
PlatformId
:
platform_id
,
PlatformId
:
platform_id
,
PageNum
:
util
.
GetPage
(
c
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
}
}
}
article
,
err
:=
articleService
.
GetAll
()
article
,
err
:=
articleService
.
GetAll
()
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrArticleNotFound
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrArticleNotFound
,
nil
)
return
return
}
}
handler
.
SendResponse
(
c
,
nil
,
article
)
handler
.
SendResponse
(
c
,
nil
,
article
)
return
return
}
}
func
GetArticle
(
c
*
gin
.
Context
)
{
func
GetArticle
(
c
*
gin
.
Context
)
{
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
user
,
_
:=
util
.
ParseToken
(
token
)
user
,
_
:=
util
.
ParseToken
(
token
)
group
:=
user
.
UserInfo
.
Group
group
:=
user
.
UserInfo
.
Group
var
platform_id
int
var
platform_id
int
platform_id
=
user
.
UserInfo
.
PlatformId
platform_id
=
user
.
UserInfo
.
PlatformId
if
(
"administrator"
==
group
)
{
if
(
"administrator"
==
group
)
{
if
arg
:=
c
.
Query
(
"platform_id"
);
arg
!=
""
{
if
arg
:=
c
.
Query
(
"platform_id"
);
arg
!=
""
{
platform_id
=
com
.
StrTo
(
c
.
Query
(
"platform_id"
))
.
MustInt
()
platform_id
=
com
.
StrTo
(
c
.
Query
(
"platform_id"
))
.
MustInt
()
}
}
}
}
articleService
:=
article_service
.
Article
{
articleService
:=
article_service
.
Article
{
PlatformId
:
platform_id
,
PlatformId
:
platform_id
,
PageNum
:
util
.
GetPage
(
c
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
}
total
,
err
:=
articleService
.
Count
()
total
,
err
:=
articleService
.
Count
()
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountArticle
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrCountArticle
,
nil
)
return
return
}
}
article
,
err
:=
articleService
.
GetAll
()
article
,
err
:=
articleService
.
GetAll
()
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
return
}
}
data
:=
make
(
map
[
string
]
interface
{})
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
article
data
[
"items"
]
=
article
data
[
"total"
]
=
total
data
[
"total"
]
=
total
handler
.
SendResponse
(
c
,
nil
,
data
)
handler
.
SendResponse
(
c
,
nil
,
data
)
}
}
func
AddArticle
(
c
*
gin
.
Context
)
{
func
AddArticle
(
c
*
gin
.
Context
)
{
article
:=
validate_service
.
Article
{}
article
:=
validate_service
.
Article
{}
c
.
ShouldBindJSON
(
&
article
)
c
.
ShouldBindJSON
(
&
article
)
//方法一
//方法一
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
article
);
!
ok
{
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
article
);
!
ok
{
for
_
,
err
:=
range
errors
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
return
}
}
}
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
user
,
_
:=
util
.
ParseToken
(
token
)
user
,
_
:=
util
.
ParseToken
(
token
)
group
:=
user
.
UserInfo
.
Group
group
:=
user
.
UserInfo
.
Group
var
platform_id
int
var
platform_id
int
platform_id
=
user
.
UserInfo
.
PlatformId
platform_id
=
user
.
UserInfo
.
PlatformId
if
(
"administrator"
==
group
)
{
if
(
"administrator"
==
group
)
{
if
article
.
PlatformId
!=
0
{
if
article
.
PlatformId
!=
0
{
platform_id
=
article
.
PlatformId
platform_id
=
article
.
PlatformId
}
}
}
}
articleService
:=
article_service
.
Article
{
articleService
:=
article_service
.
Article
{
Title
:
article
.
Title
,
Title
:
article
.
Title
,
Source
:
article
.
Source
,
Source
:
article
.
Source
,
LogoPic
:
article
.
LogoPic
,
LogoPic
:
article
.
LogoPic
,
ImgUrl
:
article
.
ImgUrl
,
ImgUrl
:
article
.
ImgUrl
,
Content
:
article
.
Content
,
Content
:
article
.
Content
,
Top
:
article
.
Top
,
Top
:
article
.
Top
,
Highlight
:
article
.
Highlight
,
Highlight
:
article
.
Highlight
,
PlatformId
:
platform_id
,
PlatformId
:
platform_id
,
}
}
articleService
.
Add
()
articleService
.
Add
()
handler
.
SendResponse
(
c
,
nil
,
nil
)
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
}
func
EditArticle
(
c
*
gin
.
Context
)
{
func
EditArticle
(
c
*
gin
.
Context
)
{
article
:=
validate_service
.
EditArticle
{}
article
:=
validate_service
.
EditArticle
{}
c
.
ShouldBindJSON
(
&
article
)
c
.
ShouldBindJSON
(
&
article
)
//方法一
//方法一
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
article
);
!
ok
{
if
ok
,
errors
:=
validate_service
.
ValidateInputs
(
article
);
!
ok
{
for
_
,
err
:=
range
errors
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
return
}
}
}
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
user
,
_
:=
util
.
ParseToken
(
token
)
user
,
_
:=
util
.
ParseToken
(
token
)
group
:=
user
.
UserInfo
.
Group
group
:=
user
.
UserInfo
.
Group
platform_id
:=
user
.
UserInfo
.
PlatformId
platform_id
:=
user
.
UserInfo
.
PlatformId
if
(
"administrator"
==
group
)
{
if
(
"administrator"
==
group
)
{
if
article
.
PlatformId
!=
0
{
if
article
.
PlatformId
!=
0
{
platform_id
=
article
.
PlatformId
platform_id
=
article
.
PlatformId
}
}
}
}
articleService
:=
article_service
.
Article
{
articleService
:=
article_service
.
Article
{
Id
:
article
.
Id
,
Id
:
article
.
Id
,
Title
:
article
.
Title
,
Title
:
article
.
Title
,
Content
:
article
.
Content
,
Content
:
article
.
Content
,
Source
:
article
.
Source
,
Source
:
article
.
Source
,
LogoPic
:
article
.
LogoPic
,
LogoPic
:
article
.
LogoPic
,
ImgUrl
:
article
.
ImgUrl
,
ImgUrl
:
article
.
ImgUrl
,
Top
:
article
.
Top
,
Top
:
article
.
Top
,
Highlight
:
article
.
Highlight
,
Highlight
:
article
.
Highlight
,
PlatformId
:
platform_id
,
PlatformId
:
platform_id
,
}
}
if
err
:=
articleService
.
Edit
();
err
!=
nil
{
if
err
:=
articleService
.
Edit
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrUpdateArticle
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrUpdateArticle
,
nil
)
return
return
}
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
}
func
DeleteArticle
(
c
*
gin
.
Context
)
{
func
DeleteArticle
(
c
*
gin
.
Context
)
{
id
:=
com
.
StrTo
(
c
.
DefaultQuery
(
"id"
,
"0"
))
.
MustInt
()
id
:=
com
.
StrTo
(
c
.
DefaultQuery
(
"id"
,
"0"
))
.
MustInt
()
valid
:=
validation
.
Validation
{}
valid
:=
validation
.
Validation
{}
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"Id必须大于0"
)
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"Id必须大于0"
)
if
valid
.
HasErrors
()
{
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
valid
.
Errors
[
0
],
nil
)
handler
.
SendResponse
(
c
,
valid
.
Errors
[
0
],
nil
)
return
return
}
}
articleService
:=
article_service
.
Article
{
Id
:
id
}
articleService
:=
article_service
.
Article
{
Id
:
id
}
exists
,
err
:=
articleService
.
ExistById
()
exists
,
err
:=
articleService
.
ExistById
()
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrArticleNotFound
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrArticleNotFound
,
nil
)
return
return
}
}
if
!
exists
{
if
!
exists
{
handler
.
SendResponse
(
c
,
errno
.
ErrArticleNotFound
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrArticleNotFound
,
nil
)
return
return
}
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
user
,
_
:=
util
.
ParseToken
(
token
)
user
,
_
:=
util
.
ParseToken
(
token
)
group
:=
user
.
UserInfo
.
Group
group
:=
user
.
UserInfo
.
Group
if
(
"administrator"
!=
group
)
{
if
(
"administrator"
!=
group
)
{
article
,
_
:=
articleService
.
Get
()
article
,
_
:=
articleService
.
Get
()
if
article
.
PlatformId
!=
user
.
UserInfo
.
PlatformId
{
if
article
.
PlatformId
!=
user
.
UserInfo
.
PlatformId
{
handler
.
SendResponse
(
c
,
errno
.
ErrUserAuthIncorrect
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrUserAuthIncorrect
,
nil
)
return
return
}
}
}
}
err
=
articleService
.
Delete
()
err
=
articleService
.
Delete
()
if
err
!=
nil
{
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrDeleteArticle
,
nil
)
handler
.
SendResponse
(
c
,
errno
.
ErrDeleteArticle
,
nil
)
return
return
}
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
}
service/article_service/article.go
View file @
92ebe143
...
@@ -56,7 +56,7 @@ func (a *Article) Get() (*models.Article, error) {
...
@@ -56,7 +56,7 @@ func (a *Article) Get() (*models.Article, error) {
condition
.
Add
(
"language"
,
params
[
"language"
])
condition
.
Add
(
"language"
,
params
[
"language"
])
condition
.
Add
(
"timestamp"
,
params
[
"timestamp"
])
condition
.
Add
(
"timestamp"
,
params
[
"timestamp"
])
sign
:=
util
.
StringToMd5
(
condition
.
Encode
()
+
"09395dc651588c375d066666e072a714"
)
sign
:=
util
.
StringToMd5
(
condition
.
Encode
()
+
"09395dc651588c375d066666e072a714"
)
condition
.
Add
(
"sign"
,
sign
)
condition
.
Add
(
"sign"
,
sign
)
req
.
URL
.
RawQuery
=
condition
.
Encode
()
req
.
URL
.
RawQuery
=
condition
.
Encode
()
//fmt.Println(req.URL.String())
//fmt.Println(req.URL.String())
...
@@ -117,6 +117,7 @@ func (a *Article) Edit() error {
...
@@ -117,6 +117,7 @@ func (a *Article) Edit() error {
"title"
:
a
.
Title
,
"title"
:
a
.
Title
,
"source"
:
a
.
Source
,
"source"
:
a
.
Source
,
"logo_pic"
:
a
.
LogoPic
,
"logo_pic"
:
a
.
LogoPic
,
"img_url"
:
a
.
ImgUrl
,
"content"
:
a
.
Content
,
"content"
:
a
.
Content
,
"top"
:
a
.
Top
,
"top"
:
a
.
Top
,
"highlight"
:
a
.
Highlight
,
"highlight"
:
a
.
Highlight
,
...
...
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