From 5e780ec66ef2424027378336abfd1cc0dde1f57a Mon Sep 17 00:00:00 2001
From: duyanhehe <duyanhex@gmail.com>
Date: Thu, 6 Mar 2025 19:26:49 +0700
Subject: [PATCH] resolve conflict

---
 .env.example       | 18 +++++++-----------
 app/core/config.py | 11 +++++++++--
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/.env.example b/.env.example
index 56e7c06..5b74985 100644
--- a/.env.example
+++ b/.env.example
@@ -1,11 +1,7 @@
-# Copy this file to .env
-
-APP_NAME = Shopping App
-# Change to your own database
-DATABASE_URL = mysql+pymysql://your_user:your_password@localhost/shopping     # This template use mysql
-# change your_user to your mysql username
-# change your_password to your mysql password
-# change localhost to 127.0.0.1 if youre running on local
-
-SECRET_KEY = your_secret_key
-DEBUG = True    # Only True or False
\ No newline at end of file
+APP_NAME="Shopping App"
+DATABASE_USERNAME="your_mysql_username"
+DATABASE_PASSWORD="your_mysql_password"
+DATABASE_HOST="127.0.0.1"
+DATABASE_NAME="shopping"
+SECRET_KEY="your_secret_key"
+DEBUG=True
diff --git a/app/core/config.py b/app/core/config.py
index 4045933..6aed5e9 100644
--- a/app/core/config.py
+++ b/app/core/config.py
@@ -4,14 +4,21 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
 
 class Settings(BaseSettings):
     app_name: str = "Shopping App"
-    database_url: str  # Ensure lowercase to match the .env key
+    database_username: str
+    database_password: str
+    database_host: str
+    database_name: str
     secret_key: str
     debug: bool = True
 
+    @property
+    def database_url(self) -> str:
+        return f"mysql+pymysql://{self.database_username}:{self.database_password}@{self.database_host}/{self.database_name}"
+
     model_config = SettingsConfigDict(
         env_file=str(Path(__file__).resolve().parent.parent / ".env"),
         env_file_encoding="utf-8",
-        case_sensitive=False,  # Allows case-insensitive environment variable keys
+        case_sensitive=False,
     )
 
 
-- 
GitLab