Skip to content

Commit

Permalink
Merge pull request #94 from MEME-UMC/add/#91
Browse files Browse the repository at this point in the history
[Add] 문의하기
  • Loading branch information
yeopyeop-82 authored Feb 3, 2024
2 parents a47744c + be96dc3 commit 9a108e9
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
36 changes: 36 additions & 0 deletions src/main/java/umc/meme/shop/domain/mypage/entity/Inquiry.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Inquiry, Long> {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -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);
}

}
3 changes: 2 additions & 1 deletion src/main/java/umc/meme/shop/global/ErrorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/umc/meme/shop/global/SuccessStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9a108e9

Please sign in to comment.