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/models"
"sheetless-server/utils"
"strconv"
"time"
"github.com/gin-gonic/gin"
@@ -27,12 +26,6 @@ func init() {
}
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
title := c.PostForm("title")
if title == "" {
@@ -58,7 +51,7 @@ func UploadSheet(c *gin.Context) {
}
// 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)
// Save file
@@ -123,17 +116,7 @@ func UploadSheet(c *gin.Context) {
func ListSheets(c *gin.Context) {
var sheets []models.Sheet
query := database.DB.Preload("User")
// 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 {
if err := database.DB.Find(&sheets).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to fetch sheets"})
return
}