diff --git a/pkg/api/api_account.go b/pkg/api/api_account.go index bf0058a876b..d2efdf2730a 100644 --- a/pkg/api/api_account.go +++ b/pkg/api/api_account.go @@ -5,11 +5,27 @@ import "github.com/gin-gonic/gin" func init() { addRoutes(func(self *HttpServer) { self.addRoute("POST", "/api/account/collaborators/add", self.addCollaborator) + self.addRoute("GET", "/api/account/", self.getAccount) }) } -type addCollaboratorDto struct { - Email string `json:"email" binding:"required"` +func (self *HttpServer) getAccount(c *gin.Context, auth *authContext) { + var account = auth.userAccount + + model := accountInfoDto{ + Login: account.Login, + Email: account.Email, + AccountName: account.AccountName, + } + + for _, collaborator := range account.Collaborators { + model.Collaborators = append(model.Collaborators, &collaboratorInfoDto{ + AccountId: collaborator.AccountId, + Role: collaborator.Role, + }) + } + + c.JSON(200, model) } func (self *HttpServer) addCollaborator(c *gin.Context, auth *authContext) { diff --git a/pkg/api/api_dtos.go b/pkg/api/api_dtos.go new file mode 100644 index 00000000000..4644eb5f782 --- /dev/null +++ b/pkg/api/api_dtos.go @@ -0,0 +1,18 @@ +package api + +type accountInfoDto struct { + Login string `json:"login"` + Email string `json:"email"` + AccountName string `json:"accountName"` + Collaborators []*collaboratorInfoDto `json:"collaborators"` +} + +type collaboratorInfoDto struct { + AccountId int `json:"accountId"` + Email string `json:"email"` + Role string `json:"role"` +} + +type addCollaboratorDto struct { + Email string `json:"email" binding:"required"` +} diff --git a/pkg/api/api_register.go b/pkg/api/api_register.go index 827a35e6482..f735b14ecce 100644 --- a/pkg/api/api_register.go +++ b/pkg/api/api_register.go @@ -28,7 +28,6 @@ func (self *HttpServer) registerUserPost(c *gin.Context) { } account := models.Account{ - UserName: registerModel.Email, Login: registerModel.Email, Email: registerModel.Email, Password: registerModel.Password, diff --git a/pkg/models/account.go b/pkg/models/account.go index 06b3e2c57c6..ebcbb2515f0 100644 --- a/pkg/models/account.go +++ b/pkg/models/account.go @@ -14,15 +14,17 @@ type CollaboratorLink struct { type Account struct { Id int `gorethink:"id"` - UserName string + Version int Login string Email string + AccountName string Password string NextDashboardId int UsingAccountId int Collaborators []CollaboratorLink CreatedOn time.Time ModifiedOn time.Time + LastLoginOn time.Time } func (account *Account) AddCollaborator(accountId int) error {