Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨(feature): customized reporting module #3

Open
wants to merge 15 commits into
base: base-sha/d60c9ad21e4d3f7e72a4d6f67407152cf2b04784
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .github/workflows/atlas-ci.yml

This file was deleted.

53 changes: 53 additions & 0 deletions .github/workflows/ci-atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Atlas
on:
push:
branches:
- master
paths:
- .github/workflows/ci-atlas.yaml
- 'internal/ent/migrate/*'
pull_request:
paths:
- 'internal/ent/migrate/*'
# Permissions to write comments on the pull request.
permissions:
contents: read
pull-requests: write
jobs:
atlas:
services:
# Spin up a postgres:15 container to be used as the dev-database for analysis.
postgres:
image: postgres:15
env:
POSTGRES_DB: dev
POSTGRES_PASSWORD: pass
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-start-period 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ariga/setup-atlas@v0
with:
cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }}
- uses: ariga/atlas-action/migrate/lint@v1
with:
dir: 'file://internal/ent/migrate'
dev-url: 'postgres://postgres:pass@localhost:5432/dev?search_path=public&sslmode=disable'
dir-name: 'trenova'
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: ariga/atlas-action/migrate/push@v1
if: github.ref == 'refs/heads/master'
with:
dir: 'file://internal/ent/migrate'
dev-url: 'postgres://postgres:pass@localhost:5432/dev?search_path=public&sslmode=disable'
dir-name: 'trenova'
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: 1.22
cache: true
cache: false

- name: Lint with golangci-lint
uses: golangci/golangci-lint-action@v4
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ new-entity: ## Create a new entity. Usage: make new-entity ENTITY_NAME=<name>
ifndef ENTITY_NAME
$(error ENTITY_NAME is undefined. Usage: make new-entity ENTITY_NAME=entity_name)
endif
go run -mod=mod entgo.io/ent/cmd/ent new ${ENTITY_NAME}
go run -mod=mod entgo.io/ent/cmd/ent new --target ./internal/ent/schema/ new ${ENTITY_NAME}

