Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rename method
  • Loading branch information
AbhineetJain committed Jul 14, 2022
commit 1330dc806245ff091a92d6120c29db6eb4806099
17 changes: 9 additions & 8 deletions coderd/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (api *API) templateVersion(rw http.ResponseWriter, r *http.Request) {
return
}

createdByName, err := getCreatedByNameByTemplateVersionID(r.Context(), api.Database, templateVersion)
createdByName, err := getUsernameByUserID(r.Context(), api.Database, templateVersion.CreatedBy)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching creator name.",
Expand Down Expand Up @@ -486,10 +486,11 @@ func (api *API) templateVersionsByTemplate(rw http.ResponseWriter, r *http.Reque
})
return err
}
createdByName, err := getCreatedByNameByTemplateVersionID(r.Context(), api.Database, version)
createdByName, err := getUsernameByUserID(r.Context(), api.Database, version.CreatedBy)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: fmt.Sprintf("Internal error fetching creator name (user %q) for version %q.", version.CreatedBy, version.ID),
Message: "Internal error fetching creator name.",
Detail: err.Error(),
})
return err
}
Expand Down Expand Up @@ -542,7 +543,7 @@ func (api *API) templateVersionByName(rw http.ResponseWriter, r *http.Request) {
return
}

createdByName, err := getCreatedByNameByTemplateVersionID(r.Context(), api.Database, templateVersion)
createdByName, err := getUsernameByUserID(r.Context(), api.Database, templateVersion.CreatedBy)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching creator name.",
Expand Down Expand Up @@ -775,7 +776,7 @@ func (api *API) postTemplateVersionsByOrganization(rw http.ResponseWriter, r *ht
return
}

createdByName, err := getCreatedByNameByTemplateVersionID(r.Context(), api.Database, templateVersion)
createdByName, err := getUsernameByUserID(r.Context(), api.Database, templateVersion.CreatedBy)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching creator name.",
Expand Down Expand Up @@ -832,12 +833,12 @@ func (api *API) templateVersionLogs(rw http.ResponseWriter, r *http.Request) {
api.provisionerJobLogs(rw, r, job)
}

func getCreatedByNameByTemplateVersionID(ctx context.Context, db database.Store, templateVersion database.TemplateVersion) (string, error) {
creator, err := db.GetUserByID(ctx, templateVersion.CreatedBy)
func getUsernameByUserID(ctx context.Context, db database.Store, userID uuid.UUID) (string, error) {
user, err := db.GetUserByID(ctx, userID)
if err != nil {
return "", err
}
return creator.Username, nil
return user.Username, nil
}

func convertTemplateVersion(version database.TemplateVersion, job codersdk.ProvisionerJob, createdByName string) codersdk.TemplateVersion {
Expand Down