From 786291cfbe7f2b557aed08b84e304ccdcb7ee1d3 Mon Sep 17 00:00:00 2001 From: "taekyu.kang" Date: Wed, 20 Mar 2024 13:54:12 +0900 Subject: [PATCH] trivial. change api role for organizations --- api/swagger/docs.go | 118 +++--------------- api/swagger/swagger.json | 118 +++--------------- api/swagger/swagger.yaml | 79 ++---------- internal/delivery/api/endpoint.go | 3 +- .../delivery/api/generated_endpoints.go.go | 20 +-- internal/delivery/http/organization.go | 53 +------- internal/route/route.go | 1 - pkg/domain/organization.go | 15 +-- 8 files changed, 55 insertions(+), 352 deletions(-) diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 56497339..899b040f 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -202,52 +202,6 @@ const docTemplate = `{ } } }, - "/admin/organizations/{organizationId}": { - "put": { - "security": [ - { - "JWT": [] - } - ], - "description": "Update organization detail ( for admin )", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Organizations" - ], - "summary": "Update organization detail ( for admin )", - "parameters": [ - { - "type": "string", - "description": "organizationId", - "name": "organizationId", - "in": "path", - "required": true - }, - { - "description": "update organization request", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationResponse" - } - } - } - } - }, "/admin/organizations/{organizationId}/projects": { "get": { "security": [ @@ -7395,53 +7349,6 @@ const docTemplate = `{ } } }, - "github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationRequest": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "description": { - "type": "string", - "maxLength": 100, - "minLength": 0 - }, - "name": { - "type": "string", - "maxLength": 30, - "minLength": 1 - }, - "policyTemplateIds": { - "type": "array", - "items": { - "type": "string" - } - }, - "primaryClusterId": { - "type": "string" - }, - "stackTemplateIds": { - "type": "array", - "items": { - "type": "string" - } - }, - "systemNotificationTemplateIds": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationResponse": { - "type": "object", - "properties": { - "id": { - "type": "string" - } - } - }, "github_com_openinfradev_tks-api_pkg_domain.AppGroupResponse": { "type": "object", "properties": { @@ -11276,22 +11183,31 @@ const docTemplate = `{ "maxLength": 30, "minLength": 1 }, - "primaryClusterId": { - "type": "string" + "policyTemplateIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "stackTemplateIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "systemNotificationTemplateIds": { + "type": "array", + "items": { + "type": "string" + } } } }, "github_com_openinfradev_tks-api_pkg_domain.UpdateOrganizationResponse": { "type": "object", "properties": { - "description": { - "type": "string" - }, "id": { "type": "string" - }, - "name": { - "type": "string" } } }, diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 77d56851..3187f9a6 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -196,52 +196,6 @@ } } }, - "/admin/organizations/{organizationId}": { - "put": { - "security": [ - { - "JWT": [] - } - ], - "description": "Update organization detail ( for admin )", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Organizations" - ], - "summary": "Update organization detail ( for admin )", - "parameters": [ - { - "type": "string", - "description": "organizationId", - "name": "organizationId", - "in": "path", - "required": true - }, - { - "description": "update organization request", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationResponse" - } - } - } - } - }, "/admin/organizations/{organizationId}/projects": { "get": { "security": [ @@ -7389,53 +7343,6 @@ } } }, - "github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationRequest": { - "type": "object", - "required": [ - "name" - ], - "properties": { - "description": { - "type": "string", - "maxLength": 100, - "minLength": 0 - }, - "name": { - "type": "string", - "maxLength": 30, - "minLength": 1 - }, - "policyTemplateIds": { - "type": "array", - "items": { - "type": "string" - } - }, - "primaryClusterId": { - "type": "string" - }, - "stackTemplateIds": { - "type": "array", - "items": { - "type": "string" - } - }, - "systemNotificationTemplateIds": { - "type": "array", - "items": { - "type": "string" - } - } - } - }, - "github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationResponse": { - "type": "object", - "properties": { - "id": { - "type": "string" - } - } - }, "github_com_openinfradev_tks-api_pkg_domain.AppGroupResponse": { "type": "object", "properties": { @@ -11270,22 +11177,31 @@ "maxLength": 30, "minLength": 1 }, - "primaryClusterId": { - "type": "string" + "policyTemplateIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "stackTemplateIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "systemNotificationTemplateIds": { + "type": "array", + "items": { + "type": "string" + } } } }, "github_com_openinfradev_tks-api_pkg_domain.UpdateOrganizationResponse": { "type": "object", "properties": { - "description": { - "type": "string" - }, "id": { "type": "string" - }, - "name": { - "type": "string" } } }, diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index d89bcc96..9aff6be7 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -147,38 +147,6 @@ definitions: $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.ProjectMemberRequest' type: array type: object - github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationRequest: - properties: - description: - maxLength: 100 - minLength: 0 - type: string - name: - maxLength: 30 - minLength: 1 - type: string - policyTemplateIds: - items: - type: string - type: array - primaryClusterId: - type: string - stackTemplateIds: - items: - type: string - type: array - systemNotificationTemplateIds: - items: - type: string - type: array - required: - - name - type: object - github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationResponse: - properties: - id: - type: string - type: object github_com_openinfradev_tks-api_pkg_domain.AppGroupResponse: properties: appGroupType: @@ -2744,19 +2712,25 @@ definitions: maxLength: 30 minLength: 1 type: string - primaryClusterId: - type: string + policyTemplateIds: + items: + type: string + type: array + stackTemplateIds: + items: + type: string + type: array + systemNotificationTemplateIds: + items: + type: string + type: array required: - name type: object github_com_openinfradev_tks-api_pkg_domain.UpdateOrganizationResponse: properties: - description: - type: string id: type: string - name: - type: string type: object github_com_openinfradev_tks-api_pkg_domain.UpdatePasswordRequest: properties: @@ -3212,35 +3186,6 @@ paths: summary: Get Audit tags: - Audits - /admin/organizations/{organizationId}: - put: - consumes: - - application/json - description: Update organization detail ( for admin ) - parameters: - - description: organizationId - in: path - name: organizationId - required: true - type: string - - description: update organization request - in: body - name: body - required: true - schema: - $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationRequest' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.Admin_UpdateOrganizationResponse' - security: - - JWT: [] - summary: Update organization detail ( for admin ) - tags: - - Organizations /admin/organizations/{organizationId}/projects: get: consumes: diff --git a/internal/delivery/api/endpoint.go b/internal/delivery/api/endpoint.go index 31cabce6..ef22dee0 100644 --- a/internal/delivery/api/endpoint.go +++ b/internal/delivery/api/endpoint.go @@ -41,10 +41,9 @@ const ( // Organization Admin_CreateOrganization Admin_DeleteOrganization - Admin_UpdateOrganization + UpdateOrganization GetOrganizations GetOrganization - UpdateOrganization UpdatePrimaryCluster CheckOrganizationName diff --git a/internal/delivery/api/generated_endpoints.go.go b/internal/delivery/api/generated_endpoints.go.go index a02951c3..a7d7a599 100644 --- a/internal/delivery/api/generated_endpoints.go.go +++ b/internal/delivery/api/generated_endpoints.go.go @@ -99,8 +99,8 @@ var ApiMap = map[Endpoint]EndpointInfo{ Name: "Admin_DeleteOrganization", Group: "Organization", }, - Admin_UpdateOrganization: { - Name: "Admin_UpdateOrganization", + UpdateOrganization: { + Name: "UpdateOrganization", Group: "Organization", }, GetOrganizations: { @@ -111,10 +111,6 @@ var ApiMap = map[Endpoint]EndpointInfo{ Name: "GetOrganization", Group: "Organization", }, - UpdateOrganization: { - Name: "UpdateOrganization", - Group: "Organization", - }, UpdatePrimaryCluster: { Name: "UpdatePrimaryCluster", Group: "Organization", @@ -830,14 +826,12 @@ func (e Endpoint) String() string { return "Admin_CreateOrganization" case Admin_DeleteOrganization: return "Admin_DeleteOrganization" - case Admin_UpdateOrganization: - return "Admin_UpdateOrganization" + case UpdateOrganization: + return "UpdateOrganization" case GetOrganizations: return "GetOrganizations" case GetOrganization: return "GetOrganization" - case UpdateOrganization: - return "UpdateOrganization" case UpdatePrimaryCluster: return "UpdatePrimaryCluster" case CheckOrganizationName: @@ -1224,14 +1218,12 @@ func GetEndpoint(name string) Endpoint { return Admin_CreateOrganization case "Admin_DeleteOrganization": return Admin_DeleteOrganization - case "Admin_UpdateOrganization": - return Admin_UpdateOrganization + case "UpdateOrganization": + return UpdateOrganization case "GetOrganizations": return GetOrganizations case "GetOrganization": return GetOrganization - case "UpdateOrganization": - return UpdateOrganization case "UpdatePrimaryCluster": return UpdatePrimaryCluster case "CheckOrganizationName": diff --git a/internal/delivery/http/organization.go b/internal/delivery/http/organization.go index 1932db7c..ea446b40 100644 --- a/internal/delivery/http/organization.go +++ b/internal/delivery/http/organization.go @@ -325,57 +325,6 @@ func (h *OrganizationHandler) UpdateOrganization(w http.ResponseWriter, r *http. log.Info(r.Context(), err) } - organization, err := h.usecase.Update(r.Context(), organizationId, dto) - if err != nil { - log.Errorf(r.Context(), "error is :%s(%T)", err.Error(), err) - if _, status := httpErrors.ErrorResponse(err); status == http.StatusNotFound { - ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "", "")) - return - } - ErrorJSON(w, r, err) - return - } - - var out domain.UpdateOrganizationResponse - if err = serializer.Map(r.Context(), organization, &out); err != nil { - log.Error(r.Context(), err) - } - - ResponseJSON(w, r, http.StatusOK, out) -} - -// Admin_UpdateOrganization godoc -// -// @Tags Organizations -// @Summary Update organization detail ( for admin ) -// @Description Update organization detail ( for admin ) -// @Accept json -// @Produce json -// @Param organizationId path string true "organizationId" -// @Param body body domain.Admin_UpdateOrganizationRequest true "update organization request" -// @Success 200 {object} domain.Admin_UpdateOrganizationResponse -// @Router /admin/organizations/{organizationId} [put] -// @Security JWT -func (h *OrganizationHandler) Admin_UpdateOrganization(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - organizationId, ok := vars["organizationId"] - if !ok { - ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("invalid organizationId"), "C_INVALID_ORGANIZATION_ID", "")) - return - } - - input := domain.Admin_UpdateOrganizationRequest{} - err := UnmarshalRequestInput(r, &input) - if err != nil { - ErrorJSON(w, r, err) - return - } - - var dto model.Organization - if err = serializer.Map(r.Context(), input, &dto); err != nil { - log.Info(r.Context(), err) - } - for _, strId := range input.StackTemplateIds { stackTemplateId, err := uuid.Parse(strId) if err != nil || stackTemplateId == uuid.Nil { @@ -407,7 +356,7 @@ func (h *OrganizationHandler) Admin_UpdateOrganization(w http.ResponseWriter, r return } - var out domain.Admin_UpdateOrganizationResponse + var out domain.UpdateOrganizationResponse out.ID = organizationId ResponseJSON(w, r, http.StatusOK, out) diff --git a/internal/route/route.go b/internal/route/route.go index 265cd513..bf7b1627 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -129,7 +129,6 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa organizationHandler := delivery.NewOrganizationHandler(usecaseFactory) r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/organizations", customMiddleware.Handle(internalApi.Admin_CreateOrganization, http.HandlerFunc(organizationHandler.Admin_CreateOrganization))).Methods(http.MethodPost) r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/organizations/{organizationId}", customMiddleware.Handle(internalApi.Admin_DeleteOrganization, http.HandlerFunc(organizationHandler.Admin_DeleteOrganization))).Methods(http.MethodDelete) - r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/organizations/{organizationId}", customMiddleware.Handle(internalApi.Admin_UpdateOrganization, http.HandlerFunc(organizationHandler.Admin_UpdateOrganization))).Methods(http.MethodPut) r.Handle(API_PREFIX+API_VERSION+"/organizations", customMiddleware.Handle(internalApi.GetOrganizations, http.HandlerFunc(organizationHandler.GetOrganizations))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}", customMiddleware.Handle(internalApi.GetOrganization, http.HandlerFunc(organizationHandler.GetOrganization))).Methods(http.MethodGet) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}", customMiddleware.Handle(internalApi.UpdateOrganization, http.HandlerFunc(organizationHandler.UpdateOrganization))).Methods(http.MethodPut) diff --git a/pkg/domain/organization.go b/pkg/domain/organization.go index 8f97f42d..478dc45b 100644 --- a/pkg/domain/organization.go +++ b/pkg/domain/organization.go @@ -91,19 +91,6 @@ type ListOrganizationResponse struct { } type UpdateOrganizationRequest struct { - PrimaryClusterId string `json:"primaryClusterId"` - Name string `json:"name" validate:"required,min=1,max=30"` - Description string `json:"description" validate:"omitempty,min=0,max=100"` -} - -type UpdateOrganizationResponse struct { - ID string `json:"id"` - Name string `json:"name"` - Description string `json:"description"` -} - -type Admin_UpdateOrganizationRequest struct { - PrimaryClusterId string `json:"primaryClusterId"` Name string `json:"name" validate:"required,min=1,max=30"` Description string `json:"description" validate:"omitempty,min=0,max=100"` StackTemplateIds []string `json:"stackTemplateIds"` @@ -111,7 +98,7 @@ type Admin_UpdateOrganizationRequest struct { SystemNotificationTemplateIds []string `json:"systemNotificationTemplateIds"` } -type Admin_UpdateOrganizationResponse struct { +type UpdateOrganizationResponse struct { ID string `json:"id"` }