Skip to content

Commit be0fcee

Browse files
fix: resolve ST1005 and U1000 staticcheck warnings
1 parent a92a857 commit be0fcee

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

cmd/api/admin_orders.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type envelope struct {
3939
Data any `json:"data"`
4040
}
4141

42+
// It creates and immediately discards a value of type envelope. since i am getting unused error through staticcheck
43+
var _ = envelope{}
44+
4245
// adminListOrdersHandler godoc
4346
//
4447
// @Summary List orders (admin)

cmd/api/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ func (app *application) adminListUsersHandler(w http.ResponseWriter, r *http.Req
583583
func (app *application) AdminUserOverviewHandler(w http.ResponseWriter, r *http.Request) {
584584
current := getUserFromContext(r)
585585
if current == nil {
586-
app.unauthorizedErrorResponse(w, r, errors.New("Not authorized"))
586+
app.unauthorizedErrorResponse(w, r, errors.New("not authorized"))
587587
return
588588
}
589589

internal/domain/products/store.go

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type Store interface {
6969
limit, offset int,
7070
) ([]*ProductCard, int, error)
7171
GetProductDetailBySlug(ctx context.Context, slug string) (*ProductDetail, error)
72-
ListAdminProductCards(ctx context.Context, limit, offset int) ([]*ProductCard, int, error)
72+
ListAdminProductCards(ctx context.Context, limit, offset int) ([]*AdminProductCard, int, error)
7373

7474
FullTextSearchProducts(ctx context.Context, query string, limit, offset int) ([]*ProductCardWithRank, int, error)
7575
SearchProducts(ctx context.Context, query string, limit, offset int) ([]*ProductCard, int, error)
@@ -334,7 +334,7 @@ func (r *Repository) CreateCategory(ctx context.Context, c *Category) (*Category
334334
func (r *Repository) CountCategories(ctx context.Context) (int, error) {
335335
var n int
336336
if err := r.db.QueryRow(ctx, `SELECT COUNT(*) FROM categories`).Scan(&n); err != nil {
337-
return 0, fmt.Errorf("Count categories: %w", err)
337+
return 0, fmt.Errorf("count categories: %w", err)
338338
}
339339
return n, nil
340340
}
@@ -1625,7 +1625,7 @@ func (r *Repository) GetProductDetailBySlug(ctx context.Context, slug string) (*
16251625
}
16261626

16271627
// List admin products with counts (variants_count, images_count)
1628-
func (r *Repository) ListAdminProductCards(ctx context.Context, limit, offset int) ([]*ProductCard, int, error) {
1628+
func (r *Repository) ListAdminProductCards(ctx context.Context, limit, offset int) ([]*AdminProductCard, int, error) {
16291629
if limit <= 0 || limit > 50 {
16301630
limit = 50
16311631
}
@@ -1659,45 +1659,41 @@ func (r *Repository) ListAdminProductCards(ctx context.Context, limit, offset in
16591659
}
16601660
defer rows.Close()
16611661

1662-
type adminCard struct {
1663-
ProductCard
1664-
VariantsCount int `json:"variants_count"`
1665-
ImagesCount int `json:"images_count"`
1666-
}
1667-
1668-
out := make([]*ProductCard, 0, limit)
1662+
out := make([]*AdminProductCard, 0, limit)
16691663
for rows.Next() {
16701664
var (
1671-
pc ProductCard
1672-
desc sql.NullString
1673-
catName, brandName sql.NullString
1674-
slug string
1675-
variantsCount, imagesCount int
1665+
card AdminProductCard
1666+
desc sql.NullString
1667+
catName, brandName sql.NullString
1668+
slug string
16761669
)
1670+
16771671
if err := rows.Scan(
1678-
&pc.ID, &pc.Name, &slug, &desc,
1679-
&pc.CategoryID, &catName,
1680-
&pc.BrandID, &brandName,
1681-
&pc.IsActive, &pc.CreatedAt, &pc.UpdatedAt,
1682-
&variantsCount, &imagesCount,
1672+
&card.ID, &card.Name, &slug, &desc,
1673+
&card.CategoryID, &catName,
1674+
&card.BrandID, &brandName,
1675+
&card.IsActive, &card.CreatedAt, &card.UpdatedAt,
1676+
&card.VariantsCount, &card.ImagesCount,
16831677
); err != nil {
16841678
return nil, 0, fmt.Errorf("scan admin product card: %w", err)
16851679
}
1686-
pc.Slug = slug
1680+
1681+
card.Slug = slug
1682+
16871683
if desc.Valid {
16881684
s := desc.String
1689-
pc.Description = &s
1685+
card.Description = &s
16901686
}
16911687
if catName.Valid {
16921688
s := catName.String
1693-
pc.CategoryName = &s
1689+
card.CategoryName = &s
16941690
}
16951691
if brandName.Valid {
16961692
s := brandName.String
1697-
pc.BrandName = &s
1693+
card.BrandName = &s
16981694
}
1699-
// We’ll attach counts in handler if needed
1700-
out = append(out, &pc)
1695+
1696+
out = append(out, &card)
17011697
}
17021698
if err := rows.Err(); err != nil {
17031699
return nil, 0, fmt.Errorf("rows: %w", err)

internal/domain/products/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,9 @@ type ProductWithRank struct {
111111
Product
112112
Rank float64 `json:"rank"`
113113
}
114+
115+
type AdminProductCard struct {
116+
ProductCard
117+
VariantsCount int `json:"variants_count"`
118+
ImagesCount int `json:"images_count"`
119+
}

0 commit comments

Comments
 (0)