Skip to content

Commit 356cd30

Browse files
committed
docs: add section headers to Go files for better organization and readability
1 parent 4a815b0 commit 356cd30

File tree

10 files changed

+52
-27
lines changed

10 files changed

+52
-27
lines changed

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package config
22

3+
// ###############################################################################
4+
// Configurations
5+
// ###############################################################################
6+
37
import (
48
"os"
59

internal/config/mongodb.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package config
22

3+
// ###############################################################################
4+
// MongoDB Configuration
5+
// ###############################################################################
6+
37
import (
48
"context"
59
"log"

internal/handlers/errors.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package handlers
22

3+
// ###############################################################################
4+
// Error Handling Functions
5+
// ###############################################################################
6+
37
import (
48
"github.com/anqorithm/naqa-api/internal/models"
59
"github.com/gofiber/fiber/v2"
610
)
711

8-
// ###############################################################################
9-
// Error Handling Functions
10-
// ###############################################################################
11-
12+
// SendError sends an error response to the client
1213
func SendError(c *fiber.Ctx, status int, code string, message string, details interface{}) error {
1314
return c.Status(status).JSON(&models.ErrorResponse{
1415
Status: "error",

internal/handlers/handlers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package handlers
22

3+
// ###############################################################################
4+
// Handler Functions
5+
// ###############################################################################
6+
37
import (
48
"fmt"
59
"os"
@@ -21,10 +25,6 @@ func NewHandler(db *mongo.Database) *Handler {
2125
}
2226
}
2327

24-
// ###############################################################################
25-
// Handler Functions
26-
// ###############################################################################
27-
2828
// RootHandler handles the "/" endpoint
2929
func (h *Handler) RootHandler(c *fiber.Ctx) error {
3030
return c.JSON(fiber.Map{

internal/handlers/stocks.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package handlers
22

3+
// ###############################################################################
4+
// Stock Handler Functions
5+
// ###############################################################################
6+
37
import (
48
"strconv"
59
"time"
@@ -12,10 +16,7 @@ import (
1216
"go.mongodb.org/mongo-driver/bson/primitive"
1317
)
1418

15-
// ###############################################################################
16-
// Stock Handler Functions
17-
// ###############################################################################
18-
19+
// GetStocksHandler fetches all stocks for a given year
1920
func (h *Handler) GetStocksByYearHandler(c *fiber.Ctx) error {
2021
collection := h.db.Collection(c.Params("year"))
2122

@@ -48,6 +49,7 @@ func (h *Handler) GetStocksByYearHandler(c *fiber.Ctx) error {
4849
return c.JSON(models.StockResponse{Stocks: result})
4950
}
5051

52+
// GetStockByCodeHandler fetches a stock by its code for a given year
5153
func (h *Handler) SearchStocksHandler(c *fiber.Ctx) error {
5254
filter := bson.M{}
5355

@@ -95,6 +97,7 @@ func (h *Handler) SearchStocksHandler(c *fiber.Ctx) error {
9597
return c.JSON(models.StockResponse{Stocks: result})
9698
}
9799

100+
// CalculatePurificationHandler calculates purification amount for a stock
98101
func (h *Handler) CalculatePurificationHandler(c *fiber.Ctx) error {
99102
const daysInYear = 365.0
100103

@@ -154,5 +157,4 @@ func (h *Handler) CalculatePurificationHandler(c *fiber.Ctx) error {
154157
}
155158

156159
return c.JSON(response)
157-
}
158-
160+
}

internal/middleware/middleware.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package middleware
22

3+
// ###############################################################################
4+
// Middleware Functions
5+
// ###############################################################################
6+
37
import (
48
"fmt"
59
"time"
@@ -14,10 +18,6 @@ import (
1418
"github.com/gofiber/fiber/v2/middleware/monitor"
1519
)
1620

17-
// ###############################################################################
18-
// Middleware Functions
19-
// ###############################################################################
20-
2121
// Logger returns a logger middleware
2222
func Logger() fiber.Handler {
2323
return logger.New(logger.Config{

internal/middleware/year_validator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package middleware
22

3+
// ###############################################################################
4+
// Year Validation Middleware
5+
// ###############################################################################
6+
37
import (
48
"fmt"
59

@@ -9,11 +13,7 @@ import (
913
"github.com/gofiber/fiber/v2"
1014
)
1115

12-
// ###############################################################################
13-
// Year Validation Middleware
14-
// ###############################################################################
15-
16-
16+
// ValidateYear validates the year parameter
1717
func ValidateYear() fiber.Handler {
1818
return func(c *fiber.Ctx) error {
1919
year := c.Params("year")

internal/models/error.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package models
22

3+
// ###############################################################################
4+
// Error Response Model
5+
// ###############################################################################
6+
37
type ErrorResponse struct {
48
Status string `json:"status"`
59
Code string `json:"code"`
@@ -16,4 +20,4 @@ const (
1620
ErrCodeDatabaseError = "DATABASE_ERROR"
1721
ErrCodeInvalidDateFormat = "INVALID_DATE_FORMAT"
1822
ErrCodeInvalidData = "INVALID_DATA"
19-
)
23+
)

internal/models/stock.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package models
22

3+
// ###############################################################################
4+
// Stock Model
5+
// ###############################################################################
6+
37
import "go.mongodb.org/mongo-driver/bson/primitive"
48

9+
// Stock represents a stock entity
510
type Stock struct {
611
ID primitive.ObjectID `json:"_id" bson:"_id,omitempty"`
712
Name string `json:"name" bson:"name"`
@@ -11,22 +16,23 @@ type Stock struct {
1116
Purification string `json:"purification" bson:"purification"`
1217
}
1318

19+
// StockResponse represents a response containing a list of stocks
1420
type StockResponse struct {
1521
Stocks []Stock `json:"stocks"`
1622
}
1723

18-
24+
// PurificationRequest represents a request to calculate purification amount
1925
type PurificationRequest struct {
2026
StartDate string `json:"start_date" validate:"required,datetime=2006-01-02"`
2127
EndDate string `json:"end_date" validate:"required,datetime=2006-01-02"`
2228
NumberOfStocks int `json:"number_of_stocks" validate:"required,gt=0"`
2329
StockCode string `json:"stock_code" validate:"required"`
2430
}
2531

26-
32+
// PurificationResponse represents a response containing the purification amount
2733
type PurificationResponse struct {
2834
ID primitive.ObjectID `json:"_id" bson:"_id,omitempty"`
2935
PurificationAmount float64 `json:"purification_amount"`
3036
DaysHeld int `json:"days_held"`
3137
PurificationRate float64 `json:"purification_rate"`
32-
}
38+
}

internal/routes/routes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package routes
22

3+
// ###############################################################################
4+
// Routes
5+
// ###############################################################################
6+
37
import (
48
"github.com/anqorithm/naqa-api/internal/handlers"
59
"github.com/anqorithm/naqa-api/internal/middleware"

0 commit comments

Comments
 (0)