Skip to content

Commit 726968a

Browse files
committed
Refactor configuration management and remove unused development settings
1 parent c461e2a commit 726968a

File tree

14 files changed

+39
-59
lines changed

14 files changed

+39
-59
lines changed

backend/src/AuthService/AuthService.Api/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using AuthService.Application;
2+
using AuthService.Domain.Constants;
23
using AuthService.Infrastructure;
34
using AuthService.Persistence;
45
using Microsoft.EntityFrameworkCore;
56

67
var builder = WebApplication.CreateBuilder(args);
7-
builder.WebHost.UseUrls("http://0.0.0.0:8082");
8+
9+
var hostingUrl = builder.Configuration[AppSettingsConstants.WebHostUrl];
10+
11+
builder.WebHost.UseUrls(hostingUrl ?? throw new ArgumentNullException(nameof(hostingUrl), "Hosting URL is not configured."));
812

913
builder.Services
1014
.AddPersistenceServices(builder.Configuration)

backend/src/AuthService/AuthService.Api/appsettings.Development.json

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

backend/src/AuthService/AuthService.Api/appsettings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"Microsoft.AspNetCore": "Warning"
66
}
77
},
8-
"AllowedHosts": "*"
8+
"AllowedHosts": "*",
9+
"ConnectionStrings": {
10+
"DefaultConnection": "Host=localhost;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=AuthDb"
11+
},
12+
"WebHostUrl": "http://0.0.0.0:8082"
913
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace AuthService.Domain.Constants;
2+
3+
public static class AppSettingsConstants
4+
{
5+
public const string WebHostUrl = "WebHostUrl";
6+
}

backend/src/AuthService/AuthService.Domain/Entities/User.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class User
1313

1414
public User(string externalId, string firstName, string lastName, string username, string email, string imageUrl)
1515
{
16-
Id = Guid.NewGuid();
1716
ExternalId = externalId;
1817
FirstName = firstName;
1918
LastName = lastName;

backend/src/PostService/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG ASPNETCORE_ENVIRONMENT
66
ARG DB_CONNECTION_STRING
77

88
ENV ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT:-Docker}
9-
ENV ConnectionStrings__DefaultConnection=${DB_CONNECTION_STRING:-Host=postgres-posts;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=posts-db}
9+
ENV ConnectionStrings__DefaultConnection=${DB_CONNECTION_STRING:-Host=postgres;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=PostsDb}
1010

1111
RUN apt-get update && apt-get install -y curl && apt-get clean
1212

backend/src/PostService/PostService.Api/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
using PostService.Api.GraphQL.Mutations;
33
using PostService.Api.GraphQL.Queries;
44
using PostService.Application;
5+
using PostService.Domain.Constants;
56
using PostService.Infrastructure;
67
using PostService.Persistence;
78

89
var builder = WebApplication.CreateBuilder(args);
9-
builder.WebHost.UseUrls("http://0.0.0.0:8081");
10+
11+
var hostingUrl = builder.Configuration[AppSettingsConstants.WebHostUrl];
12+
13+
builder.WebHost.UseUrls(hostingUrl ?? throw new ArgumentNullException(nameof(hostingUrl), "Hosting URL is not configured."));
1014

1115
builder.Services
1216
.AddPersistenceServices(builder.Configuration)

backend/src/PostService/PostService.Api/appsettings.Development.json

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

backend/src/PostService/PostService.Api/appsettings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"Microsoft.AspNetCore": "Warning"
66
}
77
},
8-
"AllowedHosts": "*"
8+
"AllowedHosts": "*",
9+
"ConnectionStrings": {
10+
"DefaultConnection": "Host=localhost;Port=5432;Username=postgres;Password=mysecretpasswordfordevelopment;Database=PostsDb"
11+
},
12+
"WebHostUrl": "http://0.0.0.0:8081"
913
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace PostService.Domain.Constants;
2+
3+
public static class AppSettingsConstants
4+
{
5+
public const string WebHostUrl = "WebHostUrl";
6+
}

backend/src/PostService/PostService.Domain/Entities/Comment.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public Comment(Guid postId, Guid userId, string username, string content)
3131
throw new ArgumentException("Content cannot be empty or whitespace.", nameof(content));
3232
}
3333

34-
Id = Guid.NewGuid();
3534
PostId = postId;
3635
UserId = userId;
3736
Username = username;

backend/src/PostService/PostService.Domain/Entities/Like.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public Like(Guid postId, Guid userId)
1919
throw new ArgumentException("UserId cannot be empty.", nameof(userId));
2020
}
2121

22-
Id = Guid.NewGuid();
2322
PostId = postId;
2423
UserId = userId;
2524
CreatedAt = DateTime.UtcNow;

backend/src/PostService/PostService.Domain/Entities/Post.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ private Post(Guid userId, string title, string description, string contentUrl, C
2323

2424
ValidateContent(contentType, title, description, contentUrl);
2525

26-
Id = Guid.NewGuid();
2726
UserId = userId;
2827
Title = title;
2928
Description = description;

docker-compose.yml

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424
ports:
2525
- "8081:8081"
2626
depends_on:
27-
postgres-posts:
27+
postgres:
2828
condition: service_healthy
2929
healthcheck:
3030
test: [ "CMD-SHELL", "curl -f http://post-service:8081/health || exit 1" ]
@@ -34,43 +34,22 @@ services:
3434
networks:
3535
- microservices
3636

37-
postgres-auth:
38-
container_name: postgres-auth
37+
postgres:
38+
container_name: postgres
3939
image: postgres:15-alpine
4040
environment:
4141
POSTGRES_USER: postgres
4242
POSTGRES_PASSWORD: mysecretpasswordfordevelopment
43-
POSTGRES_DB: auth-db
4443
ports:
45-
- "5433:5432"
44+
- "5432:5432"
4645
restart: always
4746
healthcheck:
4847
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
4948
interval: 10s
5049
timeout: 5s
5150
retries: 5
5251
volumes:
53-
- auth-service-data:/var/lib/postgresql/data
54-
networks:
55-
- microservices
56-
57-
postgres-posts:
58-
container_name: postgres-posts
59-
image: postgres:15-alpine
60-
environment:
61-
POSTGRES_USER: postgres
62-
POSTGRES_PASSWORD: mysecretpasswordfordevelopment
63-
POSTGRES_DB: posts-db
64-
ports:
65-
- "5434:5432"
66-
restart: always
67-
healthcheck:
68-
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
69-
interval: 10s
70-
timeout: 5s
71-
retries: 5
72-
volumes:
73-
- post-service-data:/var/lib/postgresql/data
52+
- postgres-data:/var/lib/postgresql/data
7453
networks:
7554
- microservices
7655

@@ -90,5 +69,4 @@ services:
9069
- microservices
9170

9271
volumes:
93-
auth-service-data:
94-
post-service-data:
72+
postgres-data:

0 commit comments

Comments
 (0)