Skip to content

Commit

Permalink
[FEAT] 지하철에 관련된 엔티티 생성 및 레포지토리 구현 (#58)
Browse files Browse the repository at this point in the history
- 지하철 역 엔티티 구현
- 지하철 혼잡도 엔티티 구현
- 지하철 시간표 엔티티 구현
- 각 레포지토리 구현

Closes #56 

**현재까지 진행내용 merge하여 충돌 해결**
  • Loading branch information
ss0ngcode authored Aug 10, 2024
1 parent c78e7c2 commit 6061c06
Show file tree
Hide file tree
Showing 23 changed files with 502 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.talkka.server.review.enums;
package com.talkka.server.common.enums;

import com.talkka.server.common.util.EnumCodeInterface;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.talkka.server.review.util;
package com.talkka.server.common.util;

import com.talkka.server.common.util.EnumCodeConverter;
import com.talkka.server.review.enums.TimeSlot;
import com.talkka.server.common.enums.TimeSlot;

import jakarta.persistence.Converter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import com.talkka.server.bus.dao.BusRouteEntity;
import com.talkka.server.bus.dao.BusRouteStationEntity;
import com.talkka.server.review.enums.TimeSlot;
import com.talkka.server.review.util.TimeSlotConverter;
import com.talkka.server.common.enums.TimeSlot;
import com.talkka.server.common.util.TimeSlotConverter;
import com.talkka.server.user.dao.UserEntity;

import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.talkka.server.review.enums.TimeSlot;
import com.talkka.server.common.enums.TimeSlot;

@Repository
public interface BusReviewRepository extends JpaRepository<BusReviewEntity, Long> {
// 실제로 조회할 경우, 해당 쿼리를 항상 사용함. 따라서 네이밍을 findReviews로 변경
List<BusReviewEntity> findAllByWriterIdAndRouteIdAndStationIdAndTimeSlot(
Long userId,
Long routeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.talkka.server.bus.dao.BusRouteEntity;
import com.talkka.server.bus.dao.BusRouteStationEntity;
import com.talkka.server.common.enums.TimeSlot;
import com.talkka.server.review.dao.BusReviewEntity;
import com.talkka.server.review.enums.TimeSlot;
import com.talkka.server.user.dao.UserEntity;

import jakarta.validation.constraints.Max;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import com.talkka.server.bus.dao.BusRouteRepository;
import com.talkka.server.bus.dao.BusRouteStationEntity;
import com.talkka.server.bus.dao.BusRouteStationRepository;
import com.talkka.server.common.enums.TimeSlot;
import com.talkka.server.common.exception.http.ForbiddenException;
import com.talkka.server.common.exception.http.NotFoundException;
import com.talkka.server.common.util.EnumCodeConverterUtils;
import com.talkka.server.review.dao.BusReviewEntity;
import com.talkka.server.review.dao.BusReviewRepository;
import com.talkka.server.review.dto.BusReviewReqDto;
import com.talkka.server.review.dto.BusReviewRespDto;
import com.talkka.server.review.enums.TimeSlot;
import com.talkka.server.user.dao.UserEntity;
import com.talkka.server.user.dao.UserRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.talkka.server.subway.dao;

import java.util.Objects;

import com.talkka.server.common.enums.TimeSlot;
import com.talkka.server.common.util.TimeSlotConverter;
import com.talkka.server.subway.enums.DayType;
import com.talkka.server.subway.enums.Line;
import com.talkka.server.subway.enums.Updown;
import com.talkka.server.subway.util.DayTypeConverter;
import com.talkka.server.subway.util.LineConverter;
import com.talkka.server.subway.util.UpdownConverter;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity(name = "subway_confusion")
@Getter
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class SubwayConfusionEntity {

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

@ManyToOne
@JoinColumn(name = "station_id")
private SubwayStationEntity subwayStation;

@Column(name = "day_type", nullable = false)
@Convert(converter = DayTypeConverter.class)
private DayType dayType;

@Column(name = "line_cd", nullable = false)
@Convert(converter = LineConverter.class)
private Line line;

@Column(name = "fr_code", nullable = false)
private String frCode;

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

@Column(name = "updown", nullable = false)
@Convert(converter = UpdownConverter.class)
private Updown updown;

@Column(name = "time_slot", nullable = false)
@Convert(converter = TimeSlotConverter.class)
private TimeSlot timeslot;

@Column(name = "confusion")
private Double confusion;

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SubwayConfusionEntity that = (SubwayConfusionEntity)o;
return Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hashCode(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.talkka.server.subway.dao;

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

@Repository
public interface SubwayConfusionRepository extends JpaRepository<SubwayConfusionEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.talkka.server.subway.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.talkka.server.subway.enums.Line;
import com.talkka.server.subway.util.LineConverter;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity(name = "subway_station")
@Getter
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class SubwayStationEntity {

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

@Column(name = "api_station_id")
private String apiStationId;

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

@Column(name = "fr_code", nullable = false)
private String frCode;

@Column(name = "line_code", nullable = false)
@Convert(converter = LineConverter.class)
private Line line;

@OneToMany(mappedBy = "subwayStation")
@Builder.Default
private List<SubwayTimetableEntity> timetables = new ArrayList<>();

@OneToMany(mappedBy = "subwayStation")
@Builder.Default
private List<SubwayConfusionEntity> confusions = new ArrayList<>();

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SubwayStationEntity that = (SubwayStationEntity)o;
return Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hashCode(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.talkka.server.subway.dao;

import java.util.List;

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

@Repository
public interface SubwayStationRepository extends JpaRepository<SubwayStationEntity, Long> {
List<SubwayStationEntity> findByStationNameLikeOrderByStationNameAsc(String stationName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.talkka.server.subway.dao;

import java.time.LocalTime;
import java.util.Objects;

import com.talkka.server.subway.enums.DayType;
import com.talkka.server.subway.enums.Express;
import com.talkka.server.subway.enums.Line;
import com.talkka.server.subway.enums.Updown;
import com.talkka.server.subway.util.DayTypeConverter;
import com.talkka.server.subway.util.ExpressConverter;
import com.talkka.server.subway.util.LineConverter;
import com.talkka.server.subway.util.UpdownConverter;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity(name = "subway_timetable")
@Getter
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class SubwayTimetableEntity {

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

@ManyToOne
@JoinColumn(name = "station_id", nullable = false)
private SubwayStationEntity subwayStation;

@Column(name = "line_code", nullable = false)
@Convert(converter = LineConverter.class)
private Line line;

@Column(name = "fr_code", nullable = false)
private String frCode;

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

@Column(name = "day_type", nullable = false)
@Convert(converter = DayTypeConverter.class)
private DayType dayType;

@Column(name = "updown", nullable = false)
@Convert(converter = UpdownConverter.class)
private Updown updown;

@Column(name = "is_express", nullable = false)
@Convert(converter = ExpressConverter.class)
private Express express;

@Column(name = "train_code", nullable = false)
private String trainCode;

@Column(name = "arrival_time", nullable = false)
private LocalTime arrivalTime;

@Column(name = "depart_time", nullable = false)
private LocalTime departTime;

@Column(name = "start_station_name", nullable = false)
private String startStationName;

@Column(name = "end_station_name", nullable = false)
private String endStationName;

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SubwayTimetableEntity that = (SubwayTimetableEntity)o;
return Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hashCode(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.talkka.server.subway.dao;

import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter;
import org.springframework.stereotype.Repository;

@Repository
public interface SubwayTimetableRepository extends JpaAttributeConverter<SubwayTimetableEntity, Long> {
}
20 changes: 20 additions & 0 deletions server/src/main/java/com/talkka/server/subway/enums/DayType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.talkka.server.subway.enums;

import com.talkka.server.common.util.EnumCodeInterface;

import lombok.Getter;

@Getter
public enum DayType implements EnumCodeInterface {
DAY("평일", "DAY"),
SAT("토요일", "SAT"),
SUN("일요일", "SUN");

private String name;
private String code;

DayType(String name, String code) {
this.name = name;
this.code = code;
}
}
18 changes: 18 additions & 0 deletions server/src/main/java/com/talkka/server/subway/enums/Express.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.talkka.server.subway.enums;

import com.talkka.server.common.util.EnumCodeInterface;

import lombok.Getter;

@Getter
public enum Express implements EnumCodeInterface {
EXPRESS("급행", "0"), NORMAL("일반", "1");

private final String type;
private final String code;

Express(String type, String code) {
this.type = type;
this.code = code;
}
}
Loading

0 comments on commit 6061c06

Please sign in to comment.