feat: common code for back functions are now in handlers/common.go

This commit is contained in:
Iron_Felix 2025-11-01 21:17:42 +03:00
parent 6ed47b667c
commit 6d538ed154
2 changed files with 29 additions and 11 deletions

View file

@ -0,0 +1,19 @@
package handlers
import (
sqlc "nyanimedb/sql"
"strconv"
)
type Server struct {
db *sqlc.Queries
}
func NewServer(db *sqlc.Queries) Server {
return Server{db: db}
}
func parseInt64(s string) (int32, error) {
i, err := strconv.ParseInt(s, 10, 64)
return int32(i), err
}

View file

@ -4,24 +4,23 @@ import (
"context" "context"
oapi "nyanimedb/api" oapi "nyanimedb/api"
sqlc "nyanimedb/sql" sqlc "nyanimedb/sql"
"strconv"
"github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
"github.com/oapi-codegen/runtime/types" "github.com/oapi-codegen/runtime/types"
) )
type Server struct { // type Server struct {
db *sqlc.Queries // db *sqlc.Queries
} // }
func NewServer(db *sqlc.Queries) Server { // func NewServer(db *sqlc.Queries) Server {
return Server{db: db} // return Server{db: db}
} // }
func parseInt64(s string) (int32, error) { // func parseInt64(s string) (int32, error) {
i, err := strconv.ParseInt(s, 10, 64) // i, err := strconv.ParseInt(s, 10, 64)
return int32(i), err // return int32(i), err
} // }
func mapUser(u sqlc.GetUserByIDRow) oapi.User { func mapUser(u sqlc.GetUserByIDRow) oapi.User {
return oapi.User{ return oapi.User{