Skip to content

Commit 634979a

Browse files
authored
Merge pull request #27 from NLipatov/feature/2
Feature/2
2 parents c1df9ba + ccd2e38 commit 634979a

File tree

22 files changed

+858
-639
lines changed

22 files changed

+858
-639
lines changed

.env

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ PLANS_DB_PASS=m1E416AwQv0sXsijwcx53o41pk2EXnvd
1212
PLANS_DB_HOST=plan-postgres
1313
PLANS_DB_PORT=5432
1414

15-
#LT BILLING DB
16-
LT_BILLING_DB_USER=admin
17-
LT_BILLING_DB_PASS=m1E416AwQv0sXsijwcx53o41pk2EXnvd
18-
LT_BILLING_DB_DATABASE=lt-billing
19-
LT_BILLING_DB_HOST=lt-billing-postgres
20-
LT_BILLING_DB_PORT=5432
15+
#BILLING DB
16+
BILLING_DB_USER=admin
17+
BILLING_DB_PASS=m1E416AwQv0sXsijwcx53o41pk2EXnvd
18+
BILLING_DB_DATABASE=billing
19+
BILLING_DB_HOST=billing-postgres
20+
BILLING_DB_PORT=5432
21+
BILLING_CACHE_HOST=billing-cache
22+
BILLING_CACHE_PORT=6379
23+
BILLING_CACHE_USER=default
2124

2225
#TrafficCache
2326
TC_CACHE_HOST=plan-controller-cache
@@ -40,4 +43,14 @@ GOOGLE_AUTH_PORT=3030
4043

4144
#REST API KAFKA
4245
USERS_REST_API_KAFKA_GROUP_ID=rest-api
43-
USERS_REST_API_KAFKA_TOPIC=PROXY
46+
USERS_REST_API_KAFKA_TOPIC=PROXY
47+
48+
#CRYPTO CLOUD BILLING API
49+
CC_BILLING_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:2020
50+
CC_BILLING_KAFKA_AUTO_OFFSET_RESET=earliest
51+
CC_BILLING_KAFKA_BOOTSTRAP_SERVERS=kafka:9092
52+
CC_BILLING_KAFKA_GROUP_ID=crypto-cloud-billing
53+
CC_BILLING_KAFKA_TOPIC=crypto-cloud-billing
54+
CC_BILLING_SECRET_KEY=secret
55+
CC_BILLING_SHOP_ID=secret
56+
CC_BILLING_API_KEY=secret

docker-compose.yml

Lines changed: 108 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ services:
3838
timeout: 5s
3939
retries: 5
4040

41-
lt-billing-postgres:
41+
billing-postgres:
4242
image: postgres:17.2-bookworm
4343
container_name: lavatop-billing-postgres
4444
environment:
45-
POSTGRES_USER: ${LT_BILLING_DB_USER}
46-
POSTGRES_PASSWORD: ${LT_BILLING_DB_PASS}
47-
POSTGRES_DB: ${LT_BILLING_DB_DATABASE}
45+
POSTGRES_USER: ${BILLING_DB_USER}
46+
POSTGRES_PASSWORD: ${BILLING_DB_PASS}
47+
POSTGRES_DB: ${BILLING_DB_DATABASE}
4848
ports:
4949
- "5435:5432"
5050
volumes:
51-
- lt-billing-postgres_data:/var/lib/postgresql/data
51+
- billing-postgres_data:/var/lib/postgresql/data
5252
healthcheck:
5353
test: [ "CMD-SHELL", "pg_isready -U ${DB_USER}" ]
5454
interval: 10s
@@ -85,19 +85,19 @@ services:
8585
plan-postgres:
8686
condition: service_healthy
8787

