Skip to content

Commit

Permalink
feat(*): add more sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquin-diaz committed Jul 22, 2024
1 parent 007ea1f commit 3510b76
Show file tree
Hide file tree
Showing 33 changed files with 399 additions and 123 deletions.
51 changes: 51 additions & 0 deletions backend/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[proxy]
app_port = 0
enabled = false
proxy_port = 0

[screen]
clear_on_rebuild = false
keep_scroll = true
4 changes: 3 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM golang:1.22.0

WORKDIR /app

RUN go install github.com/air-verse/air@latest

COPY go.mod go.sum ./
RUN go mod download

Expand All @@ -11,4 +13,4 @@ RUN go build -o main .

EXPOSE 8080

CMD ["./main"]
CMD ["air", "-c", ".air.toml"]
5 changes: 4 additions & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ install:
go mod tidy

podman:
podman-compose --file compose.yaml build && podman-compose --file compose.yaml up --remove-orphans
podman-compose --file compose.yaml build && podman-compose --file compose.yaml up --remove-orphans --detach

podman_down:
podman-compose --file compose.yaml down -v

rebuild_server:
podman-compose --file compose.yaml stop server && podman-compose --file compose.yaml start --build --detach server

migrate:
atlas migrate apply --dir "file://migrations" --url "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"
9 changes: 8 additions & 1 deletion backend/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ services:
networks:
- backend
depends_on:
- db
db:
condition: service_healthy
restart: on-failure

jaeger:
image: jaegertracing/all-in-one:1.58.0
Expand All @@ -32,6 +34,11 @@ services:
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
healthcheck:
test: [ "CMD", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5

networks:
backend:
Expand Down
6 changes: 6 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDm
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 h1:DzHpqpoJVaCgOUdVHxE8QB52S6NiVdDQvGlny1qvPqA=
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/bytedance/sonic v1.11.9 h1:LFHENlIY/SLzDWverzdOvgMztTxcfcF+cqNsz9pK5zg=
github.com/bytedance/sonic v1.11.9/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
Expand Down Expand Up @@ -196,6 +198,8 @@ golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down Expand Up @@ -247,6 +251,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 h1:0+ozOGcrp+Y8Aq8TLNN2Aliibms5LEzsq99ZZmAGYm0=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094/go.mod h1:fJ/e3If/Q67Mj99hin0hMhiNyCRmt6BQ2aWIJshUSJw=
Expand Down
13 changes: 13 additions & 0 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,18 @@ func main() {
c.JSON(http.StatusOK, products)
})

r.GET("/products/:id", func(c *gin.Context) {
var product models.Product

result := db.WithContext(c.Request.Context()).First(&product, c.Param("id"))

if result.Error != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": result.Error})
return
}

c.JSON(http.StatusOK, product)
})

r.Run()
}
6 changes: 3 additions & 3 deletions backend/migrations/20240705154902.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
insert into public.products (name, price)
values
('T-Shirt', 50),
('Mug', 20),
('Hat', 30);
('Traces', 50),
('Logs', 20),
('Metrics', 30);
2 changes: 2 additions & 0 deletions backend/migrations/20240719183430.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "products" table
ALTER TABLE "public"."products" ADD COLUMN "description" text NULL;
1 change: 1 addition & 0 deletions backend/migrations/20240719183523.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
update products set description = 'This is a new product' where name = 'Traces';
2 changes: 2 additions & 0 deletions backend/migrations/20240719183744.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "products" table
ALTER TABLE "public"."products" ADD COLUMN "short_description" text NULL;
20 changes: 20 additions & 0 deletions backend/migrations/20240719183751.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
update
products
set
short_description = 'The path of a request through your application.',
description = 'Traces give us the big picture of what happens when a request is made to an application. Whether your application is a monolith with a single database or a sophisticated mesh of services, traces are essential to understanding the full “path” a request takes in your application.'
where name = 'Traces';

update
products
set
short_description = 'A measurement captured at runtime.',
description = 'A metric is a measurement of a service captured at runtime. The moment of capturing a measurements is known as a metric event, which consists not only of the measurement itself, but also the time at which it was captured and associated metadata.'
where name = 'Metrics';

