Refactor and improve code consistency across multiple files
- Enhanced SQL queries in `session.go` and `share.go` for clarity and consistency. - Updated comments for better understanding and maintenance. - Ensured consistent error handling and return statements across various methods.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -33,3 +33,5 @@ build/
|
||||
|
||||
# Docker volumes and data
|
||||
postgres_data/
|
||||
|
||||
.claude/
|
||||
@@ -142,7 +142,7 @@ func GetUserFromContext(c *gin.Context) *uuid.UUID {
|
||||
// 修正点:使用和存入时完全一样的 Key
|
||||
val, exists := c.Get(ContextUserIDKey)
|
||||
fmt.Println("within getFromContext the id is ... ")
|
||||
fmt.Println(val);
|
||||
fmt.Println(val)
|
||||
if !exists {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
return &DocumentHandler{store: s}
|
||||
}
|
||||
|
||||
|
||||
// CreateDocument creates a new document (requires auth)
|
||||
func (h *DocumentHandler) CreateDocument(c *gin.Context) {
|
||||
userID := auth.GetUserFromContext(c)
|
||||
@@ -66,7 +65,6 @@ func (h *DocumentHandler) CreateDocument(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func (h *DocumentHandler) GetDocument(c *gin.Context) {
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
@@ -104,6 +102,7 @@ func (h *DocumentHandler) CreateDocument(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, doc)
|
||||
}
|
||||
|
||||
// GetDocumentState returns the Yjs state for a document
|
||||
// GetDocumentState retrieves document state (requires view permission)
|
||||
func (h *DocumentHandler) GetDocumentState(c *gin.Context) {
|
||||
@@ -290,7 +289,9 @@ func (h *DocumentHandler) GetDocumentPermission(c *gin.Context) {
|
||||
}
|
||||
tokenPerm = p
|
||||
// 处理数据库老数据的 fallback
|
||||
if tokenPerm == "" { tokenPerm = "view" }
|
||||
if tokenPerm == "" {
|
||||
tokenPerm = "view"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ func (h *ShareHandler) DeleteShare(c *gin.Context) {
|
||||
|
||||
c.Status(204)
|
||||
}
|
||||
|
||||
// CreateShareLink generates a public share link
|
||||
func (h *ShareHandler) CreateShareLink(c *gin.Context) {
|
||||
documentID, err := uuid.Parse(c.Param("id"))
|
||||
|
||||
@@ -24,7 +24,6 @@ type Document struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
|
||||
type CreateDocumentRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Type DocumentType `json:"type" binding:"required"`
|
||||
@@ -38,4 +37,3 @@ type CreateDocumentRequest struct {
|
||||
Documents []Document `json:"documents"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,9 @@ type Store interface {
|
||||
GetDocumentVersion(ctx context.Context, versionID uuid.UUID) (*models.DocumentVersion, error)
|
||||
GetLatestDocumentVersion(ctx context.Context, documentID uuid.UUID) (*models.DocumentVersion, error)
|
||||
|
||||
|
||||
Close() error
|
||||
}
|
||||
|
||||
|
||||
type PostgresStore struct {
|
||||
db *sql.DB
|
||||
}
|
||||
@@ -100,7 +98,6 @@ func (s *PostgresStore) CreateDocument(name string, docType models.DocumentType)
|
||||
doc.Type,
|
||||
doc.CreatedAt,
|
||||
doc.UpdatedAt,
|
||||
|
||||
).Scan(&doc.ID, &doc.Name, &doc.Type, &doc.CreatedAt, &doc.UpdatedAt)
|
||||
|
||||
if err != nil {
|
||||
@@ -140,7 +137,6 @@ func (s *PostgresStore) CreateDocument(name string, docType models.DocumentType)
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
|
||||
// ListDocuments retrieves all documents
|
||||
func (s *PostgresStore) ListDocuments() ([]models.Document, error) {
|
||||
query := `
|
||||
|
||||
Reference in New Issue
Block a user