-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from goormthon-Univ/feature/15-postRecruitment
[feature/15-postRecruitment] 모집글 등록 API
- Loading branch information
Showing
9 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
src/main/java/com/hatcher/haemo/common/enums/RecruitType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/hatcher/haemo/recruitment/application/RecruitmentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/hatcher/haemo/recruitment/dto/RecruitmentPostRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hatcher.haemo.recruitment.dto; | ||
|
||
public record RecruitmentPostRequest(String name, | ||
String type, | ||
Integer participantLimit, | ||
String contactUrl, | ||
String description) {} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/hatcher/haemo/recruitment/presentation/RecruitmentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/hatcher/haemo/recruitment/repository/RecruitmentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Recruitment, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters