Skip to content

Commit 7d6078e

Browse files
authored
feat: S3 integration (#25)
* chore: basic aws s3 setup * feat: terraform * fix: finally its working * chore: model revert * chore: remove todo
1 parent dc93fed commit 7d6078e

30 files changed

+281
-204
lines changed

backend/.gitignore

+30-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,33 @@ static/
3636

3737
# OS generated files
3838
.DS_Store
39-
Thumbs.db
39+
Thumbs.db
40+
41+
# Local .terraform directories
42+
.terraform/
43+
44+
# Terraform state files
45+
*.tfstate
46+
*.tfstate.*
47+
48+
# Crash log files
49+
crash.log
50+
51+
# Terraform variable files (containing sensitive data)
52+
*.tfvars
53+
*.tfvars.json
54+
55+
# Override files, which may contain sensitive data
56+
override.tf
57+
override.tf.json
58+
59+
# .terraform.lock.hcl files (optional to include, especially in team environments)
60+
.terraform.lock.hcl
61+
62+
# IDE and editor folders
63+
.vscode/
64+
.idea/
65+
66+
# Operating system files
67+
.DS_Store
68+
Thumbs.db

backend/bitmatch/a3/__init__.py

Whitespace-only changes.

backend/bitmatch/a3/admin.py

-3
This file was deleted.

backend/bitmatch/a3/apps.py

-6
This file was deleted.

backend/bitmatch/a3/migrations/__init__.py

Whitespace-only changes.

backend/bitmatch/a3/models.py

-3
This file was deleted.

backend/bitmatch/a3/tests.py

-3
This file was deleted.

backend/bitmatch/a3/urls.py

-12
This file was deleted.

backend/bitmatch/a3/views.py

-26
This file was deleted.

backend/bitmatch/a4/__init__.py

Whitespace-only changes.

backend/bitmatch/a4/admin.py

-3
This file was deleted.

backend/bitmatch/a4/apps.py

-6
This file was deleted.

backend/bitmatch/a4/migrations/0001_initial.py

-21
This file was deleted.

backend/bitmatch/a4/migrations/__init__.py

Whitespace-only changes.

backend/bitmatch/a4/models.py

-19
This file was deleted.

backend/bitmatch/a4/settings.py

-3
This file was deleted.

backend/bitmatch/a4/tests.py

-3
This file was deleted.

backend/bitmatch/a4/urls.py

-9
This file was deleted.

backend/bitmatch/a4/views.py

-67
This file was deleted.

backend/bitmatch/bitmatch/settings.py

+30-7
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,37 @@
5555
'django.contrib.sessions',
5656
'django.contrib.messages',
5757
'django.contrib.staticfiles',
58-
"rest_framework",
59-
"corsheaders",
60-
"userauth",
61-
"projects",
62-
"a3",
63-
"a4",
58+
'rest_framework',
59+
'corsheaders',
60+
'storages',
61+
'userauth',
62+
'projects'
6463
]
6564

65+
66+
# AWS S3 Settings
67+
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
68+
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
69+
AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")
70+
AWS_S3_REGION_NAME = "us-west-1"
71+
72+
AWS_S3_FILE_OVERWRITE = False
73+
AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com"
74+
75+
MEDIA_URL = 'media/'
76+
STATIC_URL = 'staticfiles/'
77+
78+
STORAGES={
79+
# Media Files
80+
"default": {
81+
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
82+
},
83+
# CSS and JS file management
84+
'staticfiles': {
85+
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage"
86+
}
87+
}
88+
6689
MIDDLEWARE = [
6790
'django.middleware.security.SecurityMiddleware',
6891
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -101,7 +124,7 @@
101124
DATABASES = {
102125
"default": {
103126
"ENGINE": "django.db.backends.postgresql",
104-
"NAME": "djangoapp",
127+
"NAME": "bitmatchdjangodb",
105128
"USER": os.getenv("DB_USER"),
106129
"PASSWORD": os.getenv("DB_PASSWORD"),
107130
"HOST": os.getenv("DB_HOST"),

backend/bitmatch/bitmatch/urls.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@
2121
urlpatterns = [
2222
path('', views.home),
2323
path('admin/', admin.site.urls),
24-
path('a3/', include('a3.urls')),
25-
path('a4/', include('a4.urls')),
26-
path('projects/', include('projects.urls')),
24+
path('projects/', include('projects.urls'))
2725
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 5.1.6 on 2025-03-16 00:23
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('projects', '0002_project_images'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='project',
15+
old_name='images',
16+
new_name='slider_images',
17+
),
18+
migrations.RemoveField(
19+
model_name='project',
20+
name='image_url',
21+
),
22+
migrations.AddField(
23+
model_name='project',
24+
name='image',
25+
field=models.ImageField(blank=True, null=True, upload_to='projects/'),
26+
),
27+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 5.1.6 on 2025-03-16 04:55
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('projects', '0003_rename_images_project_slider_images_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='project',
15+
old_name='image',
16+
new_name='image_url',
17+
),
18+
migrations.RenameField(
19+
model_name='project',
20+
old_name='slider_images',
21+
new_name='images',
22+
),
23+
]

backend/bitmatch/projects/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Project(models.Model):
1111
followers = models.IntegerField(default=0)
1212
likes = models.IntegerField(default=0)
1313
positions = models.JSONField(default=list)
14-
image_url = models.URLField(blank=True, null=True)
14+
image_url = models.ImageField(upload_to="projects/", blank=True, null=True)
1515
images = models.JSONField(default=list)
1616

1717
def __str__(self):

backend/bitmatch/projects/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .views import ProjectCRUDView, get_projects
33

44
urlpatterns = [
5-
path('', get_projects, name='get_projects'), # Fetch all projects
5+
path('', get_projects, name='get_projects'), # Fetch all projects
66
path('create/', ProjectCRUDView.as_view(), name='project-create'), # Create project
77
path('<int:pk>/', ProjectCRUDView.as_view(), name='project-detail'), # Read, Update, Delete project by ID
88
]

0 commit comments

Comments
 (0)