-
Notifications
You must be signed in to change notification settings - Fork 13
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
c5ed242
commit 98dcdf7
Showing
71 changed files
with
2,702 additions
and
406 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package controllers | ||
|
||
import ( | ||
"keizer-auth/internal/services" | ||
"keizer-auth/internal/utils" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type ApplicationController struct { | ||
applicationService *services.ApplicationService | ||
} | ||
|
||
func NewApplicationController( | ||
applicationService *services.ApplicationService, | ||
) *ApplicationController { | ||
return &ApplicationController{ | ||
applicationService: applicationService, | ||
} | ||
} | ||
|
||
func (self *ApplicationController) Get(c *fiber.Ctx) error { | ||
user := utils.GetCurrentUser(c) | ||
applications := self.applicationService.Get(user.ID, user.ID) | ||
} |
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,15 @@ | ||
package app | ||
|
||
import ( | ||
"keizer-auth/internal/middlewares" | ||
) | ||
|
||
type ServerMiddlewares struct { | ||
Auth *middlewares.AuthMiddleware | ||
} | ||
|
||
func GetMiddlewares(container *Container) *ServerMiddlewares { | ||
return &ServerMiddlewares{ | ||
Auth: middlewares.NewAuthMiddleware(container.SessionService), | ||
} | ||
} |
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,3 @@ | ||
package constants | ||
|
||
const UserContextKey = "currentUser" |
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,55 @@ | ||
package controllers | ||
|
||
import ( | ||
"keizer-auth/internal/models" | ||
"keizer-auth/internal/services" | ||
"keizer-auth/internal/utils" | ||
"keizer-auth/internal/validators" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type AccountController struct { | ||
accountService *services.AccountService | ||
} | ||
|
||
func NewAccountController( | ||
accountService *services.AccountService, | ||
) *AccountController { | ||
return &AccountController{accountService: accountService} | ||
} | ||
|
||
func (self *AccountController) Get(c *fiber.Ctx) error { | ||
user := utils.GetCurrentUser(c) | ||
accounts, err := self.accountService.GetAccountsByUser(user.ID) | ||
if err != nil { | ||
return c.SendStatus(fiber.StatusInternalServerError) | ||
} | ||
return c.JSON(accounts) | ||
} | ||
|
||
func (self *AccountController) Create(c *fiber.Ctx) error { | ||
var err error | ||
user := utils.GetCurrentUser(c) | ||
body := new(validators.CreateAccount) | ||
|
||
if err := c.BodyParser(body); err != nil { | ||
return c. | ||
Status(fiber.StatusBadRequest). | ||
JSON(fiber.Map{"error": "Invalid request body"}) | ||
} | ||
|
||
if err := body.ValidateFile(); err != nil { | ||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ | ||
"error": err.Error(), | ||
}) | ||
} | ||
|
||
account := new(models.Account) | ||
account, err = self.accountService.Create(body.Name, user.ID) | ||
if err != nil { | ||
return c.SendStatus(fiber.StatusInternalServerError) | ||
} | ||
|
||
return c.JSON(account) | ||
} |
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,57 @@ | ||
package controllers | ||
|
||
import ( | ||
"keizer-auth/internal/models" | ||
"keizer-auth/internal/services" | ||
"keizer-auth/internal/utils" | ||
"keizer-auth/internal/validators" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type ApplicationController struct { | ||
applicationService *services.ApplicationService | ||
} | ||
|
||
func NewApplicationController( | ||
applicationService *services.ApplicationService, | ||
) *ApplicationController { | ||
return &ApplicationController{ | ||
applicationService: applicationService, | ||
} | ||
} | ||
|
||
func (self *ApplicationController) Get(c *fiber.Ctx) error { | ||
user := utils.GetCurrentUser(c) | ||
applications, err := self.applicationService.Get(user.ID, user.ID) | ||
if err != nil { | ||
return c.SendStatus(fiber.StatusInternalServerError) | ||
} | ||
return c.JSON(applications) | ||
} | ||
|
||
func (self *ApplicationController) Create(c *fiber.Ctx) error { | ||
var err error | ||
user := utils.GetCurrentUser(c) | ||
body := new(validators.CreateApplication) | ||
|
||
if err := c.BodyParser(body); err != nil { | ||
return c. | ||
Status(fiber.StatusBadRequest). | ||
JSON(fiber.Map{"error": "Invalid request body"}) | ||
} | ||
|
||
if err := body.ValidateFile(); err != nil { | ||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{ | ||
"error": err.Error(), | ||
}) | ||
} | ||
|
||
account := new(models.Account) | ||
account, err = self.applicationService.Create(body.Name, account.ID user.ID) | ||
if err != nil { | ||
return c.SendStatus(fiber.StatusInternalServerError) | ||
} | ||
|
||
return c.JSON(account) | ||
} |
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.