Skip to content

Commit

Permalink
[feat] 모임 개설 API 구현
Browse files Browse the repository at this point in the history
[feat] 모임 개설 API 구현
  • Loading branch information
lreowy authored Jul 11, 2024
2 parents 1e3f29d + edd27cb commit 5df51a8
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<List<String>> getAllCategories() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@Getter
public class ImageInfo {

private String imageUrl1;

private String imageUrl2;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/pickple/server/api/moim/domain/Moim.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,9 @@ public class Moim extends BaseTimeEntity {

private int fee;

@JdbcTypeCode(SqlTypes.JSON)
private AccountInfo accountList;

@JdbcTypeCode(SqlTypes.JSON)
private QuestionInfo questionList;

Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5df51a8

Please sign in to comment.