Simplify user management

This commit is contained in:
2026-01-23 22:37:36 +01:00
parent 16ac84eaf9
commit 6ed4dec4f0
2 changed files with 2 additions and 20 deletions

View File

@@ -10,7 +10,6 @@ import (
"sheetless-server/database" "sheetless-server/database"
"sheetless-server/models" "sheetless-server/models"
"sheetless-server/utils" "sheetless-server/utils"
"strconv"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -27,12 +26,6 @@ func init() {
} }
func UploadSheet(c *gin.Context) { func UploadSheet(c *gin.Context) {
userID, exists := c.Get("user_id")
if !exists {
c.JSON(http.StatusUnauthorized, gin.H{"error": "User not authenticated"})
return
}
// Get form data // Get form data
title := c.PostForm("title") title := c.PostForm("title")
if title == "" { if title == "" {
@@ -58,7 +51,7 @@ func UploadSheet(c *gin.Context) {
} }
// Generate unique filename // Generate unique filename
filename := fmt.Sprintf("%d_%d%s", userID.(uint), time.Now().Unix(), filepath.Ext(header.Filename)) filename := fmt.Sprintf("%d%s", time.Now().Unix(), filepath.Ext(header.Filename))
filePath := filepath.Join(uploadDir, filename) filePath := filepath.Join(uploadDir, filename)
// Save file // Save file
@@ -123,17 +116,7 @@ func UploadSheet(c *gin.Context) {
func ListSheets(c *gin.Context) { func ListSheets(c *gin.Context) {
var sheets []models.Sheet var sheets []models.Sheet
query := database.DB.Preload("User") if err := database.DB.Find(&sheets).Error; err != nil {
// Filter by user if specified
if userIDStr := c.Query("user_id"); userIDStr != "" {
userID, err := strconv.ParseUint(userIDStr, 10, 32)
if err == nil {
query = query.Where("user_id = ?", uint(userID))
}
}
if err := query.Find(&sheets).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch sheets"}) c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch sheets"})
return return
} }

View File

@@ -15,7 +15,6 @@ type Sheet struct {
FilePath string `json:"file_path" gorm:"not null"` FilePath string `json:"file_path" gorm:"not null"`
FileSize int64 `json:"file_size"` FileSize int64 `json:"file_size"`
FileHash uint64 `json:"file_hash"` FileHash uint64 `json:"file_hash"`
User User `json:"user" gorm:"foreignKey:UserID"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`