Skip to content

Commit 00829b0

Browse files
authored
release: v0.1.0.alpha.2
Complete TUI rework: - Built new component-based architecture replacing fragmented old views. - Consolidated components into reusable OptionsProvider pattern with proper separation between views, components, styles, and keybinds packages. Backend and architecture improvements: - Implemented centralized messaging system for consistent view communication. - Added message-driven CRUD operations, enhanced endpoint management for flexible creation and updates. UI/UX redesign: - Redesigned entire interface from scratch with intuitive navigation patterns. - Prototyped user-visible error handling. - Moved pagination logic from backend to frontend for better UX.
2 parents f74c039 + ad0e1ed commit 00829b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1391
-2656
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ testdata/
3838
.pyssg/
3939
__pycache__/
4040
*.pyc
41+
42+
# build stuff
43+
build/
44+
45+
# old tui
46+
internal/old_tui/

db/queries/collections.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ SELECT * FROM collections
66
ORDER BY created_at DESC
77
LIMIT ? OFFSET ?;
88

9+
-- name: GetCollections :many
10+
SELECT * FROM collections
11+
ORDER BY created_at DESC;
12+
913
-- name: CountCollections :one
1014
SELECT COUNT(*) FROM collections;
1115

db/queries/endpoints.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ RETURNING *;
1616
SELECT * FROM endpoints
1717
WHERE id = ? LIMIT 1;
1818

19+
-- name: ListEndpointsByCollection :many
20+
SELECT * FROM endpoints
21+
WHERE collection_id = ?
22+
ORDER BY created_at DESC;
23+
1924
-- name: ListEndpointsPaginated :many
2025
SELECT * FROM endpoints
2126
WHERE collection_id = ?
@@ -26,6 +31,19 @@ LIMIT ? OFFSET ?;
2631
SELECT COUNT(*) FROM endpoints
2732
WHERE collection_id = ?;
2833

34+
-- name: GetEndpointCountsByCollections :many
35+
SELECT collection_id, COUNT(*) as count
36+
FROM endpoints
37+
GROUP BY collection_id;
38+
39+
-- name: UpdateEndpointName :one
40+
UPDATE endpoints
41+
SET
42+
name = ?
43+
WHERE
44+
id = ?
45+
RETURNING *;
46+
2947
-- name: UpdateEndpoint :one
3048
UPDATE endpoints
3149
SET

internal/backend/collections/manager.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,17 @@ func (c *CollectionsManager) Delete(ctx context.Context, id int64) error {
9696
}
9797

9898
func (c *CollectionsManager) List(ctx context.Context) ([]CollectionEntity, error) {
99-
log.Debug("listing all collections with default pagination")
100-
paginated, err := c.ListPaginated(ctx, 50, 0)
99+
collections, err := c.DB.GetCollections(ctx)
101100
if err != nil {
102101
return nil, err
103102
}
104-
return paginated.Collections, nil
103+
104+
entities := make([]CollectionEntity, len(collections))
105+
for i, collection := range collections {
106+
entities[i] = CollectionEntity{Collection: collection}
107+
}
108+
109+
return entities, nil
105110
}
106111