update
products
set
short_description = 'A recording of an event.',
description = 'A log is a timestamped text record, either structured (recommended) or unstructured, with metadata. Of all telemetry signals, logs have the biggest legacy. Most programming languages have built-in logging capabilities or well-known, widely used logging libraries. Although logs are an independent data source, they may also be attached to spans. In OpenTelemetry, any data that is not part of a distributed trace or a metric is a log. For example, events are a specific type of log. Logs often contain detailed debugging/diagnostic info, such as inputs to an operation, the result of the operation, and any supporting metadata for that operation.'
where name = 'Logs';
8 changes: 6 additions & 2 deletions backend/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
h1:QIOvf+plxnk42197hMw76H2V96QvzQoGaewUsmOcYtc=
h1:IdnCvRcbZst0RjlXZz9iK13fdcGRSFZsMEKELMPTkvk=
20240704190447.sql h1:cTsU9q4yxks6IJvIOcQACGf0xo2IhoKreaW51hJ7fAY=
20240705154902.sql h1:egIJ70UOzP7Ah0EwFbcY1etlxpnFs9Y2fJ/g6pShASE=
20240705154902.sql h1:pGaKlcbrnbPk4+kopDV/pJC3UoKoGlBm8Ho65tT//Rk=
20240719183430.sql h1:jBEGqka7kyvYRZqXA//Ca9GRUFWcIF2xy4G0HDJoMc0=
20240719183523.sql h1:sF0BSoo1q8UyNUP9u+FNIs4eSmBccaiQWB2oA5tMOPU=
20240719183744.sql h1:ket+uWKlHqisARD3/3tIKg1xiG8kD+6i3Jgh2iJ6ORw=
20240719183751.sql h1:OWIWY3m847KcrBKY1DUa6hk1yTHt/EuZkqZhW07WQcI=
8 changes: 5 additions & 3 deletions backend/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import "gorm.io/gorm"

type Product struct {
gorm.Model
ID int `json:"id"`
Name string `json:"name"`
Price int `json:"price"`
ID int `json:"id"`
Name string `json:"name"`
Price int `json:"price"`
ShortDescription string `json:"short_description"`
Description string `json:"description"`
}
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="preload" data-rocket-preload="" as="style" href="https://fonts.googleapis.com/css2?family=Open+Sans+Condensed:ital,wght@0,300;0,700;1,300&amp;family=Open+Sans+Condensed:ital,wght@0,300;0,700;1,300&amp;family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&amp;family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&amp;family=IBM+Plex+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&amp;family=Source+Serif+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900&amp;display=swap">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
Expand Down
42 changes: 0 additions & 42 deletions frontend/src/App.css

This file was deleted.

20 changes: 10 additions & 10 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import "./App.css";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Home from "./pages/Home";

const router = createBrowserRouter([
{
path: "/",
element: <Home />,
},
]);
import ProductDetails from "./pages/ProductDetails";

const App = () => {
return <RouterProvider router={router} />;
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/products/:productId" element={<ProductDetails />} />
</Routes>
</BrowserRouter>
);
};

export default App;
Binary file added frontend/src/assets/fake-product-picture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/components/Container/Container.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.container {
max-width: 80%;
margin: 0 auto;
}
21 changes: 21 additions & 0 deletions frontend/src/components/Container/Container.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FC, PropsWithChildren } from "react";

import styles from "./Container.module.css";
import classes from "../../helpers/classes";

type ContainerProps = {
className?: string;
};

const Container: FC<PropsWithChildren<ContainerProps>> = ({
children,
className,
}) => {
return (
<section className={classes(styles.container, className)}>
{children}
</section>
);
};

export default Container;
Empty file.
4 changes: 4 additions & 0 deletions frontend/src/helpers/classes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const classes = (...args: (string | undefined)[]) =>
args.filter(Boolean).join(" ");

export default classes;
Loading

0 comments on commit 3510b76

Please sign in to comment.