diff --git a/build.gradle b/build.gradle index 63479ed..4113fd0 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,9 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' } tasks.named('test') { diff --git a/src/main/java/com/dnd/dndtravel/config/SwaggerConfig.java b/src/main/java/com/dnd/dndtravel/config/SwaggerConfig.java new file mode 100644 index 0000000..d7ff76f --- /dev/null +++ b/src/main/java/com/dnd/dndtravel/config/SwaggerConfig.java @@ -0,0 +1,19 @@ +package com.dnd.dndtravel.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 openAPI() { + return new OpenAPI() + .info(new Info() + .title("MAPDDANG API") + .description("맵땅 앱 관련 API") + .version("1.0.0")); + + } +} diff --git a/src/main/java/com/dnd/dndtravel/map/controller/MapController.java b/src/main/java/com/dnd/dndtravel/map/controller/MapController.java index 76133d3..a750a13 100644 --- a/src/main/java/com/dnd/dndtravel/map/controller/MapController.java +++ b/src/main/java/com/dnd/dndtravel/map/controller/MapController.java @@ -1,5 +1,7 @@ package com.dnd.dndtravel.map.controller; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -14,6 +16,8 @@ public class MapController { private final MapService mapService; + @Tag(name = "MAP", description = "지도 API") + @Operation(summary = "전체 지역 조회", description = "전체 지역 방문 횟수를 조회합니다.") @GetMapping("/maps") public RegionResponse map() { return mapService.allRegions(); diff --git a/src/main/java/com/dnd/dndtravel/map/service/MapService.java b/src/main/java/com/dnd/dndtravel/map/service/MapService.java index 3f70715..67a1056 100644 --- a/src/main/java/com/dnd/dndtravel/map/service/MapService.java +++ b/src/main/java/com/dnd/dndtravel/map/service/MapService.java @@ -1,16 +1,14 @@ package com.dnd.dndtravel.map.service; -import java.util.List; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import com.dnd.dndtravel.map.domain.Region; import com.dnd.dndtravel.map.repository.MapRepository; import com.dnd.dndtravel.map.service.dto.RegionDto; import com.dnd.dndtravel.map.service.dto.response.RegionResponse; - import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; @RequiredArgsConstructor @Service diff --git a/src/main/java/com/dnd/dndtravel/map/service/dto/response/RegionResponse.java b/src/main/java/com/dnd/dndtravel/map/service/dto/response/RegionResponse.java index 7ca098f..2eb49a4 100644 --- a/src/main/java/com/dnd/dndtravel/map/service/dto/response/RegionResponse.java +++ b/src/main/java/com/dnd/dndtravel/map/service/dto/response/RegionResponse.java @@ -1,9 +1,9 @@ package com.dnd.dndtravel.map.service.dto.response; -import java.util.List; - import com.dnd.dndtravel.map.service.dto.RegionDto; +import java.util.List; + public record RegionResponse( List regions, int visitCount, diff --git a/src/main/java/com/dnd/dndtravel/test/TestController.java b/src/main/java/com/dnd/dndtravel/test/TestController.java deleted file mode 100644 index bbc01ba..0000000 --- a/src/main/java/com/dnd/dndtravel/test/TestController.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.dnd.dndtravel.test; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class TestController { - @GetMapping("test") - public String printTest() { - return "CI/CD Success!"; - } -} \ No newline at end of file diff --git a/src/test/java/com/dnd/dndtravel/map/controller/MapControllerTest.java b/src/test/java/com/dnd/dndtravel/map/controller/MapControllerTest.java index 81b6868..44e9f21 100644 --- a/src/test/java/com/dnd/dndtravel/map/controller/MapControllerTest.java +++ b/src/test/java/com/dnd/dndtravel/map/controller/MapControllerTest.java @@ -1,8 +1,6 @@ package com.dnd.dndtravel.map.controller; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - +import com.dnd.dndtravel.map.service.MapService; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -11,7 +9,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.web.servlet.MockMvc; -import com.dnd.dndtravel.map.service.MapService; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @WebMvcTest(MapController.class) diff --git a/src/test/java/com/dnd/dndtravel/map/service/MapServiceTest.java b/src/test/java/com/dnd/dndtravel/map/service/MapServiceTest.java index c5dcb3a..9583492 100644 --- a/src/test/java/com/dnd/dndtravel/map/service/MapServiceTest.java +++ b/src/test/java/com/dnd/dndtravel/map/service/MapServiceTest.java @@ -1,11 +1,9 @@ package com.dnd.dndtravel.map.service; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -import java.util.List; -import java.util.stream.Stream; - +import com.dnd.dndtravel.map.domain.Region; +import com.dnd.dndtravel.map.domain.VisitOpacity; +import com.dnd.dndtravel.map.repository.MapRepository; +import com.dnd.dndtravel.map.service.dto.response.RegionResponse; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.extension.ExtendWith; @@ -16,10 +14,11 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.dnd.dndtravel.map.domain.VisitOpacity; -import com.dnd.dndtravel.map.domain.Region; -import com.dnd.dndtravel.map.repository.MapRepository; -import com.dnd.dndtravel.map.service.dto.response.RegionResponse; +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith(MockitoExtension.class)