Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions resources/postman/Switcher GitOps.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
{
"name": "Create",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{gitopsToken}}",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"body": {
Expand All @@ -38,6 +48,16 @@
{
"name": "Update",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{gitopsToken}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [],
"body": {
Expand All @@ -64,6 +84,16 @@
{
"name": "Update (token)",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{gitopsToken}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [],
"body": {
Expand All @@ -90,6 +120,16 @@
{
"name": "Update (force sync)",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{gitopsToken}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [],
"body": {
Expand Down Expand Up @@ -119,6 +159,16 @@
"disableBodyPruning": true
},
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{gitopsToken}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"body": {
Expand Down Expand Up @@ -146,6 +196,16 @@
{
"name": "Fetch By Domain Id / Env",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{gitopsToken}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
Expand All @@ -165,6 +225,16 @@
{
"name": "Delete By Domain Id / Env",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{gitopsToken}}",
"type": "string"
}
]
},
"method": "DELETE",
"header": [],
"body": {
Expand Down
20 changes: 20 additions & 0 deletions resources/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ servers:
description: Local
- url: https://localhost:8000
description: Remote
tags:
- name: API
description: API status & docs
- name: Account API
description: Account management
paths:
/api/check:
get:
Expand Down Expand Up @@ -64,6 +69,8 @@ paths:
- Account API
summary: Create a new account
description: Create a new account and starts handler when active
security:
- bearerAuth: []
requestBody:
required: true
content:
Expand Down Expand Up @@ -94,6 +101,8 @@ paths:
- Account API
summary: Update an existing account
description: Update an existing account and starts handler when active
security:
- bearerAuth: []
requestBody:
required: true
content:
Expand Down Expand Up @@ -125,6 +134,8 @@ paths:
- Account API
summary: Get All accounts by domain ID
description: Get all accounts by domain ID
security:
- bearerAuth: []
parameters:
- name: domainId
in: path
Expand Down Expand Up @@ -166,6 +177,8 @@ paths:
- Account API
summary: Get account by domain ID and environment
description: Get account by domain ID and environment
security:
- bearerAuth: []
parameters:
- name: domainId
in: path
Expand Down Expand Up @@ -210,6 +223,8 @@ paths:
- Account API
summary: Delete account by domain ID and environment
description: Delete account by domain ID and environment
security:
- bearerAuth: []
parameters:
- name: domainId
in: path
Expand Down Expand Up @@ -240,6 +255,11 @@ paths:
schema:
$ref: '#/components/schemas/ErrorResponse'
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
schemas:
AccountRequest:
type: object
Expand Down
25 changes: 10 additions & 15 deletions src/controller/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ func NewAccountController(repo repository.AccountRepository, coreHandler *core.C
}

func (controller *AccountController) RegisterRoutes(r *mux.Router) http.Handler {
r.NewRoute().Path(controller.routeAccountPath).Name("CreateAccount").HandlerFunc(controller.CreateAccountHandler).Methods(http.MethodPost)
r.NewRoute().Path(controller.routeAccountPath).Name("UpdateAccount").HandlerFunc(controller.UpdateAccountHandler).Methods(http.MethodPut)
r.NewRoute().Path(controller.routeAccountPath + "/{domainId}").Name("GelAllAccountsByDomainId").HandlerFunc(controller.FetchAllAccountsByDomainIdHandler).Methods(http.MethodGet)
r.NewRoute().Path(controller.routeAccountPath + "/{domainId}/{enviroment}").Name("GetAccount").HandlerFunc(controller.FetchAccountHandler).Methods(http.MethodGet)
r.NewRoute().Path(controller.routeAccountPath + "/{domainId}/{enviroment}").Name("DeleteAccount").HandlerFunc(controller.DeleteAccountHandler).Methods(http.MethodDelete)
r.NewRoute().Path(controller.routeAccountPath).Name("CreateAccount").Handler(
ValidateToken(http.HandlerFunc(controller.CreateAccountHandler))).Methods(http.MethodPost)
r.NewRoute().Path(controller.routeAccountPath).Name("UpdateAccount").Handler(
ValidateToken(http.HandlerFunc(controller.UpdateAccountHandler))).Methods(http.MethodPut)
r.NewRoute().Path(controller.routeAccountPath + "/{domainId}").Name("GelAllAccountsByDomainId").Handler(
ValidateToken(http.HandlerFunc(controller.FetchAllAccountsByDomainIdHandler))).Methods(http.MethodGet)
r.NewRoute().Path(controller.routeAccountPath + "/{domainId}/{enviroment}").Name("GetAccount").Handler(
ValidateToken(http.HandlerFunc(controller.FetchAccountHandler))).Methods(http.MethodGet)
r.NewRoute().Path(controller.routeAccountPath + "/{domainId}/{enviroment}").Name("DeleteAccount").Handler(
ValidateToken(http.HandlerFunc(controller.DeleteAccountHandler))).Methods(http.MethodDelete)

return r
}

func (controller *AccountController) CreateAccountHandler(w http.ResponseWriter, r *http.Request) {
ConfigureHeaders(w)

var accountRequest model.Account
err := json.NewDecoder(r.Body).Decode(&accountRequest)
if err != nil {
Expand Down Expand Up @@ -71,8 +74,6 @@ func (controller *AccountController) CreateAccountHandler(w http.ResponseWriter,
}

func (controller *AccountController) FetchAccountHandler(w http.ResponseWriter, r *http.Request) {
ConfigureHeaders(w)

domainId := mux.Vars(r)["domainId"]
enviroment := mux.Vars(r)["enviroment"]

Expand All @@ -88,8 +89,6 @@ func (controller *AccountController) FetchAccountHandler(w http.ResponseWriter,
}

func (controller *AccountController) FetchAllAccountsByDomainIdHandler(w http.ResponseWriter, r *http.Request) {
ConfigureHeaders(w)

domainId := mux.Vars(r)["domainId"]

accounts := controller.accountRepository.FetchAllByDomainId(domainId)
Expand All @@ -109,8 +108,6 @@ func (controller *AccountController) FetchAllAccountsByDomainIdHandler(w http.Re
}

func (controller *AccountController) UpdateAccountHandler(w http.ResponseWriter, r *http.Request) {
ConfigureHeaders(w)

var accountRequest model.Account
err := json.NewDecoder(r.Body).Decode(&accountRequest)
if err != nil {
Expand All @@ -136,8 +133,6 @@ func (controller *AccountController) UpdateAccountHandler(w http.ResponseWriter,
}

func (controller *AccountController) DeleteAccountHandler(w http.ResponseWriter, r *http.Request) {
ConfigureHeaders(w)

domainId := mux.Vars(r)["domainId"]
enviroment := mux.Vars(r)["enviroment"]

Expand Down
Loading