Skip to content

Commit 6acb98d

Browse files
committed
feat(stocks.go): add year parameter to SearchStocksHandler for dynamic collection access
This change allows the SearchStocksHandler to retrieve stocks from a collection based on the year specified in the URL parameters, enhancing the flexibility of the stock search functionality.
1 parent 60d55e0 commit 6acb98d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/handlers/stocks.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func (h *Handler) GetStocksByYearHandler(c *fiber.Ctx) error {
5050
}
5151

5252
func (h *Handler) SearchStocksHandler(c *fiber.Ctx) error {
53+
// Get year from URL parameters
54+
year := c.Params("year")
55+
5356
// Get query parameters
5457
name := c.Query("name")
5558
code := c.Query("code")
@@ -72,7 +75,7 @@ func (h *Handler) SearchStocksHandler(c *fiber.Ctx) error {
7275
filter["sharia_opinion"] = shariaOpinion
7376
}
7477

75-
collection := h.db.Collection("2023")
78+
collection := h.db.Collection(year)
7679
cursor, err := collection.Find(c.Context(), filter)
7780
if err != nil {
7881
return c.Status(500).JSON(fiber.Map{

0 commit comments

Comments
 (0)