This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
canbus-server/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/bus/persistence/Bus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package kr.hs.dgsw.canbusserver.domain.bus.persistence | ||
|
||
import jakarta.persistence.* | ||
|
||
@Entity | ||
@Table(name = "bus") | ||
class Bus ( | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long? = null, | ||
|
||
val duration: String, | ||
|
||
val timeRange: String, | ||
|
||
val busNumber: String, | ||
|
||
@OneToMany | ||
@JoinColumn(name = "bus_id") | ||
val stations: List<Station> | ||
|
||
) |
6 changes: 6 additions & 0 deletions
6
...us-server/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/bus/persistence/BusRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package kr.hs.dgsw.canbusserver.domain.bus.persistence | ||
|
||
import org.springframework.data.repository.CrudRepository | ||
|
||
interface BusRepository : CrudRepository<Bus, Long> { | ||
} |
17 changes: 17 additions & 0 deletions
17
canbus-server/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/bus/persistence/Station.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kr.hs.dgsw.canbusserver.domain.bus.persistence | ||
|
||
import jakarta.persistence.* | ||
|
||
@Entity | ||
@Table(name = "station") | ||
class Station( | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long? = null, | ||
|
||
val name: String, | ||
|
||
val time: String, | ||
|
||
) |
24 changes: 24 additions & 0 deletions
24
...s-server/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/bus/presentation/BusController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package kr.hs.dgsw.canbusserver.domain.bus.presentation | ||
|
||
import kr.hs.dgsw.canbusserver.domain.bus.presentation.dto.ApplyBusRequest | ||
import kr.hs.dgsw.canbusserver.domain.bus.presentation.dto.BusResponse | ||
import kr.hs.dgsw.canbusserver.domain.bus.service.BusService | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@RestController | ||
@RequestMapping("/bus") | ||
class BusController( | ||
private val busService: BusService | ||
) { | ||
|
||
@GetMapping | ||
fun getBusList(): List<BusResponse> { | ||
return busService.getBusList() | ||
} | ||
|
||
@PostMapping("/apply") | ||
fun applyBus(@RequestBody request: ApplyBusRequest) { | ||
busService.applyBus(request) | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...er/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/bus/presentation/dto/ApplyBusRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kr.hs.dgsw.canbusserver.domain.bus.presentation.dto | ||
|
||
class ApplyBusRequest( | ||
|
||
val arrivalPlace: String, | ||
|
||
val departurePlace: String, | ||
|
||
val departureTime: String, | ||
|
||
) |
20 changes: 20 additions & 0 deletions
20
...server/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/bus/presentation/dto/BusResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kr.hs.dgsw.canbusserver.domain.bus.presentation.dto | ||
|
||
class BusResponse( | ||
|
||
val duration: String, | ||
|
||
val timeRange: String, | ||
|
||
val busNumber: String, | ||
|
||
val stations: List<Station>, | ||
|
||
) { | ||
|
||
class Station( | ||
val name: String, | ||
val time: String, | ||
) | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
canbus-server/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/bus/service/BusService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package kr.hs.dgsw.canbusserver.domain.bus.service | ||
|
||
import kr.hs.dgsw.canbusserver.domain.bus.persistence.BusRepository | ||
import kr.hs.dgsw.canbusserver.domain.bus.presentation.dto.ApplyBusRequest | ||
import kr.hs.dgsw.canbusserver.domain.bus.presentation.dto.BusResponse | ||
import kr.hs.dgsw.canbusserver.domain.passenger.Passenger | ||
import kr.hs.dgsw.canbusserver.domain.passenger.PassengerRepository | ||
import kr.hs.dgsw.canbusserver.domain.user.UserRepository | ||
import kr.hs.dgsw.canbusserver.global.security.SecurityUtil | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class BusService( | ||
private val busRepository: BusRepository, | ||
private val userRepository: UserRepository, | ||
private val passengerRepository: PassengerRepository, | ||
private val securityUtil: SecurityUtil | ||
) { | ||
|
||
fun getBusList(): List<BusResponse> { | ||
|
||
val busList = busRepository.findAll() | ||
|
||
return busList.map { bus -> | ||
BusResponse( | ||
busNumber = bus.busNumber, | ||
duration = bus.duration, | ||
timeRange = bus.timeRange, | ||
stations = bus.stations.map { | ||
BusResponse.Station( | ||
name = it.name, | ||
time = it.time, | ||
) | ||
} | ||
) | ||
} | ||
} | ||
|
||
fun applyBus(request: ApplyBusRequest) { | ||
|
||
val user = userRepository.findByIdOrNull(securityUtil.getCurrentUserId())!! | ||
|
||
val passenger = Passenger( | ||
arrivalPlace = request.arrivalPlace, | ||
departurePlace = request.departurePlace, | ||
departureTime = request.departureTime, | ||
user = user | ||
) | ||
|
||
passengerRepository.save(passenger) | ||
|
||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
canbus-server/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/passenger/Passenger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package kr.hs.dgsw.canbusserver.domain.passenger | ||
|
||
import jakarta.persistence.* | ||
import kr.hs.dgsw.canbusserver.domain.user.User | ||
|
||
@Entity | ||
@Table(name = "passenger") | ||
class Passenger ( | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long? = null, | ||
|
||
val arrivalPlace: String, | ||
|
||
val departurePlace: String, | ||
|
||
val departureTime: String, | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
val user: User, | ||
|
||
) |
6 changes: 6 additions & 0 deletions
6
...us-server/src/main/kotlin/kr/hs/dgsw/canbusserver/domain/passenger/PassengerRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package kr.hs.dgsw.canbusserver.domain.passenger | ||
|
||
import org.springframework.data.repository.CrudRepository | ||
|
||
interface PassengerRepository : CrudRepository<Passenger, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters