From fd5e3ec112e3d3ba7e408bbde9b07befb947a9a7 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Thu, 21 Mar 2024 19:00:30 +0900 Subject: [PATCH 1/4] =?UTF-8?q?#15=20fix:=20status=20default=20=EA=B0=92?= =?UTF-8?q?=20active=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/hatcher/haemo/common/BaseEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/hatcher/haemo/common/BaseEntity.java b/src/main/java/com/hatcher/haemo/common/BaseEntity.java index a09f409..28e54b3 100644 --- a/src/main/java/com/hatcher/haemo/common/BaseEntity.java +++ b/src/main/java/com/hatcher/haemo/common/BaseEntity.java @@ -16,7 +16,7 @@ @EntityListeners(AuditingEntityListener.class) public class BaseEntity { - @Column(columnDefinition = "varchar(10) default 'recruiting'") + @Column(columnDefinition = "varchar(10) default 'active'") @Setter private String status; From fc46ceaee8702d7270698d250c2e3292b99a2b84 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Thu, 21 Mar 2024 19:18:10 +0900 Subject: [PATCH 2/4] =?UTF-8?q?#15=20feat:=20=EB=AA=A8=EC=A7=91=EA=B8=80?= =?UTF-8?q?=20=EB=93=B1=EB=A1=9D=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haemo/common/constants/RequestURI.java | 1 + .../common/enums/BaseResponseStatus.java | 1 + .../application/RecruitmentService.java | 43 +++++++++++++++++++ .../dto/RecruitmentPostRequest.java | 7 +++ .../presentation/RecruitmentController.java | 32 ++++++++++++++ .../repository/RecruitmentRepository.java | 7 +++ 6 files changed, 91 insertions(+) create mode 100644 src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java create mode 100644 src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentPostRequest.java create mode 100644 src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java create mode 100644 src/main/java/com/hatcher/haemo/recruitment/repository/RecruitmentRepository.java diff --git a/src/main/java/com/hatcher/haemo/common/constants/RequestURI.java b/src/main/java/com/hatcher/haemo/common/constants/RequestURI.java index 85bdb83..a94d20a 100644 --- a/src/main/java/com/hatcher/haemo/common/constants/RequestURI.java +++ b/src/main/java/com/hatcher/haemo/common/constants/RequestURI.java @@ -2,4 +2,5 @@ public class RequestURI { public final static String user = "/users"; + public final static String recruitment = "/recruitments"; } diff --git a/src/main/java/com/hatcher/haemo/common/enums/BaseResponseStatus.java b/src/main/java/com/hatcher/haemo/common/enums/BaseResponseStatus.java index a4853b8..975aa3b 100644 --- a/src/main/java/com/hatcher/haemo/common/enums/BaseResponseStatus.java +++ b/src/main/java/com/hatcher/haemo/common/enums/BaseResponseStatus.java @@ -33,6 +33,7 @@ public enum BaseResponseStatus { DUPLICATED_LOGIN_ID(false, HttpStatus.CONFLICT, "중복된 로그인 아이디입니다."), // recruitment(2100-2199) + WRONG_RECRUIT_TYPE(false, HttpStatus.NOT_FOUND, "해당 Recruit type을 찾을 수 없습니다."), // comment(2200-2299) diff --git a/src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java b/src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java new file mode 100644 index 0000000..50ba942 --- /dev/null +++ b/src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java @@ -0,0 +1,43 @@ +package com.hatcher.haemo.recruitment.application; + +import com.hatcher.haemo.common.BaseException; +import com.hatcher.haemo.common.enums.RecruitType; +import com.hatcher.haemo.recruitment.domain.Recruitment; +import com.hatcher.haemo.recruitment.dto.RecruitmentPostRequest; +import com.hatcher.haemo.recruitment.repository.RecruitmentRepository; +import com.hatcher.haemo.user.application.UserService; +import com.hatcher.haemo.user.domain.User; +import com.hatcher.haemo.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static com.hatcher.haemo.common.constants.Constant.Recruitment.RECRUITING; +import static com.hatcher.haemo.common.enums.BaseResponseStatus.INTERNAL_SERVER_ERROR; +import static com.hatcher.haemo.common.enums.BaseResponseStatus.INVALID_USER_IDX; + +@Service +@RequiredArgsConstructor +public class RecruitmentService { + + private final UserService userService; + private final UserRepository userRepository; + private final RecruitmentRepository recruitmentRepository; + + // 모집글 등록 + @Transactional(rollbackFor = Exception.class) + public void postRecruitment(RecruitmentPostRequest recruitmentPostRequest) throws BaseException { + try { + User leader = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); + + Recruitment recruitment = new Recruitment(recruitmentPostRequest.name(), leader, RecruitType.getEnumByName(recruitmentPostRequest.type()), + recruitmentPostRequest.participantLimit(), recruitmentPostRequest.contactUrl(), recruitmentPostRequest.description()); + recruitment.setStatus(RECRUITING); + recruitmentRepository.save(recruitment); + } catch (BaseException e) { + throw e; + } catch (Exception e) { + throw new BaseException(INTERNAL_SERVER_ERROR); + } + } +} diff --git a/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentPostRequest.java b/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentPostRequest.java new file mode 100644 index 0000000..7409d38 --- /dev/null +++ b/src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentPostRequest.java @@ -0,0 +1,7 @@ +package com.hatcher.haemo.recruitment.dto; + +public record RecruitmentPostRequest(String name, + String type, + Integer participantLimit, + String contactUrl, + String description) {} diff --git a/src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java b/src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java new file mode 100644 index 0000000..2bc1346 --- /dev/null +++ b/src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java @@ -0,0 +1,32 @@ +package com.hatcher.haemo.recruitment.presentation; + +import com.hatcher.haemo.common.BaseException; +import com.hatcher.haemo.common.BaseResponse; +import com.hatcher.haemo.recruitment.application.RecruitmentService; +import com.hatcher.haemo.recruitment.dto.RecruitmentPostRequest; +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; + +import static com.hatcher.haemo.common.constants.RequestURI.recruitment; + +@RestController +@RequiredArgsConstructor +@RequestMapping(recruitment) +public class RecruitmentController { + + private final RecruitmentService recruitmentService; + + // 모집글 등록 + @PostMapping("") + public BaseResponse postRecruitment(@RequestBody RecruitmentPostRequest recruitmentPostRequest) { + try { + recruitmentService.postRecruitment(recruitmentPostRequest); + return BaseResponse.success(); + } catch (BaseException e) { + return BaseResponse.failure(e.getStatus()); + } + } +} diff --git a/src/main/java/com/hatcher/haemo/recruitment/repository/RecruitmentRepository.java b/src/main/java/com/hatcher/haemo/recruitment/repository/RecruitmentRepository.java new file mode 100644 index 0000000..e032f16 --- /dev/null +++ b/src/main/java/com/hatcher/haemo/recruitment/repository/RecruitmentRepository.java @@ -0,0 +1,7 @@ +package com.hatcher.haemo.recruitment.repository; + +import com.hatcher.haemo.recruitment.domain.Recruitment; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RecruitmentRepository extends JpaRepository { +} From 6890a8b40b298bc99d52bf3aeeeb6f931de11789 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Thu, 21 Mar 2024 19:21:26 +0900 Subject: [PATCH 3/4] =?UTF-8?q?#15=20feat:=20RecruitType=20enum=20?= =?UTF-8?q?=EA=B5=AC=EC=B2=B4=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haemo/common/enums/RecruitType.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hatcher/haemo/common/enums/RecruitType.java b/src/main/java/com/hatcher/haemo/common/enums/RecruitType.java index 76be97c..d716fc4 100644 --- a/src/main/java/com/hatcher/haemo/common/enums/RecruitType.java +++ b/src/main/java/com/hatcher/haemo/common/enums/RecruitType.java @@ -1,5 +1,27 @@ package com.hatcher.haemo.common.enums; +import com.hatcher.haemo.common.BaseException; + +import java.util.Arrays; + +import static com.hatcher.haemo.common.enums.BaseResponseStatus.WRONG_RECRUIT_TYPE; + public enum RecruitType { - EXHIBITION + RESTAURANT("맛집"), + CAFE("카페"), + MOVIE("영화"), + EXHIBITION("전시회"), + BOARD_GAME("보드게임"), + ESCAPE_GAME("방탈출"), + COIN_KARAOKE("코인노래방"), + DELIVERY_FOOD("배달음식"); + + RecruitType(String name) {} + + public static RecruitType getEnumByName(String name) throws BaseException { + return Arrays.stream(RecruitType.values()) + .filter(contents -> contents.name().equalsIgnoreCase(name)) + .findFirst() + .orElseThrow(() -> new BaseException(WRONG_RECRUIT_TYPE)); + } } From 76c0eaa90f440443568690af300e23e82f3dab21 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Thu, 21 Mar 2024 19:22:36 +0900 Subject: [PATCH 4/4] =?UTF-8?q?#5=20feat:=20validation=20check=EC=99=80=20?= =?UTF-8?q?=ED=95=A8=EA=BB=98=20userIdx=EB=A5=BC=20=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hatcher/haemo/user/application/UserService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/hatcher/haemo/user/application/UserService.java b/src/main/java/com/hatcher/haemo/user/application/UserService.java index 48e4c0a..4b9772f 100644 --- a/src/main/java/com/hatcher/haemo/user/application/UserService.java +++ b/src/main/java/com/hatcher/haemo/user/application/UserService.java @@ -71,4 +71,10 @@ public User getUserByUserIdx(Long userIdx) { return user.orElse(null); } } + + public Long getUserIdxWithValidation() throws BaseException { + Long userIdx = authService.getUserIdx(); + if (userIdx == null) throw new BaseException(NULL_ACCESS_TOKEN); + return userIdx; + } }