migrate-create: ## Create a new migration. Usage: make migrate-create MIGRATION_NAME=<name>
ifndef MIGRATION_NAME
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/dispatch/LocationCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function LocationCategories() {
columns={columns}
link="/location-categories/"
name="Location Category"
exportModelName="LocationCategory"
exportModelName="location_categories"
filterColumn="name"
TableSheet={LocationCategoryDialog}
TableEditSheet={LocationCategoryEditDialog}
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/dispatch/Locations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function Locations() {
columns={columns}
link="/locations/"
name="Locations"
exportModelName="Location"
exportModelName="locations"
filterColumn="name"
tableFacetedFilters={filters}
TableSheet={LocationTableSheet}
Expand Down
12 changes: 6 additions & 6 deletions client/src/services/ReportRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import axios from "@/lib/axiosConfig";

/**
* Fetches the columns for the specified model from the server.
* @param model_name - The name of the model to fetch columns for.
* @returns A promise that resolves to the columns of the model.
* Fetches the columns for the specified table from the server.
* @param tableName - The name of the table to fetch columns for.
* @returns A promise that resolves to the columns of the table.
*/
export async function getColumns(model_name: string): Promise<any> {
const response = await axios.get("/get_columns/", {
export async function getColumns(tableName: string): Promise<any> {
const response = await axios.get("/reports/column-names/", {
params: {
model_name: model_name,
tableName: tableName,
},
});
return response.data.results;
Expand Down
2 changes: 1 addition & 1 deletion client/src/types/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export type API_ENDPOINTS =
| "/table-columns/"
| "/transfer-to-billing/"
| "/untransfer-invoice/"
| "/get-columns/"
| "reports/column-names"
| "/generate-report/"
| "/users/notifications/"
| "/billing/shipments-ready/"
Expand Down
11 changes: 10 additions & 1 deletion cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

func main() {
ctx := context.Background()
serverConfig := config.DefaultServiceConfigFromEnv()

zerolog.TimeFieldFormat = time.RFC3339Nano
Expand All @@ -31,7 +32,7 @@ func main() {

s := api.NewServer(serverConfig)

if err := s.InitClient(context.Background()); err != nil {
if err := s.InitClient(ctx); err != nil {
log.Fatal().Err(err).Msg("Failed to initialize entity client")
}

Expand All @@ -47,6 +48,14 @@ func main() {
log.Fatal().Err(err).Msg("Failed to initialize Kafka client")
}

if err := s.InitRedisClient(ctx); err != nil {
log.Fatal().Err(err).Msg("Failed to initialize Redis client")
}

if err := s.InitMinioClient(ctx); err != nil {
log.Fatal().Err(err).Msg("Failed to initialize Minio client")
}

router.Init(s)

go func() {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require (
github.com/gofiber/storage/redis/v2 v2.0.3
github.com/mattn/go-sqlite3 v1.14.22
github.com/nyaruka/phonenumbers v1.3.4
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.5.1
github.com/stretchr/testify v1.9.0
github.com/subosito/gotenv v1.6.0
github.com/valyala/fasthttp v1.52.0
Expand Down Expand Up @@ -53,7 +55,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/redis/go-redis/v9 v9.5.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/xid v1.5.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions internal/api/handlers/auth.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func (h *AuthenticationHandler) AuthenticateUser() fiber.Handler {
}

// Authenticate the user
user, err := h.Service.
AuthenticateUser(c.UserContext(), loginRequest.Username, loginRequest.Password)
user, err := h.Service.AuthenticateUser(c.UserContext(), loginRequest.Username, loginRequest.Password)
if err != nil {
return c.Status(fiber.StatusUnauthorized).JSON(types.ValidationErrorResponse{
Type: "unauthorized",
Expand Down
4 changes: 4 additions & 0 deletions internal/api/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,8 @@ func AttachAllRoutes(s *api.Server, api fiber.Router) { //nolint:funlen // This
trailersAPI.Get("/", NewTrailerHandler(s).GetTrailers())
trailersAPI.Post("/", NewTrailerHandler(s).CreateTrailer())
trailersAPI.Put("/:trailerID", NewTrailerHandler(s).UpdateTrailer())

// Register the handlers for the reports.
reportsAPI := api.Group("/reports")
reportsAPI.Get("/column-names", NewReportHandler(s).GetColumnNames())
}
51 changes: 51 additions & 0 deletions internal/api/handlers/report.handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package handlers

import (
"github.com/emoss08/trenova/internal/api"
"github.com/emoss08/trenova/internal/api/services"
"github.com/emoss08/trenova/internal/util"
"github.com/emoss08/trenova/internal/util/types"
"github.com/gofiber/fiber/v2"
)

type ReportHandler struct {
Server *api.Server
Service *services.ReportService
}

func NewReportHandler(s *api.Server) *ReportHandler {
return &ReportHandler{
Server: s,
Service: services.NewReportService(s),
}
}

// GetColumnNames returns the column names for a given table name.
func (h *ReportHandler) GetColumnNames() fiber.Handler {
return func(c *fiber.Ctx) error {
tableName := c.Query("tableName")
if tableName == "" {
return c.Status(fiber.StatusBadRequest).JSON(types.ValidationErrorResponse{
Type: "invalidRequest",
Errors: []types.ValidationErrorDetail{
{
Code: "invalidRequest",
Detail: "query parameter 'tableName' is required",
Attr: "tableName",
},
},
})
}

columns, count, err := h.Service.GetColumnsByTableName(c.UserContext(), tableName)
if err != nil {
errorResponse := util.CreateDBErrorResponse(err)
return c.Status(fiber.StatusInternalServerError).JSON(errorResponse)
}

return c.Status(fiber.StatusOK).JSON(types.HTTPResponse{
Results: columns,
Count: count,
})
}
}
2 changes: 1 addition & 1 deletion internal/api/router/router.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package router //nolint: cyclop // This package is responsible for setting up the router and registering all the routes.
package router //nolint:cyclop // This package is responsible for setting up the router and registering all the routes.

import (
"github.com/bytedance/sonic"
Expand Down
Loading