feat: Add new handlers and repository for oauth2
All checks were successful
Backend ci / build (push) Successful in 3m36s
All checks were successful
Backend ci / build (push) Successful in 3m36s
This commit is contained in:
27
backend/internal/handlers/auth_handlers.go
Normal file
27
backend/internal/handlers/auth_handlers.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/repositories"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthHandlers struct {
|
||||||
|
repo repositories.AuthRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthHandlers(repo repositories.AuthRepository) *AuthHandlers {
|
||||||
|
return &AuthHandlers{repo: repo}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callback godoc
|
||||||
|
// @Summary Callback for oauth2 providers
|
||||||
|
// @Description Callback for oauth2 providers
|
||||||
|
// @Tags auth
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} map[string]string
|
||||||
|
// @Router /callback [get]
|
||||||
|
func (h *AuthHandlers) Callback(c *gin.Context) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ type PostHandlers struct {
|
|||||||
repo repositories.PostRepository
|
repo repositories.PostRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPostHandler(repo repositories.PostRepository) *PostHandlers {
|
func NewPostHandlers(repo repositories.PostRepository) *PostHandlers {
|
||||||
return &PostHandlers{repo: repo}
|
return &PostHandlers{repo: repo}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Register(router *gin.Engine, db *sql.DB) {
|
func Register(router *gin.Engine, db *sql.DB) {
|
||||||
handler_posts := NewPostHandler(repositories.NewPostRepository(db))
|
handler_posts := NewPostHandlers(repositories.NewPostRepository(db))
|
||||||
|
handler_auth := NewAuthHandlers(repositories.NewAuthRepository(db))
|
||||||
v1 := router.Group("api/v1")
|
v1 := router.Group("api/v1")
|
||||||
|
v1.GET("/callback", handler_auth.Callback)
|
||||||
posts := v1.Group("posts")
|
posts := v1.Group("posts")
|
||||||
{
|
{
|
||||||
posts.GET("/", handler_posts.GetPosts)
|
posts.GET("/", handler_posts.GetPosts)
|
||||||
|
|||||||
22
backend/internal/repositories/auth_repository.go
Normal file
22
backend/internal/repositories/auth_repository.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package repositories
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"gitea.d3m0k1d.ru/d3m0k1d/d3m0k1d.ru/backend/internal/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
type authRepository struct {
|
||||||
|
db *sql.DB
|
||||||
|
logger *logger.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthRepository(db *sql.DB) AuthRepository {
|
||||||
|
return &authRepository{
|
||||||
|
db: db,
|
||||||
|
logger: logger.New(false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (a *authRepository) Test(ctx context.Context) {
|
||||||
|
}
|
||||||
@@ -13,3 +13,7 @@ type PostRepository interface {
|
|||||||
Update(ctx context.Context, id int, post storage.Post) error
|
Update(ctx context.Context, id int, post storage.Post) error
|
||||||
Delete(ctx context.Context, id int) error
|
Delete(ctx context.Context, id int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AuthRepository interface {
|
||||||
|
Test(ctx context.Context)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user