@@ -295,6 +295,9 @@ class FeedStatusView(APIView):
295295 CALC-003(남은허용량/잔수), CALC-005(개인화 θ),
296296 CALC-006(한계효용)을 이 안에서 호출해 한 번에 내려준다.
297297 ?compact=true면 drinks/graph를 생략한다.
298+ ?drink_id=<id>를 주면 CALC-002/003/006의 "1잔" 기준량을
299+ 그 음료의 caffeine_mg로 바꿔 다시 계산한다("한잔 마시기"
300+ 버튼에서 고른 음료가 바뀔 때 프론트가 미리보기용으로 호출).
298301
299302 명세(Notion API 명세서) URI는 /feed이지만, 그 경로는 diary/urls.py의
300303 "feed/"에서 프론트가 작업 중인 HTML 화면(FeedView)이 이미 쓰고 있다.
@@ -336,7 +339,7 @@ def get(self, request):
336339 current_mg = round (concentration_at (doses , now ), 1 )
337340
338341 bedtime = resolve_next_occurrence (profile .target_sleeptime , local_now )
339- ref_dose = reference_dose_mg ( user )
342+ ref_dose = self . _resolve_ref_dose ( request , user )
340343
341344 cutoff_result = calc_cutoff (now , bedtime , ref_dose , doses , theta_mg )
342345 allowance_result = calc_allowance (bedtime , doses , theta_mg , ref_dose )
@@ -366,6 +369,7 @@ def get(self, request):
366369 "target_bedtime" : profile .target_sleeptime .strftime ("%H:%M" ),
367370 "threshold_mg" : theta_mg ,
368371 "current_mg" : current_mg ,
372+ "ref_dose_mg" : ref_dose ,
369373 "cutoff_at" : cutoff_at_local .isoformat () if cutoff_at_local else None ,
370374 "remaining_mg" : allowance_result .remaining_mg ,
371375 "remaining_cups" : allowance_result .cups ,
@@ -396,6 +400,24 @@ def get(self, request):
396400
397401 return Response (data , status = status .HTTP_200_OK )
398402
403+ @staticmethod
404+ def _resolve_ref_dose (request , user ):
405+ """CALC-002/003/006에 쓸 '1잔' 기준량(mg).
406+
407+ ?drink_id=<id>가 오면 그 음료의 caffeine_mg로 미리보기 계산을 해준다
408+ ("한잔 마시기" 버튼에서 고른 음료가 바뀔 때마다 프론트가 재조회).
409+ caffeine_mg는 CaffeineLogSerializer의 스냅샷 원칙과 동일하게 클라이언트가
410+ 직접 보낸 값을 쓰지 않고, 반드시 본인 소유 활성 음료의 id로만 조회해 채운다.
411+ id가 없거나, 숫자가 아니거나, 본인 소유가 아니면 기존 기본값
412+ (reference_dose_mg: 가장 최근 즐겨찾기, 없으면 180mg)으로 조용히 폴백한다.
413+ """
414+ drink_id = request .query_params .get ("drink_id" , "" )
415+ if drink_id .isdigit ():
416+ drink = Drink .objects .filter (user = user , id = int (drink_id ), is_active = True ).first ()
417+ if drink :
418+ return drink .caffeine_mg
419+ return reference_dose_mg (user )
420+
399421 @staticmethod
400422 def _sleep_survey_required (user , local_now , today , day_start ):
401423 """SLEEP-001: 수면설문 노출 판정.
@@ -447,6 +469,13 @@ class AllNightModeView(LoginRequiredMixin, TemplateView):
447469 template_name = "diary/allnight_mode.html"
448470 extra_context = {"page_title" : "밤샘모드" }
449471
472+
473+ # 나의 다이어리 — /feed-status/, /sleep-logs/, /caffeine-logs/를 호출하므로 로그인 필수.
474+ class MyDiaryView (LoginRequiredMixin , TemplateView ):
475+ login_url = "/auth/login"
476+ template_name = "diary/mydiary.html"
477+ extra_context = {"page_title" : "나의 다이어리" }
478+
450479# 수면 설문
451480class SleepLogTimeView (LoginRequiredMixin , TemplateView ):
452481 login_url = "/auth/login"
0 commit comments