Skip to content

Commit

Permalink
feat: 버스관련 API 구현
Browse files Browse the repository at this point in the history
- 노선 검색 API
- 노선 등록 service
- 정류장 검색 service
- 정류장 등록 service
- 노선별 경유 정류장 검색 service
- 노선별 경유 정류장 등록 service
  • Loading branch information
Gyaak committed Aug 6, 2024
1 parent be296c7 commit 1f46696
Show file tree
Hide file tree
Showing 19 changed files with 649 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.talkka.server.bus.controller;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.talkka.server.bus.dto.BusRouteRespDto;
import com.talkka.server.bus.service.BusRouteService;
import com.talkka.server.common.dto.ApiRespDto;
import com.talkka.server.common.enums.StatusCode;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/bus/route")
public class BusRouteController {
private final BusRouteService busRouteService;

@GetMapping("")
public ResponseEntity<ApiRespDto<List<BusRouteRespDto>>> findByRouteName(@RequestParam("search") String routeName) {
return ResponseEntity.ok(
ApiRespDto.<List<BusRouteRespDto>>builder()
.statusCode(StatusCode.OK.getCode())
.message(StatusCode.OK.getMessage())
.data(busRouteService.findByRouteName(routeName))
.build()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
public class BusRouteEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "route_id", nullable = false)
private Long routeId;
@Column(name = "route_id")
private Long id;

@Column(name = "api_route_id", nullable = false, length = 40)
private String apiRouteId; // 공공 api 에서 제공해주는 식별자

@Column(name = "route_name", nullable = false, length = 50)
private String routeName; // 노선 번호
Expand Down Expand Up @@ -132,11 +135,11 @@ public boolean equals(Object o) {
}

BusRouteEntity that = (BusRouteEntity)o;
return getRouteId().equals(that.getRouteId());
return getId().equals(that.getId());
}

@Override
public int hashCode() {
return getRouteId().hashCode();
return getId().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.talkka.server.bus.dao;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BusRouteRepository extends JpaRepository<BusRouteEntity, Long> {

boolean existsByApiRouteId(String apiRouteId);

Optional<BusRouteEntity> findByApiRouteId(String apiRouteId);

List<BusRouteEntity> findByRouteNameLikeOrderByRouteNameAsc(String routeName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class BusRouteStationEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "bus_route_station_id", nullable = false)
private Long busRouteStationId;
private Long id;

@ManyToOne
@JoinColumn(name = "route_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.talkka.server.bus.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BusRouteStationRepository extends JpaRepository<BusRouteStationEntity, Long> {
List<BusRouteStationEntity> findByRouteId(Long routeId);

List<BusRouteStationEntity> findByStationId(Long stationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -32,7 +34,15 @@
public class BusStationEntity {

@Id
private Long stationId;
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "station_id")
private Long id;

@Column(name = "api_station_id", nullable = false, length = 40)
private String apiStationId;

@Column(name = "station_name", nullable = false, length = 100)
private String stationName;

@Column(name = "region_name", nullable = false, length = 100)
private String regionName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.talkka.server.bus.dao;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BusStationRepository extends JpaRepository<BusStationEntity, Long> {
Optional<BusStationEntity> findByApiStationId(String apiStationId);

List<BusStationEntity> findByStationNameLikeOrderByStationNameAsc(String stationName);

boolean existsByApiStationId(String apiStationId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.talkka.server.bus.dto;

import com.talkka.server.bus.dao.BusRouteEntity;
import com.talkka.server.bus.enums.BusRouteType;
import com.talkka.server.bus.enums.DistrictCode;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@Builder
@ToString
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class BusRouteCreateDto {

private String apiRouteId; // 공공 api 에서 제공해주는 식별자
private String routeName; // 노선 번호
private BusRouteType routeTypeCd; // 노선 유형 코드
private String routeTypeName; // 노선 유형명
private String companyId; // 운수업체 아이디
private String companyName; // 운수업체명
private String companyTel; // 운수업체 전화번호
private DistrictCode districtCd; // 관할 지역 코드
private String upFirstTime; // 평일 기점 첫차 시간
private String upLastTime; // 평일 기점 막차 시간
private String downFirstTime; // 평일 종점 첫차 시간
private String downLastTime; // 평일 종점 막차 시간
private String startMobileNo; // 기점 정류소 번호
private Long startStationId; // 기점 정류소 아이디
private String startStationName; // 기점 정류소명
private Long endStationId; // 종점 정류소 아이디
private String endMobileNo; // 종점 정류소 번호
private String endStationName; // 종점 정류소명
private String regionName; // 지역명
private Integer peekAlloc; // 평일 최소 배차 시간
private Integer nPeekAlloc; // 평일 최대 배차 시간

public BusRouteEntity toEntity() {
return BusRouteEntity.builder()
.apiRouteId(apiRouteId)
.routeName(routeName)
.routeTypeCd(routeTypeCd)
.routeTypeName(routeTypeName)
.companyId(companyId)
.companyName(companyName)
.companyTel(companyTel)
.districtCd(districtCd)
.upFirstTime(upFirstTime)
.upLastTime(upLastTime)
.downFirstTime(downFirstTime)
.downLastTime(downLastTime)
.startMobileNo(startMobileNo)
.startStationId(startStationId)
.startStationName(startStationName)
.endStationId(endStationId)
.endMobileNo(endMobileNo)
.endStationName(endStationName)
.regionName(regionName)
.peekAlloc(peekAlloc)
.nPeekAlloc(nPeekAlloc)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.talkka.server.bus.dto;

import com.talkka.server.bus.dao.BusRouteEntity;
import com.talkka.server.bus.enums.BusRouteType;
import com.talkka.server.bus.enums.DistrictCode;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@Builder
@ToString
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class BusRouteRespDto {

private Long routeId;
private String routeName; // 노선 번호
private BusRouteType routeTypeCd; // 노선 유형 코드
private String routeTypeName; // 노선 유형명
private DistrictCode districtCd; // 관할 지역 코드
private String upFirstTime; // 평일 기점 첫차 시간
private String upLastTime; // 평일 기점 막차 시간
private String downFirstTime; // 평일 종점 첫차 시간
private String downLastTime; // 평일 종점 막차 시간
private String startMobileNo; // 기점 정류소 번호
private Long startStationId; // 기점 정류소 아이디
private String startStationName; // 기점 정류소명
private Long endStationId; // 종점 정류소 아이디
private String endMobileNo; // 종점 정류소 번호
private String endStationName; // 종점 정류소명
private String regionName; // 지역명
private Integer peekAlloc; // 평일 최소 배차 시간
private Integer nPeekAlloc; // 평일 최대 배차 시간

public static BusRouteRespDto of(BusRouteEntity busRouteEntity) {
return BusRouteRespDto.builder()
.routeId(busRouteEntity.getId())
.routeName(busRouteEntity.getRouteName())
.routeTypeCd(busRouteEntity.getRouteTypeCd())
.routeTypeName(busRouteEntity.getRouteTypeName())
.districtCd(busRouteEntity.getDistrictCd())
.upFirstTime(busRouteEntity.getUpFirstTime())
.upLastTime(busRouteEntity.getUpLastTime())
.downFirstTime(busRouteEntity.getDownFirstTime())
.downLastTime(busRouteEntity.getDownLastTime())
.startMobileNo(busRouteEntity.getStartMobileNo())
.startStationId(busRouteEntity.getStartStationId())
.startStationName(busRouteEntity.getStartStationName())
.endStationId(busRouteEntity.getEndStationId())
.endMobileNo(busRouteEntity.getEndMobileNo())
.endStationName(busRouteEntity.getEndStationName())
.regionName(busRouteEntity.getRegionName())
.peekAlloc(busRouteEntity.getPeekAlloc())
.nPeekAlloc(busRouteEntity.getNPeekAlloc())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.talkka.server.bus.dto;

import com.talkka.server.bus.dao.BusStationEntity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@Builder
@ToString
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class BusRouteStationCreateDto {

private String apiRouteId;
private String apiStationId;
private BusStationEntity station;
private Short stationSeq;
private String stationName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.talkka.server.bus.dto;

import java.time.LocalDateTime;

import com.talkka.server.bus.dao.BusRouteStationEntity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Getter
@Builder
@ToString
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class BusRouteStationRespDto {

private Long busRouteStationId;
private BusRouteRespDto route;
private BusStationRespDto station;
private Short stationSeq;
private String stationName;
private LocalDateTime createdAt;

public static BusRouteStationRespDto of(BusRouteStationEntity busRouteStationEntity) {
return BusRouteStationRespDto.builder()
.busRouteStationId(busRouteStationEntity.getId())
.route(BusRouteRespDto.of(busRouteStationEntity.getRoute()))
.station(BusStationRespDto.of(busRouteStationEntity.getStation()))
.stationSeq(busRouteStationEntity.getStationSeq())
.stationName(busRouteStationEntity.getStationName())
.createdAt(busRouteStationEntity.getCreatedAt())
.build();
}
}
Loading

0 comments on commit 1f46696

Please sign in to comment.