-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: 일정 만들기 주소 추가 #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "feat/#5-\uCF54\uC2A4\uB9CC\uB4E4\uAE30,\uC870\uD68C,\uC218\uC815,\uC0AD\uC81C"
Changes from all commits
61f3357
46f6392
eecf651
cbac5d7
831542c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,9 @@ class Schedule(models.Model): # 일정(코스) | |
| meet_date_first = models.DateTimeField(null=True, blank= True) # 만나는 날짜(최대 3개로 설정하게 하려면 조금 복잡해서 일단 이렇게 해놓음..) | ||
| meet_date_second = models.DateTimeField(null=True, blank= True) # 2024-12-10T15:30:00 식으로 json 받기 | ||
| meet_date_third = models.DateTimeField(null=True , blank= True) | ||
| course_name = models.CharField(max_length=20, null=True, blank= True) | ||
| course_name = models.CharField(max_length=20, blank=True, default="일정 이름을 정해주세요") | ||
| meet_place = models.CharField(max_length=50, null=True, blank= True) | ||
| address = models.CharField(null=True, blank = True, max_length=150) | ||
| latitude = models.FloatField(default=0.0) # 만나는 장소의 위도 | ||
| longitude = models.FloatField(default=0.0) # 만나는 장소의 경도 | ||
| created_at = models.DateField(auto_now_add=True) | ||
|
|
@@ -32,7 +33,7 @@ def __str__(self): | |
| class ScheduleEntry(models.Model): # 각 코스의 일정들 | ||
| schedule = models.ForeignKey(Schedule, on_delete=models.CASCADE) # 코스의 외래키 | ||
| num = models.IntegerField(null=True, blank=True) # 순번 | ||
| entry_name = models.CharField(max_length=30) # 일정의 이름 | ||
| entry_name = models.CharField(max_length=30, blank=True, default="기본 일정") # 일정의 이름 | ||
| time = models.TimeField(null=True, blank=True) # 그 일정의 시간 | ||
| open_time = models.TimeField(null=True, blank=True) # 오픈 시간 | ||
| close_time = models.TimeField(null=True, blank=True) # 마감 시간 | ||
|
|
@@ -44,17 +45,20 @@ class ScheduleEntry(models.Model): # 각 코스의 일정들 | |
|
|
||
| # 순번 자동 증가 로직 | ||
| def save(self, *args, **kwargs): | ||
| if self.num is None: # num이 None인 경우에만 자동으로 계산 | ||
| if self.num is None: # num이 None인 경우 자동으로 계산 | ||
| last_entry = ScheduleEntry.objects.filter(schedule=self.schedule).order_by('-num').first() | ||
| if last_entry: | ||
| if last_entry and last_entry.num is not None: | ||
| self.num = last_entry.num + 1 # 이전 num 값에서 +1 | ||
| else: | ||
| self.num = 0 # 해당 schedule의 첫 번째 항목일 경우 0으로 설정 | ||
| self.num = 1 # 해당 schedule의 첫 번째 항목일 경우 1부터 시작 | ||
|
|
||
| if not self.entry_name: | ||
| self.entry_name = f"{self.num}번째 일정" | ||
|
|
||
| super().save(*args, **kwargs) # 부모 클래스의 save 호출 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 1번 부터 시작하도록 바꿔줬고, 위와 같은 이유로 default 값을 지정해줬습니다! |
||
|
|
||
|
|
||
| def __str__(self): | ||
| return self.entry_name | ||
| return self.entry_name if self.entry_name else f"ScheduleEntry {self.pk}" | ||
|
|
||
| class AlternativePlace(models.Model): # 대안장소 | ||
| schedule_entry = models.ForeignKey(ScheduleEntry, on_delete=models.CASCADE) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,21 +25,18 @@ class Meta: | |
| model = ScheduleEntry | ||
| fields = '__all__' | ||
|
|
||
| class CreateCourseSerializser(serializers.ModelSerializer): | ||
| user_id = serializers.CharField(write_only=True) # 요청에서 유저 ID (id 필드) 처리 | ||
|
|
||
| class CreateCourseSerializer(serializers.ModelSerializer): | ||
| class Meta: | ||
| model = Schedule | ||
| fields = '__all__' | ||
| # [ | ||
| # 'meet_date_first', 'meet_date_second', 'meet_date_third', | ||
| # 'course_name', 'meet_place', 'latitude', 'longitude', 'user_id' | ||
| # ] | ||
| fields = '__all__' # 모든 필드 포함 | ||
|
|
||
| def create(self, validated_data): | ||
| # user_id로 User 객체 가져오기 | ||
| user_id = validated_data.pop('user_id') # 요청 데이터에서 user_id 추출 | ||
| user = get_object_or_404(CustomUser, id=user_id) # User 모델의 id 필드로 조회 | ||
| request = self.context.get('request') | ||
| if not request or not request.user: | ||
| raise serializers.ValidationError("유효한 사용자 정보를 찾을 수 없습니다.") | ||
|
|
||
| user = request.user # request.user 사용 | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 http body로 user_id로 받던거 수정했습니다! |
||
| # 일정 생성 | ||
| schedule = Schedule.objects.create(**validated_data) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,12 +273,12 @@ class ScheduleUpdateView(APIView): | |
| @swagger_auto_schema( | ||
| tags=["일정(코스)"], | ||
| operation_summary="일정(코스) 생성", | ||
| request_body=CreateCourseSerializser, | ||
| responses={201: CreateCourseSerializser, 400: "Validation Error"} | ||
| request_body=CreateCourseSerializer, | ||
| responses={201: CreateCourseSerializer, 400: "Validation Error"} | ||
| ) | ||
| def post(self, request, *args, **kwargs): | ||
|
|
||
| serializer = CreateCourseSerializser(data=request.data, context={'request': request}) | ||
| serializer = CreateCourseSerializer(data=request.data, context={'request': request}) | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 시리얼라이저 오타가 있길래 그것도 수정해줬어요! |
||
| if serializer.is_valid(): | ||
| serializer.save() | ||
|
|
@@ -294,12 +294,12 @@ class ScheduleDetailView(APIView): | |
| @swagger_auto_schema( | ||
| tags=["일정(코스)"], | ||
| operation_summary="일정 수정", | ||
| request_body=CreateCourseSerializser, | ||
| responses={200: CreateCourseSerializser, 400: "Validation Error"} | ||
| request_body=CreateCourseSerializer, | ||
| responses={200: CreateCourseSerializer, 400: "Validation Error"} | ||
| ) | ||
| def patch(self, request, schedule_id, *args, **kwargs): | ||
| schedule = get_object_or_404(Schedule, pk=schedule_id) | ||
| serializer = CreateCourseSerializser(schedule, data=request.data, partial=True, context={'request': request}) | ||
| serializer = CreateCourseSerializer(schedule, data=request.data, partial=True, context={'request': request}) | ||
|
|
||
| if serializer.is_valid(): | ||
| serializer.save() | ||
|
|
@@ -317,7 +317,7 @@ def patch(self, request, schedule_id, *args, **kwargs): | |
| def get(self, request, schedule_id, *args, **kwargs): | ||
| # 특정일정 상세조회 | ||
| schedule = get_object_or_404(Schedule, pk=schedule_id) | ||
| serializer = CreateCourseSerializser(schedule) | ||
| serializer = CreateCourseSerializer(schedule) | ||
|
|
||
| schedule_entry = ScheduleEntry.objects.filter(schedule=schedule_id) | ||
| entry_serializer = ScheduleEntrySerializer(schedule_entry, many=True) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ def get_secret(setting,secrets_dict = secrets): | |
|
|
||
| SIMPLE_JWT = { | ||
| 'SIGNING_KEY': 'hellomakourse', | ||
| 'ACCESS_TOKEN_LIFETIME': timedelta(hours=1), | ||
| 'ACCESS_TOKEN_LIFETIME': timedelta(days=30), | ||
| 'REFRESH_TOKEN_LIFETIME': timedelta(days=7), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accesstoken 기한 30일로 변경해서 개발하는데 편리하게 해줬습니다! |
||
| 'ROTATE_REFRESH_TOKENS': True, | ||
| 'BLACKLIST_AFTER_ROTATION': True, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기 "일정 이름을 정해주세요" 로 default값을 수정했슴다!