Skip to content

Commit

Permalink
#9 feat: create intership_register api (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
0321minji authored Apr 10, 2024
1 parent 3ffdedc commit 943baf4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ class Certification(admin.ModelAdmin):

@admin.register(models.Competition)
class Competition(admin.ModelAdmin):
pass

@admin.register(models.Internship)
class Intership(admin.ModelAdmin):
pass
12 changes: 10 additions & 2 deletions users/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from django.core.files.uploadedfile import InMemoryUploadedFile
from django.core.files import File
from django.core.files.base import ContentFile

from users.models import User, ReformerProfile, Certification, Competition
from users.models import User, ReformerProfile, Certification, Competition, Internship
from users.selectors import UserSelector
# from core.exceptions import ApplicationError

Expand Down Expand Up @@ -198,3 +197,12 @@ def competition_register(self,profile:ReformerProfile,name:str,organizer:str,awa
os.makedirs(os.path.dirname(file_path), exist_ok=True)
competition.proof_document.save(file_path,ContentFile(proof_document.read()),save=False)
competition.save()

def intership_register(self,profile:ReformerProfile,company_name:str,department:str,position:str,start_date:str,end_date:str,proof_document:InMemoryUploadedFile):
intership=Internship(profile=profile,company_name=company_name,department=department,position=position,start_date=start_date,end_date=end_date)

ext = proof_document.name.split(".")[-1]
file_path = 'users/profile/internship/{}{}'.format(str(time.time())+str(uuid.uuid4().hex), ext)
os.makedirs(os.path.dirname(file_path), exist_ok=True)
intership.proof_document.save(file_path,ContentFile(proof_document.read()),save=False)
intership.save()
5 changes: 2 additions & 3 deletions users/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.urls import path
from rest_framework_simplejwt.views import TokenRefreshView, TokenVerifyView
from .views import UserSignUpApi,UserLoginApi,ReformerProfileApi,CertificationCreateApi,CompetitionCreateApi

from .views import UserSignUpApi,UserLoginApi,ReformerProfileApi,CertificationCreateApi,CompetitionCreateApi,IntershipCreateApi
app_name = "users"

urlpatterns =[
Expand All @@ -13,5 +12,5 @@
path('profile_register/',ReformerProfileApi.as_view(),name='profile_register'),
path('certification_register/',CertificationCreateApi.as_view(),name='certification'),
path('competition_register/',CompetitionCreateApi.as_view(),name='competition'),

path('intership_register/',IntershipCreateApi.as_view(),name='intership'),
]
32 changes: 32 additions & 0 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,36 @@ def post(self,request):
return Response({
'status':'success',
},status=status.HTTP_200_OK)

class IntershipCreateApi(APIView):
permission_classes=(AllowAny,)

class IntershipCreateInputSerializer(serializers.Serializer):
company_name = serializers.CharField()
department = serializers.CharField(required=False)
position = serializers.CharField(required=False)
start_date = serializers.DateField()
end_date = serializers.DateField()
proof_document = serializers.FileField()

def post(self,request):
input_serializer = self.IntershipCreateInputSerializer(data=request.data)
input_serializer.is_valid(raise_exception=True)
data = input_serializer.validated_data

service=UserService()

service.intership_register(
profile=request.user.reformer_profile,
company_name=data.get('company_name'),
department=data.get('department',None),
position=data.get('position',None),
start_date=data.get('start_date'),
end_date=data.get('end_date'),
proof_document=data.get('proof_document'),
)

return Response({
'status':'success',
},status=status.HTTP_200_OK)

0 comments on commit 943baf4

Please sign in to comment.