Skip to content

Commit

Permalink
Revert "[REFACTOR] 게시글 업데이트 방식 변경(PUT->PATCH), 게시글 추가 필드 선언" (#177)
Browse files Browse the repository at this point in the history
Revert "[REFACTOR] 게시글 업데이트 방식 변경(PUT->PATCH), 게시글 추가 필드 선언 (#176)"

This reverts commit 88a9fd7.
  • Loading branch information
Profile-exe authored Oct 3, 2024
1 parent 88a9fd7 commit 3d61424
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import econo.buddybridge.post.dto.PostCustomPage;
import econo.buddybridge.post.dto.PostReqDto;
import econo.buddybridge.post.dto.PostResDto;
import econo.buddybridge.post.dto.PostUpdateReqDto;
import econo.buddybridge.post.entity.AssistanceType;
import econo.buddybridge.post.entity.PostStatus;
import econo.buddybridge.post.entity.PostType;
Expand All @@ -16,21 +15,19 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/posts")
Expand Down Expand Up @@ -76,7 +73,7 @@ public ApiResponse<ApiResponse.CustomBody<PostCustomPage>> getAllPosts(
@Operation(summary = "게시글 생성", description = "게시글을 생성합니다.")
@PostMapping
public ApiResponse<ApiResponse.CustomBody<Long>> createPost(
@Valid @RequestBody PostReqDto postReqDto,
@RequestBody PostReqDto postReqDto,
HttpServletRequest request
) {
Long memberId = SessionUtils.getMemberId(request);
Expand All @@ -99,14 +96,14 @@ public ApiResponse<ApiResponse.CustomBody<PostResDto>> getPost(

// 게시글 업데이트
@Operation(summary = "게시글 수정", description = "게시글을 수정합니다.")
@PatchMapping("/{post-id}")
@PutMapping("/{post-id}")
public ApiResponse<ApiResponse.CustomBody<Long>> updatePost(
@PathVariable("post-id") Long postId,
@RequestBody PostUpdateReqDto postUpdateReqDto,
@RequestBody PostReqDto postReqDto,
HttpServletRequest request
) {
Long memberId = SessionUtils.getMemberId(request);
Long updatedPostId = postService.updatePost(postId, postUpdateReqDto, memberId);
Long updatedPostId = postService.updatePost(postId, postReqDto, memberId);
return ApiResponseGenerator.success(updatedPostId, HttpStatus.OK);
}

Expand Down
58 changes: 7 additions & 51 deletions src/main/java/econo/buddybridge/post/dto/PostReqDto.java
Original file line number Diff line number Diff line change
@@ -1,67 +1,30 @@
package econo.buddybridge.post.dto;

import econo.buddybridge.member.entity.DisabilityType;
import econo.buddybridge.member.entity.Gender;
import econo.buddybridge.member.entity.Member;
import econo.buddybridge.post.entity.AssistanceTime;
import econo.buddybridge.post.entity.AssistanceType;
import econo.buddybridge.post.entity.District;
import econo.buddybridge.post.entity.Post;
import econo.buddybridge.post.entity.PostStatus;
import econo.buddybridge.post.entity.PostType;
import econo.buddybridge.post.entity.Schedule;
import econo.buddybridge.post.entity.ScheduleType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

import java.time.LocalDateTime;
import lombok.Builder;

@Builder
public record PostReqDto(
@NotBlank(message = "제목을 입력해주세요.")
Long memberId,
String title,

@NotNull(message = "도움 종류를 선택해주세요. 교육 or 생활")
AssistanceType assistanceType,

@NotNull(message = "봉사 시작 날짜를 입력해주세요.")
LocalDateTime startDate,

@NotNull(message = "봉사 종료 날짜를 입력해주세요.")
LocalDateTime endDate,

@NotNull(message = "일정 종류를 선택해주세요. 정기 or 비정기")
LocalDateTime startTime,
LocalDateTime endTime,
ScheduleType scheduleType,

@NotBlank(message = "일정 상세를 입력해주세요. 예) 매주 월요일, 화목")
String scheduleDetails,

@NotNull(message = "지역을 선택해주세요.")
District district,

@NotBlank(message = "상세 내용을 입력해주세요.")
String content,

PostType postType,

@NotNull(message = "장애 종류를 선택해주세요.")
DisabilityType disabilityType,

@NotNull(message = "성별을 선택해주세요.")
Gender gender,

@NotNull(message = "나이를 입력해주세요.")
Integer age,

@NotNull(message = "봉사 시작 시간을 입력해주세요.")
LocalDateTime assistanceStartTime,

@NotNull(message = "봉사 종료 시간을 입력해주세요.")
LocalDateTime assistanceEndTime,

@NotNull(message = "모집 인원을 입력해주세요.")
Integer headcount
DisabilityType disabilityType
) {

public Post toEntity(Member author) {
Expand All @@ -70,8 +33,8 @@ public Post toEntity(Member author) {
.title(title)
.assistanceType(assistanceType)
.schedule(Schedule.builder()
.startDate(startDate)
.endDate(endDate)
.startTime(startTime)
.endTime(endTime)
.scheduleType(scheduleType)
.scheduleDetails(scheduleDetails)
.build())
Expand All @@ -80,13 +43,6 @@ public Post toEntity(Member author) {
.postType(postType)
.postStatus(PostStatus.RECRUITING)
.disabilityType(disabilityType)
.gender(gender)
.age(age)
.assistanceTime(AssistanceTime.builder()
.assistanceStartTime(assistanceStartTime)
.assistanceEndTime(assistanceEndTime)
.build())
.headcount(headcount)
.build();
}
}
43 changes: 26 additions & 17 deletions src/main/java/econo/buddybridge/post/dto/PostResDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@

import econo.buddybridge.member.dto.MemberResDto;
import econo.buddybridge.member.entity.DisabilityType;
import econo.buddybridge.member.entity.Gender;
import econo.buddybridge.post.entity.AssistanceType;
import econo.buddybridge.post.entity.District;
import econo.buddybridge.post.entity.Post;
import econo.buddybridge.post.entity.PostStatus;
import econo.buddybridge.post.entity.PostType;
import econo.buddybridge.post.entity.ScheduleType;
import lombok.Builder;

import java.time.LocalDateTime;
import lombok.Builder;

@Builder
public record PostResDto(
Long id,
MemberResDto author,
String title,
AssistanceType assistanceType,
LocalDateTime startDate,
LocalDateTime endDate,
LocalDateTime startTime,
LocalDateTime endTime,
ScheduleType scheduleType,
String scheduleDetails,
District district,
Expand All @@ -30,22 +28,38 @@ public record PostResDto(
LocalDateTime modifiedAt,
PostStatus postStatus,
DisabilityType disabilityType,
Gender gender,
Integer age,
LocalDateTime assistanceStartTime,
LocalDateTime assistanceEndTime,
Integer headcount,
Boolean isLiked
) {

public PostResDto(Post post) {
this(
post.getId(),
new MemberResDto(post.getAuthor()),
post.getTitle(),
post.getAssistanceType(),
post.getSchedule().getStartTime(),
post.getSchedule().getEndTime(),
post.getSchedule().getScheduleType(),
post.getSchedule().getScheduleDetails(),
post.getDistrict(),
post.getContent(),
post.getPostType(),
post.getCreatedAt(),
post.getModifiedAt(),
post.getPostStatus(),
post.getDisabilityType(),
false
);
}

public PostResDto(Post post, Boolean isLiked) {
this(
post.getId(),
new MemberResDto(post.getAuthor()),
post.getTitle(),
post.getAssistanceType(),
post.getSchedule().getStartDate(),
post.getSchedule().getEndDate(),
post.getSchedule().getStartTime(),
post.getSchedule().getEndTime(),
post.getSchedule().getScheduleType(),
post.getSchedule().getScheduleDetails(),
post.getDistrict(),
Expand All @@ -55,11 +69,6 @@ public PostResDto(Post post, Boolean isLiked) {
post.getModifiedAt(),
post.getPostStatus(),
post.getDisabilityType(),
post.getGender(),
post.getAge(),
post.getAssistanceTime().getAssistanceStartTime(),
post.getAssistanceTime().getAssistanceEndTime(),
post.getHeadcount(),
isLiked
);
}
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/econo/buddybridge/post/dto/PostUpdateReqDto.java

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/java/econo/buddybridge/post/entity/AssistanceTime.java

This file was deleted.

Loading

0 comments on commit 3d61424

Please sign in to comment.