Skip to content

Commit

Permalink
feat: add swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
edikgoose committed Dec 4, 2023
1 parent 8c73373 commit fa061b3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Parking Service

Backend for Poga Parking Service

SwaggerUI - http://localhost:8080/swagger-ui.html
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("io.github.oshai:kotlin-logging-jvm:5.1.0")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0")

runtimeOnly("org.postgresql:postgresql")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package poga.parking.parkingservice

import io.swagger.v3.oas.annotations.OpenAPIDefinition
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
@OpenAPIDefinition
class ParkingServiceApplication

fun main(args: Array<String>) {
runApplication<ParkingServiceApplication>(*args)
runApplication<ParkingServiceApplication>(*args)
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
package poga.parking.parkingservice.controller

import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import poga.parking.parkingservice.controller.model.input.BookPlaceRequest
import poga.parking.parkingservice.controller.model.ouput.FreePlacesResponse
import poga.parking.parkingservice.controller.model.ouput.StatisticsResponse
import poga.parking.parkingservice.service.PlaceService
import poga.parking.parkingservice.support.toHttpStatusCode

@RestController("/place")
@RestController
@RequestMapping("/place")
@Tag(name = "API for parking places")
class PlaceController(
@Autowired private val placeService: PlaceService
) {

@GetMapping("/free")
@Operation(summary = "Get all free places")
fun gerFreePlaces(): ResponseEntity<FreePlacesResponse> =
ResponseEntity(
placeService.getFreePlaces(),
HttpStatus.OK.toHttpStatusCode()
)

@PostMapping("/book")
@Operation(summary = "Book a parking place by user")
fun bookPlace(request: BookPlaceRequest): ResponseEntity<Long> =
TODO("$request")

@PostMapping("/free/{id}")
@Operation(summary = "Free up a parking place by user")
fun freeUpPlace(@PathVariable id: Long): ResponseEntity<Boolean> =
TODO("$id")

@GetMapping("/free/{id}")
@Operation(summary = "Get statistics of a free parking place by id")
fun getStatisticsAfterFreeUp(@PathVariable id: Long): ResponseEntity<StatisticsResponse> =
TODO("$id")
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package poga.parking.parkingservice.controller

import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.beans.factory.annotation.Autowired
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 poga.parking.parkingservice.controller.model.ouput.StatisticsResponse
import poga.parking.parkingservice.service.StatisticsService

@RestController("/statistics")
@RestController
@RequestMapping("/statistics")
@Tag(name = "API for retrieving statistics")
class StatisticsController(
@Autowired private val statisticsService: StatisticsService
) {

@GetMapping
@Operation(summary = "Get statistics for a given phone number")
fun getTotalStatistics(
@RequestParam phoneNumber: String,
@RequestParam isBookedNow: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package poga.parking.parkingservice.controller

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import poga.parking.parkingservice.entity.ParkingPlace
import poga.parking.parkingservice.entity.User
Expand All @@ -13,7 +14,8 @@ import poga.parking.parkingservice.repository.UserRepository
import poga.parking.parkingservice.repository.UserStatisticsRepository
import java.time.Instant

@RestController("/tech")
@RestController
@RequestMapping("/tech")
class TechController(
@Autowired private val userRepository: UserRepository,
@Autowired private val parkingPlaceRepository: ParkingPlaceRepository,
Expand Down

0 comments on commit fa061b3

Please sign in to comment.