Auto-création du compte utilisateur à la première connexion
- Sauvegarde de l'adresse courriel de l'utilisateur en session - Implémentation d'une première Query GraphQL pour récupérer le profil de l'utilisateur connecté - Utilisation de la pattern CQRS pour les commandes/requêtes sur la base de données
This commit is contained in:
@ -2,7 +2,13 @@
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Name *string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Name *string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
ConnectedAt time.Time `json:"connectedAt"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
@ -2,9 +2,13 @@
|
||||
#
|
||||
# https://gqlgen.com/getting-started/
|
||||
|
||||
scalar Time
|
||||
|
||||
type User {
|
||||
name: String
|
||||
email: String!
|
||||
connectedAt: Time!
|
||||
createdAt: Time!
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
@ -5,14 +5,49 @@ package graph
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"forge.cadoles.com/Cadoles/daddy/internal/query"
|
||||
|
||||
"forge.cadoles.com/Cadoles/daddy/internal/session"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/cqrs"
|
||||
"gitlab.com/wpetit/goweb/middleware/container"
|
||||
|
||||
"forge.cadoles.com/Cadoles/daddy/internal/graph/generated"
|
||||
"forge.cadoles.com/Cadoles/daddy/internal/graph/model"
|
||||
)
|
||||
|
||||
func (r *queryResolver) UserProfile(ctx context.Context) (*model.User, error) {
|
||||
panic(fmt.Errorf("not implemented"))
|
||||
userEmail, err := session.UserEmail(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
ctn, err := container.From(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
dispatcher, err := cqrs.From(ctn)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
qry := &query.FindUserQueryRequest{
|
||||
Email: userEmail,
|
||||
}
|
||||
|
||||
result, err := dispatcher.Query(ctx, qry)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
findUserData, ok := result.Data().(*query.FindUserData)
|
||||
if !ok {
|
||||
return nil, errors.WithStack(cqrs.ErrUnexpectedData)
|
||||
}
|
||||
|
||||
return findUserData.User, nil
|
||||
}
|
||||
|
||||
// Query returns generated.QueryResolver implementation.
|
||||
|
Reference in New Issue
Block a user