Skip to content

Commit

Permalink
handlers: add git parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
hayzamjs committed Sep 7, 2024
1 parent 52a6cc1 commit 04973cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion handlers/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func CreateDocumentation(services *services.ServiceRegistry, w http.ResponseWrit
MoreLabelLinks string `json:"moreLabelLinks"`
CopyrightText string `json:"copyrightText" validate:"required"`
RequireAuth bool `json:"requireAuth"`
GitRepo string `json:"gitRepo"`
GitBranch string `json:"gitBranch"`
GitUser string `json:"gitUser"`
GitPassword string `json:"gitPassword"`
}

req, err := ValidateRequest[Request](w, r)
Expand Down Expand Up @@ -114,6 +118,10 @@ func CreateDocumentation(services *services.ServiceRegistry, w http.ResponseWrit
MoreLabelLinks: req.MoreLabelLinks,
CopyrightText: req.CopyrightText,
RequireAuth: req.RequireAuth,
GitRepo: req.GitRepo,
GitBranch: req.GitBranch,
GitUser: req.GitUser,
GitPassword: req.GitPassword,
}

err = services.DocService.CreateDocumentation(documentation, user)
Expand Down Expand Up @@ -146,6 +154,10 @@ func EditDocumentation(services *services.ServiceRegistry, w http.ResponseWriter
MoreLabelLinks string `json:"moreLabelLinks"`
CopyrightText string `json:"copyrightText" validate:"required"`
RequireAuth bool `json:"requireAuth"`
GitRepo string `json:"gitRepo"`
GitBranch string `json:"gitBranch"`
GitUser string `json:"gitUser"`
GitPassword string `json:"gitPassword"`
}

req, err := ValidateRequest[Request](w, r)
Expand All @@ -166,7 +178,9 @@ func EditDocumentation(services *services.ServiceRegistry, w http.ResponseWriter
return
}

err = services.DocService.EditDocumentation(user, req.ID, req.Name, req.Description, req.Version, req.Favicon, req.MetaImage, req.NavImage, req.NavImageDark, req.CustomCSS, req.FooterLabelLinks, req.MoreLabelLinks, req.CopyrightText, req.URL, req.OrganizationName, req.ProjectName, req.BaseURL, req.LanderDetails, req.RequireAuth)
err = services.DocService.EditDocumentation(user, req.ID, req.Name, req.Description, req.Version, req.Favicon, req.MetaImage,
req.NavImage, req.NavImageDark, req.CustomCSS, req.FooterLabelLinks, req.MoreLabelLinks, req.CopyrightText,
req.URL, req.OrganizationName, req.ProjectName, req.BaseURL, req.LanderDetails, req.RequireAuth, req.GitRepo, req.GitBranch, req.GitUser, req.GitPassword)

if err != nil {
SendJSONResponse(http.StatusInternalServerError, w, map[string]string{"status": "error", "message": err.Error()})
Expand Down
13 changes: 12 additions & 1 deletion services/docs_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ func (service *DocService) CreateDocumentation(documentation *models.Documentati
return nil
}

func (service *DocService) EditDocumentation(user models.User, id uint, name, description, version, favicon, metaImage, navImage, navImageDark, customCSS, footerLabelLinks, moreLabelLinks, copyrightText, url, organizationName, projectName, baseURL, landerDetails string, requireAuth bool) error {
func (service *DocService) EditDocumentation(user models.User, id uint, name, description, version, favicon, metaImage, navImage,
navImageDark, customCSS, footerLabelLinks, moreLabelLinks, copyrightText, url,
organizationName, projectName, baseURL, landerDetails string, requireAuth bool,
gitRepo string, gitBranch string, gitUser string, gitPassword string) error {
tx := service.DB.Begin()
if !utils.IsBaseURLValid(baseURL) {
return fmt.Errorf("invalid_base_url")
Expand All @@ -282,6 +285,10 @@ func (service *DocService) EditDocumentation(user models.User, id uint, name, de
doc.MoreLabelLinks = moreLabelLinks
doc.CopyrightText = copyrightText
doc.RequireAuth = requireAuth
doc.GitRepo = gitRepo
doc.GitBranch = gitBranch
doc.GitUser = gitUser
doc.GitPassword = gitPassword
if isTarget && version != "" {
doc.Version = version
}
Expand Down Expand Up @@ -506,6 +513,10 @@ func (service *DocService) CreateDocumentationVersion(originalDocId uint, newVer
Editors: originalDoc.Editors,
LastEditorID: originalDoc.LastEditorID,
RequireAuth: originalDoc.RequireAuth,
GitRepo: originalDoc.GitRepo,
GitBranch: originalDoc.GitBranch,
GitUser: originalDoc.GitUser,
GitPassword: originalDoc.GitPassword,
}

err = service.DB.Transaction(func(tx *gorm.DB) error {
Expand Down

0 comments on commit 04973cf

Please sign in to comment.