Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ type Conf struct {
GRPC conf.AddrConf `mapstructure:"grpc"`
Listen conf.AddrConf `mapstructure:"listen"`
Login login.Config `mapstructure:"login"`
Minis []struct{
Minis []struct {
Key string `mapstructure:"key"`
ID int `mapstructure:"id"`
ID int `mapstructure:"id"`
} `mapstructure:"mini"`
}

Expand Down Expand Up @@ -144,7 +144,17 @@ func main() {

roomService := pb.NewRoomServiceClient(conn)

loginEndpoints := login.NewEndpoint(ub, loginState, s, ms, ib, queue, appleClient, roomService, config.Login)
loginEndpoints := login.NewEndpoint(login.Parameters{
Users: ub,
State: loginState,
Sessions: s,
Mail: ms,
Images: ib,
Queue: queue,
SignInWithApple: appleClient,
RoomService: roomService,
EmailRegistrationEnabled: config.Login.RegisterWithEmailEnabled,
})
loginRouter := loginEndpoints.Router()
mount(r, "/v1/login", loginRouter)

Expand Down Expand Up @@ -189,9 +199,17 @@ func main() {
config.Twitter.Secret,
)

pb := linkedaccounts.NewLinkedAccountsBackend(db)
meEndpoint := me.NewEndpoint(me.Parameters{
Users: ub,
NotificationsStorage: ns,
OauthConfig: oauth,
LinkedAccountsBackend: linkedaccounts.NewLinkedAccountsBackend(db),
StoriesBackend: storiesBackend,
Queue: queue,
ActiveUsersBackend: activeusers.NewBackend(db),
NotificationSettings: notifications.NewSettings(db),
})

meEndpoint := me.NewEndpoint(ub, ns, oauth, pb, storiesBackend, queue, activeusers.NewBackend(db), notifications.NewSettings(db))
meRoutes := meEndpoint.Router()

meRoutes.Use(amw.Middleware)
Expand Down
46 changes: 24 additions & 22 deletions pkg/login/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,32 @@ type Endpoint struct {
signInWithApple apple.SignInWithApple
roomService pb.RoomServiceClient

config Config
emailRegistrationEnabled bool
}

func NewEndpoint(
ub *users.Backend,
state *StateManager,
manager *sessions.SessionManager,
mail *mail.Service,
ib *images.Backend,
queue *pubsub.Queue,
signInWithApple apple.SignInWithApple,
roomService pb.RoomServiceClient,
config Config,
) Endpoint {
type Parameters struct {
Users *users.Backend
State *StateManager
Sessions *sessions.SessionManager
Mail *mail.Service
Images *images.Backend
Queue *pubsub.Queue
SignInWithApple apple.SignInWithApple
RoomService pb.RoomServiceClient
EmailRegistrationEnabled bool
}

func NewEndpoint(params Parameters) Endpoint {
return Endpoint{
users: ub,
state: state,
sessions: manager,
mail: mail,
ib: ib,
queue: queue,
signInWithApple: signInWithApple,
roomService: roomService,
config: config,
users: params.Users,
state: params.State,
sessions: params.Sessions,
mail: params.Mail,
ib: params.Images,
queue: params.Queue,
signInWithApple: params.SignInWithApple,
roomService: params.RoomService,
emailRegistrationEnabled: params.EmailRegistrationEnabled,
}
}

Expand Down Expand Up @@ -148,7 +150,7 @@ func (e *Endpoint) start(w http.ResponseWriter, r *http.Request) {
return
}

if !e.config.RegisterWithEmailEnabled {
if !e.emailRegistrationEnabled {
isRegistered, err := e.users.IsRegistered(email)
if err != nil {
httputil.JsonError(w, http.StatusInternalServerError, httputil.ErrorCodeInvalidRequestBody, "")
Expand Down
38 changes: 20 additions & 18 deletions pkg/me/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,27 @@ type Notification struct {
Category notifications.NotificationCategory `json:"category"`
}

func NewEndpoint(
users *users.Backend,
ns *notifications.Storage,
config *oauth1.Config,
la *linkedaccounts.Backend,
backend *stories.Backend,
queue *pubsub.Queue,
actives *activeusers.Backend,
targets *notifications.Settings,
) *Endpoint {
type Parameters struct {
Users *users.Backend
NotificationsStorage *notifications.Storage
OauthConfig *oauth1.Config
LinkedAccountsBackend *linkedaccounts.Backend
StoriesBackend *stories.Backend
Queue *pubsub.Queue
ActiveUsersBackend *activeusers.Backend
NotificationSettings *notifications.Settings
}

func NewEndpoint(p Parameters) *Endpoint {
return &Endpoint{
users: users,
ns: ns,
oauthConfig: config,
la: la,
stories: backend,
queue: queue,
actives: actives,
targets: targets,
users: p.Users,
ns: p.NotificationsStorage,
oauthConfig: p.OauthConfig,
la: p.LinkedAccountsBackend,
stories: p.StoriesBackend,
queue: p.Queue,
actives: p.ActiveUsersBackend,
targets: p.NotificationSettings,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/minis/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestEndpoint_SaveScores(t *testing.T) {
t.Fatal(err)
}

req, err := http.NewRequest("POST", "/scores?token=" + key + "&room=" + room, bytes.NewBuffer(body))
req, err := http.NewRequest("POST", "/scores?token="+key+"&room="+room, bytes.NewBuffer(body))
if err != nil {
t.Fatal(err)
}
Expand Down