diff --git a/src/main/java/umc/meme/shop/domain/mypage/controller/MyPageController.java b/src/main/java/umc/meme/shop/domain/mypage/controller/MyPageController.java index 5ddaead..79007df 100644 --- a/src/main/java/umc/meme/shop/domain/mypage/controller/MyPageController.java +++ b/src/main/java/umc/meme/shop/domain/mypage/controller/MyPageController.java @@ -3,7 +3,9 @@ import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import umc.meme.shop.domain.mypage.dto.request.MypageInquiryDto; import umc.meme.shop.domain.mypage.service.MypageService; +import umc.meme.shop.domain.portfolio.dto.request.CreatePortfolioDto; import umc.meme.shop.global.SuccessStatus; import umc.meme.shop.global.response.ApiResponse; @@ -28,7 +30,14 @@ public ApiResponse tos(){ @Operation(summary = "문의하기", description = "문의하기 API입니다.") @PostMapping("/contact") - public ApiResponse contact(){ - return ApiResponse.SuccessResponse(SuccessStatus.CONTACT_CREATE, ""); + public ApiResponse contact(@RequestBody MypageInquiryDto mypageInquiryDto){ + mypageService.createInquiry(mypageInquiryDto); + return ApiResponse.SuccessResponse(SuccessStatus.CONTACT_CREATE); + } + + @Operation(summary = "문의 조회하기", description = "문의 조회하기 API입니다.") + @GetMapping("/contact/{userId}") + public ApiResponse contact(@PathVariable Long userId){ + return ApiResponse.SuccessResponse(SuccessStatus.CONTACT_GET, mypageService.getInquiry(userId)); } } diff --git a/src/main/java/umc/meme/shop/domain/mypage/dto/request/MypageInquiryDto.java b/src/main/java/umc/meme/shop/domain/mypage/dto/request/MypageInquiryDto.java new file mode 100644 index 0000000..ca182bf --- /dev/null +++ b/src/main/java/umc/meme/shop/domain/mypage/dto/request/MypageInquiryDto.java @@ -0,0 +1,24 @@ +package umc.meme.shop.domain.mypage.dto.request; + + +import lombok.*; +import umc.meme.shop.domain.mypage.entity.Inquiry; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MypageInquiryDto { + private Long inquiryId; + private Long userId; + private String inquiryTitle; + private String inquiryText; + + public static MypageInquiryDto from(Inquiry inquiry) { + return MypageInquiryDto.builder() + .inquiryId(inquiry.getInquiryId()) + .inquiryTitle(inquiry.getInquiryTitle()) + .inquiryText(inquiry.getInquiryText()) + .build(); + } +} diff --git a/src/main/java/umc/meme/shop/domain/mypage/entity/Inquiry.java b/src/main/java/umc/meme/shop/domain/mypage/entity/Inquiry.java new file mode 100644 index 0000000..32b7bdf --- /dev/null +++ b/src/main/java/umc/meme/shop/domain/mypage/entity/Inquiry.java @@ -0,0 +1,36 @@ +package umc.meme.shop.domain.mypage.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import umc.meme.shop.domain.mypage.dto.request.MypageInquiryDto; + +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Entity +public class Inquiry { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "inquiry_id") + private Long inquiryId; + + @Column(nullable = false) + private String inquiryTitle; + + @Column(nullable = false) + private String inquiryText; + + + public void updateInquiry(MypageInquiryDto request) { + if (request.getInquiryTitle() != null) { + this.inquiryTitle = request.getInquiryTitle(); + } + if (request.getInquiryText() != null) { + this.inquiryText = request.getInquiryText(); + } + } +} diff --git a/src/main/java/umc/meme/shop/domain/mypage/repository/InquiryRepository.java b/src/main/java/umc/meme/shop/domain/mypage/repository/InquiryRepository.java new file mode 100644 index 0000000..6005b4c --- /dev/null +++ b/src/main/java/umc/meme/shop/domain/mypage/repository/InquiryRepository.java @@ -0,0 +1,7 @@ +package umc.meme.shop.domain.mypage.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import umc.meme.shop.domain.mypage.entity.Inquiry; + +public interface InquiryRepository extends JpaRepository { +} diff --git a/src/main/java/umc/meme/shop/domain/mypage/service/MypageService.java b/src/main/java/umc/meme/shop/domain/mypage/service/MypageService.java index 3667bb0..fadca17 100644 --- a/src/main/java/umc/meme/shop/domain/mypage/service/MypageService.java +++ b/src/main/java/umc/meme/shop/domain/mypage/service/MypageService.java @@ -1,8 +1,18 @@ package umc.meme.shop.domain.mypage.service; +import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import umc.meme.shop.domain.artist.entity.Artist; +import umc.meme.shop.domain.artist.repository.ArtistRepository; +import umc.meme.shop.domain.model.entity.Model; +import umc.meme.shop.domain.model.repository.ModelRepository; +import umc.meme.shop.domain.mypage.dto.request.MypageInquiryDto; +import umc.meme.shop.domain.mypage.dto.response.MypageDetailDto; +import umc.meme.shop.domain.mypage.dto.response.MypageTosDto; +import umc.meme.shop.domain.mypage.entity.Inquiry; +import umc.meme.shop.domain.mypage.repository.InquiryRepository; import umc.meme.shop.domain.mypage.dto.response.MypageDetailDto; import umc.meme.shop.domain.mypage.dto.response.MypageTosDto; import umc.meme.shop.domain.user.User; @@ -14,8 +24,10 @@ @RequiredArgsConstructor public class MypageService { + private final ModelRepository modelRepository; + private final ArtistRepository artistRepository; + private final InquiryRepository inquiryRepository; private final UserRepository userRepository; - @Transactional public MypageDetailDto getProfile(Long userId) { User user = userRepository.findById(userId) @@ -36,4 +48,22 @@ public MypageTosDto getTos() { .tos("Example") .build(); } + + //문의하기 + @Transactional + public void createInquiry(MypageInquiryDto mypageInquiryDto) { + Inquiry inquiry = new Inquiry(); + inquiry.updateInquiry(mypageInquiryDto); + inquiryRepository.save(inquiry); + } + + // 문의하기 조회 + @Transactional + public MypageInquiryDto getInquiry(Long inquiryId) { + Inquiry inquiry = inquiryRepository.findById(inquiryId) + .orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_INQUIRY)); + + return MypageInquiryDto.from(inquiry); + } + } diff --git a/src/main/java/umc/meme/shop/global/ErrorStatus.java b/src/main/java/umc/meme/shop/global/ErrorStatus.java index 48ce7a3..34f0019 100644 --- a/src/main/java/umc/meme/shop/global/ErrorStatus.java +++ b/src/main/java/umc/meme/shop/global/ErrorStatus.java @@ -67,8 +67,9 @@ public enum ErrorStatus { NOT_EXIST_FAVORITE_ARTIST(404, "존재하지 않는 관심 아티스트입니다."), NOT_EXIST_FAVORITE_PORTFOLIO(404, "존재하지 않는 관심 메이크업입니다."), NOT_EXIST_REVIEW(404, "존재하지 않는 리뷰입니다."), + NOT_EXIST_INQUIRY(404, "존재하지 않는 문의입니다."), SEARCH_NOT_FOUNT(404, "검색 결과가 존재하지 않습니다."), - PAGE_NOT_FOUND(404,"페이지를 찾을 수 없습니다"), ; + PAGE_NOT_FOUND(404,"페이지를 찾을 수 없습니다"); private final int code; diff --git a/src/main/java/umc/meme/shop/global/SuccessStatus.java b/src/main/java/umc/meme/shop/global/SuccessStatus.java index 506331e..266dc81 100644 --- a/src/main/java/umc/meme/shop/global/SuccessStatus.java +++ b/src/main/java/umc/meme/shop/global/SuccessStatus.java @@ -46,7 +46,8 @@ public enum SuccessStatus { MYPAGE_GET(200, "마이페이지 조회가 완료되었습니다"), DETAILS_GET(200, "내 정보 조회가 완료되었습니다"), TOS_GET(200, "약관 및 정책 조회가 완료되었습니다"), - CONTACT_CREATE(200, "문의 작성이 완료되었습니다"); + CONTACT_CREATE(200, "문의 작성이 완료되었습니다"), + CONTACT_GET(200, "문의 조회가 완료되었습니다."); private final int code;