-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d3a04f
commit 943ec56
Showing
8 changed files
with
228 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package interaction | ||
|
||
import ( | ||
"github.com/ClubWeGo/douyin/tools/errno" | ||
"github.com/cloudwego/hertz/pkg/app" | ||
"github.com/cloudwego/hertz/pkg/protocol/consts" | ||
) | ||
|
||
type Response struct { | ||
StatusCode int32 `json:"status_code"` | ||
StatusMessage string `json:"status_message"` | ||
} | ||
|
||
// SendResponse pack response | ||
func SendResponse(c *app.RequestContext, err error, data interface{}) { | ||
if err != nil { | ||
Err := errno.ConvertErr(err) | ||
c.JSON(consts.StatusOK, Response{ | ||
StatusCode: Err.ErrCode, | ||
StatusMessage: Err.ErrMsg, | ||
}) | ||
return | ||
} | ||
c.JSON(consts.StatusOK, data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package kitex_server | ||
|
||
import ( | ||
"context" | ||
"github.com/ClubWeGo/douyin/biz/model/interaction" | ||
"github.com/ClubWeGo/douyin/tools/errno" | ||
"github.com/ClubWeGo/favoritemicro/kitex_gen/favorite" | ||
) | ||
|
||
func AddFavorite(ctx context.Context, uid int64, vid int64) (*interaction.FavoriteResp, error) { | ||
resp, err := FavoriteClient.FavoriteMethod(ctx, &favorite.FavoriteReq{ | ||
UserId: uid, | ||
VideoId: vid, | ||
ActionType: 1, | ||
}) | ||
if err != nil { | ||
return nil, errno.RPCErr | ||
} | ||
return &interaction.FavoriteResp{ | ||
StatusCode: resp.BaseResp.StatusCode, | ||
StatusMsg: resp.BaseResp.StatusMsg, | ||
}, nil | ||
} | ||
|
||
func DeleteFavorite(ctx context.Context, uid int64, vid int64) (*interaction.FavoriteResp, error) { | ||
resp, err := FavoriteClient.FavoriteMethod(ctx, &favorite.FavoriteReq{ | ||
UserId: uid, | ||
VideoId: vid, | ||
ActionType: 2, | ||
}) | ||
if err != nil { | ||
return nil, errno.RPCErr | ||
} | ||
return &interaction.FavoriteResp{ | ||
StatusCode: resp.BaseResp.StatusCode, | ||
StatusMsg: resp.BaseResp.StatusMsg, | ||
}, nil | ||
} | ||
|
||
func GetFavoriteList(ctx context.Context, uid int64) (favorites []*interaction.FavoriteListReq, err error) { | ||
//res, err := FavoriteClient.FavoriteListMethod(ctx, &favorite.FavoriteListReq{ | ||
// UserId: uid, | ||
//}) | ||
//Videoclient.GetVideoMethod(ctx, &videomicro.GetVideoReq{}) | ||
//if err != nil { | ||
// return nil, errno.RPCErr | ||
//} | ||
|
||
return | ||
} | ||
|
||
func GetFavoriteRelation(ctx context.Context, uid int64, vid int64) (bool, error) { | ||
res, err := FavoriteClient.FavoriteRelationMethod(ctx, &favorite.FavoriteRelationReq{ | ||
UserId: uid, | ||
VideoId: vid, | ||
}) | ||
if err != nil { | ||
return false, errno.RPCErr | ||
} | ||
return res.IsFavorite, nil | ||
} | ||
|
||
func CountVideoFavorite(ctx context.Context, vid int64) (cnt int64, err error) { | ||
res, err := FavoriteClient.VideoFavoriteCountMethod(ctx, &favorite.VideoFavoriteCountReq{ | ||
VideoId: vid, | ||
}) | ||
if err != nil { | ||
return 0, errno.RPCErr | ||
} | ||
return res.FavoriteCount, nil | ||
} | ||
|
||
func CountUserFavorite(ctx context.Context, uid int64) (int64, int64, error) { | ||
res, err := FavoriteClient.UserFavoriteCountMethod(ctx, &favorite.UserFavoriteCountReq{ | ||
UserId: uid, | ||
}) | ||
if err != nil { | ||
return 0, 0, errno.RPCErr | ||
} | ||
return res.FavoriteCount, res.FavoritedCount, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package errno | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
const ( | ||
SuccessCode = 0 | ||
ServiceErrCode = 10001 | ||
ParamErrCode = 10002 | ||
UserAlreadyExistErrCode = 10003 | ||
AuthorizationFailedErrCode = 10004 | ||
DBErrCode = 10005 | ||
RPCErrCode = 10006 | ||
) | ||
|
||
type ErrNo struct { | ||
ErrCode int32 | ||
ErrMsg string | ||
} | ||
|
||
func (e ErrNo) Error() string { | ||
return fmt.Sprintf("err_code=%d, err_msg=%s", e.ErrCode, e.ErrMsg) | ||
} | ||
|
||
func NewErrNo(code int32, msg string) ErrNo { | ||
return ErrNo{code, msg} | ||
} | ||
|
||
func (e ErrNo) WithMessage(msg string) ErrNo { | ||
e.ErrMsg = msg | ||
return e | ||
} | ||
|
||
var ( | ||
Success = NewErrNo(SuccessCode, "Success") | ||
ServiceErr = NewErrNo(ServiceErrCode, "Service is unable to start successfully") | ||
ParamErr = NewErrNo(ParamErrCode, "Wrong Parameter has been given") | ||
UserAlreadyExistErr = NewErrNo(UserAlreadyExistErrCode, "User already exists") | ||
AuthorizationFailedErr = NewErrNo(AuthorizationFailedErrCode, "Authorization failed") | ||
DBErr = NewErrNo(DBErrCode, "DB error") | ||
RPCErr = NewErrNo(RPCErrCode, "RPC error") | ||
) | ||
|
||
// ConvertErr convert error to Errno | ||
func ConvertErr(err error) ErrNo { | ||
Err := ErrNo{} | ||
if errors.As(err, &Err) { | ||
return Err | ||
} | ||
|
||
s := ServiceErr | ||
s.ErrMsg = err.Error() | ||
return s | ||
} |