Documentation
¶
Index ¶
- Constants
- Variables
- type CreateNoteRequest
- type ErrorDetail
- type ErrorResponse
- type Handler
- type HealthResponse
- type ListFilters
- type ListNotesRequest
- type ListNotesResponse
- type Note
- type NotesService
- func (s *NotesService) Create(ctx context.Context, req CreateNoteRequest) (*Note, error)
- func (s *NotesService) Delete(ctx context.Context, id string) error
- func (s *NotesService) GetByID(ctx context.Context, id string) (*Note, error)
- func (s *NotesService) List(ctx context.Context, req ListNotesRequest) (*ListNotesResponse, error)
- func (s *NotesService) Update(ctx context.Context, id string, req UpdateNoteRequest) (*Note, error)
- type PaginationMetadata
- type PostgreSQLRepository
- func (r *PostgreSQLRepository) Create(ctx context.Context, note *Note) error
- func (r *PostgreSQLRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *PostgreSQLRepository) GetByID(ctx context.Context, id uuid.UUID) (*Note, error)
- func (r *PostgreSQLRepository) List(ctx context.Context, filters ListFilters) ([]Note, int, error)
- func (r *PostgreSQLRepository) Update(ctx context.Context, id uuid.UUID, updates map[string]interface{}) (*Note, error)
- type Repository
- type Service
- type UpdateNoteRequest
Constants ¶
const ( ErrCodeValidation = "VALIDATION_ERROR" ErrCodeNotFound = "NOT_FOUND" ErrCodeInternal = "INTERNAL_ERROR" )
Domain errors
Variables ¶
var ( // ErrNotFound is returned when a note is not found ErrNotFound = errors.New("note not found") // ErrInvalidInput is returned when input validation fails ErrInvalidInput = errors.New("invalid input") )
Functions ¶
This section is empty.
Types ¶
type CreateNoteRequest ¶
type CreateNoteRequest struct {
Title string `json:"title" validate:"required,min=1,max=200"`
Content string `json:"content" validate:"max=10000"`
Tags []string `json:"tags,omitempty" validate:"omitempty,max=10,dive,max=50"`
IsArchived *bool `json:"is_archived,omitempty"`
}
CreateNoteRequest represents the request payload for creating a note
type ErrorDetail ¶
type ErrorDetail struct {
Code string `json:"code"`
Message string `json:"message"`
Details interface{} `json:"details,omitempty"`
}
ErrorDetail represents error details
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
ErrorResponse represents an error response
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for notes
func NewHandler ¶
NewHandler creates a new notes handler
func (*Handler) CreateNote ¶
CreateNote handles POST /v1/notes
func (*Handler) DeleteNote ¶
DeleteNote handles DELETE /v1/notes/:id
func (*Handler) UpdateNote ¶
UpdateNote handles PATCH /v1/notes/:id
type HealthResponse ¶
type HealthResponse struct {
Status string `json:"status"`
}
HealthResponse represents health check response
type ListFilters ¶
type ListFilters struct {
Offset int
Limit int
Query string
Tags []string
Sort string
Order string
}
ListFilters represents filters for listing notes
type ListNotesRequest ¶
type ListNotesRequest struct {
Page int `form:"page" validate:"omitempty,min=1"`
PageSize int `form:"page_size" validate:"omitempty,min=1,max=100"`
Query string `form:"q" validate:"omitempty,max=200"`
Tags []string `form:"tags" validate:"omitempty,max=10,dive,max=50"`
Sort string `form:"sort" validate:"omitempty,oneof=created_at updated_at"`
Order string `form:"order" validate:"omitempty,oneof=asc desc"`
}
ListNotesRequest represents query parameters for listing notes
type ListNotesResponse ¶
type ListNotesResponse struct {
Data []Note `json:"data"`
Pagination PaginationMetadata `json:"pagination"`
}
ListNotesResponse represents the response for listing notes
type Note ¶
type Note struct {
ID uuid.UUID `json:"id" db:"id"`
Title string `json:"title" db:"title"`
Content string `json:"content" db:"content"`
Tags []string `json:"tags" db:"tags"`
IsArchived bool `json:"is_archived" db:"is_archived"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
Note represents a note entity
type NotesService ¶
type NotesService struct {
// contains filtered or unexported fields
}
NotesService implements the Service interface
func NewService ¶
func NewService(repo Repository, cfg *config.Config) *NotesService
NewService creates a new notes service
func (*NotesService) Create ¶
func (s *NotesService) Create(ctx context.Context, req CreateNoteRequest) (*Note, error)
Create creates a new note
func (*NotesService) Delete ¶
func (s *NotesService) Delete(ctx context.Context, id string) error
Delete deletes a note
func (*NotesService) List ¶
func (s *NotesService) List(ctx context.Context, req ListNotesRequest) (*ListNotesResponse, error)
List retrieves notes with filtering and pagination
func (*NotesService) Update ¶
func (s *NotesService) Update(ctx context.Context, id string, req UpdateNoteRequest) (*Note, error)
Update updates a note
type PaginationMetadata ¶
type PaginationMetadata struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
Total int `json:"total"`
NextPage *int `json:"next_page,omitempty"`
}
PaginationMetadata represents pagination information
type PostgreSQLRepository ¶
type PostgreSQLRepository struct {
// contains filtered or unexported fields
}
PostgreSQLRepository implements Repository using PostgreSQL
func NewPostgreSQLRepository ¶
func NewPostgreSQLRepository(pool *pgxpool.Pool) *PostgreSQLRepository
NewPostgreSQLRepository creates a new PostgreSQL repository
func (*PostgreSQLRepository) Create ¶
func (r *PostgreSQLRepository) Create(ctx context.Context, note *Note) error
Create creates a new note
func (*PostgreSQLRepository) List ¶
func (r *PostgreSQLRepository) List(ctx context.Context, filters ListFilters) ([]Note, int, error)
List retrieves notes with filtering, sorting, and pagination
type Repository ¶
type Repository interface {
Create(ctx context.Context, note *Note) error
GetByID(ctx context.Context, id uuid.UUID) (*Note, error)
Update(ctx context.Context, id uuid.UUID, updates map[string]interface{}) (*Note, error)
Delete(ctx context.Context, id uuid.UUID) error
List(ctx context.Context, filters ListFilters) ([]Note, int, error)
}
Repository defines the interface for note data operations
type Service ¶
type Service interface {
Create(ctx context.Context, req CreateNoteRequest) (*Note, error)
GetByID(ctx context.Context, id string) (*Note, error)
Update(ctx context.Context, id string, req UpdateNoteRequest) (*Note, error)
Delete(ctx context.Context, id string) error
List(ctx context.Context, req ListNotesRequest) (*ListNotesResponse, error)
}
Service defines the business logic interface for notes
type UpdateNoteRequest ¶
type UpdateNoteRequest struct {
Title *string `json:"title,omitempty" validate:"omitempty,min=1,max=200"`
Content *string `json:"content,omitempty" validate:"omitempty,max=10000"`
Tags []string `json:"tags,omitempty" validate:"omitempty,max=10,dive,max=50"`
IsArchived *bool `json:"is_archived,omitempty"`
}
UpdateNoteRequest represents the request payload for updating a note