88-
lt-billing-ctx-migrator:
88+
billing-ctx-migrator:
8989
build:
9090
context: ./src
91-
container_name: lt-billing-ctx-migrator
91+
container_name: billing-ctx-migrator
9292
environment:
9393
- MODE=migrator
94-
- DB_DATABASE=${LT_BILLING_DB_DATABASE}
95-
- DB_USER=${LT_BILLING_DB_USER}
96-
- DB_PASS=${LT_BILLING_DB_PASS}
97-
- DB_HOST=${LT_BILLING_DB_HOST}
98-
- DB_PORT=${LT_BILLING_DB_PORT}
94+
- DB_DATABASE=${BILLING_DB_DATABASE}
95+
- DB_USER=${BILLING_DB_USER}
96+
- DB_PASS=${BILLING_DB_PASS}
97+
- DB_HOST=${BILLING_DB_HOST}
98+
- DB_PORT=${BILLING_DB_PORT}
9999
depends_on:
100-
lt-billing-postgres:
100+
billing-postgres:
101101
condition: service_healthy
102102

103103
google-auth-api:
@@ -263,6 +263,99 @@ services:
263263
timeout: 5s
264264
retries: 3
265265
start_period: 5s
266+
267+
billing-cache:
268+
image: valkey/valkey:8.0-bookworm
269+
container_name: billing-cache
270+
ports:
271+
- "6380:6379"
272+
volumes:
273+
- billing-cache_data:/data
274+
healthcheck:
275+
test: ["CMD", "redis-cli", "ping"]
276+
interval: 30s
277+
timeout: 5s
278+
retries: 3
279+
start_period: 5s
280+
281+
billing-api:
282+
build:
283+
context: ./src
284+
container_name: billing-api
285+
ports:
286+
- "4040:4040"
287+
environment:
288+
- MODE=billing-api
289+
- HTTP_PORT=4040
290+
- ALLOWED_ORIGINS=*
291+
- DB_DATABASE=${BILLING_DB_DATABASE}
292+
- DB_HOST=${BILLING_DB_HOST}
293+
- DB_PASS=${BILLING_DB_PASS}
294+
- DB_PORT=${BILLING_DB_PORT}
295+
- DB_USER=${BILLING_DB_USER}
296+
- TC_CACHE_HOST=${BILLING_CACHE_HOST}
297+
- TC_CACHE_PORT=${BILLING_CACHE_PORT}
298+
- TC_CACHE_USER=${BILLING_CACHE_USER}
299+
depends_on:
300+
init-kafka-topics:
301+
condition: service_completed_successfully
302+
billing-postgres:
303+
condition: service_healthy
304+
kafka:
305+
condition: service_healthy
306+
billing-cache:
307+
condition: service_healthy
308+
309+
plans-api:
310+
build:
311+
context: ./src
312+
container_name: plans-api
313+
ports:
314+
- "9090:9090"
315+
environment:
316+
- MODE=plans-api
317+
- HTTP_PORT=9090
318+
- ALLOWED_ORIGINS=*
319+
- DB_DATABASE=${PLANS_DB_DATABASE}
320+
- DB_HOST=${PLANS_DB_HOST}
321+
- DB_PASS=${PLANS_DB_PASS}
322+
- DB_PORT=${PLANS_DB_PORT}
323+
- DB_USER=${PLANS_DB_USER}
324+
- TC_CACHE_HOST=${TC_CACHE_HOST}
325+
- TC_CACHE_PORT=${TC_CACHE_PORT}
326+
- TC_CACHE_USER=${TC_CACHE_USER}
327+
depends_on:
328+
init-kafka-topics:
329+
condition: service_completed_successfully
330+
kafka:
331+
condition: service_healthy
332+
plan-controller-cache:
333+
condition: service_healthy
334+
335+
crypto-cloud-billing-api:
336+
build:
337+
context: ./src
338+
container_name: crypto-cloud-billing-api
339+
ports:
340+
- "2020:2020"
341+
environment:
342+
- MODE=crypto-cloud-billing-api
343+
- HTTP_PORT=2020
344+
- ALLOWED_ORIGINS=${CC_BILLING_ALLOWED_ORIGINS}
345+
- BILLING_KAFKA_AUTO_OFFSET_RESET=${CC_BILLING_KAFKA_AUTO_OFFSET_RESET}
346+
- BILLING_KAFKA_BOOTSTRAP_SERVERS=${CC_BILLING_KAFKA_BOOTSTRAP_SERVERS}
347+
- BILLING_KAFKA_GROUP_ID=${CC_BILLING_KAFKA_GROUP_ID}
348+
- BILLING_KAFKA_TOPIC=${CC_BILLING_KAFKA_TOPIC}
349+
- API_KEY=${CC_BILLING_API_KEY}
350+
- SECRET_KEY=${CC_BILLING_SECRET_KEY}
351+
- SHOP_ID=${CC_BILLING_SHOP_ID}
352+
depends_on:
353+
init-kafka-topics:
354+
condition: service_completed_successfully
355+
kafka:
356+
condition: service_healthy
357+
plan-controller-cache:
358+
condition: service_healthy
266359

