From 393b8b4a57caff62cd7f08079425d459974a178c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=97=B0?= Date: Fri, 5 Jul 2024 02:45:21 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20workflow=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index e7bdcc8..05a2968 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -41,16 +41,16 @@ jobs: run: ./gradlew build -x test shell: bash - ## create application-prod.yml - - name: create application-prod.yml - if: contains(github.ref, 'main') - run: | - cd ./src/main - mkdir -p resources - cd ./resources - touch ./application.properties - echo "${{ secrets.PROPERTIES_PROD }}" > ./application-prod.yml - shell: bash +# ## create application-prod.yml +# - name: create application-prod.yml +# if: contains(github.ref, 'main') +# run: | +# cd ./src/main +# mkdir -p resources +# cd ./resources +# touch ./application.properties +# echo "${{ secrets.PROPERTIES_PROD }}" > ./application-prod.yml +# shell: bash - name: Build With Gradle if: contains(github.ref, 'main') From afd6487778148e4373ac618c4bff029b4e859caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=97=B0?= Date: Fri, 5 Jul 2024 02:45:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EC=A0=84=EB=AC=B8=EA=B0=80=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=9E=91=EC=84=B1=20API=20?= =?UTF-8?q?=EA=BE=B8=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/dream/controller/ProController.java | 29 +++++++++++++++++ .../umc/dream/converter/ProPostConverter.java | 32 +++++++++++++++++++ src/main/java/com/umc/dream/domain/User.java | 7 ++++ .../java/com/umc/dream/dto/ProRequestDTO.java | 14 ++++++++ .../com/umc/dream/dto/ProResponseDTO.java | 25 +++++++++++++++ .../umc/dream/repository/PostRepository.java | 7 ++++ .../dream/service/ProService/ProService.java | 31 ++++++++++++++++++ .../service/ProService/ProServiceImpl.java | 8 +++++ 8 files changed, 153 insertions(+) create mode 100644 src/main/java/com/umc/dream/controller/ProController.java create mode 100644 src/main/java/com/umc/dream/converter/ProPostConverter.java create mode 100644 src/main/java/com/umc/dream/dto/ProRequestDTO.java create mode 100644 src/main/java/com/umc/dream/dto/ProResponseDTO.java create mode 100644 src/main/java/com/umc/dream/repository/PostRepository.java create mode 100644 src/main/java/com/umc/dream/service/ProService/ProService.java create mode 100644 src/main/java/com/umc/dream/service/ProService/ProServiceImpl.java diff --git a/src/main/java/com/umc/dream/controller/ProController.java b/src/main/java/com/umc/dream/controller/ProController.java new file mode 100644 index 0000000..e82fb99 --- /dev/null +++ b/src/main/java/com/umc/dream/controller/ProController.java @@ -0,0 +1,29 @@ +package com.umc.dream.controller; + +import com.umc.dream.apiPayload.ApiResponse; +import com.umc.dream.converter.ProPostConverter; +import com.umc.dream.domain.Post; +import com.umc.dream.dto.ProRequestDTO; +import com.umc.dream.dto.ProResponseDTO; +import com.umc.dream.service.ProService.ProService; +import io.swagger.v3.oas.annotations.Operation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/posts/pro") +public class ProController { + + private final ProService proService; + + @Operation(summary = "전문가 게시글 작성 API") + @PostMapping + public ApiResponse createProPost(@RequestBody ProRequestDTO.CreateRequestDTO request){ + Post post = proService.createProPost(request); + return ApiResponse.onSuccess(ProPostConverter.toProPostResultDTO(post)); + } +} diff --git a/src/main/java/com/umc/dream/converter/ProPostConverter.java b/src/main/java/com/umc/dream/converter/ProPostConverter.java new file mode 100644 index 0000000..94d7295 --- /dev/null +++ b/src/main/java/com/umc/dream/converter/ProPostConverter.java @@ -0,0 +1,32 @@ +package com.umc.dream.converter; + +import com.umc.dream.domain.Post; +import com.umc.dream.domain.User; +import com.umc.dream.domain.enums.Type; +import com.umc.dream.dto.ProRequestDTO; +import com.umc.dream.dto.ProResponseDTO; + +public class ProPostConverter { + + public static ProResponseDTO.CreateResultDTO toProPostResultDTO(Post post) { + return ProResponseDTO.CreateResultDTO.builder() + .name(post.getWriter().getName()) + .postId(post.getId()) + .title(post.getTitle()) + .content(post.getContent()) + .proName(post.getPro().getName()) + .createdAt(post.getPro().getCreatedDate()) + .build(); + } + + public static Post toProPost(ProRequestDTO.CreateRequestDTO request, User writer, User pro) { + return Post.builder() + .title(request.getTitle()) + .content(request.getContent()) + .type(Type.PRO) + .writer(writer) + .pro(pro) + .build(); + } + +} diff --git a/src/main/java/com/umc/dream/domain/User.java b/src/main/java/com/umc/dream/domain/User.java index 9dfad15..ec379da 100644 --- a/src/main/java/com/umc/dream/domain/User.java +++ b/src/main/java/com/umc/dream/domain/User.java @@ -2,6 +2,7 @@ import com.umc.dream.domain.common.BaseEntity; import com.umc.dream.domain.enums.Role; +import jakarta.annotation.Nullable; import jakarta.persistence.*; import lombok.*; @@ -24,6 +25,12 @@ public class User extends BaseEntity { @Column(nullable = false, length = 20) private String password; + + @Nullable + private String description; + + @Nullable + private String price; @Enumerated(EnumType.STRING) private Role role; diff --git a/src/main/java/com/umc/dream/dto/ProRequestDTO.java b/src/main/java/com/umc/dream/dto/ProRequestDTO.java new file mode 100644 index 0000000..610e69e --- /dev/null +++ b/src/main/java/com/umc/dream/dto/ProRequestDTO.java @@ -0,0 +1,14 @@ +package com.umc.dream.dto; + +import lombok.Getter; + +public class ProRequestDTO { + + @Getter + public static class CreateRequestDTO { + Long userId; // 유저 id + Long proId; // 전문가 id + String title; + String content; + } +} diff --git a/src/main/java/com/umc/dream/dto/ProResponseDTO.java b/src/main/java/com/umc/dream/dto/ProResponseDTO.java new file mode 100644 index 0000000..b596127 --- /dev/null +++ b/src/main/java/com/umc/dream/dto/ProResponseDTO.java @@ -0,0 +1,25 @@ +package com.umc.dream.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +public class ProResponseDTO { + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class CreateResultDTO { + String name; // 유저 이름 + Long postId; + String title; + String content; + String proName; // 전문가 이름 + LocalDateTime createdAt; + } + +} diff --git a/src/main/java/com/umc/dream/repository/PostRepository.java b/src/main/java/com/umc/dream/repository/PostRepository.java new file mode 100644 index 0000000..54b0ead --- /dev/null +++ b/src/main/java/com/umc/dream/repository/PostRepository.java @@ -0,0 +1,7 @@ +package com.umc.dream.repository; + +import com.umc.dream.domain.Post; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PostRepository extends JpaRepository { +} diff --git a/src/main/java/com/umc/dream/service/ProService/ProService.java b/src/main/java/com/umc/dream/service/ProService/ProService.java new file mode 100644 index 0000000..10b0d07 --- /dev/null +++ b/src/main/java/com/umc/dream/service/ProService/ProService.java @@ -0,0 +1,31 @@ +package com.umc.dream.service.ProService; + +import com.umc.dream.apiPayload.code.status.ErrorStatus; +import com.umc.dream.apiPayload.exception.GeneralException; +import com.umc.dream.converter.ProPostConverter; +import com.umc.dream.domain.Post; +import com.umc.dream.domain.User; +import com.umc.dream.dto.ProRequestDTO; +import com.umc.dream.repository.PostRepository; +import com.umc.dream.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ProService implements ProServiceImpl{ + + private final UserRepository userRepository; + private final PostRepository postRepository; + + @Override + public Post createProPost(ProRequestDTO.CreateRequestDTO request) { + User writer = userRepository.findById(request.getUserId()) + .orElseThrow(() -> new GeneralException(ErrorStatus._BAD_REQUEST)); + User pro = userRepository.findById(request.getUserId()) + .orElseThrow(() -> new GeneralException(ErrorStatus._BAD_REQUEST)); + + Post post = ProPostConverter.toProPost(request, writer, pro); + return postRepository.save(post); + } +} diff --git a/src/main/java/com/umc/dream/service/ProService/ProServiceImpl.java b/src/main/java/com/umc/dream/service/ProService/ProServiceImpl.java new file mode 100644 index 0000000..b5935e7 --- /dev/null +++ b/src/main/java/com/umc/dream/service/ProService/ProServiceImpl.java @@ -0,0 +1,8 @@ +package com.umc.dream.service.ProService; + +import com.umc.dream.domain.Post; +import com.umc.dream.dto.ProRequestDTO; + +public interface ProServiceImpl { + Post createProPost(ProRequestDTO.CreateRequestDTO request); +}