Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bf0b292
new tui work:
yashranjan1 Aug 4, 2025
3bb9be3
app view modelled, some new packages created
yashranjan1 Aug 4, 2025
03c2674
changes:
yashranjan1 Aug 5, 2025
bffb049
changes:
yashranjan1 Aug 6, 2025
2c438d9
changes:
yashranjan1 Aug 7, 2025
23b2832
added endpoint count to collections and made it so that the db query …
yashranjan1 Aug 8, 2025
ba724d2
changes:
yashranjan1 Aug 8, 2025
765149b
changes:
yashranjan1 Aug 9, 2025
5b3b803
added delete collection
yashranjan1 Aug 9, 2025
74ba653
added edit collection
yashranjan1 Aug 9, 2025
eb1fa71
input extracted into its own package to make it more reusable
yashranjan1 Aug 9, 2025
05b8fb1
added help menu
yashranjan1 Aug 9, 2025
96de05f
help menu is now structured in a better way
yashranjan1 Aug 10, 2025
bdbccbe
changes:
yashranjan1 Aug 10, 2025
0c7ee6b
input moved back into options provider (behaviour too specific to gen…
yashranjan1 Aug 10, 2025
2664cda
changes:
yashranjan1 Aug 12, 2025
d098bb7
changes:
yashranjan1 Aug 12, 2025
ce6a779
minor style fix
yashranjan1 Aug 12, 2025
00dc5d7
fix: remove EndpointCount from CollectionEntity
maniac-en Aug 17, 2025
1af51e5
refactor: use message-driven navigation
maniac-en Aug 17, 2025
84ab6c5
feat: Prototype message-driven flow for ItemAdded
maniac-en Aug 17, 2025
b0311e1
chore: bump version to v0.1.0-alpha.3
maniac-en Aug 17, 2025
c5e663e
chore: add navigation with q/esc for back navigation
maniac-en Aug 17, 2025
92a274f
Revert "chore: bump version to v0.1.0-alpha.3"
maniac-en Aug 17, 2025
d1a0951
fix:test update for the empty URL tests for endpoints manager
yashranjan1 Aug 23, 2025
8a3989a
fix: made manager tests have better error messages
yashranjan1 Aug 24, 2025
ad0e1ed
fix: mistake
yashranjan1 Aug 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ testdata/
.pyssg/
__pycache__/
*.pyc

# build stuff
build/

# old tui
internal/old_tui/
4 changes: 4 additions & 0 deletions db/queries/collections.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ SELECT * FROM collections
ORDER BY created_at DESC
LIMIT ? OFFSET ?;

-- name: GetCollections :many
SELECT * FROM collections
ORDER BY created_at DESC;

-- name: CountCollections :one
SELECT COUNT(*) FROM collections;

Expand Down
18 changes: 18 additions & 0 deletions db/queries/endpoints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ RETURNING *;
SELECT * FROM endpoints
WHERE id = ? LIMIT 1;

-- name: ListEndpointsByCollection :many
SELECT * FROM endpoints
WHERE collection_id = ?
ORDER BY created_at DESC;

-- name: ListEndpointsPaginated :many
SELECT * FROM endpoints
WHERE collection_id = ?
Expand All @@ -26,6 +31,19 @@ LIMIT ? OFFSET ?;
SELECT COUNT(*) FROM endpoints
WHERE collection_id = ?;

-- name: GetEndpointCountsByCollections :many
SELECT collection_id, COUNT(*) as count
FROM endpoints
GROUP BY collection_id;

-- name: UpdateEndpointName :one
UPDATE endpoints
SET
name = ?
WHERE
id = ?
RETURNING *;

-- name: UpdateEndpoint :one
UPDATE endpoints
SET
Expand Down
11 changes: 8 additions & 3 deletions internal/backend/collections/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ func (c *CollectionsManager) Delete(ctx context.Context, id int64) error {
}

func (c *CollectionsManager) List(ctx context.Context) ([]CollectionEntity, error) {
log.Debug("listing all collections with default pagination")
paginated, err := c.ListPaginated(ctx, 50, 0)
collections, err := c.DB.GetCollections(ctx)
if err != nil {
return nil, err
}
return paginated.Collections, nil

entities := make([]CollectionEntity, len(collections))
for i, collection := range collections {
entities[i] = CollectionEntity{Collection: collection}
}

return entities, nil
}

func (c *CollectionsManager) ListPaginated(ctx context.Context, limit, offset int) (*PaginatedCollections, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/backend/collections/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (c CollectionEntity) GetName() string {
return c.Name
}


func (c CollectionEntity) GetCreatedAt() time.Time {
return crud.ParseTimestamp(c.CreatedAt)
}
Expand Down
33 changes: 33 additions & 0 deletions internal/backend/database/collections.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions internal/backend/database/endpoints.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 68 additions & 5 deletions internal/backend/endpoints/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (e *EndpointsManager) List(ctx context.Context) ([]EndpointEntity, error) {
return nil, fmt.Errorf("use ListByCollection to list endpoints for a specific collection")
}

func (e *EndpointsManager) ListByCollection(ctx context.Context, collectionID int64, limit, offset int) (*PaginatedEndpoints, error) {
func (e *EndpointsManager) ListByCollectionByPage(ctx context.Context, collectionID int64, limit, offset int) (*PaginatedEndpoints, error) {
if err := crud.ValidateID(collectionID); err != nil {
log.Warn("endpoint list failed collection validation", "collection_id", collectionID)
return nil, crud.ErrInvalidInput
Expand Down Expand Up @@ -103,6 +103,29 @@ func (e *EndpointsManager) ListByCollection(ctx context.Context, collectionID in
return result, nil
}

func (e *EndpointsManager) ListByCollection(ctx context.Context, collectionID int64) ([]EndpointEntity, error) {
if err := crud.ValidateID(collectionID); err != nil {
log.Warn("endpoint list failed collection validation", "collection_id", collectionID)
return nil, crud.ErrInvalidInput
}

log.Debug("listing endpoints", "collection_id", collectionID, "limit")

endpoints, err := e.DB.ListEndpointsByCollection(context.Background(), collectionID)
if err != nil && err != sql.ErrNoRows {
log.Warn("error occured while fetching endpoints", "collection_id", collectionID)
return nil, err
}

entities := make([]EndpointEntity, len(endpoints))
for i, endpoint := range endpoints {
entities[i] = EndpointEntity{Endpoint: endpoint}
}

log.Info("retrieved endpoints", "collection_id", collectionID, "count")
return entities, nil
}

func (e *EndpointsManager) CreateEndpoint(ctx context.Context, data EndpointData) (EndpointEntity, error) {
if err := crud.ValidateID(data.CollectionID); err != nil {
log.Warn("endpoint creation failed collection validation", "collection_id", data.CollectionID)
Expand All @@ -112,8 +135,8 @@ func (e *EndpointsManager) CreateEndpoint(ctx context.Context, data EndpointData
log.Warn("endpoint creation failed name validation", "name", data.Name)
return EndpointEntity{}, crud.ErrInvalidInput
}
if data.Method == "" || data.URL == "" {
log.Warn("endpoint creation failed - method and URL required", "method", data.Method, "url", data.URL)
if data.Method == "" {
log.Warn("endpoint creation failed - method required", "method", data.Method)
return EndpointEntity{}, crud.ErrInvalidInput
}

Expand Down Expand Up @@ -151,6 +174,37 @@ func (e *EndpointsManager) CreateEndpoint(ctx context.Context, data EndpointData
return EndpointEntity{Endpoint: endpoint}, nil
}

func (e *EndpointsManager) UpdateEndpointName(ctx context.Context, id int64, name string) (EndpointEntity, error) {
if err := crud.ValidateID(id); err != nil {
log.Warn("endpoint update failed ID validation", "id", id)
return EndpointEntity{}, crud.ErrInvalidInput
}

if err := crud.ValidateName(name); err != nil {
log.Warn("endpoint update failed name validation", "name", name)
return EndpointEntity{}, crud.ErrInvalidInput
}

log.Debug("updating endpoint name", "id", id, "name", name)

endpoint, err := e.DB.UpdateEndpointName(ctx, database.UpdateEndpointNameParams{
Name: name,
ID: id,
})

if err != nil {
if err == sql.ErrNoRows {
log.Debug("endpoint not found for update", "id", id)
return EndpointEntity{}, crud.ErrNotFound
}
log.Error("failed to update endpoint", "id", id, "name", name, "error", err)
return EndpointEntity{}, err
}

log.Info("updated endpoint", "id", endpoint.ID, "name", endpoint.Name)
return EndpointEntity{Endpoint: endpoint}, nil
}

func (e *EndpointsManager) UpdateEndpoint(ctx context.Context, id int64, data EndpointData) (EndpointEntity, error) {
if err := crud.ValidateID(id); err != nil {
log.Warn("endpoint update failed ID validation", "id", id)
Expand All @@ -160,8 +214,8 @@ func (e *EndpointsManager) UpdateEndpoint(ctx context.Context, id int64, data En
log.Warn("endpoint update failed name validation", "name", data.Name)
return EndpointEntity{}, crud.ErrInvalidInput
}
if data.Method == "" || data.URL == "" {
log.Warn("endpoint update failed - method and URL required", "method", data.Method, "url", data.URL)
if data.Method == "" {
log.Warn("endpoint update failed - method required", "method", data.Method)
return EndpointEntity{}, crud.ErrInvalidInput
}

Expand Down Expand Up @@ -202,3 +256,12 @@ func (e *EndpointsManager) UpdateEndpoint(ctx context.Context, id int64, data En
log.Info("updated endpoint", "id", endpoint.ID, "name", endpoint.Name)
return EndpointEntity{Endpoint: endpoint}, nil
}

func (e *EndpointsManager) GetCountsByCollections(ctx context.Context) ([]database.GetEndpointCountsByCollectionsRow, error) {
counts, err := e.DB.GetEndpointCountsByCollections(ctx)
if err != nil {
log.Error("failed to get endpoint counts", "error", err)
return nil, err
}
return counts, nil
}
Loading
Loading