Skip to content

Commit 2b11abe

Browse files
authored
Merge pull request #31 from Wayble-Project/feature/seungin
[feat] 웨이블존 목록 조회 API 구현
2 parents 4518fab + 3bdaefa commit 2b11abe

File tree

6 files changed

+103
-19
lines changed

6 files changed

+103
-19
lines changed

src/main/java/com/wayble/server/common/entity/Address.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,14 @@ public class Address {
3838
/** 경도 */
3939
@Column(name = "longitude", columnDefinition = "DECIMAL(10,7)", nullable = false)
4040
private Double longitude;
41+
42+
public String toFullAddress() {
43+
StringBuilder sb = new StringBuilder();
44+
if (state != null) sb.append(state).append(" ");
45+
if (city != null) sb.append(city).append(" ");
46+
if (district != null) sb.append(district).append(" ");
47+
if (streetAddress != null) sb.append(streetAddress).append(" ");
48+
if (detailAddress != null) sb.append(detailAddress);
49+
return sb.toString().trim();
50+
}
4151
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
package com.wayble.server.wayblezone.controller;
22

33
import com.wayble.server.common.response.CommonResponse;
4+
import com.wayble.server.wayblezone.dto.WaybleZoneListResponseDto;
45
import com.wayble.server.wayblezone.service.WaybleZoneService;
6+
import jakarta.validation.constraints.NotBlank;
57
import lombok.RequiredArgsConstructor;
68
import org.springframework.web.bind.annotation.GetMapping;
79
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestParam;
811
import org.springframework.web.bind.annotation.RestController;
912

13+
import java.util.List;
14+
1015
@RestController
1116
@RequiredArgsConstructor
12-
@RequestMapping("/wayble-zones")
17+
@RequestMapping("/api/v1/wayble-zones")
1318
public class WaybleZoneController {
1419

1520
private final WaybleZoneService waybleZoneService;
1621

17-
// 참고용 컨트롤러(지우셔도 돼요)
18-
@GetMapping("/hello")
19-
public CommonResponse<String> hello() {
20-
return CommonResponse.success("hello");
21-
}
22-
23-
// 예외 사용 참고용 컨트롤러(지우셔도 돼요)
24-
@GetMapping("/ex")
25-
public CommonResponse<String> exception() {
26-
waybleZoneService.makeException();
27-
return CommonResponse.success("예외 발생!");
22+
@GetMapping
23+
public CommonResponse<List<WaybleZoneListResponseDto>> getWaybleZoneList(
24+
@RequestParam @NotBlank(message = "city는 필수입니다.") String city,
25+
@RequestParam @NotBlank(message = "category는 필수입니다.") String category
26+
) {
27+
return CommonResponse.success(waybleZoneService.getWaybleZones(city, category));
2828
}
29-
}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.wayble.server.wayblezone.dto;
2+
3+
import lombok.Builder;
4+
5+
@Builder
6+
public record WaybleZoneListResponseDto(
7+
Long waybleZoneId,
8+
String name,
9+
String category,
10+
String address,
11+
double rating,
12+
int reviewCount,
13+
String imageUrl,
14+
String contactNumber,
15+
FacilityDto facilities
16+
) {
17+
@Builder
18+
public record FacilityDto(
19+
boolean hasSlope,
20+
boolean hasNoDoorStep,
21+
boolean hasElevator,
22+
boolean hasTableSeat,
23+
boolean hasDisabledToilet,
24+
String floorInfo
25+
) {}
26+
}
27+

src/main/java/com/wayble/server/wayblezone/exception/WaybleZoneErrorCase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
@RequiredArgsConstructor
99
public enum WaybleZoneErrorCase implements ErrorCase {
1010

11-
WAYBLE_ZONE_NOT_FOUND(404, 2001, "해당 웨이블존을 찾을 수 없습니다.");
11+
WAYBLE_ZONE_NOT_FOUND(404, 2001, "해당 웨이블존을 찾을 수 없습니다."),
12+
INVALID_CATEGORY(400, 2002, "유효하지 않은 category 파라미터입니다."),
13+
WAYBLE_ZONE_FACILITY_NOT_FOUND(404, 2003, "해당 웨이블존에 대한 시설 정보가 존재하지 않습니다.");
1214

1315
private final Integer httpStatusCode;
1416
private final Integer errorCode;

src/main/java/com/wayble/server/wayblezone/repository/WaybleZoneRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
import com.wayble.server.wayblezone.entity.WaybleZone;
44
import org.springframework.data.jpa.repository.JpaRepository;
55

6+
import java.util.List;
7+
68
public interface WaybleZoneRepository extends JpaRepository<WaybleZone, Long> {
9+
List<WaybleZone> findByAddress_CityContainingAndZoneType(String city, com.wayble.server.wayblezone.entity.WaybleZoneType category);
710
}
Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,63 @@
11
package com.wayble.server.wayblezone.service;
22

33
import com.wayble.server.common.exception.ApplicationException;
4+
import com.wayble.server.wayblezone.dto.WaybleZoneListResponseDto;
5+
import com.wayble.server.wayblezone.entity.WaybleZone;
6+
import com.wayble.server.wayblezone.entity.WaybleZoneFacility;
7+
import com.wayble.server.wayblezone.entity.WaybleZoneImage;
8+
import com.wayble.server.wayblezone.entity.WaybleZoneType;
49
import com.wayble.server.wayblezone.exception.WaybleZoneErrorCase;
5-
import com.wayble.server.wayblezone.repository.WaybleZoneImageRepository;
610
import com.wayble.server.wayblezone.repository.WaybleZoneRepository;
711
import lombok.RequiredArgsConstructor;
812
import org.springframework.stereotype.Service;
913

14+
import java.util.List;
15+
16+
import static com.wayble.server.wayblezone.dto.WaybleZoneListResponseDto.*;
17+
1018
@Service
1119
@RequiredArgsConstructor
1220
public class WaybleZoneService {
1321

1422
private final WaybleZoneRepository waybleZoneRepository;
1523

16-
private final WaybleZoneImageRepository imageRepository;
24+
public List<WaybleZoneListResponseDto> getWaybleZones(String city, String category) {
25+
WaybleZoneType zoneType;
26+
27+
try {
28+
zoneType = WaybleZoneType.valueOf(category.toUpperCase());
29+
} catch (IllegalArgumentException e) {
30+
throw new ApplicationException(WaybleZoneErrorCase.INVALID_CATEGORY);
31+
}
32+
33+
List<WaybleZone> zones = waybleZoneRepository.findByAddress_CityContainingAndZoneType(city, zoneType);
34+
35+
return zones.stream().map(zone -> {
36+
WaybleZoneFacility f = zone.getFacility();
37+
if (f == null) {
38+
throw new ApplicationException(WaybleZoneErrorCase.WAYBLE_ZONE_FACILITY_NOT_FOUND);
39+
}
40+
41+
WaybleZoneImage image = zone.getWaybleZoneImageList().stream().findFirst().orElse(null);
1742

18-
public void makeException() {
19-
throw new ApplicationException(WaybleZoneErrorCase.WAYBLE_ZONE_NOT_FOUND);
43+
return WaybleZoneListResponseDto.builder()
44+
.waybleZoneId(zone.getId())
45+
.name(zone.getZoneName())
46+
.category(zone.getZoneType().toString())
47+
.address(zone.getAddress().toFullAddress())
48+
.rating(zone.getRating())
49+
.reviewCount(zone.getReviewCount())
50+
.imageUrl(image != null ? image.getImageUrl() : null)
51+
.contactNumber(zone.getContactNumber())
52+
.facilities(FacilityDto.builder()
53+
.hasSlope(f.isHasSlope())
54+
.hasNoDoorStep(f.isHasNoDoorStep())
55+
.hasElevator(f.isHasElevator())
56+
.hasTableSeat(f.isHasTableSeat())
57+
.hasDisabledToilet(f.isHasDisabledToilet())
58+
.floorInfo(f.getFloorInfo())
59+
.build()
60+
).build();
61+
}).toList();
2062
}
21-
}
63+
}

0 commit comments

Comments
 (0)