Skip to content

Commit

Permalink
Merge pull request #113 from filecoin-project/feat/lt/refactor-user-r…
Browse files Browse the repository at this point in the history
…elated

Feat/lt/refactor user related
  • Loading branch information
simlecode authored Nov 16, 2022
2 parents c134386 + e0c23cd commit bd140cb
Show file tree
Hide file tree
Showing 37 changed files with 3,263 additions and 1,087 deletions.
180 changes: 146 additions & 34 deletions auth/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (

"golang.org/x/xerrors"

"github.com/filecoin-project/venus-auth/config"
"github.com/gin-gonic/gin"

"github.com/filecoin-project/venus-auth/config"
)

type OAuthApp interface {
Expand All @@ -19,9 +20,8 @@ type OAuthApp interface {

CreateUser(c *gin.Context)
GetUser(c *gin.Context)
GetUserByMiner(c *gin.Context)
VerifyUsers(c *gin.Context)
ListUsers(c *gin.Context)
HasMiner(c *gin.Context)
HasUser(c *gin.Context)
UpdateUser(c *gin.Context)
DeleteUser(c *gin.Context)
Expand All @@ -33,8 +33,19 @@ type OAuthApp interface {
DelUserRateLimit(c *gin.Context)

UpsertMiner(c *gin.Context)
HasMiner(c *gin.Context)
MinerExistInUser(c *gin.Context)
ListMiners(c *gin.Context)
DelMiner(c *gin.Context)
DeleteMiner(c *gin.Context)
GetUserByMiner(c *gin.Context)

RegisterSigners(c *gin.Context)
SignerExistInUser(c *gin.Context)
ListSigner(c *gin.Context)
UnregisterSigners(c *gin.Context)
HasSigner(c *gin.Context)
DelSigner(c *gin.Context)
GetUserBySigner(c *gin.Context)
}

type oauthApp struct {
Expand Down Expand Up @@ -62,8 +73,7 @@ func SuccessResponse(c *gin.Context, obj interface{}) {

func Response(c *gin.Context, err error) {
if err != nil {
c.Error(err) // nolint
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
BadResponse(c, err)
return
}
c.AbortWithStatus(http.StatusOK)
Expand Down Expand Up @@ -179,7 +189,7 @@ func (o *oauthApp) CreateUser(c *gin.Context) {
BadResponse(c, err)
return
}
// todo check miner exit

res, err := o.srv.CreateUser(c, req)
if err != nil {
BadResponse(c, err)
Expand All @@ -195,10 +205,6 @@ func (o *oauthApp) UpdateUser(c *gin.Context) {
return
}
err := o.srv.UpdateUser(c, req)
if err != nil {
BadResponse(c, err)
return
}
Response(c, err)
}

Expand All @@ -208,6 +214,7 @@ func (o *oauthApp) ListUsers(c *gin.Context) {
BadResponse(c, err)
return
}

res, err := o.srv.ListUsers(c, req)
if err != nil {
BadResponse(c, err)
Expand All @@ -230,32 +237,29 @@ func (o *oauthApp) GetUserByMiner(c *gin.Context) {
SuccessResponse(c, res)
}

func (o *oauthApp) HasMiner(c *gin.Context) {
req := new(HasMinerRequest)
if err := c.ShouldBindQuery(req); err != nil {
func (o *oauthApp) GetUser(c *gin.Context) {
req := new(GetUserRequest)
if err := c.ShouldBind(req); err != nil {
BadResponse(c, err)
return
}
res, err := o.srv.HasMiner(c, req)
res, err := o.srv.GetUser(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)
}

func (o *oauthApp) GetUser(c *gin.Context) {
req := new(GetUserRequest)
func (o *oauthApp) VerifyUsers(c *gin.Context) {
req := new(VerifyUsersReq)
if err := c.ShouldBind(req); err != nil {
BadResponse(c, err)
return
}
res, err := o.srv.GetUser(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)

err := o.srv.VerifyUsers(c, req)
Response(c, err)
}

func (o *oauthApp) HasUser(c *gin.Context) {
Expand All @@ -279,11 +283,7 @@ func (o *oauthApp) DeleteUser(c *gin.Context) {
return
}
err := o.srv.DeleteUser(c, req)
if err != nil {
BadResponse(c, err)
return
}
Response(c, nil)
Response(c, err)
}

func (o *oauthApp) RecoverUser(c *gin.Context) {
Expand All @@ -293,11 +293,7 @@ func (o *oauthApp) RecoverUser(c *gin.Context) {
return
}
err := o.srv.RecoverUser(c, req)
if err != nil {
BadResponse(c, err)
return
}
Response(c, nil)
Response(c, err)
}

func (o *oauthApp) AddUserRateLimit(c *gin.Context) {
Expand Down Expand Up @@ -373,6 +369,34 @@ func (o *oauthApp) UpsertMiner(c *gin.Context) {
SuccessResponse(c, isCreate)
}

func (o *oauthApp) HasMiner(c *gin.Context) {
req := new(HasMinerRequest)
if err := c.ShouldBindQuery(req); err != nil {
BadResponse(c, err)
return
}
res, err := o.srv.HasMiner(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)
}

func (o *oauthApp) MinerExistInUser(c *gin.Context) {
req := new(MinerExistInUserRequest)
if err := c.ShouldBindQuery(req); err != nil {
BadResponse(c, err)
return
}
res, err := o.srv.MinerExistInUser(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)
}

func (o *oauthApp) ListMiners(c *gin.Context) {
req := new(ListMinerReq)
if err := c.ShouldBind(req); err != nil {
Expand All @@ -387,7 +411,7 @@ func (o *oauthApp) ListMiners(c *gin.Context) {
SuccessResponse(c, res)
}

func (o *oauthApp) DelMiner(c *gin.Context) {
func (o *oauthApp) DeleteMiner(c *gin.Context) {
req := new(DelMinerReq)
if err := c.ShouldBind(req); err != nil {
BadResponse(c, err)
Expand All @@ -399,3 +423,91 @@ func (o *oauthApp) DelMiner(c *gin.Context) {
}
SuccessResponse(c, res)
}

func (o *oauthApp) RegisterSigners(c *gin.Context) {
req := new(RegisterSignersReq)
if err := c.ShouldBind(req); err != nil {
BadResponse(c, err)
return
}
err := o.srv.RegisterSigners(c, req)
Response(c, err)
}

func (o *oauthApp) SignerExistInUser(c *gin.Context) {
req := new(SignerExistInUserReq)
if err := c.ShouldBindQuery(req); err != nil {
BadResponse(c, err)
return
}
res, err := o.srv.SignerExistInUser(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)
}

func (o *oauthApp) ListSigner(c *gin.Context) {
req := new(ListSignerReq)
if err := c.ShouldBind(req); err != nil {
BadResponse(c, err)
return
}
res, err := o.srv.ListSigner(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)
}

func (o *oauthApp) UnregisterSigners(c *gin.Context) {
req := new(UnregisterSignersReq)
if err := c.ShouldBind(req); err != nil {
BadResponse(c, err)
return
}
err := o.srv.UnregisterSigners(c, req)
Response(c, err)
}

func (o *oauthApp) HasSigner(c *gin.Context) {
req := new(HasSignerReq)
if err := c.ShouldBind(req); err != nil {
BadResponse(c, err)
}
res, err := o.srv.HasSigner(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)
}

func (o *oauthApp) DelSigner(c *gin.Context) {
req := new(DelSignerReq)
if err := c.ShouldBind(req); err != nil {
BadResponse(c, err)
}
res, err := o.srv.DelSigner(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)
}

func (o *oauthApp) GetUserBySigner(c *gin.Context) {
req := new(GetUserBySignerReq)
if err := c.ShouldBindQuery(req); err != nil {
BadResponse(c, err)
return
}
res, err := o.srv.GetUserBySigner(c, req)
if err != nil {
BadResponse(c, err)
return
}
SuccessResponse(c, res)
}
Loading

0 comments on commit bd140cb

Please sign in to comment.