62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"github.com/golang-jwt/jwt/v5"
|
|
"net/http"
|
|
|
|
"git.urec56.ru/urec/chat_back_go/config"
|
|
"git.urec56.ru/urec/chat_back_go/internal/domain"
|
|
"git.urec56.ru/urec/chat_back_go/internal/logger"
|
|
"git.urec56.ru/urec/chat_back_go/internal/repository"
|
|
)
|
|
|
|
//go:generate mockgen -source=service.go -destination=mocks/mock.go
|
|
|
|
type User interface {
|
|
Get(userID int) (domain.User, error)
|
|
GetVerificated(userID int) (domain.User, error)
|
|
GetAll(username string) ([]domain.User, error)
|
|
FindOne(username, email string) (domain.User, error)
|
|
Register(userData domain.UserRegister) (string, error)
|
|
}
|
|
|
|
type Auth interface {
|
|
ExtractAuthToken(r *http.Request) (string, error)
|
|
DecodeAuthToken(token string) (int, error)
|
|
EncodeAuthToken(userID int) (string, error)
|
|
HashPassword(p string) (string, error)
|
|
VerifyHashedPassword(p, hp string) bool
|
|
}
|
|
|
|
type Chat interface {
|
|
}
|
|
|
|
type Parser interface {
|
|
Parse(tokenString string, keyFunc jwt.Keyfunc) (*jwt.Token, error)
|
|
ParseWithClaims(tokenString string, claims jwt.Claims, keyFunc jwt.Keyfunc) (*jwt.Token, error)
|
|
ParseUnverified(tokenString string, claims jwt.Claims) (token *jwt.Token, parts []string, err error)
|
|
DecodeSegment(seg string) ([]byte, error)
|
|
}
|
|
|
|
type Claims interface{ jwt.Claims }
|
|
|
|
type Service struct {
|
|
User
|
|
Auth
|
|
Chat
|
|
}
|
|
|
|
type Serv interface {
|
|
User
|
|
Auth
|
|
Chat
|
|
}
|
|
|
|
func NewService(repo repository.Repo, cfg config.Config, l logger.Log) *Service {
|
|
auth := newAuthService(cfg.JWT, l)
|
|
return &Service{
|
|
User: newUserService(repo, auth, l),
|
|
Auth: auth,
|
|
Chat: newChatService(repo, l),
|
|
}
|
|
}
|