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] response body 수정 (json return 값) #9

Closed
chhs2131 opened this issue Sep 3, 2022 · 4 comments · Fixed by #46
Closed

[FEAT] response body 수정 (json return 값) #9

chhs2131 opened this issue Sep 3, 2022 · 4 comments · Fixed by #46
Labels
enhancement New feature or request

Comments

@chhs2131
Copy link
Owner

chhs2131 commented Sep 3, 2022

  1. statusCode 를 body에 포함시키기 (filter 사용 예정)
  2. JSON 반환의 그룹화 필요 (ex. 일정, 기본정보, 공모정보 등)
  • 테이블 정규화 문제가 엮여있어 고민해 봐야할 부분
  • 차라리 현 시점에서 JPA로 이전하는게 나을 수도 있다.

적용 예시 (인터넷에 있던 자료)

image

참고

CustomResponse DTO

ControllerAdvice

With Filter, Interceptor, AOP

ResponseBodyAdvice

{
  "statusCode": 200,
  "body": [
    {
      "category_id": "17011000",
      "name": "풍성한 고기반찬",
      "items": [
        {
          "detail_hash": "HBDEF",
          "image": "http://public.codesquad.kr/jk/storeapp/data/main/1155_ZIP_P_0081_T.jpg",
          "alt": "오리 주물럭_반조리",
          "delivery_type": [
            "새벽배송",
            "전국택배"
          ],
          "title": "오리 주물럭_반조리",
          "description": "감칠맛 나는 매콤한 양념",
          "n_price": "15,800원",
          "s_price": "12,640원",
          "badge": [
            "런칭특가"
          ]
        },
        {
          "detail_hash": "HF778",
          "image": "http://public.codesquad.kr/jk/storeapp/data/main/349_ZIP_P_0024_T.jpg",
          "alt": "소갈비찜",
          "delivery_type": [
            "새벽배송",
            "전국택배"
          ],
          "title": "소갈비찜",
          "description": "촉촉하게 벤 양념이 일품",
          "n_price": "28,900원",
          "s_price": "26,010원",
          "badge": [
            "이벤트특가"
          ]
        },
        {
          "detail_hash": "HEDFB",
          "image": "http://public.codesquad.kr/jk/storeapp/data/main/510_ZIP_P_0047_T.jpg",
          "alt": "쭈꾸미 한돈 제육볶음_반조림",
          "delivery_type": [
            "새벽배송",
            "전국택배"
          ],
          "title": "쭈꾸미 한돈 제육볶음_반조림",
          "description": "쫄깃한 쭈꾸미와 고소한 돼지고기가 일품",
          "s_price": "16,900원"
        }
      ]
    },

    ...

    {
      "category_id": "17011400",
      "name": "우리아이 영양반찬",
      "items": [
        {
          "detail_hash": "H26C7",
          "image": "http://public.codesquad.kr/jk/storeapp/data/soup/818_ZIP_P_1033_T.jpg",
          "alt": "순한 오징어무국",
          "delivery_type": [
            "새벽배송",
            "전국택배"
          ],
          "title": "순한 오징어무국",
          "description": "부드럽고 담백한 국물",
          "s_price": "11,900원"
        },
        {
          "detail_hash": "H602F",
          "image": "http://public.codesquad.kr/jk/storeapp/data/side/84_ZIP_P_6006_T.jpg",
          "alt": "야채 어묵볶음",
          "delivery_type": [
            "새벽배송",
            "전국택배"
          ],
          "title": "야채 어묵볶음",
          "description": "첨가물 없는 순수어묵과 야채의 만남",
          "n_price": "4,900원",
          "s_price": "4,410원"
        },
        {
          "detail_hash": "H4665",
          "image": "http://public.codesquad.kr/jk/storeapp/data/main/675_ZIP_P_0057_T.jpg",
          "alt": "궁중 떡볶이_반조리",
          "delivery_type": [
            "새벽배송",
            "전국택배"
          ],
          "title": "궁중 떡볶이_반조리",
          "description": "영양 듬뿍 프리미엄 간장 떡볶이",
          "s_price": "7,800원"
        }
      ]
    }
  ]
}
@chhs2131 chhs2131 changed the title response body 수정 (json return 값) response body 수정 필요 (json return 값) Sep 3, 2022
@chhs2131 chhs2131 added the enhancement New feature or request label Sep 6, 2022
@chhs2131 chhs2131 changed the title response body 수정 필요 (json return 값) [FEAT] response body 수정 (json return 값) Sep 7, 2022
@chhs2131
Copy link
Owner Author

chhs2131 commented Sep 22, 2022

현재 반환 상태

꿍참

정상반환

{
  "status": 200,
  "code": "",
  "message": "",
  "body": {
    "index": 999,
    "name": "안녕하세요",
    "registerDate": "2022-09-22"
  },
  "timestamp": "2022-09-22T15:43:55.905"
}

CustomException

{
  "status": 404,
  "code": "T000",
  "message": "yeah",
  "body": [],
  "timestamp": "2022-09-22T15:44:07.6"
}

@chhs2131
Copy link
Owner Author

chhs2131 commented Sep 22, 2022

이렇게 하면 모든 모든 반환이 ResponseEntity 형태가 되어버림.

chhs2131 added a commit that referenced this issue Sep 26, 2022
Feature/#9 - 공통 반환 데이터 클래스 작성 (1차 취합용)
@chhs2131
Copy link
Owner Author

@psw9999 침범하지마

chhs2131 added a commit that referenced this issue Oct 7, 2022
chhs2131 added a commit that referenced this issue Oct 7, 2022
Feature/#9 - 공통반환 전체 적용 (정상반환, 예외반환)
@chhs2131
Copy link
Owner Author

chhs2131 commented Oct 7, 2022

204 ( no content) 헤더에 대해 200 헤더로 바꾸는 작업을 추가함.

  • 204 헤더를 responseEntity에 대입할 경우 자동으로 no content 동작이 발생함

  • no content 동작으로 인해 body에 값이 있더라도 사라짐

  • 클라이언트에서 header의 httpStatus가 아닌 공통응답 form 에 있는 status를 통해서만 판단하고잇음

  • 때문에 공통반환을 살리기 위하여 204 헤더를 200으로 바꾸되, 대신 공통반환내의 status 항목에는 204라고 표기되도록 함

  • 예시

HTTP HEADER 200 OK
{
  "status": 204,
  "code": "IS000",
  "message": "조건에 맞는 조회 결과가 없습니다.",
  "body": [],
  "timestamp": "2022-10-07T19:34:09.344"
}

@chhs2131 chhs2131 closed this as completed Oct 7, 2022
@chhs2131 chhs2131 mentioned this issue Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant