[1편]국세청_사업자등록정보 진위확인 및 상태조회 서비스 만들기

Yeomso(BE)·2023년 7월 14일
0

1일차 API 신청하고 프로젝트 구축하기!

API 신청 사이트 및 간단한 테스트

https://www.data.go.kr/data/15081808/openapi.do

저는 해당 프로젝트를 만드는 이유가 어머니가 사업자등록정보를 찾기 위해서 한건한건 홈택스에 하는걸 보고선 반복 노동을 줄여드리기 위해서 구축 하는 것입니다.

그래서 /status API만 테스트 진행하고 구축 하도록 하려고 합니다.

테스트로 Curl을 한번 요청을 하면

curl -X 'POST' \
  'https://api.odcloud.kr/api/nts-businessman/v1/status?serviceKey=비밀이에용' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "b_no": [
    "0000000000"
  ]
}'

아래처럼 정상적으로 response를 주네요
엇 그런데 camel case가 아니고 snake case 네요 ㅠ
이러면 response 받는 dto에 또 하나의 설정을 추가해야 하겠네요 아쉽...

{
  "request_cnt": 1,
  "status_code": "OK",
  "data": [
    {
      "b_no": "0000000000",
      "b_stt": "",
      "b_stt_cd": "",
      "tax_type": "국세청에 등록되지 않은 사업자등록번호입니다.",
      "tax_type_cd": "",
      "end_dt": "",
      "utcc_yn": "",
      "tax_type_change_dt": "",
      "invoice_apply_dt": "",
      "rbf_tax_type": "",
      "rbf_tax_type_cd": ""
    }
  ]
}

프로젝트 구축 시작!

프로젝트 명은 간단하게 data-business로 만들도록 하겠습니다.

저번에 모듈화를 진행했기 때문에 blog repo에 data-business모듈을 구축 하도록 하겠습니다.

settings.gradle.kts에 data-business 추가해서 진행 하도록 하겠습니다.

현재는 data-business 모듈에 rest template 설정을 진행 하겠지만, 추후에는 public-web 이라는 공유 모듈을 만들어서 따로 구축 하던가 이번에 같이 구축 하던가 하도록 하겠슴돠.

rootProject.name = "blog"

listOf(
    "exam-retry",
    "exam-module",
    "data-business"
).forEach {
    include(it)
    project(":$it").projectDir = File("$rootDir/modules/$it")
}

해당 설정을 하고 gradle을 다시 셋팅해주니 정상적으로 모듈이 인식이 되었네요

이제 본격적으로 프로젝트 구성을 하도록 하겠습니다.
가장 첫번째로 Spring boot 셋팅을 해야겠죠

package com.example.blog

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class DataBusinessApp

fun main(args: Array<String>) {
    runApplication<DataBusinessApp>(*args)
}

추후 공통 모듈을 만들걸 염두해서 아래와 같이 application.yml을 셋팅 했습니다.

server:
  port: 10010
  shutdown: graceful
management:
  server:
    port: 10011
spring:
  profiles:
    include:
    group:
      local:

    active: local
  application:
    name: business
  lifecycle:
    timeout-per-shutdown-phase: 15s

그리고 실행 결과 아래처럼 정상적으로 실행이 되었습니다.

2023-07-14 11:56:38.689  INFO 32457 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 10010 (http) with context path ''

간단한 Rest Template 구축 및 데이터 연동하기

연동할 client를 만들기 및 자세한 내용은 2회차에서 진행하겠습니다.

intellij 기능 중 http 기능으로 간단하게 요청을 보내는 rest를 만들어 보았다.

###
POST {{business}}/v1/business/internal/business/status
Content-Type: application/json

{
  "b_no": [
    "0000000000"
  ]
}

실행 결과 정상적으로 아까와 같은 데이터가 나오는 것을 확인할 수 있다.

POST http://localhost:10010/v1/business/internal/business/status

HTTP/1.1 200 
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 14 Jul 2023 03:50:05 GMT
Keep-Alive: timeout=60
Connection: keep-alive

{
  "request_cnt": 1, "status_code": "OK", "data": [
  {
    "tax_type": "국세청에 등록되지 않은 사업자등록번호입니다.", "tax_type_cd": "", "end_dt": "", "utcc_yn": "",
    "tax_type_change_dt": "", "invoice_apply_dt": "", "rbf_tax_type": "", "rbf_tax_type_cd": "",
    "bno": "0000000000", "bstt": "", "bsttCd": ""
  }
]
}
profile
나 혼자만 개발중

0개의 댓글