Skip to content

Commit

Permalink
Merge pull request #96 from MEME-UMC/add/#91-1
Browse files Browse the repository at this point in the history
add : 문의하기 완료
  • Loading branch information
yeopyeop-82 authored Feb 3, 2024
2 parents ff7c445 + daea910 commit 19e5cfd
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ApiResponse contact(@RequestBody MypageInquiryDto mypageInquiryDto){

@Operation(summary = "문의 조회하기", description = "문의 조회하기 API입니다.")
@GetMapping("/contact/{userId}")
public ApiResponse contact(@PathVariable Long userId){
public ApiResponse getContact(@PathVariable Long userId){
return ApiResponse.SuccessResponse(SuccessStatus.CONTACT_GET, mypageService.getInquiry(userId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@

import lombok.*;
import umc.meme.shop.domain.mypage.entity.Inquiry;
import umc.meme.shop.domain.user.User;

@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) {

User user = inquiry.getUser();

return MypageInquiryDto.builder()
.inquiryId(inquiry.getInquiryId())
.userId(user.getUserId())
.inquiryTitle(inquiry.getInquiryTitle())
.inquiryText(inquiry.getInquiryText())
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package umc.meme.shop.domain.mypage.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.mypage.entity.Inquiry;
import umc.meme.shop.domain.user.User;

import java.util.List;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MypageInquiryResponseDto {
private String userEmail;
private String inquiryTitle;
private String inquiryText;

public static MypageInquiryResponseDto from(Inquiry inquiry) {

return MypageInquiryResponseDto.builder()
.inquiryText(inquiry.getInquiryText())
.inquiryTitle(inquiry.getInquiryTitle())
.userEmail(inquiry.getUser().getEmail())
.build();
}
}
13 changes: 5 additions & 8 deletions src/main/java/umc/meme/shop/domain/mypage/entity/Inquiry.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.mypage.dto.request.MypageInquiryDto;
import umc.meme.shop.domain.user.User;
import umc.meme.shop.domain.user.UserRepository;

@Builder
@Getter
Expand All @@ -24,13 +26,8 @@ public class Inquiry {
@Column(nullable = false)
private String inquiryText;

@ManyToOne
@JoinColumn(name="user_id", nullable = false)
private User user;

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
Expand Up @@ -9,8 +9,7 @@
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.dto.response.*;
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;
Expand All @@ -20,6 +19,9 @@
import umc.meme.shop.global.ErrorStatus;
import umc.meme.shop.global.exception.GlobalException;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class MypageService {
Expand Down Expand Up @@ -52,18 +54,30 @@ public MypageTosDto getTos() {
//문의하기
@Transactional
public void createInquiry(MypageInquiryDto mypageInquiryDto) {
Inquiry inquiry = new Inquiry();
inquiry.updateInquiry(mypageInquiryDto);
User user = userRepository.findById(mypageInquiryDto.getUserId())
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_USER));

Inquiry inquiry = Inquiry.builder()
.inquiryText(mypageInquiryDto.getInquiryText())
.inquiryTitle(mypageInquiryDto.getInquiryTitle())
.user(user)
.build();

user.updateInquiryList(inquiry);
inquiryRepository.save(inquiry);
}

// 문의하기 조회
@Transactional
public MypageInquiryDto getInquiry(Long inquiryId) {
Inquiry inquiry = inquiryRepository.findById(inquiryId)
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_INQUIRY));
public List<MypageInquiryResponseDto> getInquiry(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new GlobalException(ErrorStatus.NOT_EXIST_USER));

List<Inquiry> inquiryList = user.getInquiryList();

return MypageInquiryDto.from(inquiry);
return inquiryList.stream()
.map(MypageInquiryResponseDto::from)
.toList();
}

}
10 changes: 10 additions & 0 deletions src/main/java/umc/meme/shop/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import umc.meme.shop.domain.artist.entity.enums.Gender;
import umc.meme.shop.domain.mypage.entity.Inquiry;

import java.util.List;
import umc.meme.shop.global.enums.Provider;

@SuperBuilder
Expand Down Expand Up @@ -37,6 +40,13 @@ public class User {
@Column(nullable = false, length = 40)
protected String email;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
protected List<Inquiry> inquiryList;

public void updateInquiryList(Inquiry inquiry) {
this.inquiryList.add(inquiry);
}

@Enumerated(EnumType.STRING)
@Column(nullable = false)
protected Provider provider;
Expand Down

0 comments on commit 19e5cfd

Please sign in to comment.