generated from daystram/go-gin-gorm-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from daystram/dev
- Loading branch information
Showing
31 changed files
with
890 additions
and
137 deletions.
There are no files selected for viewing
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,40 @@ | ||
package v1 | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
|
||
"github.com/daystram/ratify/ratify-be/constants" | ||
"github.com/daystram/ratify/ratify-be/datatransfers" | ||
"github.com/daystram/ratify/ratify-be/handlers" | ||
"github.com/daystram/ratify/ratify-be/models" | ||
) | ||
|
||
// @Summary Get dashboard info | ||
// @Tags dashboard | ||
// @Security BearerAuth | ||
// @Success 200 "OK" | ||
// @Router /api/v1/dashboard [GET] | ||
func GETDashboardInfo(c *gin.Context) { | ||
var err error | ||
// retrieve user | ||
var user models.User | ||
if user, err = handlers.Handler.UserGetOneBySubject(c.GetString(constants.UserSubjectKey)); err != nil { | ||
c.JSON(http.StatusNotFound, datatransfers.APIResponse{Error: "user not found"}) | ||
return | ||
} | ||
// retrieve all sessions | ||
var activeSessions []*datatransfers.SessionInfo | ||
if activeSessions, err = handlers.Handler.SessionGetAllActive(c.GetString(constants.UserSubjectKey)); err != nil { | ||
c.JSON(http.StatusInternalServerError, datatransfers.APIResponse{Error: "cannot retrieve active sessions"}) | ||
return | ||
} | ||
dashboardInfo := datatransfers.DashboardInfo{ | ||
SignInCount: user.LoginCount, | ||
LastSignIn: user.LastLogin, | ||
SessionCount: len(activeSessions), | ||
} | ||
c.JSON(http.StatusOK, datatransfers.APIResponse{Data: dashboardInfo}) | ||
return | ||
} |
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
package datatransfers | ||
|
||
type ApplicationInfo struct { | ||
ClientID string `json:"client_id,omitempty" binding:"-"` | ||
Name string `json:"name" binding:"required"` | ||
Description string `json:"description,omitempty" binding:"-"` | ||
LoginURL string `json:"login_url,omitempty" binding:"required"` | ||
CallbackURL string `json:"callback_url,omitempty" binding:"required"` | ||
LogoutURL string `json:"logout_url,omitempty" binding:"required"` | ||
Metadata string `json:"metadata" binding:"-"` | ||
Locked *bool `json:"locked,omitempty" binding:"-"` | ||
CreatedAt int64 `json:"created_at,omitempty" binding:"-"` | ||
UpdatedAt int64 `json:"updated_at,omitempty" binding:"-"` | ||
ClientID string `json:"client_id,omitempty" binding:"-"` | ||
Name string `json:"name" binding:"required"` | ||
Description string `json:"description,omitempty" binding:"-"` | ||
LoginURL string `json:"login_url,omitempty" binding:"required"` | ||
CallbackURL string `json:"callback_url,omitempty" binding:"required"` | ||
LogoutURL string `json:"logout_url,omitempty" binding:"required"` | ||
Metadata string `json:"metadata" binding:"-"` | ||
Locked *bool `json:"locked,omitempty" binding:"-"` // using pointers tackles omitempty for 'false' or '0' values | ||
CreatedAt int64 `json:"created_at,omitempty" binding:"-"` | ||
UpdatedAt int64 `json:"updated_at,omitempty" binding:"-"` | ||
LastAuthorize *int64 `json:"last_authorize,omitempty" binding:"-"` | ||
AuthorizeCount *int `json:"authorize_count,omitempty" binding:"-"` | ||
} |
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,7 @@ | ||
package datatransfers | ||
|
||
type DashboardInfo struct { | ||
SignInCount int `json:"signin_count"` | ||
LastSignIn int64 `json:"last_signin"` | ||
SessionCount int `json:"session_count"` | ||
} |
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
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
Oops, something went wrong.