Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GET 마감임박 소피 모아보기 조회 #46

Merged
merged 14 commits into from
Jul 13, 2023
Merged
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
13 changes: 9 additions & 4 deletions src/main/java/org/sophy/sophy/controller/BooktalkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import org.sophy.sophy.controller.dto.BooktalkUpdateDto;
import org.sophy.sophy.controller.dto.request.BooktalkRequestDto;
import org.sophy.sophy.controller.dto.request.CityRequestDto;
import org.sophy.sophy.controller.dto.response.BooktalkCreateResponseDto;
import org.sophy.sophy.controller.dto.response.BooktalkDeleteResponseDto;
import org.sophy.sophy.controller.dto.response.BooktalkDetailResponseDto;
import org.sophy.sophy.controller.dto.response.BooktalkResponseDto;
import org.sophy.sophy.controller.dto.response.*;
import org.sophy.sophy.exception.SuccessStatus;
import org.sophy.sophy.service.BooktalkService;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -42,12 +39,20 @@ public ApiResponseDto<BooktalkDeleteResponseDto> deleteBooktalk(@PathVariable("b
}

@GetMapping("/{booktalkId}/detail")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<BooktalkDetailResponseDto> getBooktalkDetail(@PathVariable("booktalkId") Long booktalkId) {
return ApiResponseDto.success(SuccessStatus.GET_BOOKTALK_DETAIL_SUCCESS, booktalkService.getBooktalkDetail(booktalkId));
}

@GetMapping("/search")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<List<BooktalkResponseDto>> getPlacesByCity(@Valid @RequestBody CityRequestDto cityRequestDto) {
return ApiResponseDto.success(SuccessStatus.GET_BOOKTALKS_BY_CITY_SUCCESS, booktalkService.getBooktalksByCity(cityRequestDto));
}

@GetMapping("/deadline-upcoming")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<List<BooktalkDeadlineUpcomingDto>> getBooktalkDeadlineUpcoming() {
return ApiResponseDto.success(SuccessStatus.GET_BOOKTALKS_DEADLINE_UPCOMING_SUCCESS, booktalkService.getBooktalkDeadlineUpcoming());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.sophy.sophy.controller.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.sophy.sophy.domain.Booktalk;

import java.time.LocalDateTime;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class BooktalkDeadlineUpcomingDto {
private Long booktalkId;
private String title;
private LocalDateTime startDate;
private LocalDateTime endDate;
private String PlaceName;
private String PlaceAddress;

public static BooktalkDeadlineUpcomingDto of(Booktalk booktalk) {
return new BooktalkDeadlineUpcomingDto(
booktalk.getId(),
booktalk.getTitle(),
booktalk.getStartDate(),
booktalk.getEndDate(),
booktalk.getPlace().getName(),
booktalk.getPlace().getAddress()
);
}
}
1 change: 1 addition & 0 deletions src/main/java/org/sophy/sophy/exception/SuccessStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum SuccessStatus {
DELETE_BOOKTALK_SUCCESS(HttpStatus.OK, "북토크를 성공적으로 삭제했습니다."),
GET_BOOKTALK_DETAIL_SUCCESS(HttpStatus.OK, "북토크 상세정보를 성공적으로 불러왔습니다."),
GET_BOOKTALKS_BY_CITY_SUCCESS(HttpStatus.OK, "지역으로 북토크 리스트를 성공적으로 불러왔습니다"),
GET_BOOKTALKS_DEADLINE_UPCOMING_SUCCESS(HttpStatus.OK, "마감임박 소피 북토크 리스트를 성공적으로 불러왔습니다."),
GET_MY_BOOKTALKS_SUCCESS(HttpStatus.OK, "예정된 북토크 리스트를 성공적으로 불러왔습니다"),
GET_AUTHOR_BOOKTALKS_SUCCESS(HttpStatus.OK, "작가 북토크 리스트를 성공적으로 불러왔습니다"),
TEST_SUCCESS(HttpStatus.OK, "Test :: OK"),
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/org/sophy/sophy/service/BooktalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import org.sophy.sophy.controller.dto.BooktalkUpdateDto;
import org.sophy.sophy.controller.dto.request.BooktalkRequestDto;
import org.sophy.sophy.controller.dto.request.CityRequestDto;
import org.sophy.sophy.controller.dto.response.BooktalkCreateResponseDto;
import org.sophy.sophy.controller.dto.response.BooktalkDeleteResponseDto;
import org.sophy.sophy.controller.dto.response.BooktalkDetailResponseDto;
import org.sophy.sophy.controller.dto.response.BooktalkResponseDto;
import org.sophy.sophy.controller.dto.response.*;
import org.sophy.sophy.domain.*;
import org.sophy.sophy.exception.ErrorStatus;
import org.sophy.sophy.exception.model.ForbiddenException;
Expand Down Expand Up @@ -63,6 +60,26 @@ public BooktalkDetailResponseDto getBooktalkDetail(Long booktalkId) {
return BooktalkDetailResponseDto.of(booktalk);
}

public List<BooktalkDeadlineUpcomingDto> getBooktalkDeadlineUpcoming() {
List<Place> placeList = placeRepository.findAll();

List<BooktalkDeadlineUpcomingDto> booktalkList = new ArrayList<>();
placeList.forEach(place -> {
place.getBooktalkList().forEach(booktalk -> {
// 모집중인 북토크만 추가
if (booktalk.getBooktalkStatus() == BooktalkStatus.RECRUITING) {
booktalkList.add(BooktalkDeadlineUpcomingDto.of(booktalk));
}
}
);
});

// 마감 임박순으로 정렬
booktalkList.sort(Comparator.comparing(BooktalkDeadlineUpcomingDto::getEndDate));

return booktalkList;
}

private Member getMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION, ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));
Expand Down