notes

package
v0.0.0-...-a7f2a9d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeValidation = "VALIDATION_ERROR"
	ErrCodeNotFound   = "NOT_FOUND"
	ErrCodeInternal   = "INTERNAL_ERROR"
)

Domain errors

Variables

View Source
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

func NewHandler(service Service, logger zerolog.Logger) *Handler

NewHandler creates a new notes handler

func (*Handler) CreateNote

func (h *Handler) CreateNote(c *gin.Context)

CreateNote handles POST /v1/notes

func (*Handler) DeleteNote

func (h *Handler) DeleteNote(c *gin.Context)

DeleteNote handles DELETE /v1/notes/:id

func (*Handler) GetNote

func (h *Handler) GetNote(c *gin.Context)

GetNote handles GET /v1/notes/:id

func (*Handler) ListNotes

func (h *Handler) ListNotes(c *gin.Context)

ListNotes handles GET /v1/notes

func (*Handler) UpdateNote

func (h *Handler) UpdateNote(c *gin.Context)

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) GetByID

func (s *NotesService) GetByID(ctx context.Context, id string) (*Note, error)

GetByID retrieves a note by ID

func (*NotesService) List

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) Delete

func (r *PostgreSQLRepository) Delete(ctx context.Context, id uuid.UUID) error

Delete deletes a note

func (*PostgreSQLRepository) GetByID

func (r *PostgreSQLRepository) GetByID(ctx context.Context, id uuid.UUID) (*Note, error)

GetByID retrieves a note by ID

func (*PostgreSQLRepository) List

func (r *PostgreSQLRepository) List(ctx context.Context, filters ListFilters) ([]Note, int, error)

List retrieves notes with filtering, sorting, and pagination

func (*PostgreSQLRepository) Update

func (r *PostgreSQLRepository) Update(ctx context.Context, id uuid.UUID, updates map[string]interface{}) (*Note, error)

Update updates a note

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL