feat: Implement error handling and response structure for API
- Added standardized error response structure in `errors.go` for consistent error handling across the API. - Implemented specific response functions for various HTTP status codes (400, 401, 403, 404, 500) to enhance error reporting. - Introduced validation error handling to provide detailed feedback on input validation issues. test: Add comprehensive tests for share handler functionality - Created a suite of tests for share handler endpoints, covering scenarios for creating, listing, deleting shares, and managing share links. - Included tests for permission checks, validation errors, and edge cases such as unauthorized access and invalid document IDs. chore: Set up test utilities and database for integration tests - Established a base handler suite for common setup tasks in tests, including database initialization and teardown. - Implemented test data seeding to facilitate consistent testing across different scenarios. migration: Add public sharing support in the database schema - Modified the `documents` table to include `share_token` and `is_public` columns for managing public document sharing. - Added constraints to ensure data integrity, preventing public documents from lacking a share token.
This commit is contained in:
20
backend/scripts/003_add_public_sharing.sql
Normal file
20
backend/scripts/003_add_public_sharing.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- Migration: Add public sharing support via share tokens
|
||||
-- Dependencies: Run after 002_add_document_shares.sql
|
||||
-- Purpose: Add share_token and is_public columns used by share link feature
|
||||
|
||||
-- Add columns for public sharing
|
||||
ALTER TABLE documents ADD COLUMN IF NOT EXISTS share_token VARCHAR(255);
|
||||
ALTER TABLE documents ADD COLUMN IF NOT EXISTS is_public BOOLEAN DEFAULT false NOT NULL;
|
||||
|
||||
-- Create indexes for performance
|
||||
CREATE INDEX IF NOT EXISTS idx_documents_share_token ON documents(share_token) WHERE share_token IS NOT NULL;
|
||||
CREATE INDEX IF NOT EXISTS idx_documents_is_public ON documents(is_public) WHERE is_public = true;
|
||||
|
||||
-- Constraint: public documents must have a token
|
||||
-- This ensures data integrity - a document can't be public without a share token
|
||||
ALTER TABLE documents ADD CONSTRAINT check_public_has_token
|
||||
CHECK (is_public = false OR (is_public = true AND share_token IS NOT NULL));
|
||||
|
||||
-- Documentation
|
||||
COMMENT ON COLUMN documents.share_token IS 'Public share token for link-based access (base64-encoded random string, 32 bytes)';
|
||||
COMMENT ON COLUMN documents.is_public IS 'Whether document is publicly accessible via share link';
|
||||
Reference in New Issue
Block a user