Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pandadiestro committed Nov 23, 2024
2 parents 8e3a5a1 + a4f8fc6 commit df19570
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 29 deletions.
15 changes: 9 additions & 6 deletions stiller-backend/internal/dbutils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,22 @@ type StillerTemplate struct {
}

type StillerGallerySlot struct {
Id string `json:"id"`
Res int `json:"res"`
Title string `json:"title"`
Description string `json:"description"`
ResId int `json:"res"`
Title string `json:"title"`
Description string `json:"description"`
Ref string `json:"ref"`
Type string `json:"type"`
Props interface{} `json:"props"`
Vertices [][]float64 `json:"v"`
}

type StillerGallery struct {
Id int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
OwnerId int `json:"ownerid"`
TemplateId int `json:"templateid"`
Slug string `json:"slug"`
Title string `json:"title"`
Description string `json:"description"`
Slots []StillerGallerySlot `json:"slots"`
}

2 changes: 0 additions & 2 deletions stiller-backend/internal/handlers/auth/userlogin/handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package userlogin

import (
"log"
"net/http"
"stiller/internal/dbutils"
"stiller/internal/handlers/handleutils"
Expand Down Expand Up @@ -47,7 +46,6 @@ func NetHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
defer query_stmt.Close()

query := query_stmt.String()
log.Println(query, query_stmt.Args())

new_dbconn, dbconn_err := dbutils.NewConn()
if handleutils.RequestLog(
Expand Down
38 changes: 22 additions & 16 deletions stiller-backend/internal/handlers/file/filetree/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

jsonexp "github.com/go-json-experiment/json"
"github.com/julienschmidt/httprouter"
"github.com/leporo/sqlf"
"zombiezen.com/go/sqlite"
"zombiezen.com/go/sqlite/sqlitex"
)
Expand All @@ -31,18 +32,22 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params

defer new_dbconn.Close()

ver_query := `select count(*) from user where (id=?1);`
ver_query_stmt, _, ver_query_err := new_dbconn.PrepareTransient(ver_query)
if handleutils.RequestLog(ver_query_err, "", http.StatusInternalServerError, &w) {
return
}
user_count := int(-1)
count_users_stmt := sqlf.
Select("count(id)").
From("user").
Where("id = ?", user_tk.UserId)

user_count, user_count_err := sqlitex.ResultInt(ver_query_stmt)
if handleutils.RequestLog(user_count_err, "", http.StatusInternalServerError, &w) {
return
}
sqlitex.ExecuteTransient(new_dbconn, count_users_stmt.String(), &sqlitex.ExecOptions{
ResultFunc: func(stmt *sqlite.Stmt) error {
user_count = stmt.ColumnInt(0)
return nil
},

Args: count_users_stmt.Args(),
})

if user_count != 1 {
if user_count == -1 {
w.WriteHeader(http.StatusNotFound)
handleutils.GenericLog(nil, "user does not exist")
return
Expand All @@ -69,13 +74,15 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
return
}

query = ""
query = `select * from file where (owner=?1);`
getfiles_stmt := sqlf.
Select("*").
From("file").
Where("owner = ?", user_tk.UserId)

files := make([]dbutils.StillerFile, 0, row_len)
exec_err := sqlitex.ExecuteTransient(
new_dbconn,
query,
getfiles_stmt.String(),
&sqlitex.ExecOptions{
ResultFunc: func(stmt *sqlite.Stmt) error {
tmp_newf := dbutils.StillerFile{
Expand All @@ -95,9 +102,8 @@ func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
files = append(files, tmp_newf)
return nil
},
Args: []any{
user_tk.UserId,
},

Args: getfiles_stmt.Args(),
},
)

Expand Down
34 changes: 30 additions & 4 deletions stiller-backend/internal/handlers/gallery/addgallery/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NetHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
}

type ResPayload dbutils.StillerGallery

req_payload := ReqPayload{}
unmarshal_err := jsonexp.UnmarshalRead(r.Body, &req_payload, jsonexp.DefaultOptionsV2())
if handleutils.RequestLog(unmarshal_err, "", http.StatusBadRequest, &w) {
Expand Down Expand Up @@ -100,19 +101,19 @@ func NetHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params

buftar := bufio.NewReader(tar_reader)

slots := []templates.MetatemplateSlot{}
slotunmarshal_exp := jsonexp.UnmarshalRead(buftar, &slots, jsonexp.DefaultOptionsV2())
templatefile_slots := []templates.MetatemplateSlot{}
slotunmarshal_exp := jsonexp.UnmarshalRead(buftar, &templatefile_slots, jsonexp.DefaultOptionsV2())
if handleutils.RequestLog(slotunmarshal_exp, "", http.StatusInternalServerError, &w) {
return
}

insert_slots_stmt := sqlf.
InsertInto("galleryslot")

for index := range slots {
for index := range templatefile_slots {
insert_slots_stmt.NewRow().
Set("gallery", newgallery_id).
Set("slotid", slots[index].Id)
Set("slotid", templatefile_slots[index].Ref)
}

insert_slots_err := sqlitex.ExecuteTransient(dbconn, insert_slots_stmt.String(), &sqlitex.ExecOptions{
Expand All @@ -122,5 +123,30 @@ func NetHandler(w http.ResponseWriter, r *http.Request, params httprouter.Params
if handleutils.RequestLog(insert_slots_err, "", http.StatusInternalServerError, &w) {
return
}

gallery_slots := make([]dbutils.StillerGallerySlot, 0, len(templatefile_slots))
for index := range templatefile_slots {
gallery_slots = append(gallery_slots, dbutils.StillerGallerySlot{
Ref: templatefile_slots[index].Ref,
Type: templatefile_slots[index].Type,
Props: templatefile_slots[index].Props,
Vertices: templatefile_slots[index].Vertices,
})
}

res_payload := dbutils.StillerGallery{
Id: newgallery_id,
Title: req_payload.Title,
Description: req_payload.Description,
OwnerId: user_id,
TemplateId: req_payload.Template,
Slug: req_payload.Slug,
Slots: gallery_slots,
}

marshal_err := jsonexp.MarshalWrite(w, res_payload, jsonexp.DefaultOptionsV2())
if handleutils.RequestLog(marshal_err, "", http.StatusInternalServerError, &w) {
return
}
}

6 changes: 5 additions & 1 deletion stiller-backend/internal/templates/templates.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package templates

type MetatemplateSlot struct {
Id string `json:"id"`
Ref string `json:"ref"`
Type string `json:"type"`
Props interface{} `json:"props"`
Vertices [][]float64 `json:"v"`
}

type MetatemplateData struct {
Origin []float64 `json:"origin"`
Slots []MetatemplateSlot `json:"slots"`
}

0 comments on commit df19570

Please sign in to comment.