Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] setting swagger #24

Merged
merged 3 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ dependencies {
//aws
implementation 'com.amazonaws:aws-java-sdk-dynamodb:1.11.563'

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.cloudcomputing.ohhanahana.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info().title("오하나하나 API")
.version("1.0")
.description("API documentation for 오하나하나 application"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
import com.cloudcomputing.ohhanahana.dto.response.RecommendResponse;
import com.cloudcomputing.ohhanahana.dto.response.ShuttleResponse;
import com.cloudcomputing.ohhanahana.service.BusService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.xml.bind.JAXBException;
import lombok.RequiredArgsConstructor;
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.RestController;

@Tag(name = "버스 API", description = "버스 관련 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/bus")
public class BusController {

private final BusService busService;

@Operation(summary = "주변 정류장 버스 도착 정보 조회 API", description = "주변 정류장 버스 도착 정보를 조회하는 API입니다.")
@GetMapping("/recommend")
public ResponseEntity<RecommendResponse> recommendBus() {
try {
Expand All @@ -28,13 +32,15 @@ public ResponseEntity<RecommendResponse> recommendBus() {
}
}

@Operation(summary = "셔틀버스 도착 정보 조회 API", description = "셔틀버스 도착 정보를 조회하는 API입니다.")
@GetMapping("/shuttle")
public ResponseEntity<ShuttleResponse> shuttleBus() {
return busService.getShuttleBus()
.map(ResponseEntity::ok)
.orElseGet(() -> ResponseEntity.ok(null));
}

@Operation(summary = "전체 버스 도착 정보 조회 API", description = "전체 버스 도착 정보를 조회하는 API입니다.")
@GetMapping
public ResponseEntity<BusResponse> findAllBus() {
try {
Expand All @@ -45,6 +51,7 @@ public ResponseEntity<BusResponse> findAllBus() {
}
}

@Operation(summary = "511번 버스 도착 정보 조회 API", description = "511번 버스 도착 정보를 조회하는 API입니다.")
@GetMapping("/511")
public ResponseEntity<RecommendResponse.Bus> get511Bus() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import com.cloudcomputing.ohhanahana.entity.Person;
import com.cloudcomputing.ohhanahana.repository.PersonRepository;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -14,35 +15,41 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "Person API", description = "Person 관련 API")
@RestController
@RequestMapping("/persons")
public class PersonController {

@Autowired
private PersonRepository personRepository;

@Operation(summary = "Person 저장 API", description = "Person을 저장하는 API입니다.")
@PostMapping
public Person save(@RequestBody Person person) {

return personRepository.save(person);
}

@Operation(summary = "Person 조회 API", description = "Person을 조회하는 API입니다.")
@GetMapping("/{id}")
public Person findById(@PathVariable(value = "id") String id) {
return personRepository.findById(id);
}

@Operation(summary = "Person 전체 조회 API", description = "Person 전체를 조회하는 API입니다.")
@GetMapping("/all")
public List<Person> findAll() {
return personRepository.findAll();
}

@Operation(summary = "Person 수정 API", description = "Person을 수정하는 API입니다.")
@PutMapping("/{id}")
public String update(@PathVariable(value="id") String id,
@RequestBody Person person) {
return personRepository.update(id, person);
}

@Operation(summary = "Person 삭제 API", description = "Person을 삭제하는 API입니다.")
@DeleteMapping("/{id}")
public String delete(@PathVariable(value="id") String id) {
return personRepository.delete(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

import com.cloudcomputing.ohhanahana.dto.response.SensorDataResponse;
import com.cloudcomputing.ohhanahana.service.SensorDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.xml.bind.JAXBException;
import lombok.RequiredArgsConstructor;
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.RestController;

@Tag(name = "혼잡도 API", description = "혼잡도 관련 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/congestion")
public class SensorDataController {

private final SensorDataService sensorDataService;

@Operation(summary = "혼잡도 조회 API", description = "혼잡도를 조회하는 API입니다.")
@GetMapping("/")
public ResponseEntity<Object> findTest() throws JAXBException {
return ResponseEntity.ok(sensorDataService.findLatestSensorData());
}

@Operation(summary = "혼잡도 랜덤 조회 API", description = "혼잡도를 랜덤으로 조회하는 API입니다.")
@GetMapping("/random")
public ResponseEntity<Object> findRandomSensorData() throws JAXBException {
return ResponseEntity.ok(sensorDataService.generateRandomSensorData());
Expand Down