diff --git a/src/main/java/com/fullcar/carpool/application/CarpoolMapper.java b/src/main/java/com/fullcar/carpool/application/carpool/CarpoolMapper.java similarity index 89% rename from src/main/java/com/fullcar/carpool/application/CarpoolMapper.java rename to src/main/java/com/fullcar/carpool/application/carpool/CarpoolMapper.java index 7cea456..59e48eb 100644 --- a/src/main/java/com/fullcar/carpool/application/CarpoolMapper.java +++ b/src/main/java/com/fullcar/carpool/application/carpool/CarpoolMapper.java @@ -1,11 +1,11 @@ -package com.fullcar.carpool.application; +package com.fullcar.carpool.application.carpool; -import com.fullcar.carpool.domain.Carpool; -import com.fullcar.carpool.domain.Cost; -import com.fullcar.carpool.domain.Driver; +import com.fullcar.carpool.domain.carpool.Carpool; +import com.fullcar.carpool.domain.carpool.Cost; +import com.fullcar.carpool.domain.carpool.Driver; import com.fullcar.carpool.domain.service.CarpoolIdService; -import com.fullcar.carpool.presentation.dto.request.CarpoolRequestDto; -import com.fullcar.carpool.presentation.dto.response.CarpoolResponseDto; +import com.fullcar.carpool.presentation.carpool.dto.request.CarpoolRequestDto; +import com.fullcar.carpool.presentation.carpool.dto.response.CarpoolResponseDto; import com.fullcar.member.domain.car.Car; import com.fullcar.member.domain.member.Member; diff --git a/src/main/java/com/fullcar/carpool/application/CarpoolService.java b/src/main/java/com/fullcar/carpool/application/carpool/CarpoolService.java similarity index 83% rename from src/main/java/com/fullcar/carpool/application/CarpoolService.java rename to src/main/java/com/fullcar/carpool/application/carpool/CarpoolService.java index 44fb8bc..708b308 100644 --- a/src/main/java/com/fullcar/carpool/application/CarpoolService.java +++ b/src/main/java/com/fullcar/carpool/application/carpool/CarpoolService.java @@ -1,10 +1,10 @@ -package com.fullcar.carpool.application; +package com.fullcar.carpool.application.carpool; -import com.fullcar.carpool.domain.Carpool; -import com.fullcar.carpool.domain.CarpoolId; -import com.fullcar.carpool.domain.CarpoolRepository; -import com.fullcar.carpool.presentation.dto.request.CarpoolRequestDto; -import com.fullcar.carpool.presentation.dto.response.CarpoolResponseDto; +import com.fullcar.carpool.domain.carpool.Carpool; +import com.fullcar.carpool.domain.carpool.CarpoolId; +import com.fullcar.carpool.domain.carpool.CarpoolRepository; +import com.fullcar.carpool.presentation.carpool.dto.request.CarpoolRequestDto; +import com.fullcar.carpool.presentation.carpool.dto.response.CarpoolResponseDto; import com.fullcar.core.exception.CustomException; import com.fullcar.core.response.ErrorCode; import com.fullcar.member.domain.car.Car; @@ -26,7 +26,7 @@ @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class CarpoolService { private final CarpoolRepository carpoolRepository; - private final CarRepository carRepository; + private final CarRepository carRepository; //:TODO Event 기반으로 변경 private final CarpoolMapper carpoolMapper; @Transactional diff --git a/src/main/java/com/fullcar/carpool/application/form/FormMapper.java b/src/main/java/com/fullcar/carpool/application/form/FormMapper.java new file mode 100644 index 0000000..adbbba5 --- /dev/null +++ b/src/main/java/com/fullcar/carpool/application/form/FormMapper.java @@ -0,0 +1,53 @@ +package com.fullcar.carpool.application.form; + +import com.fullcar.carpool.domain.carpool.CarpoolId; +import com.fullcar.carpool.domain.form.Cost; +import com.fullcar.carpool.domain.form.Form; +import com.fullcar.carpool.domain.form.Passenger; +import com.fullcar.carpool.domain.service.FormIdService; +import com.fullcar.carpool.presentation.form.dto.request.FormRequestDto; +import com.fullcar.carpool.presentation.form.dto.response.FormResponseDto; +import com.fullcar.member.domain.member.Member; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +public class FormMapper { + private final FormIdService formIdService; + + public FormResponseDto toDto(Form form, Member member) { + return FormResponseDto.builder() + .id(form.getFormId().getId()) + .pickupLocation(form.getPickupLocation()) + .periodType(form.getCost().getPeriodType()) + .money(form.getCost().getMoney()) + .content(form.getContent()) + .formState(form.getFormState()) + .companyName(member.getCompany().getCompanyName()) + .nickname(member.getNickname()) + .createdAt(form.getCreatedAt()) + .build(); + } + + public Form toEntity(Member member, CarpoolId carpoolId, FormRequestDto formRequestDto) { + return Form.builder() + .formId(formIdService.nextId()) + .content(formRequestDto.getContent()) + .pickupLocation(formRequestDto.getPickupLocation()) + .cost( + Cost.builder() + .periodType(formRequestDto.getPeriodType()) + .money(formRequestDto.getMoney()) + .build() + ) + .passenger( + Passenger.builder() + .memberId(member.getId()) + .build() + ) + .carpoolId(carpoolId) + .build(); + } +} diff --git a/src/main/java/com/fullcar/carpool/application/form/FormService.java b/src/main/java/com/fullcar/carpool/application/form/FormService.java new file mode 100644 index 0000000..9ca0621 --- /dev/null +++ b/src/main/java/com/fullcar/carpool/application/form/FormService.java @@ -0,0 +1,40 @@ +package com.fullcar.carpool.application.form; + +import com.fullcar.carpool.domain.carpool.Carpool; +import com.fullcar.carpool.domain.carpool.CarpoolId; +import com.fullcar.carpool.domain.carpool.CarpoolRepository; +import com.fullcar.carpool.domain.form.Form; +import com.fullcar.carpool.domain.form.FormRepository; +import com.fullcar.carpool.presentation.form.dto.request.FormRequestDto; +import com.fullcar.carpool.presentation.form.dto.response.FormResponseDto; +import com.fullcar.core.exception.CustomException; +import com.fullcar.core.response.ErrorCode; +import com.fullcar.member.domain.member.Member; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +@Validated +@Service +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +public class FormService { + private final FormRepository formRepository; + private final CarpoolRepository carpoolRepository; + private final FormMapper formMapper; + + @Transactional + public FormResponseDto requestForm(Member member, CarpoolId carpoolId, FormRequestDto formRequestDto) { + Carpool carpool = carpoolRepository.findByCarpoolIdAndIsDeleted(carpoolId, false) + .orElseThrow(() -> new CustomException(ErrorCode.NOT_EXIST_CARPOOL)); + + Form form = formMapper.toEntity(member, carpoolId, formRequestDto); + + return formMapper.toDto( + formRepository.saveAndFlush(form), + member + ); + } + +} diff --git a/src/main/java/com/fullcar/carpool/domain/Carpool.java b/src/main/java/com/fullcar/carpool/domain/carpool/Carpool.java similarity index 96% rename from src/main/java/com/fullcar/carpool/domain/Carpool.java rename to src/main/java/com/fullcar/carpool/domain/carpool/Carpool.java index d0fc364..4f26d7f 100644 --- a/src/main/java/com/fullcar/carpool/domain/Carpool.java +++ b/src/main/java/com/fullcar/carpool/domain/carpool/Carpool.java @@ -1,4 +1,4 @@ -package com.fullcar.carpool.domain; +package com.fullcar.carpool.domain.carpool; import jakarta.persistence.*; import lombok.*; diff --git a/src/main/java/com/fullcar/carpool/domain/CarpoolId.java b/src/main/java/com/fullcar/carpool/domain/carpool/CarpoolId.java similarity index 90% rename from src/main/java/com/fullcar/carpool/domain/CarpoolId.java rename to src/main/java/com/fullcar/carpool/domain/carpool/CarpoolId.java index 59d9960..0b8903c 100644 --- a/src/main/java/com/fullcar/carpool/domain/CarpoolId.java +++ b/src/main/java/com/fullcar/carpool/domain/carpool/CarpoolId.java @@ -1,4 +1,4 @@ -package com.fullcar.carpool.domain; +package com.fullcar.carpool.domain.carpool; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; diff --git a/src/main/java/com/fullcar/carpool/domain/CarpoolRepository.java b/src/main/java/com/fullcar/carpool/domain/carpool/CarpoolRepository.java similarity index 89% rename from src/main/java/com/fullcar/carpool/domain/CarpoolRepository.java rename to src/main/java/com/fullcar/carpool/domain/carpool/CarpoolRepository.java index 4cd733e..933bd25 100644 --- a/src/main/java/com/fullcar/carpool/domain/CarpoolRepository.java +++ b/src/main/java/com/fullcar/carpool/domain/carpool/CarpoolRepository.java @@ -1,11 +1,10 @@ -package com.fullcar.carpool.domain; +package com.fullcar.carpool.domain.carpool; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; import java.util.Optional; @Repository diff --git a/src/main/java/com/fullcar/carpool/domain/CarpoolState.java b/src/main/java/com/fullcar/carpool/domain/carpool/CarpoolState.java similarity index 53% rename from src/main/java/com/fullcar/carpool/domain/CarpoolState.java rename to src/main/java/com/fullcar/carpool/domain/carpool/CarpoolState.java index 8901d99..652d28e 100644 --- a/src/main/java/com/fullcar/carpool/domain/CarpoolState.java +++ b/src/main/java/com/fullcar/carpool/domain/carpool/CarpoolState.java @@ -1,4 +1,4 @@ -package com.fullcar.carpool.domain; +package com.fullcar.carpool.domain.carpool; public enum CarpoolState { OPEN, diff --git a/src/main/java/com/fullcar/carpool/domain/Cost.java b/src/main/java/com/fullcar/carpool/domain/carpool/Cost.java similarity index 92% rename from src/main/java/com/fullcar/carpool/domain/Cost.java rename to src/main/java/com/fullcar/carpool/domain/carpool/Cost.java index 97f985c..f625610 100644 --- a/src/main/java/com/fullcar/carpool/domain/Cost.java +++ b/src/main/java/com/fullcar/carpool/domain/carpool/Cost.java @@ -1,4 +1,4 @@ -package com.fullcar.carpool.domain; +package com.fullcar.carpool.domain.carpool; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; diff --git a/src/main/java/com/fullcar/carpool/domain/Driver.java b/src/main/java/com/fullcar/carpool/domain/carpool/Driver.java similarity index 92% rename from src/main/java/com/fullcar/carpool/domain/Driver.java rename to src/main/java/com/fullcar/carpool/domain/carpool/Driver.java index f18a224..4a357f5 100644 --- a/src/main/java/com/fullcar/carpool/domain/Driver.java +++ b/src/main/java/com/fullcar/carpool/domain/carpool/Driver.java @@ -1,4 +1,4 @@ -package com.fullcar.carpool.domain; +package com.fullcar.carpool.domain.carpool; import com.fullcar.member.domain.member.MemberId; import jakarta.persistence.*; diff --git a/src/main/java/com/fullcar/carpool/domain/MoodType.java b/src/main/java/com/fullcar/carpool/domain/carpool/MoodType.java similarity index 52% rename from src/main/java/com/fullcar/carpool/domain/MoodType.java rename to src/main/java/com/fullcar/carpool/domain/carpool/MoodType.java index cbe55ff..1fcc89f 100644 --- a/src/main/java/com/fullcar/carpool/domain/MoodType.java +++ b/src/main/java/com/fullcar/carpool/domain/carpool/MoodType.java @@ -1,4 +1,4 @@ -package com.fullcar.carpool.domain; +package com.fullcar.carpool.domain.carpool; public enum MoodType { CHATTY, diff --git a/src/main/java/com/fullcar/carpool/domain/PeriodType.java b/src/main/java/com/fullcar/carpool/domain/carpool/PeriodType.java similarity index 68% rename from src/main/java/com/fullcar/carpool/domain/PeriodType.java rename to src/main/java/com/fullcar/carpool/domain/carpool/PeriodType.java index 190a6c9..3caa46a 100644 --- a/src/main/java/com/fullcar/carpool/domain/PeriodType.java +++ b/src/main/java/com/fullcar/carpool/domain/carpool/PeriodType.java @@ -1,4 +1,4 @@ -package com.fullcar.carpool.domain; +package com.fullcar.carpool.domain.carpool; public enum PeriodType { ONCE, diff --git a/src/main/java/com/fullcar/carpool/domain/form/Cost.java b/src/main/java/com/fullcar/carpool/domain/form/Cost.java new file mode 100644 index 0000000..f2b3ba8 --- /dev/null +++ b/src/main/java/com/fullcar/carpool/domain/form/Cost.java @@ -0,0 +1,26 @@ +package com.fullcar.carpool.domain.form; + +import com.fullcar.carpool.domain.carpool.PeriodType; +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import static lombok.AccessLevel.PROTECTED; + +@Embeddable +@Getter +@Builder +@NoArgsConstructor(access = PROTECTED) +@AllArgsConstructor(access = PROTECTED) +public class Cost { + private Long money; + + @Enumerated(EnumType.STRING) + @Column(name = "period_type") + private PeriodType periodType; +} diff --git a/src/main/java/com/fullcar/carpool/domain/form/Form.java b/src/main/java/com/fullcar/carpool/domain/form/Form.java new file mode 100644 index 0000000..b1c52fd --- /dev/null +++ b/src/main/java/com/fullcar/carpool/domain/form/Form.java @@ -0,0 +1,55 @@ +package com.fullcar.carpool.domain.form; + +import com.fullcar.carpool.domain.carpool.CarpoolId; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@EntityListeners(AuditingEntityListener.class) +@Table(name = "form") +public class Form { + + @EmbeddedId + private FormId formId; + + private String content; + + @Column(name = "pickup_location") + private String pickupLocation; + + @Embedded + private Cost cost; + + @Enumerated(EnumType.STRING) + @Column(name = "form_state") + @Builder.Default + private FormState formState = FormState.REQUEST; + + @Embedded + private Passenger passenger; + + @Embedded + @AttributeOverride(name = "id", column = @Column(name = "carpool_id")) + private CarpoolId carpoolId; + + @Column(name = "is_deleted", nullable = false) + @Builder.Default + private boolean isDeleted = false; + + @Column(name = "created_at") + @CreatedDate + private LocalDateTime createdAt; + + @Column(name = "updated_at") + @LastModifiedDate + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/fullcar/carpool/domain/form/FormId.java b/src/main/java/com/fullcar/carpool/domain/form/FormId.java new file mode 100644 index 0000000..fe3e73d --- /dev/null +++ b/src/main/java/com/fullcar/carpool/domain/form/FormId.java @@ -0,0 +1,21 @@ +package com.fullcar.carpool.domain.form; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +import static lombok.AccessLevel.PROTECTED; + +@Embeddable +@Getter +@NoArgsConstructor(access = PROTECTED) +@AllArgsConstructor +public class FormId implements Serializable { + + @Column(name = "id") + private Long id; +} diff --git a/src/main/java/com/fullcar/carpool/domain/form/FormRepository.java b/src/main/java/com/fullcar/carpool/domain/form/FormRepository.java new file mode 100644 index 0000000..2a7ad6c --- /dev/null +++ b/src/main/java/com/fullcar/carpool/domain/form/FormRepository.java @@ -0,0 +1,8 @@ +package com.fullcar.carpool.domain.form; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface FormRepository extends JpaRepository { +} diff --git a/src/main/java/com/fullcar/carpool/domain/form/FormState.java b/src/main/java/com/fullcar/carpool/domain/form/FormState.java new file mode 100644 index 0000000..6888056 --- /dev/null +++ b/src/main/java/com/fullcar/carpool/domain/form/FormState.java @@ -0,0 +1,7 @@ +package com.fullcar.carpool.domain.form; + +public enum FormState { + REQUEST, + ACCEPT, + REJECT +} diff --git a/src/main/java/com/fullcar/carpool/domain/form/Passenger.java b/src/main/java/com/fullcar/carpool/domain/form/Passenger.java new file mode 100644 index 0000000..8e5e407 --- /dev/null +++ b/src/main/java/com/fullcar/carpool/domain/form/Passenger.java @@ -0,0 +1,16 @@ +package com.fullcar.carpool.domain.form; + +import com.fullcar.member.domain.member.MemberId; +import jakarta.persistence.*; +import lombok.*; + +@Embeddable +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +public class Passenger { + @Embedded + @AttributeOverride(name = "id", column = @Column(name = "passenger_id")) + private MemberId memberId; +} diff --git a/src/main/java/com/fullcar/carpool/domain/service/CarpoolIdService.java b/src/main/java/com/fullcar/carpool/domain/service/CarpoolIdService.java index 2ccaa0d..c8a9217 100644 --- a/src/main/java/com/fullcar/carpool/domain/service/CarpoolIdService.java +++ b/src/main/java/com/fullcar/carpool/domain/service/CarpoolIdService.java @@ -1,6 +1,6 @@ package com.fullcar.carpool.domain.service; -import com.fullcar.carpool.domain.CarpoolId; +import com.fullcar.carpool.domain.carpool.CarpoolId; import com.fullcar.core.id.SnowFlake; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/fullcar/carpool/domain/service/FormIdService.java b/src/main/java/com/fullcar/carpool/domain/service/FormIdService.java new file mode 100644 index 0000000..be38b88 --- /dev/null +++ b/src/main/java/com/fullcar/carpool/domain/service/FormIdService.java @@ -0,0 +1,17 @@ +package com.fullcar.carpool.domain.service; + +import com.fullcar.carpool.domain.form.FormId; +import com.fullcar.core.id.SnowFlake; +import org.springframework.stereotype.Service; + +@Service +public class FormIdService { + private final SnowFlake snowFlake; + + public FormIdService() { + snowFlake = new SnowFlake(255); + } + public FormId nextId() { + return new FormId(snowFlake.nextId()); + } +} diff --git a/src/main/java/com/fullcar/carpool/presentation/CarpoolController.java b/src/main/java/com/fullcar/carpool/presentation/carpool/CarpoolController.java similarity index 89% rename from src/main/java/com/fullcar/carpool/presentation/CarpoolController.java rename to src/main/java/com/fullcar/carpool/presentation/carpool/CarpoolController.java index b272389..cb6d5f5 100644 --- a/src/main/java/com/fullcar/carpool/presentation/CarpoolController.java +++ b/src/main/java/com/fullcar/carpool/presentation/carpool/CarpoolController.java @@ -1,9 +1,9 @@ -package com.fullcar.carpool.presentation; +package com.fullcar.carpool.presentation.carpool; -import com.fullcar.carpool.application.CarpoolService; -import com.fullcar.carpool.domain.CarpoolId; -import com.fullcar.carpool.presentation.dto.request.CarpoolRequestDto; -import com.fullcar.carpool.presentation.dto.response.CarpoolResponseDto; +import com.fullcar.carpool.application.carpool.CarpoolService; +import com.fullcar.carpool.domain.carpool.CarpoolId; +import com.fullcar.carpool.presentation.carpool.dto.request.CarpoolRequestDto; +import com.fullcar.carpool.presentation.carpool.dto.response.CarpoolResponseDto; import com.fullcar.core.annotation.CurrentMember; import com.fullcar.core.response.ApiResponse; import com.fullcar.core.response.SuccessCode; diff --git a/src/main/java/com/fullcar/carpool/presentation/dto/request/CarpoolRequestDto.java b/src/main/java/com/fullcar/carpool/presentation/carpool/dto/request/CarpoolRequestDto.java similarity index 75% rename from src/main/java/com/fullcar/carpool/presentation/dto/request/CarpoolRequestDto.java rename to src/main/java/com/fullcar/carpool/presentation/carpool/dto/request/CarpoolRequestDto.java index 6d0e052..1c58097 100644 --- a/src/main/java/com/fullcar/carpool/presentation/dto/request/CarpoolRequestDto.java +++ b/src/main/java/com/fullcar/carpool/presentation/carpool/dto/request/CarpoolRequestDto.java @@ -1,12 +1,9 @@ -package com.fullcar.carpool.presentation.dto.request; +package com.fullcar.carpool.presentation.carpool.dto.request; -import com.fullcar.carpool.domain.MoodType; -import com.fullcar.carpool.domain.PeriodType; +import com.fullcar.carpool.domain.carpool.MoodType; +import com.fullcar.carpool.domain.carpool.PeriodType; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; -import lombok.experimental.SuperBuilder; - -import java.time.LocalDateTime; @Getter diff --git a/src/main/java/com/fullcar/carpool/presentation/dto/response/CarpoolResponseDto.java b/src/main/java/com/fullcar/carpool/presentation/carpool/dto/response/CarpoolResponseDto.java similarity index 89% rename from src/main/java/com/fullcar/carpool/presentation/dto/response/CarpoolResponseDto.java rename to src/main/java/com/fullcar/carpool/presentation/carpool/dto/response/CarpoolResponseDto.java index 9c3c8dc..c679f95 100644 --- a/src/main/java/com/fullcar/carpool/presentation/dto/response/CarpoolResponseDto.java +++ b/src/main/java/com/fullcar/carpool/presentation/carpool/dto/response/CarpoolResponseDto.java @@ -1,8 +1,8 @@ -package com.fullcar.carpool.presentation.dto.response; +package com.fullcar.carpool.presentation.carpool.dto.response; -import com.fullcar.carpool.domain.CarpoolState; -import com.fullcar.carpool.domain.MoodType; -import com.fullcar.carpool.domain.PeriodType; +import com.fullcar.carpool.domain.carpool.CarpoolState; +import com.fullcar.carpool.domain.carpool.MoodType; +import com.fullcar.carpool.domain.carpool.PeriodType; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/fullcar/carpool/presentation/form/FormController.java b/src/main/java/com/fullcar/carpool/presentation/form/FormController.java new file mode 100644 index 0000000..21c51de --- /dev/null +++ b/src/main/java/com/fullcar/carpool/presentation/form/FormController.java @@ -0,0 +1,48 @@ +package com.fullcar.carpool.presentation.form; + +import com.fullcar.carpool.application.form.FormService; +import com.fullcar.carpool.domain.carpool.CarpoolId; +import com.fullcar.carpool.presentation.form.dto.request.FormRequestDto; +import com.fullcar.carpool.presentation.form.dto.response.FormResponseDto; +import com.fullcar.core.annotation.CurrentMember; +import com.fullcar.core.response.ApiResponse; +import com.fullcar.core.response.SuccessCode; +import com.fullcar.member.domain.member.Member; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "[Form] 신청서 관련 API") +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/carpools/{carpoolId}/forms") +public class FormController { + private final FormService formService; + + @Operation(summary = "신청서 등록 API") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "201", description = "등록 성공") + }) + @PostMapping("") + public ApiResponse postForm( + @Parameter(hidden = true) + @CurrentMember Member member, + @Parameter(description = "카풀 id", required = true) + @PathVariable Long carpoolId, + @Parameter(description = "신청서 요청모델", required = true) + @RequestBody @Valid FormRequestDto formRequestDto + ) { + return ApiResponse.success( + SuccessCode.REGISTER_SUCCESS, + formService.requestForm( + member, + new CarpoolId(carpoolId), + formRequestDto + ) + ); + } +} diff --git a/src/main/java/com/fullcar/carpool/presentation/form/dto/request/FormRequestDto.java b/src/main/java/com/fullcar/carpool/presentation/form/dto/request/FormRequestDto.java new file mode 100644 index 0000000..30f8967 --- /dev/null +++ b/src/main/java/com/fullcar/carpool/presentation/form/dto/request/FormRequestDto.java @@ -0,0 +1,25 @@ +package com.fullcar.carpool.presentation.form.dto.request; + +import com.fullcar.carpool.domain.carpool.PeriodType; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Schema(description = "신청서 요청모델") +public class FormRequestDto { + + @Schema(description = "픽업장소") + private String pickupLocation; + + @Schema(description = "희망비용(기간)") + private PeriodType periodType; + + @Schema(description = "희망비용(가격)") + private Long money; + + @Schema(description = "운전자에게 전할 말") + private String content; +} diff --git a/src/main/java/com/fullcar/carpool/presentation/form/dto/response/FormResponseDto.java b/src/main/java/com/fullcar/carpool/presentation/form/dto/response/FormResponseDto.java new file mode 100644 index 0000000..fba05a0 --- /dev/null +++ b/src/main/java/com/fullcar/carpool/presentation/form/dto/response/FormResponseDto.java @@ -0,0 +1,46 @@ +package com.fullcar.carpool.presentation.form.dto.response; + +import com.fullcar.carpool.domain.carpool.PeriodType; +import com.fullcar.carpool.domain.form.FormState; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.time.LocalDateTime; + +@Getter +@SuperBuilder +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Schema(description = "신청서 응답 모델") +public class FormResponseDto { + @Schema(description = "신청서 id") + private Long id; + + @Schema(description = "픽업장소") + private String pickupLocation; + + @Schema(description = "희망비용(기간)") + private PeriodType periodType; + + @Schema(description = "희망비용(가격)") + private Long money; + + @Schema(description = "운전자에게 전할 말") + private String content; + + @Schema(description = "신청서 상태") + private FormState formState; + + @Schema(description = "회사명") + private String companyName; + + @Schema(description = "닉네임") + private String nickname; + + @Schema(description = "생성 Timestamp") + private LocalDateTime createdAt; +}