refactor(backend): change backend file structure
This commit is contained in:
parent
057ba22b18
commit
49952c62ef
@ -1,4 +1,4 @@
|
||||
package models
|
||||
package domain
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@ -1,4 +1,4 @@
|
||||
package db
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -7,9 +7,9 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"tanabata/models"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"tanabata/internal/domain"
|
||||
)
|
||||
|
||||
// Check if user can view file
|
||||
@ -35,7 +35,7 @@ func FileGetAccess(user_id int, file_id string) (canView, canEdit bool, err erro
|
||||
}
|
||||
|
||||
// Get a set of files
|
||||
func FileGetSlice(user_id int, filter, sort string, limit, offset int) (files models.Slice[models.FileItem], statusCode int, err error) {
|
||||
func FileGetSlice(user_id int, filter, sort string, limit, offset int) (files domain.Slice[domain.FileItem], statusCode int, err error) {
|
||||
filterCond, statusCode, err := filterToSQL(filter)
|
||||
if err != nil {
|
||||
return
|
||||
@ -78,7 +78,7 @@ func FileGetSlice(user_id int, filter, sort string, limit, offset int) (files mo
|
||||
defer rows.Close()
|
||||
count := 0
|
||||
for rows.Next() {
|
||||
var file models.FileItem
|
||||
var file domain.FileItem
|
||||
err = rows.Scan(&file.ID, &file.Name, &file.MIME.Name, &file.MIME.Extension, &file.CreatedAt, &file.Creator.Name, &file.Creator.IsAdmin)
|
||||
if err != nil {
|
||||
statusCode = http.StatusInternalServerError
|
||||
@ -109,7 +109,7 @@ func FileGetSlice(user_id int, filter, sort string, limit, offset int) (files mo
|
||||
}
|
||||
|
||||
// Get file
|
||||
func FileGet(user_id int, file_id string) (file models.FileFull, statusCode int, err error) {
|
||||
func FileGet(user_id int, file_id string) (file domain.FileFull, statusCode int, err error) {
|
||||
ctx := context.Background()
|
||||
row := connPool.QueryRow(ctx, `
|
||||
SELECT
|
||||
@ -149,7 +149,7 @@ func FileGet(user_id int, file_id string) (file models.FileFull, statusCode int,
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var tag models.TagCore
|
||||
var tag domain.TagCore
|
||||
err = rows.Scan(&tag.ID, &tag.Name, &tag.Color)
|
||||
if err != nil {
|
||||
statusCode = http.StatusInternalServerError
|
||||
@ -167,7 +167,7 @@ func FileGet(user_id int, file_id string) (file models.FileFull, statusCode int,
|
||||
}
|
||||
|
||||
// Add file
|
||||
func FileAdd(user_id int, name, mime string, datetime time.Time, notes string, metadata json.RawMessage) (file models.FileCore, statusCode int, err error) {
|
||||
func FileAdd(user_id int, name, mime string, datetime time.Time, notes string, metadata json.RawMessage) (file domain.FileCore, statusCode int, err error) {
|
||||
ctx := context.Background()
|
||||
var mime_id int
|
||||
var extension string
|
||||
@ -1,4 +1,4 @@
|
||||
package db
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -1,4 +1,4 @@
|
||||
package db
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
Loading…
x
Reference in New Issue
Block a user