-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaceService.java
More file actions
40 lines (31 loc) · 1.39 KB
/
PlaceService.java
File metadata and controls
40 lines (31 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.sopkathon.domain.place.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.sopkathon.domain.place.dto.GetPlaceListResponse;
import com.sopkathon.domain.place.dto.GetPlaceResponse;
import com.sopkathon.domain.place.entity.Category;
import com.sopkathon.domain.place.entity.PlaceEntity;
import com.sopkathon.domain.place.repository.PlaceRepository;
import com.sopkathon.domain.subway.entity.SubwayEntity;
import com.sopkathon.domain.subway.service.SubwayService;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class PlaceService {
private final PlaceRepository placeRepository;
private final SubwayService SubwayService;
public GetPlaceListResponse getPlaceList(String category, String subway){
SubwayEntity subwayEntity = SubwayService.getSubwayEntity(subway);
List<PlaceEntity> placeEntityList = getPlacesByCategory(subwayEntity, category);
List<GetPlaceResponse> getPlaceResponseList = placeEntityList.stream()
.map(GetPlaceResponse::of)
.toList();
return new GetPlaceListResponse(getPlaceResponseList);
}
private List<PlaceEntity> getPlacesByCategory(SubwayEntity subwayEntity, String category) {
if ("ALL".equals(category)) {
return placeRepository.findAllBySubwayEntity(subwayEntity);
}
return placeRepository.findAllBySubwayEntityAndCategory(subwayEntity, Category.fromKorName(category));
}
}