Jelajahi Sumber

add handlers to router

Alexander Belanger 4 tahun lalu
induk
melakukan
857b96a667
2 mengubah file dengan 53 tambahan dan 3 penghapusan
  1. 24 0
      api/server/router/base.go
  2. 29 3
      api/server/router/user.go

+ 24 - 0
api/server/router/base.go

@@ -71,5 +71,29 @@ func GetBaseRoutes(
 		Router:   r,
 	})
 
+	// POST /api/cli/login/exchange -> user.NewCLILoginExchangeHandler
+	cliLoginExchangeEndpoint := factory.NewAPIEndpoint(
+		&types.APIRequestMetadata{
+			Verb:   types.APIVerbCreate,
+			Method: types.HTTPVerbPost,
+			Path: &types.Path{
+				Parent:       basePath,
+				RelativePath: "/cli/login/exchange",
+			},
+		},
+	)
+
+	cliLoginExchangeHandler := user.NewCLILoginExchangeHandler(
+		config,
+		factory.GetDecoderValidator(),
+		factory.GetResultWriter(),
+	)
+
+	routes = append(routes, &Route{
+		Endpoint: cliLoginExchangeEndpoint,
+		Handler:  cliLoginExchangeHandler,
+		Router:   r,
+	})
+
 	return routes
 }

+ 29 - 3
api/server/router/user.go

@@ -43,6 +43,32 @@ func getUserRoutes(
 ) []*Route {
 	routes := make([]*Route, 0)
 
+	// GET /api/cli/login -> user.user.NewCLILoginHandler
+	cliLoginUserEndpoint := factory.NewAPIEndpoint(
+		&types.APIRequestMetadata{
+			Verb:   types.APIVerbGet,
+			Method: types.HTTPVerbGet,
+			Path: &types.Path{
+				Parent:       basePath,
+				RelativePath: "/cli/login",
+			},
+			Scopes:         []types.PermissionScope{types.UserScope},
+			ShouldRedirect: true,
+		},
+	)
+
+	cliLoginUserHandler := user.NewCLILoginHandler(
+		config,
+		factory.GetDecoderValidator(),
+		factory.GetResultWriter(),
+	)
+
+	routes = append(routes, &Route{
+		Endpoint: cliLoginUserEndpoint,
+		Handler:  cliLoginUserHandler,
+		Router:   r,
+	})
+
 	// POST /api/logout -> user.NewUserLogoutHandler
 	logoutUserEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{
@@ -64,20 +90,20 @@ func getUserRoutes(
 		Router:   r,
 	})
 
-	// GET /api/auth/check -> user.NewAuthCheckHandler
+	// GET /api/users/current -> user.NewUserGetCurrentHandler
 	authCheckEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{
 			Verb:   types.APIVerbGet,
 			Method: types.HTTPVerbGet,
 			Path: &types.Path{
 				Parent:       basePath,
-				RelativePath: "/auth/check",
+				RelativePath: "/users/current",
 			},
 			Scopes: []types.PermissionScope{types.UserScope},
 		},
 	)
 
-	authCheckHandler := user.NewAuthCheckHandler(
+	authCheckHandler := user.NewUserGetCurrentHandler(
 		config,
 		factory.GetResultWriter(),
 	)