删除友链模块
This commit is contained in:
parent
9cc5036bc8
commit
87b857528e
@ -25,6 +25,7 @@ type ILinkV1 interface {
|
|||||||
GetLinkFriend(ctx context.Context, req *request.GetLinkFriendReq) (res *request.GetLinkFriendRes, err error)
|
GetLinkFriend(ctx context.Context, req *request.GetLinkFriendReq) (res *request.GetLinkFriendRes, err error)
|
||||||
AddLinkFriend(ctx context.Context, req *request.AddLinkFriendReq) (res *request.AddLinkFriendRes, err error)
|
AddLinkFriend(ctx context.Context, req *request.AddLinkFriendReq) (res *request.AddLinkFriendRes, err error)
|
||||||
GetSortAndLink(ctx context.Context, req *request.GetSortAndLinkReq) (res *request.GetSortAndLinkRes, err error)
|
GetSortAndLink(ctx context.Context, req *request.GetSortAndLinkReq) (res *request.GetSortAndLinkRes, err error)
|
||||||
|
DelLinkFriend(ctx context.Context, req *request.DelLinkFriendReq) (res *request.DelLinkFriendRes, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type IUserV1 interface {
|
type IUserV1 interface {
|
||||||
|
@ -11,7 +11,11 @@ type AddLinkFriendReq struct {
|
|||||||
type GetSortAndLinkReq struct {
|
type GetSortAndLinkReq struct {
|
||||||
g.Meta `path:"/sort" tags:"获取分类和友链" method:"get" summary:"获取分类和友链"`
|
g.Meta `path:"/sort" tags:"获取分类和友链" method:"get" summary:"获取分类和友链"`
|
||||||
}
|
}
|
||||||
|
type DelLinkFriendReq struct {
|
||||||
|
g.Meta `path:"/delete" tags:"删除友链" method:"delete" summary:"删除友链"`
|
||||||
|
}
|
||||||
|
|
||||||
type GetLinkFriendRes struct{}
|
type GetLinkFriendRes struct{}
|
||||||
type AddLinkFriendRes struct{}
|
type AddLinkFriendRes struct{}
|
||||||
type GetSortAndLinkRes struct{}
|
type GetSortAndLinkRes struct{}
|
||||||
|
type DelLinkFriendRes struct{}
|
||||||
|
@ -85,3 +85,39 @@ func (*ControllerV1) AddLinkFriend(ctx context.Context, _ *request.AddLinkFriend
|
|||||||
}
|
}
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DelLinkFriend
|
||||||
|
//
|
||||||
|
// 删除友链
|
||||||
|
func (*ControllerV1) DelLinkFriend(ctx context.Context, _ *request.DelLinkFriendReq) (res *request.DelLinkFriendRes, err error) {
|
||||||
|
req := ghttp.RequestFromCtx(ctx)
|
||||||
|
// 获取业务
|
||||||
|
delFriendVO := entity.LinkDelFriendVO{}
|
||||||
|
err = req.GetRequestStruct(&delFriendVO)
|
||||||
|
if err == nil {
|
||||||
|
// 检查对象
|
||||||
|
errStruct := g.Validator().Data(delFriendVO).Run(ctx)
|
||||||
|
if errStruct == nil {
|
||||||
|
hasDel, info := linkService().DelLinkFriendCustom(req, delFriendVO)
|
||||||
|
if hasDel {
|
||||||
|
ResultUtil.Success(req, "删除成功", nil)
|
||||||
|
} else {
|
||||||
|
switch info {
|
||||||
|
case "FriendLinkDoesNotExist":
|
||||||
|
ResultUtil.ErrorNoData(req, ErrorCode.FriendLinkDoesNotExist)
|
||||||
|
case "DelLinkFriendError":
|
||||||
|
ResultUtil.ErrorNoData(req, ErrorCode.ServerDatabaseInteriorError)
|
||||||
|
default:
|
||||||
|
ResultUtil.ErrorNoData(req, ErrorCode.ServerUnknownError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
g.Log().Cat("Struct").Cat("Link").Notice(ctx, errStruct.Map())
|
||||||
|
ResultUtil.Error(req, ErrorCode.RequestBodyError, errStruct.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
g.Log().Cat("Struct").Cat("Link").Error(ctx, err.Error())
|
||||||
|
ResultUtil.Error(req, ErrorCode.RequestBodyError, err.Error())
|
||||||
|
}
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
@ -108,6 +108,28 @@ func GetBlogForName(linkName string) *do.BlogDO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBlogForId
|
||||||
|
//
|
||||||
|
// 检查是否已存在此博客
|
||||||
|
func GetBlogForId(id uint64) *do.BlogDO {
|
||||||
|
// 数据库读取信息
|
||||||
|
var blogDO do.BlogDO
|
||||||
|
result, err := g.Model("xf_blog").Where("id = ?", id).One()
|
||||||
|
if err == nil {
|
||||||
|
if !result.IsEmpty() {
|
||||||
|
_ = result.Struct(&blogDO)
|
||||||
|
g.Log().Cat("Database").Cat("Blog").Notice(context.Background(), "xf_blog 数据表成功提取", id, "博客信息")
|
||||||
|
return &blogDO
|
||||||
|
} else {
|
||||||
|
g.Log().Cat("Database").Cat("Blog").Notice(context.Background(), "xf_blog 数据表中没有", id, "博客友链相关信息")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
g.Log().Cat("Database").Cat("Blog").Error(context.Background(), err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetBlogForDomain
|
// GetBlogForDomain
|
||||||
//
|
//
|
||||||
// 检查是否存在相似链接
|
// 检查是否存在相似链接
|
||||||
@ -144,3 +166,18 @@ func CreateBlog(newBlogDO do.BlogDO) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteBlog
|
||||||
|
//
|
||||||
|
// 删除博客
|
||||||
|
func DeleteBlog(id uint64) bool {
|
||||||
|
// 数据库读取信息
|
||||||
|
_, err := g.Model("xf_blog").Where("id = ?", id).Delete()
|
||||||
|
if err == nil {
|
||||||
|
g.Log().Cat("Database").Cat("Blog").Notice(context.Background(), "xf_blog 数据表成功删除", id, "博客信息")
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
g.Log().Cat("Database").Cat("Blog").Error(context.Background(), err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -101,3 +101,21 @@ func (*DefaultLinkImpl) AddLinkFriendCustom(req *ghttp.Request, addFriendVO enti
|
|||||||
return false, nil, "FriendLinkAlreadyExists"
|
return false, nil, "FriendLinkAlreadyExists"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DelLinkFriendCustom
|
||||||
|
//
|
||||||
|
// 删除友链
|
||||||
|
func (*DefaultLinkImpl) DelLinkFriendCustom(_ *ghttp.Request, delFriendVO entity.LinkDelFriendVO) (bool, string) {
|
||||||
|
// 检查是否已存在此博客
|
||||||
|
blogDO := linkDAO.GetBlogForId(delFriendVO.Id)
|
||||||
|
if blogDO != nil {
|
||||||
|
// 删除博客
|
||||||
|
if linkDAO.DeleteBlog(*blogDO.Id) {
|
||||||
|
return true, ""
|
||||||
|
} else {
|
||||||
|
return false, "DelLinkFriendError"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false, "FriendLinkDoesNotExist"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
6
internal/model/entity/linkDelFriendVO.go
Normal file
6
internal/model/entity/linkDelFriendVO.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
type LinkDelFriendVO struct {
|
||||||
|
Id uint64 `json:"id" v:"required|regex:^[0-9]+$#请输入id|id格式错误"`
|
||||||
|
LinkEmail string `json:"link_email" v:"required|email#请输入邮箱|邮箱格式错误"`
|
||||||
|
}
|
@ -15,4 +15,5 @@ type LinkService interface {
|
|||||||
GetLinkFriend(*ghttp.Request)
|
GetLinkFriend(*ghttp.Request)
|
||||||
GetSortAndLink(*ghttp.Request)
|
GetSortAndLink(*ghttp.Request)
|
||||||
AddLinkFriendCustom(*ghttp.Request, entity.LinkAddFriendVO) (bool, *do.BlogDO, string)
|
AddLinkFriendCustom(*ghttp.Request, entity.LinkAddFriendVO) (bool, *do.BlogDO, string)
|
||||||
|
DelLinkFriendCustom(*ghttp.Request, entity.LinkDelFriendVO) (bool, string)
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ var (
|
|||||||
LinkAddressError = ErrorCode{output: "LinkAddressError", code: 40303, message: "链接地址错误"}
|
LinkAddressError = ErrorCode{output: "LinkAddressError", code: 40303, message: "链接地址错误"}
|
||||||
LikeLinkAlreadyExists = ErrorCode{output: "LikeLinkAlreadyExists", code: 40304, message: "链接已存在"}
|
LikeLinkAlreadyExists = ErrorCode{output: "LikeLinkAlreadyExists", code: 40304, message: "链接已存在"}
|
||||||
LinkAcceptDenied = ErrorCode{output: "LinkAcceptDenied", code: 40305, message: "链接接受协议拒绝"}
|
LinkAcceptDenied = ErrorCode{output: "LinkAcceptDenied", code: 40305, message: "链接接受协议拒绝"}
|
||||||
|
FriendLinkDoesNotExist = ErrorCode{output: "FriendLinkDoesNotExist", code: 40306, message: "友链不存在"}
|
||||||
ServerUnknownError = ErrorCode{output: "ServerUnknownError", code: 50000, message: "服务器未知错误"}
|
ServerUnknownError = ErrorCode{output: "ServerUnknownError", code: 50000, message: "服务器未知错误"}
|
||||||
ServerDatabaseInteriorError = ErrorCode{output: "ServerDatabaseInteriorError", code: 50001, message: "服务器数据库内部错误"}
|
ServerDatabaseInteriorError = ErrorCode{output: "ServerDatabaseInteriorError", code: 50001, message: "服务器数据库内部错误"}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user