Skip to content

Commit

Permalink
transitive commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pandadiestro committed Nov 23, 2024
1 parent 807cb45 commit 0ac3310
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
13 changes: 6 additions & 7 deletions stiller-backend/internal/dbutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func CloseConn(conn *sqlite.Conn) {
db_pool.Put(conn)
}

func PushNewFile(fileptr *StillerFile) (int, error) {
func PushNewFile(fileptr *StillerFile) error {
new_dbconn, dbconn_err := NewConn()
if dbconn_err != nil {
return 0, dbconn_err
return dbconn_err
}

defer CloseConn(new_dbconn)
Expand All @@ -63,8 +63,6 @@ func PushNewFile(fileptr *StillerFile) (int, error) {
query := query_stmt.String()
query_id_res := int(-1)

log.Println(query_stmt.String())
log.Println(query_stmt.Args()...)
exec_err := sqlitex.ExecuteTransient(new_dbconn, query, &sqlitex.ExecOptions{
ResultFunc: func(stmt *sqlite.Stmt) error {
if stmt.ColumnType(0) == sqlite.TypeText {
Expand All @@ -80,13 +78,14 @@ func PushNewFile(fileptr *StillerFile) (int, error) {
})

if query_id_res == -1 {
return 0, errors.New("no new file was added")
return errors.New("no new file was added")
}

if exec_err != nil {
return 0, exec_err
return exec_err
}

return query_id_res, nil
fileptr.Id = query_id_res
return nil
}

12 changes: 3 additions & 9 deletions stiller-backend/internal/handlers/file/upload/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func NetHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
return
}

type ResPayload struct {
Id int `json:"id"`
}
type ResPayload dbutils.StillerFile

user_token := r.Header.Get("token")
user_tk, token_decode_err := jwtutils.Decode(user_token)
Expand Down Expand Up @@ -187,17 +185,13 @@ func NetHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
normal_buf = normal_buf[:cap(normal_buf)]
}

id, push_err := dbutils.PushNewFile(&new_file)
push_err := dbutils.PushNewFile(&new_file)
if handleutils.RequestLog(push_err, "", http.StatusInternalServerError, &w) {
return
}

payload := ResPayload{
Id: id,
}

w.WriteHeader(http.StatusOK)
jsonexp.MarshalWrite(w, payload, jsonexp.DefaultOptionsV2())
jsonexp.MarshalWrite(w, new_file, jsonexp.DefaultOptionsV2())
}


0 comments on commit 0ac3310

Please sign in to comment.