107112
func (c *CollectionsManager) ListPaginated(ctx context.Context, limit, offset int) (*PaginatedCollections, error) {

internal/backend/collections/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func (c CollectionEntity) GetName() string {
1919
return c.Name
2020
}
2121

22+
2223
func (c CollectionEntity) GetCreatedAt() time.Time {
2324
return crud.ParseTimestamp(c.CreatedAt)
2425
}

internal/backend/database/collections.sql.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/backend/database/endpoints.sql.go

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/backend/endpoints/manager.go

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (e *EndpointsManager) List(ctx context.Context) ([]EndpointEntity, error) {
6464
return nil, fmt.Errorf("use ListByCollection to list endpoints for a specific collection")
6565
}
6666

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

106+
func (e *EndpointsManager) ListByCollection(ctx context.Context, collectionID int64) ([]EndpointEntity, error) {
107+
if err := crud.ValidateID(collectionID); err != nil {
108+
log.Warn("endpoint list failed collection validation", "collection_id", collectionID)
109+
return nil, crud.ErrInvalidInput
110+
}
111+
112+
log.Debug("listing endpoints", "collection_id", collectionID, "limit")
113+
114+
endpoints, err := e.DB.ListEndpointsByCollection(context.Background(), collectionID)
115+
if err != nil && err != sql.ErrNoRows {
116+
log.Warn("error occured while fetching endpoints", "collection_id", collectionID)
117+
return nil, err
118+
}
119+
120+
entities := make([]EndpointEntity, len(endpoints))
121+
for i, endpoint := range endpoints {
122+
entities[i] = EndpointEntity{Endpoint: endpoint}
123+
}
124+
125+
log.Info("retrieved endpoints", "collection_id", collectionID, "count")
126+
return entities, nil
127+
}
128+
106129
func (e *EndpointsManager) CreateEndpoint(ctx context.Context, data EndpointData) (EndpointEntity, error) {
107130
if err := crud.ValidateID(data.CollectionID); err != nil {
108131
log.Warn("endpoint creation failed collection validation", "collection_id", data.CollectionID)
@@ -112,8 +135,8 @@ func (e *EndpointsManager) CreateEndpoint(ctx context.Context, data EndpointData
112135
log.Warn("endpoint creation failed name validation", "name", data.Name)
113136
return EndpointEntity{}, crud.ErrInvalidInput
114137
}
115-
if data.Method == "" || data.URL == "" {
116-
log.Warn("endpoint creation failed - method and URL required", "method", data.Method, "url", data.URL)
138+
if data.Method == "" {
139+
log.Warn("endpoint creation failed - method required", "method", data.Method)
117140
return EndpointEntity{}, crud.ErrInvalidInput
118141
}
119142

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

177+
func (e *EndpointsManager) UpdateEndpointName(ctx context.Context, id int64, name string) (EndpointEntity, error) {
178+
if err := crud.ValidateID(id); err != nil {
179+
log.Warn("endpoint update failed ID validation", "id", id)
180+
return EndpointEntity{}, crud.ErrInvalidInput
181+
}
182+
183+
if err := crud.ValidateName(name); err != nil {
184+
log.Warn("endpoint update failed name validation", "name", name)
185+
return EndpointEntity{}, crud.ErrInvalidInput
186+
}
187+
188+
log.Debug("updating endpoint name", "id", id, "name", name)
189+
190+
endpoint, err := e.DB.UpdateEndpointName(ctx, database.UpdateEndpointNameParams{
191+
Name: name,
192+
ID: id,
193+
})
194+
195+
if err != nil {
196+
if err == sql.ErrNoRows {
197+
log.Debug("endpoint not found for update", "id", id)
198+
return EndpointEntity{}, crud.ErrNotFound
199+
}
200+
log.Error("failed to update endpoint", "id", id, "name", name, "error", err)
201+
return EndpointEntity{}, err
202+
}
203+
204+
log.Info("updated endpoint", "id", endpoint.ID, "name", endpoint.Name)
205+
return EndpointEntity{Endpoint: endpoint}, nil
206+
}
207+
154208
func (e *EndpointsManager) UpdateEndpoint(ctx context.Context, id int64, data EndpointData) (EndpointEntity, error) {
155209
if err := crud.ValidateID(id); err != nil {
156210
log.Warn("endpoint update failed ID validation", "id", id)
@@ -160,8 +214,8 @@ func (e *EndpointsManager) UpdateEndpoint(ctx context.Context, id int64, data En
160214
log.Warn("endpoint update failed name validation", "name", data.Name)
161215
return EndpointEntity{}, crud.ErrInvalidInput
162216
}
163-
if data.Method == "" || data.URL == "" {
164-
log.Warn("endpoint update failed - method and URL required", "method", data.Method, "url", data.URL)
217+
if data.Method == "" {
218+
log.Warn("endpoint update failed - method required", "method", data.Method)
165219
return EndpointEntity{}, crud.ErrInvalidInput
166220
}
167221

@@ -202,3 +256,12 @@ func (e *EndpointsManager) UpdateEndpoint(ctx context.Context, id int64, data En
202256
log.Info("updated endpoint", "id", endpoint.ID, "name", endpoint.Name)
203257
return EndpointEntity{Endpoint: endpoint}, nil
204258
}
259+
260+
func (e *EndpointsManager) GetCountsByCollections(ctx context.Context) ([]database.GetEndpointCountsByCollectionsRow, error) {
261+
counts, err := e.DB.GetEndpointCountsByCollections(ctx)
262+
if err != nil {
263+
log.Error("failed to get endpoint counts", "error", err)
264+
return nil, err
265+
}
266+
return counts, nil
267+
}

0 commit comments

Comments
 (0)