Skip to content

Commit

Permalink
featue. implementation application of appGroups
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Mar 17, 2023
1 parent 1c8d00b commit f546934
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 2 deletions.
87 changes: 87 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,45 @@ const docTemplate = `{
}
}
},
"/app-groups/{appGroupId}/applications": {
"post": {
"security": [
{
"JWT": []
}
],
"description": "Update application",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"AppGroups"
],
"summary": "Update application",
"parameters": [
{
"description": "body",
"name": "object",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/domain.UpdateApplicationRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
}
},
"/app-serve-apps": {
"get": {
"security": [
Expand Down Expand Up @@ -394,6 +433,37 @@ const docTemplate = `{
}
}
},
"/auth/roles": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "roles",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Auth"
],
"summary": "roles",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/domain.Role"
}
}
}
}
}
},
"/auth/signup": {
"post": {
"security": [
Expand Down Expand Up @@ -1066,6 +1136,23 @@ const docTemplate = `{
}
}
},
"domain.UpdateApplicationRequest": {
"type": "object",
"properties": {
"appGroupId": {
"type": "string"
},
"appType": {
"type": "string"
},
"endpoint": {
"type": "string"
},
"metadata": {
"type": "string"
}
}
},
"domain.User": {
"type": "object",
"properties": {
Expand Down
87 changes: 87 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,45 @@
}
}
},
"/app-groups/{appGroupId}/applications": {
"post": {
"security": [
{
"JWT": []
}
],
"description": "Update application",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"AppGroups"
],
"summary": "Update application",
"parameters": [
{
"description": "body",
"name": "object",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/domain.UpdateApplicationRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
}
},
"/app-serve-apps": {
"get": {
"security": [
Expand Down Expand Up @@ -387,6 +426,37 @@
}
}
},
"/auth/roles": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "roles",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Auth"
],
"summary": "roles",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/domain.Role"
}
}
}
}
}
},
"/auth/signup": {
"post": {
"security": [
Expand Down Expand Up @@ -1059,6 +1129,23 @@
}
}
},
"domain.UpdateApplicationRequest": {
"type": "object",
"properties": {
"appGroupId": {
"type": "string"
},
"appType": {
"type": "string"
},
"endpoint": {
"type": "string"
},
"metadata": {
"type": "string"
}
}
},
"domain.User": {
"type": "object",
"properties": {
Expand Down
54 changes: 54 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ definitions:
password:
type: string
type: object
domain.UpdateApplicationRequest:
properties:
appGroupId:
type: string
appType:
type: string
endpoint:
type: string
metadata:
type: string
type: object
domain.User:
properties:
accountId:
Expand Down Expand Up @@ -345,6 +356,30 @@ paths:
summary: Get appGroup detail
tags:
- AppGroups
/app-groups/{appGroupId}/applications:
post:
consumes:
- application/json
description: Update application
parameters:
- description: body
in: body
name: object
required: true
schema:
$ref: '#/definitions/domain.UpdateApplicationRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
type: object
security:
- JWT: []
summary: Update application
tags:
- AppGroups
/app-serve-apps:
delete:
consumes:
Expand Down Expand Up @@ -481,6 +516,25 @@ paths:
summary: login
tags:
- Auth
/auth/roles:
get:
consumes:
- application/json
description: roles
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/domain.Role'
type: array
security:
- JWT: []
summary: roles
tags:
- Auth
/auth/signup:
post:
consumes:
Expand Down
3 changes: 3 additions & 0 deletions internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func migrateSchema(db *gorm.DB) error {
if err := db.AutoMigrate(&repository.AppGroup{}); err != nil {
return err
}
if err := db.AutoMigrate(&repository.Application{}); err != nil {
return err
}
if err := db.AutoMigrate(&repository.AppServeApp{}); err != nil {
return err
}
Expand Down
40 changes: 40 additions & 0 deletions internal/delivery/http/app-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,43 @@ func (h *AppGroupHandler) DeleteAppGroup(w http.ResponseWriter, r *http.Request)

ResponseJSON(w, nil, "", http.StatusOK)
}

// UpdateApplication godoc
// @Tags AppGroups
// @Summary Update application
// @Description Update application
// @Accept json
// @Produce json
// @Param object body domain.UpdateApplicationRequest true "body"
// @Success 200 {object} object
// @Router /app-groups/{appGroupId}/applications [post]
// @Security JWT
func (h *AppGroupHandler) UpdateApplication(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
appGroupId, ok := vars["appGroupId"]
if !ok {
ErrorJSON(w, "Invalid prameters", http.StatusBadRequest)
return
}

var input = domain.UpdateApplicationRequest{}
body, err := io.ReadAll(r.Body)
if err != nil {
ErrorJSON(w, "Invalid json", http.StatusBadRequest)
return
}
err = json.Unmarshal(body, &input)
if err != nil {
ErrorJSON(w, "Invalid json", http.StatusBadRequest)
return
}

err = h.usecase.UpdateApplication(appGroupId, input)
if err != nil {
log.Error("Failed to update application err : ", err)
InternalServerError(w, err)
return
}

ResponseJSON(w, nil, "", http.StatusOK)
}
24 changes: 24 additions & 0 deletions internal/delivery/http/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,27 @@ func (h *AuthHandler) Signup(w http.ResponseWriter, r *http.Request) {

ResponseJSON(w, out, "", http.StatusOK)
}

// GetRoles godoc
// @Tags Auth
// @Summary roles
// @Description roles
// @Accept json
// @Produce json
// @Success 200 {object} []domain.Role
// @Router /auth/roles [get]
// @Security JWT
func (h *AuthHandler) GetRoles(w http.ResponseWriter, r *http.Request) {
roles, err := h.usecase.FetchRoles()
if err != nil {
InternalServerError(w, err)
return
}

var out struct {
Roles []domain.Role
}
out.Roles = roles

ResponseJSON(w, out, "", http.StatusOK)
}
Loading

0 comments on commit f546934

Please sign in to comment.