Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ public ApiResponse<ComplaintResponseDTO.ComplaintImgDTO> uploadImages(

@Operation(summary = "새 민원글 작성")
@PostMapping()
public ApiResponse<ComplaintResponseDTO.ComplaintDTO> createComplaint(@AuthenticatedMember Member member,
public ApiResponse<ComplaintResponseDTO.ComplaintDetailDTO> createComplaint(@AuthenticatedMember Member member,
@Valid @RequestBody ComplaintRequestDTO.CreateComplaintDTO createComplaintDTO) {
return ApiResponse.onSuccess(complaintCommandService.createComplaint(member, createComplaintDTO));
}


@Operation(summary = "내가 쓴 민원글 상세 조회")
@GetMapping("/{complaintId}")
ApiResponse<ComplaintResponseDTO.ComplaintDTO>getComplaintDetail(@AuthenticatedMember Member member, @PathVariable("complaintId") Long complaintId){
@GetMapping("/my-complaints/{complaintId}")
ApiResponse<ComplaintResponseDTO.ComplaintDetailDTO>getComplaintDetail(@AuthenticatedMember Member member, @PathVariable("complaintId") Long complaintId){
return ApiResponse.onSuccess(complaintQueryService.getComplaintDetail(member, complaintId));
}

@Operation(summary = "내가 쓴 민원글 목록 조회")
@GetMapping()
@GetMapping("/my-complaints")
ApiResponse<List<ComplaintResponseDTO.ComplaintDTO>> getComplaintList(@AuthenticatedMember Member member){
return ApiResponse.onSuccess(complaintQueryService.getComplaintList(member));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,62 @@ public static getStationDTO from(Station station) {
}

@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
public static class ComplaintDTO {
public static class ComplaintDTO{
private Long complaintId;
private String title;
private String image;
private String name;
private String content;
private ComplaintType complaintType;
private String complaintType;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private List<String> images;

public static ComplaintDTO from(Complaint complaint, List<ComplaintImg> complaintImgList){
List<String> complaintImgURL = complaintImgList.stream()
.map(ComplaintImg::getImgUrl)
.collect(Collectors.toList());

public static ComplaintDTO from(Complaint complaint, ComplaintImg complaintImg) {
return ComplaintDTO.builder()
.complaintId(complaint.getId())
.complaintType(complaint.getComplaintType())
.title(complaint.getTitle())
.image(complaintImg != null ? complaintImg.getImgUrl() : null) // 이미지가 null이 아닐 경우 URL 반환, null이면 null 반환
.name(complaint.getStation().getName())
.content(complaint.getContent())
.images(complaintImgURL)
.complaintType(complaint.getComplaintType().getDescription())
.createdAt(complaint.getCreatedAt())
.updatedAt(complaint.getUpdatedAt())
.build();
}
}
@Builder
@Getter
public static class ComplaintDetailDTO {
private Long complaintId;
private String name;
private String address; //도로명
private String streetNumber;//지번
private String institutionPhone; //번호
private String title;
private String content;
private String complaintType;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private List<String> images;

//목록조회를 위해 이미지가 없는 버전
public static ComplaintDTO from(Complaint complaint){
return ComplaintDTO.builder()
public static ComplaintDetailDTO from(Complaint complaint, List<ComplaintImg> complaintImgList){
List<String> complaintImgURL = complaintImgList.stream()
.map(ComplaintImg::getImgUrl)
.collect(Collectors.toList());
return ComplaintDetailDTO.builder()
.complaintId(complaint.getId())
.complaintType(complaint.getComplaintType())
.name(complaint.getStation().getName())
.address(complaint.getStation().getAddress())
.streetNumber(complaint.getStation().getStreetNumber())
.institutionPhone(complaint.getStation().getInstitutionPhone())
.title(complaint.getTitle())
.content(complaint.getContent())
.complaintType(complaint.getComplaintType().getDescription())
.images(complaintImgURL)
.createdAt(complaint.getCreatedAt())
.updatedAt(complaint.getUpdatedAt())
.build();
}

public static List<ComplaintDTO> from(List<Complaint> complaints) {
return complaints.stream()
.map(ComplaintDTO::from)
.collect(Collectors.toList());
}
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
public interface ComplaintCommandService {
ComplaintResponseDTO.ComplaintImgDTO uploadImages(List<MultipartFile> images);

ComplaintResponseDTO.ComplaintDTO createComplaint(Member member, ComplaintRequestDTO.CreateComplaintDTO createComplaintDTO);
ComplaintResponseDTO.ComplaintDetailDTO createComplaint(Member member, ComplaintRequestDTO.CreateComplaintDTO createComplaintDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ComplaintResponseDTO.ComplaintImgDTO uploadImages(List<MultipartFile> ima
}

@Override
public ComplaintResponseDTO.ComplaintDTO createComplaint(Member member, ComplaintRequestDTO.CreateComplaintDTO createComplaintDTO) {
public ComplaintResponseDTO.ComplaintDetailDTO createComplaint(Member member, ComplaintRequestDTO.CreateComplaintDTO createComplaintDTO) {
Station station = stationRepository.findById(createComplaintDTO.getStationId()).
orElseThrow(() -> new StationException(StationErrorCode.NOT_FOUND));
Complaint complaint = ComplaintRequestDTO.CreateComplaintDTO.toEntity(createComplaintDTO, station, member);
Expand All @@ -84,11 +84,8 @@ public ComplaintResponseDTO.ComplaintDTO createComplaint(Member member, Complain
}

Complaint savedComplaint = complaintRepository.save(complaint);
return ComplaintResponseDTO.ComplaintDetailDTO.from(savedComplaint, complaintImgs);

if(complaintImgs!=null) {
return ComplaintResponseDTO.ComplaintDTO.from(savedComplaint, complaintImgs);
}
return ComplaintResponseDTO.ComplaintDTO.from(savedComplaint);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public interface ComplaintQueryService {
ComplaintResponseDTO.getStationDTO getStationName(Long stationId);

ComplaintResponseDTO.ComplaintDTO getComplaintDetail(Member member, Long complaintId);
ComplaintResponseDTO.ComplaintDetailDTO getComplaintDetail(Member member, Long complaintId);

List<ComplaintResponseDTO.ComplaintDTO> getComplaintList(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.transaction.annotation.Transactional;

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

@RequiredArgsConstructor
@Service
Expand All @@ -34,7 +35,7 @@ public ComplaintResponseDTO.getStationDTO getStationName(Long stationId) {
}

@Override
public ComplaintResponseDTO.ComplaintDTO getComplaintDetail(Member member, Long complaintId) {
public ComplaintResponseDTO.ComplaintDetailDTO getComplaintDetail(Member member, Long complaintId) {
Complaint complaint = complaintRepository.findByIdAndMember(complaintId, member);
if(complaint == null){
throw new ComplaintException(ComplaintErrorCode.COMPLAINT_NOT_FOUND);
Expand All @@ -43,12 +44,18 @@ public ComplaintResponseDTO.ComplaintDTO getComplaintDetail(Member member, Long
if(complaintImgList == null){
throw new ComplaintException(ComplaintErrorCode.INVALID_IMAGE_URLS);
}
return ComplaintResponseDTO.ComplaintDTO.from(complaint);
return ComplaintResponseDTO.ComplaintDetailDTO.from(complaint, complaintImgList);
}

@Override
public List<ComplaintResponseDTO.ComplaintDTO> getComplaintList(Member member) {
List<Complaint> complaintList = complaintRepository.findAllByMemberId(member.getId());
return ComplaintResponseDTO.ComplaintDTO.from(complaintList);
// 각 Complaint에 대해 이미지를 하나만 선택하여 가져오기
return complaintList.stream().map(complaint -> {
// 해당 Complaint와 연관된 첫 번째 이미지를 가져옴
ComplaintImg complaintImg = complaintImgRepository.findAllByComplaintId(complaint.getId()).stream().findFirst().orElse(null);
// ComplaintDTO에 이미지 정보를 포함시켜 반환
return ComplaintResponseDTO.ComplaintDTO.from(complaint, complaintImg);
}).collect(Collectors.toList());
}
}