blob: de56839b5956d80f472bb36d3d6f91c6dd277a6e [file] [log] [blame]
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package http_handlers
import (
"net/http"
"github.com/apache/dubbo-kubernetes/pkg/bufman/controllers"
registryv1alpha1 "github.com/apache/dubbo-kubernetes/pkg/bufman/gen/proto/go/registry/v1alpha1"
"github.com/gin-gonic/gin"
)
type userGroup struct {
userController *controllers.UserController
}
var UserGroup = &userGroup{
userController: controllers.NewUserController(),
}
func (group *userGroup) CreateUser(c *gin.Context) {
// 绑定参数
req := &registryv1alpha1.CreateUserRequest{}
bindErr := c.ShouldBindJSON(req)
if bindErr != nil {
c.JSON(http.StatusBadRequest, NewHTTPResponse(bindErr))
return
}
// 查询用户
resp, err := group.userController.CreateUser(c, req)
if err != nil {
c.JSON(http.StatusInternalServerError, NewHTTPResponse(err))
return
}
// 正常返回
c.JSON(http.StatusOK, NewHTTPResponse(resp))
}
func (group *userGroup) GetUser(c *gin.Context) {
// 绑定参数
req := &registryv1alpha1.GetUserRequest{}
bindErr := c.ShouldBindUri(req)
if bindErr != nil {
c.JSON(http.StatusBadRequest, NewHTTPResponse(bindErr))
return
}
resp, err := group.userController.GetUser(c, req)
if err != nil {
c.JSON(http.StatusInternalServerError, NewHTTPResponse(err))
}
// 正常返回
c.JSON(http.StatusOK, NewHTTPResponse(resp))
}
func (group *userGroup) ListUsers(c *gin.Context) {
// 绑定参数
req := &registryv1alpha1.ListUsersRequest{}
bindErr := c.ShouldBindJSON(req)
if bindErr != nil {
c.JSON(http.StatusBadRequest, NewHTTPResponse(bindErr))
return
}
resp, err := group.userController.ListUsers(c, req)
if err != nil {
c.JSON(http.StatusInternalServerError, NewHTTPResponse(err))
}
// 正常返回
c.JSON(http.StatusOK, NewHTTPResponse(resp))
}