from rest_framework import generics
from .models import Resume
from .serializers import ResumeSerializer
from apps.accounts.permissions import IsSeeker


class MyResumeView(generics.RetrieveUpdateAPIView):
    """求职者获取/更新自己的简历（不存在则自动创建）"""
    serializer_class = ResumeSerializer
    permission_classes = [IsSeeker]

    def get_object(self):
        resume, _ = Resume.objects.get_or_create(
            user=self.request.user,
            defaults={'name': self.request.user.username}
        )
        return resume
