Skip to content

Commit

Permalink
Refactor: 작성자 호출 시에 프로필 이미지 링크 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
joy-river committed Dec 29, 2024
1 parent 33fecb3 commit 5303ba3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions KUA/course/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from rest_framework.parsers import MultiPartParser, FormParser
import mimetypes
from django.db.models import F
import requests

# 강의 전체 뷰(CRUD 포함)


Expand Down Expand Up @@ -340,6 +342,21 @@ def retrieve(self, request, *args, **kwargs):

attachments = []
post_images = PostImage.objects.filter(post=post)

profile_image_url = f"http://3.37.163.236:8000/media/attachments/6789563.png"
try:
api_url = f"http://3.37.163.236:8000/student/image/?name={post.student.nickname}"
header = {
"Authorization": f"Token {request.META.get('HTTP_AUTHORIZATION')}"
}
response = requests.get(api_url, headers=header)
if response.status_code == 200:
image_data = response.json()
if (image_data.get("image")):
profile_image_url = f"http://3.37.163.236:8000/{image_data['image']}"
except requests.exceptions.RequestException:
pass


for post_image in post_images:
file_path = post_image.image.path
Expand Down Expand Up @@ -367,6 +384,7 @@ def retrieve(self, request, *args, **kwargs):
"author": {
"id": post.student.id,
"nickname": post.student.nickname,
"profileImage": profile_image_url,
},
"likes": post.likes,
"views": post.views,
Expand Down

0 comments on commit 5303ba3

Please sign in to comment.