diff --git a/src/main/java/com/pickple/server/api/moim/controller/MoimController.java b/src/main/java/com/pickple/server/api/moim/controller/MoimController.java index 265e9eca..449ce771 100644 --- a/src/main/java/com/pickple/server/api/moim/controller/MoimController.java +++ b/src/main/java/com/pickple/server/api/moim/controller/MoimController.java @@ -1,15 +1,20 @@ package com.pickple.server.api.moim.controller; import com.pickple.server.api.moim.domain.enums.Category; +import com.pickple.server.api.moim.dto.request.MoimCreateRequest; import com.pickple.server.api.moim.dto.response.MoimDetailResponse; import com.pickple.server.api.moim.dto.response.SubmittedMoimResponse; +import com.pickple.server.api.moim.service.MoimCommandService; import com.pickple.server.api.moim.service.MoimQueryService; +import com.pickple.server.global.common.annotation.HostId; import com.pickple.server.global.response.ApiResponseDto; import com.pickple.server.global.response.enums.SuccessCode; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +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; @@ -19,6 +24,13 @@ public class MoimController { private final MoimQueryService moimQueryService; + private final MoimCommandService moimCommandService; + + @PostMapping("/v1/moim") + public ApiResponseDto createMoim(@HostId Long hostId, @RequestBody MoimCreateRequest moimCreateRequest) { + moimCommandService.createMoim(hostId, moimCreateRequest); + return ApiResponseDto.success(SuccessCode.MOIM_CREATE_SUCCESS); + } @GetMapping("/v1/moim/categories") public ApiResponseDto> getAllCategories() { diff --git a/src/main/java/com/pickple/server/api/moim/domain/ImageInfo.java b/src/main/java/com/pickple/server/api/moim/domain/ImageInfo.java index e5557662..75ab91f9 100644 --- a/src/main/java/com/pickple/server/api/moim/domain/ImageInfo.java +++ b/src/main/java/com/pickple/server/api/moim/domain/ImageInfo.java @@ -4,6 +4,7 @@ @Getter public class ImageInfo { + private String imageUrl1; private String imageUrl2; diff --git a/src/main/java/com/pickple/server/api/moim/domain/Moim.java b/src/main/java/com/pickple/server/api/moim/domain/Moim.java index a0fea9ae..87a26d16 100644 --- a/src/main/java/com/pickple/server/api/moim/domain/Moim.java +++ b/src/main/java/com/pickple/server/api/moim/domain/Moim.java @@ -2,6 +2,7 @@ import com.pickple.server.api.host.domain.Host; import com.pickple.server.api.moim.domain.enums.MoimState; +import com.pickple.server.api.moimsubmission.domain.AccountInfo; import com.pickple.server.api.moimsubmission.domain.MoimSubmission; import com.pickple.server.api.notice.domain.Notice; import com.pickple.server.global.common.domain.BaseTimeEntity; @@ -56,6 +57,9 @@ public class Moim extends BaseTimeEntity { private int fee; + @JdbcTypeCode(SqlTypes.JSON) + private AccountInfo accountList; + @JdbcTypeCode(SqlTypes.JSON) private QuestionInfo questionList; @@ -84,6 +88,7 @@ public Moim( final DateInfo dateList, final int maxGuest, final int fee, + final AccountInfo accountList, final QuestionInfo questionList, final String title, final String description, @@ -97,6 +102,7 @@ public Moim( this.dateList = dateList; this.maxGuest = maxGuest; this.fee = fee; + this.accountList = accountList; this.questionList = questionList; this.title = title; this.description = description; diff --git a/src/main/java/com/pickple/server/api/moim/dto/request/.gitkeep b/src/main/java/com/pickple/server/api/moim/dto/request/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/java/com/pickple/server/api/moim/dto/request/MoimCreateRequest.java b/src/main/java/com/pickple/server/api/moim/dto/request/MoimCreateRequest.java new file mode 100644 index 00000000..9393b65f --- /dev/null +++ b/src/main/java/com/pickple/server/api/moim/dto/request/MoimCreateRequest.java @@ -0,0 +1,22 @@ +package com.pickple.server.api.moim.dto.request; + +import com.pickple.server.api.moim.domain.CategoryInfo; +import com.pickple.server.api.moim.domain.DateInfo; +import com.pickple.server.api.moim.domain.ImageInfo; +import com.pickple.server.api.moim.domain.QuestionInfo; +import com.pickple.server.api.moimsubmission.domain.AccountInfo; + +public record MoimCreateRequest( + CategoryInfo categoryList, + boolean isOffline, + String spot, + DateInfo dateList, + int maxGuest, + int fee, + AccountInfo accountList, + QuestionInfo questionList, + String title, + String description, + ImageInfo imageList +) { +} diff --git a/src/main/java/com/pickple/server/api/moim/service/MoimCommandService.java b/src/main/java/com/pickple/server/api/moim/service/MoimCommandService.java new file mode 100644 index 00000000..fe1bdf54 --- /dev/null +++ b/src/main/java/com/pickple/server/api/moim/service/MoimCommandService.java @@ -0,0 +1,40 @@ +package com.pickple.server.api.moim.service; + +import com.pickple.server.api.host.domain.Host; +import com.pickple.server.api.host.repository.HostRepository; +import com.pickple.server.api.moim.domain.Moim; +import com.pickple.server.api.moim.domain.enums.MoimState; +import com.pickple.server.api.moim.dto.request.MoimCreateRequest; +import com.pickple.server.api.moim.repository.MoimRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class MoimCommandService { + + private final HostRepository hostRepository; + private final MoimRepository moimRepository; + + public void createMoim(Long hostId, MoimCreateRequest request) { + Host host = hostRepository.findHostByIdOrThrow(hostId); + Moim moim = Moim.builder() + .host(host) + .category(request.categoryList()) + .isOffline(request.isOffline()) + .spot(request.spot()) + .dateList(request.dateList()) + .maxGuest(request.maxGuest()) + .fee(request.fee()) + .accountList(request.accountList()) + .questionList(request.questionList()) + .title(request.title()) + .description(request.description()) + .imageList(request.imageList()) + .moimState(MoimState.ONGOING) + .build(); + moimRepository.save(moim); + } +} diff --git a/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java b/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java index 8ab79d8c..5251b585 100644 --- a/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java +++ b/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java @@ -19,9 +19,10 @@ public enum SuccessCode { HOST_DETAIL_GET_SUCCESS(20007, HttpStatus.OK, "호스트 정보 조회 성공"), MOIM_SUBMISSION_POST_SUCCESS(20007, HttpStatus.OK, "모임 참여 신청 성공"), PRESIGNED_URL_GET_SUCCESS(20008, HttpStatus.OK, "presigned url 발급 성공"), - SUBMITTED_MOIM_DETAIL_GET_SUCCESS(20008, HttpStatus.OK, "신청한 모임 상세 정보 조회 성공") - - ; + SUBMITTED_MOIM_DETAIL_GET_SUCCESS(20008, HttpStatus.OK, "신청한 모임 상세 정보 조회 성공"), + + //201 Created + MOIM_CREATE_SUCCESS(20100, HttpStatus.CREATED, "모임 개설 성공"); private final int code; private final HttpStatus httpStatus;