Skip to content

Commit

Permalink
feature. add API for checking name resource on system-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Mar 28, 2024
1 parent 69ebe6c commit 6075ed7
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 0 deletions.
45 changes: 45 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,43 @@ const docTemplate = `{
}
}
},
"/admin/system-notification-templates/name/{name}/existence": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Check name for systemNotificationTemplate",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"SystemNotificationTemplates"
],
"summary": "Check name for systemNotificationTemplate",
"parameters": [
{
"type": "string",
"description": "name",
"name": "name",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificaionTemplateNameResponse"
}
}
}
}
},
"/admin/system-notification-templates/{systemNotificationTemplateId}": {
"get": {
"security": [
Expand Down Expand Up @@ -8707,6 +8744,14 @@ const docTemplate = `{
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificaionTemplateNameResponse": {
"type": "object",
"properties": {
"existed": {
"type": "boolean"
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificationRuleNameResponse": {
"type": "object",
"properties": {
Expand Down
45 changes: 45 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,43 @@
}
}
},
"/admin/system-notification-templates/name/{name}/existence": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Check name for systemNotificationTemplate",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"SystemNotificationTemplates"
],
"summary": "Check name for systemNotificationTemplate",
"parameters": [
{
"type": "string",
"description": "name",
"name": "name",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificaionTemplateNameResponse"
}
}
}
}
},
"/admin/system-notification-templates/{systemNotificationTemplateId}": {
"get": {
"security": [
Expand Down Expand Up @@ -8701,6 +8738,14 @@
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificaionTemplateNameResponse": {
"type": "object",
"properties": {
"existed": {
"type": "boolean"
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificationRuleNameResponse": {
"type": "object",
"properties": {
Expand Down
28 changes: 28 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ definitions:
existed:
type: boolean
type: object
github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificaionTemplateNameResponse:
properties:
existed:
type: boolean
type: object
github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificationRuleNameResponse:
properties:
existed:
Expand Down Expand Up @@ -4421,6 +4426,29 @@ paths:
summary: Update SystemNotificationTemplate
tags:
- SystemNotificationTemplates
/admin/system-notification-templates/name/{name}/existence:
get:
consumes:
- application/json
description: Check name for systemNotificationTemplate
parameters:
- description: name
in: path
name: name
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.CheckSystemNotificaionTemplateNameResponse'
security:
- JWT: []
summary: Check name for systemNotificationTemplate
tags:
- SystemNotificationTemplates
/app-groups:
delete:
consumes:
Expand Down
2 changes: 2 additions & 0 deletions internal/delivery/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const (
Admin_DeleteSystemNotificationTemplate
Admin_GetSystemNotificationTemplates
Admin_GetSystemNotificationTemplate
Admin_CheckSystemNotificationTemplateName
GetOrganizationSystemNotificationTemplates
AddOrganizationSystemNotificationTemplates
RemoveOrganizationSystemNotificationTemplates
Expand All @@ -131,6 +132,7 @@ const (
CreateSystemNotificationRule
GetSystemNotificationRules
GetSystemNotificationRule
CheckSystemNotificationRuleName
DeleteSystemNotificationRule
UpdateSystemNotificationRule

Expand Down
16 changes: 16 additions & 0 deletions internal/delivery/api/generated_endpoints.go.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "Admin_GetSystemNotificationTemplate",
Group: "SystemNotificationTemplate",
},
Admin_CheckSystemNotificationTemplateName: {
Name: "Admin_CheckSystemNotificationTemplateName",
Group: "SystemNotificationTemplate",
},
GetOrganizationSystemNotificationTemplates: {
Name: "GetOrganizationSystemNotificationTemplates",
Group: "SystemNotificationTemplate",
Expand All @@ -395,6 +399,10 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "GetSystemNotificationRule",
Group: "SystemNotificationRule",
},
CheckSystemNotificationRuleName: {
Name: "CheckSystemNotificationRuleName",
Group: "SystemNotificationRule",
},
DeleteSystemNotificationRule: {
Name: "DeleteSystemNotificationRule",
Group: "SystemNotificationRule",
Expand Down Expand Up @@ -998,6 +1006,8 @@ func (e Endpoint) String() string {
return "Admin_GetSystemNotificationTemplates"
case Admin_GetSystemNotificationTemplate:
return "Admin_GetSystemNotificationTemplate"
case Admin_CheckSystemNotificationTemplateName:
return "Admin_CheckSystemNotificationTemplateName"
case GetOrganizationSystemNotificationTemplates:
return "GetOrganizationSystemNotificationTemplates"
case AddOrganizationSystemNotificationTemplates:
Expand All @@ -1010,6 +1020,8 @@ func (e Endpoint) String() string {
return "GetSystemNotificationRules"
case GetSystemNotificationRule:
return "GetSystemNotificationRule"
case CheckSystemNotificationRuleName:
return "CheckSystemNotificationRuleName"
case DeleteSystemNotificationRule:
return "DeleteSystemNotificationRule"
case UpdateSystemNotificationRule:
Expand Down Expand Up @@ -1408,6 +1420,8 @@ func GetEndpoint(name string) Endpoint {
return Admin_GetSystemNotificationTemplates
case "Admin_GetSystemNotificationTemplate":
return Admin_GetSystemNotificationTemplate
case "Admin_CheckSystemNotificationTemplateName":
return Admin_CheckSystemNotificationTemplateName
case "GetOrganizationSystemNotificationTemplates":
return GetOrganizationSystemNotificationTemplates
case "AddOrganizationSystemNotificationTemplates":
Expand All @@ -1420,6 +1434,8 @@ func GetEndpoint(name string) Endpoint {
return GetSystemNotificationRules
case "GetSystemNotificationRule":
return GetSystemNotificationRule
case "CheckSystemNotificationRuleName":
return CheckSystemNotificationRuleName
case "DeleteSystemNotificationRule":
return DeleteSystemNotificationRule
case "UpdateSystemNotificationRule":
Expand Down
36 changes: 36 additions & 0 deletions internal/delivery/http/system-notification-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,39 @@ func (h *SystemNotificationTemplateHandler) RemoveOrganizationSystemNotification
}
ResponseJSON(w, r, http.StatusOK, nil)
}

// CheckSystemNotificationTemplateName godoc
//
// @Tags SystemNotificationTemplates
// @Summary Check name for systemNotificationTemplate
// @Description Check name for systemNotificationTemplate
// @Accept json
// @Produce json
// @Param name path string true "name"
// @Success 200 {object} domain.CheckSystemNotificaionTemplateNameResponse
// @Router /admin/system-notification-templates/name/{name}/existence [GET]
// @Security JWT
func (h *SystemNotificationTemplateHandler) CheckSystemNotificationTemplateName(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name, ok := vars["name"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid name"), "ST_INVALID_SYSTEM_NOTIFICATION_TEMAPLTE_NAME", ""))
return
}

exist := true
_, err := h.usecase.GetByName(r.Context(), name)
if err != nil {
if _, code := httpErrors.ErrorResponse(err); code == http.StatusNotFound {
exist = false
} else {
ErrorJSON(w, r, err)
return
}
}

var out domain.CheckSystemNotificaionTemplateNameResponse
out.Existed = exist

ResponseJSON(w, r, http.StatusOK, out)
}
2 changes: 2 additions & 0 deletions internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,15 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/system-notification-templates/{systemNotificationTemplateId}", customMiddleware.Handle(internalApi.Admin_GetSystemNotificationTemplate, http.HandlerFunc(systemNotificationTemplateHandler.GetSystemNotificationTemplate))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/system-notification-templates/{systemNotificationTemplateId}", customMiddleware.Handle(internalApi.Admin_UpdateSystemNotificationTemplate, http.HandlerFunc(systemNotificationTemplateHandler.UpdateSystemNotificationTemplate))).Methods(http.MethodPut)
r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/system-notification-templates/{systemNotificationTemplateId}", customMiddleware.Handle(internalApi.Admin_DeleteSystemNotificationTemplate, http.HandlerFunc(systemNotificationTemplateHandler.DeleteSystemNotificationTemplate))).Methods(http.MethodDelete)
r.Handle(API_PREFIX+API_VERSION+ADMINAPI_PREFIX+"/system-notification-templates/name/{name}/existence", customMiddleware.Handle(internalApi.Admin_CheckSystemNotificationTemplateName, http.HandlerFunc(systemNotificationTemplateHandler.CheckSystemNotificationTemplateName))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-templates", customMiddleware.Handle(internalApi.GetOrganizationSystemNotificationTemplates, http.HandlerFunc(systemNotificationTemplateHandler.GetOrganizationSystemNotificationTemplates))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-templates", customMiddleware.Handle(internalApi.AddOrganizationSystemNotificationTemplates, http.HandlerFunc(systemNotificationTemplateHandler.AddOrganizationSystemNotificationTemplates))).Methods(http.MethodPost)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-templates", customMiddleware.Handle(internalApi.RemoveOrganizationSystemNotificationTemplates, http.HandlerFunc(systemNotificationTemplateHandler.RemoveOrganizationSystemNotificationTemplates))).Methods(http.MethodPut)

systemNotificationRuleHandler := delivery.NewSystemNotificationRuleHandler(usecaseFactory)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules", customMiddleware.Handle(internalApi.CreateSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.CreateSystemNotificationRule))).Methods(http.MethodPost)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules", customMiddleware.Handle(internalApi.GetSystemNotificationRules, http.HandlerFunc(systemNotificationRuleHandler.GetSystemNotificationRules))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/name/{name}/existence", customMiddleware.Handle(internalApi.CheckSystemNotificationRuleName, http.HandlerFunc(systemNotificationRuleHandler.CheckSystemNotificationRuleName))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId}", customMiddleware.Handle(internalApi.GetSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.GetSystemNotificationRule))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId}", customMiddleware.Handle(internalApi.UpdateSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.UpdateSystemNotificationRule))).Methods(http.MethodPut)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/system-notification-rules/{systemNotificationRuleId}", customMiddleware.Handle(internalApi.DeleteSystemNotificationRule, http.HandlerFunc(systemNotificationRuleHandler.DeleteSystemNotificationRule))).Methods(http.MethodDelete)
Expand Down
4 changes: 4 additions & 0 deletions pkg/domain/system-notification-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ type AddOrganizationSystemNotificationTemplatesRequest struct {
type RemoveOrganizationSystemNotificationTemplatesRequest struct {
SystemNotificationTemplateIds []string `json:"systemNotificationTemplateIds" validate:"required"`
}

type CheckSystemNotificaionTemplateNameResponse struct {
Existed bool `json:"existed"`
}

0 comments on commit 6075ed7

Please sign in to comment.