Skip to content

Commit

Permalink
refactor: PageDto 변환 로직 Controller -> Service 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ddingmin committed Jan 2, 2024
1 parent 413ea31 commit e7d5d1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import lombok.RequiredArgsConstructor;
import net.teumteum.core.error.ErrorResponse;
import net.teumteum.meeting.domain.Meeting;
import net.teumteum.meeting.model.PageDto;
import net.teumteum.meeting.domain.Topic;
import net.teumteum.meeting.domain.response.MeetingResponse;
import net.teumteum.meeting.domain.response.MeetingsResponse;
import net.teumteum.meeting.model.PageDto;
import net.teumteum.meeting.service.MeetingService;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

Expand All @@ -35,9 +33,7 @@ public PageDto<MeetingsResponse> getMeetingsOrderByDate(Pageable pageable,
@RequestParam(value = "participantUserId", required = false) Long participantUserId,
@RequestParam(value = "searchWord", required = false) String searchWord) {

Slice<Meeting> meetings = meetingService.getMeetingsBySpecification(pageable, topic, meetingAreaStreet, participantUserId, searchWord, isOpen);

return PageDto.of(MeetingsResponse.of(meetings.getContent()), meetings.hasNext());
return meetingService.getMeetingsBySpecification(pageable, topic, meetingAreaStreet, participantUserId, searchWord, isOpen);
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/net/teumteum/meeting/service/MeetingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import net.teumteum.meeting.domain.MeetingSpecification;
import net.teumteum.meeting.domain.Topic;
import net.teumteum.meeting.domain.response.MeetingResponse;
import net.teumteum.meeting.domain.response.MeetingsResponse;
import net.teumteum.meeting.model.PageDto;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -27,8 +28,8 @@ public MeetingResponse getMeetingById(Long meetingId) {
}

@Transactional(readOnly = true)
public Slice<Meeting> getMeetingsBySpecification(Pageable pageable, Topic topic, String meetingAreaStreet,
Long participantUserId, String searchWord, boolean isOpen) {
public PageDto<MeetingsResponse> getMeetingsBySpecification(Pageable pageable, Topic topic, String meetingAreaStreet,
Long participantUserId, String searchWord, boolean isOpen) {

Specification<Meeting> spec = MeetingSpecification.withIsOpen(isOpen);

Expand All @@ -46,7 +47,9 @@ else if (searchWord != null) {
.and(MeetingSpecification.withIsOpen(isOpen));
}

return meetingRepository.findAll(spec, pageable);
var meetings = meetingRepository.findAll(spec, pageable);

return PageDto.of(MeetingsResponse.of(meetings.getContent()), meetings.hasNext());
}

}

0 comments on commit e7d5d1e

Please sign in to comment.