Skip to content

Commit 373b605

Browse files
committed
feat(endpoints): crud-like models/methods
- Implemented empty CRUD methods for now!
1 parent b6febb8 commit 373b605

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

internal/endpoints/manager.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package endpoints
2+
3+
import (
4+
"context"
5+
6+
"github.com/maniac-en/req/internal/database"
7+
)
8+
9+
func NewEndpointsManager(db *database.Queries) *EndpointManager {
10+
return &EndpointManager{DB: db}
11+
}
12+
13+
func (e *EndpointManager) Create(ctx context.Context, name string) (EndpointEntity, error) {
14+
return EndpointEntity{}, nil
15+
}
16+
17+
func (e *EndpointManager) Read(ctx context.Context, id int64) (EndpointEntity, error) {
18+
return EndpointEntity{}, nil
19+
}
20+
21+
func (e *EndpointManager) Update(ctx context.Context, id int64, name string) (EndpointEntity, error) {
22+
return EndpointEntity{}, nil
23+
}
24+
25+
func (e *EndpointManager) Delete(ctx context.Context, id int64) error {
26+
return nil
27+
}
28+
29+
func (e *EndpointManager) List(ctx context.Context) ([]EndpointEntity, error) {
30+
return nil, nil
31+
}
32+
33+
func (e *EndpointManager) ListPaginated(ctx context.Context, limit, offset int) (*PaginatedEndpoints, error) {
34+
return nil, nil
35+
}

internal/endpoints/models.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package endpoints
2+
3+
import (
4+
"time"
5+
6+
"github.com/maniac-en/req/internal/database"
7+
"github.com/maniac-en/req/internal/log"
8+
)
9+
10+
type EndpointEntity struct {
11+
database.Endpoint
12+
}
13+
14+
func (c EndpointEntity) GetID() int64 {
15+
return c.ID
16+
}
17+
18+
func (c EndpointEntity) GetName() string {
19+
return c.Name
20+
}
21+
22+
func (c EndpointEntity) GetCreatedAt() time.Time {
23+
parsed, err := time.Parse(time.RFC3339, c.CreatedAt)
24+
if err != nil {
25+
log.Debug("failed to parse created_at timestamp", "timestamp", c.CreatedAt, "error", err)
26+
return time.Time{}
27+
}
28+
return parsed
29+
}
30+
31+
func (c EndpointEntity) GetUpdatedAt() time.Time {
32+
parsed, err := time.Parse(time.RFC3339, c.UpdatedAt)
33+
if err != nil {
34+
log.Debug("failed to parse updated_at timestamp", "timestamp", c.UpdatedAt, "error", err)
35+
return time.Time{}
36+
}
37+
return parsed
38+
}
39+
40+
type EndpointManager struct {
41+
DB *database.Queries
42+
}
43+
44+
type PaginatedEndpoints struct {
45+
Endpoints []EndpointEntity `json:"endpoints"`
46+
Total int64 `json:"total"`
47+
Offset int `json:"offset"`
48+
Limit int `json:"limit"`
49+
HasNext bool `json:"has_next"`
50+
HasPrev bool `json:"has_prev"`
51+
TotalPages int `json:"total_pages"`
52+
CurrentPage int `json:"current_page"`
53+
}

0 commit comments

Comments
 (0)