Skip to content

Commit

Permalink
[FEAT] 게시글 작성을 위한 열거형 정보를 제공하는 엔드포인트 구현 (#189)
Browse files Browse the repository at this point in the history
* refactor: LocalTime 반환형식에서 초(second) 제거

* feat: 게시글 작성에 필요한 열거형을 갖는 DTO 정의

* feat: 게시글 작성에 필요한 열거형을 반환하는 엔드포인트 구현
  • Loading branch information
Profile-exe authored Nov 5, 2024
1 parent dc5c416 commit 802175c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import econo.buddybridge.common.annotation.AllowAnonymous;
import econo.buddybridge.member.entity.DisabilityType;
import econo.buddybridge.post.dto.PostCustomPage;
import econo.buddybridge.post.dto.PostEnumResDto;
import econo.buddybridge.post.dto.PostReqDto;
import econo.buddybridge.post.dto.PostResDto;
import econo.buddybridge.post.dto.PostUpdateReqDto;
Expand Down Expand Up @@ -98,6 +99,14 @@ public ApiResponse<ApiResponse.CustomBody<Long>> createPost(
return ApiResponseGenerator.success(createdPostId, HttpStatus.CREATED);
}

// 게시글 생성을 위한 열거형 정보들 제공
@Operation(summary = "게시글 생성을 위한 열거형 정보들 제공", description = "게시글 생성을 위한 열거형 정보들을 제공합니다.")
@GetMapping("/enums")
public ApiResponse<ApiResponse.CustomBody<PostEnumResDto>> getPostEnums() {
PostEnumResDto postEnums = postService.getPostEnums();
return ApiResponseGenerator.success(postEnums, HttpStatus.OK);
}

// 단일 게시글 조회
@Operation(summary = "게시글 조회", description = "게시글을 조회합니다.")
@GetMapping("/{post-id}")
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/econo/buddybridge/post/dto/PostEnumResDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package econo.buddybridge.post.dto;

import econo.buddybridge.member.entity.DisabilityType;
import econo.buddybridge.post.entity.AssistanceType;
import econo.buddybridge.post.entity.District;
import java.util.List;
import lombok.Builder;

@Builder
public record PostEnumResDto(
List<AssistanceType> assistanceTypes,
List<DisabilityType> disabilityTypes,
List<District> districts
) {

}
5 changes: 3 additions & 2 deletions src/main/java/econo/buddybridge/post/dto/PostResDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package econo.buddybridge.post.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import econo.buddybridge.member.dto.MemberResDto;
import econo.buddybridge.member.entity.DisabilityType;
import econo.buddybridge.member.entity.Gender;
Expand Down Expand Up @@ -32,8 +33,8 @@ public record PostResDto(
DisabilityType disabilityType,
Gender gender,
Integer age,
LocalTime assistanceStartTime,
LocalTime assistanceEndTime,
@JsonFormat(pattern = "HH:mm") LocalTime assistanceStartTime,
@JsonFormat(pattern = "HH:mm") LocalTime assistanceEndTime,
Integer headcount,
Integer matchingDoneCount,
Boolean isLiked
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/econo/buddybridge/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import econo.buddybridge.member.entity.Member;
import econo.buddybridge.member.service.MemberService;
import econo.buddybridge.post.dto.PostCustomPage;
import econo.buddybridge.post.dto.PostEnumResDto;
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.District;
import econo.buddybridge.post.entity.Post;
import econo.buddybridge.post.entity.PostStatus;
import econo.buddybridge.post.entity.PostType;
Expand Down Expand Up @@ -66,6 +68,15 @@ public Long createPost(PostReqDto postReqDto, Long memberId) {
return postRepository.save(post).getId();
}

// 게시글 작성을 위한 열거형 타입의 값들을 가져오는 메서드
public PostEnumResDto getPostEnums() {
return PostEnumResDto.builder()
.assistanceTypes(List.of(AssistanceType.values()))
.disabilityTypes(List.of(DisabilityType.values()))
.districts(List.of(District.values()))
.build();
}

@Transactional // 게시글 수정
public Long updatePost(Long postId, PostUpdateReqDto postUpdateReqDto, Long memberId) {
Post post = findPostByIdOrThrow(postId);
Expand Down

0 comments on commit 802175c

Please sign in to comment.