267360
plan-controller:
268361
build:
@@ -305,5 +398,6 @@ services:
305398
volumes:
306399
postgres_data:
307400
plan-postgres_data:
308-
lt-billing-postgres_data:
401+
billing-postgres_data:
309402
plan-controller-cache_data:
403+
billing-cache_data:

src/application/repository.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ type PlanRepository interface {
3535
GetByIdWithFeatures(id int) (aggregates.Plan, error)
3636
}
3737

38+
type PlanPriceRepository interface {
39+
Repository[dataobjects.PlanPrice]
40+
GetAllWithPlanId(planId int) ([]dataobjects.PlanPrice, error)
41+
}
42+
3843
type UserPlanRepository interface {
3944
Repository[aggregates.UserPlan]
4045
GetUserActivePlan(userId int) (aggregates.UserPlan, error)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cache_serialization
2+
3+
import "goproxy/domain/dataobjects"
4+
5+
type PriceDto struct {
6+
Id int
7+
PlanId int
8+
Cents int64
9+
Currency string
10+
}
11+
12+
type PriceCacheSerializer struct {
13+
}
14+
15+
func NewPriceCacheSerializer() CacheSerializer[dataobjects.PlanPrice, PriceDto] {
16+
return &PriceCacheSerializer{}
17+
}
18+
19+
func (p *PriceCacheSerializer) ToT(dto PriceDto) dataobjects.PlanPrice {
20+
return dataobjects.NewPlanPrice(dto.Id, dto.PlanId, dto.Cents, dto.Currency)
21+
}
22+
23+
func (p *PriceCacheSerializer) ToD(price dataobjects.PlanPrice) PriceDto {
24+
return PriceDto{
25+
Id: price.Id(),
26+
PlanId: price.PlanId(),
27+
Cents: price.Cents(),
28+
Currency: price.Currency(),
29+
}
30+
}
31+
32+
func (p *PriceCacheSerializer) ToTArray(dto []PriceDto) []dataobjects.PlanPrice {
33+
result := make([]dataobjects.PlanPrice, len(dto))
34+
for i, d := range dto {
35+
result[i] = p.ToT(d)
36+
}
37+
return result
38+
}
39+
40+
func (p *PriceCacheSerializer) ToDArray(dto []dataobjects.PlanPrice) []PriceDto {
41+
result := make([]PriceDto, len(dto))
42+
for i, d := range dto {
43+
result[i] = p.ToD(d)
44+
}
45+
return result
46+
}

src/dal/migrations/lt-billing/v1_schema_migrations_table.sql renamed to src/dal/migrations/billing/v1_schema_migrations_table.sql

File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE TABLE plan_prices(
2+
id SERIAL PRIMARY KEY,
3+
plan_id INT NOT NULL,
4+
currency VARCHAR(3) NOT NULL,
5+
cents BIGINT NOT NULL CHECK (cents >= 0),
6+
UNIQUE (plan_id, currency)
7+
);
8+
9+
CREATE INDEX idx_plan_prices_plan_id on plan_prices(plan_id);
10+
CREATE INDEX idx_plan_prices_plan_id_currency on plan_prices(plan_id, currency);

src/dal/migrations/lt-billing/v2_lavatop_orders_table.sql

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/dal/migrations/lt-billing/v3_lavatop_invoices_table.sql

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)