Skip to content

Commit

Permalink
fixing template creation i guess
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloose committed Dec 2, 2024
1 parent 746d510 commit 9a613e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 49 deletions.
64 changes: 33 additions & 31 deletions stiller-backend/internal/handlers/post_template.new.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,39 @@ func PostTemplateNew(w http.ResponseWriter, r *http.Request, params httprouter.P
return
}

abs_path := fsop.GetTemplatePath(templatefile_id)
newtempl_stmt := sqlf.
InsertInto("template").
NewRow().
Set("tier", req_payload.TierId).
Set("title", req_payload.Title).
Set("description", req_payload.Description).
Set("templatefile", templatefile_id).
Set("owner", user_id).
Returning("id")

newtempl_query, newtempl_args := newtempl_stmt.String(), newtempl_stmt.Args()
newtemp_id := int(-1)
newtemp_exec_err := sqlitex.ExecuteTransient(new_dbconn, newtempl_query, &sqlitex.ExecOptions{
ResultFunc: func(stmt *sqlite.Stmt) error {
newtemp_id = int(stmt.GetInt64("id"))
return nil
},

Args: newtempl_args,
})

if loggers.RequestLog(newtemp_exec_err, "", http.StatusInternalServerError, &w) {
return
}

if newtemp_id == -1 {
loggers.GenericErrLog(nil, "no new template was created")
w.WriteHeader(http.StatusInternalServerError)
return
}


abs_path := fsop.GetTemplatePath(newtemp_id)
tarfile, tarball_err := os.Create(abs_path)
if loggers.RequestLog(tarball_err, "", http.StatusInternalServerError, &w) {
return
Expand Down Expand Up @@ -143,36 +175,6 @@ func PostTemplateNew(w http.ResponseWriter, r *http.Request, params httprouter.P
return
}

newtempl_stmt := sqlf.
InsertInto("template").
NewRow().
Set("tier", req_payload.TierId).
Set("title", req_payload.Title).
Set("description", req_payload.Description).
Set("templatefile", templatefile_id).
Set("owner", user_id).
Returning("id")

newtempl_query, newtempl_args := newtempl_stmt.String(), newtempl_stmt.Args()
newtemp_id := int(-1)
newtemp_exec_err := sqlitex.ExecuteTransient(new_dbconn, newtempl_query, &sqlitex.ExecOptions{
ResultFunc: func(stmt *sqlite.Stmt) error {
newtemp_id = int(stmt.GetInt64("id"))
return nil
},

Args: newtempl_args,
})

if loggers.RequestLog(newtemp_exec_err, "", http.StatusInternalServerError, &w) {
return
}

if newtemp_id == -1 {
loggers.GenericErrLog(nil, "no new template was created")
w.WriteHeader(http.StatusInternalServerError)
return
}

w.WriteHeader(http.StatusOK)
}
Expand Down
19 changes: 1 addition & 18 deletions stiller-backend/pkg/dbutils/generals.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,7 @@ func GetGalleryData(gallery int) (*StillerGalleryData, error) {
return nil, ErrTemplateNotFound
}

templateFileId := int(-1)
templateFileQuery_stmt := sqlf.Select("templatefile").
From("template").
Where("id = ?", template_id)
templateFileQuery_query, templateFileQuery_args := templateFileQuery_stmt.String(), templateFileQuery_stmt.Args()
templateFileQuery_err := sqlitex.ExecuteTransient(new_dbconn, templateFileQuery_query, &sqlitex.ExecOptions{
ResultFunc: func(stmt *sqlite.Stmt) error {
templateFileId = int(stmt.GetInt64("templatefile"))
return nil
},
Args: templateFileQuery_args,
})

if templateFileId == -1 {
return nil, templateFileQuery_err
}

template_data, template_data_err := templates.GetTemplateData(templateFileId)
template_data, template_data_err := templates.GetTemplateData(template_id)
if template_data_err != nil {
return nil, template_data_err
}
Expand Down

0 comments on commit 9a613e8

Please sign in to comment.