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

경험 저장 API 요청 시 새로 추가한 데이터에 접근할 수 있도록 수정 #105

Merged
merged 4 commits into from
May 7, 2023

Conversation

seungyeonchoi
Copy link
Contributor

개요

작업사항

경험 저장 시 방금 저장한 데이터에 접근할 수 있도록 관련 로직 수정

  • record_id 컬럼은 auto increment 설정이 되어 있어서, mybatis의 useGeneratedKeys 기능을 이용해서 record_id에 셋팅된 값 읽어옴

api resonse 수정

변경 로직

경험 저장 api POST /records response 수정

  • as-is: 특별히 값을 넘겨주지 않음
  • to-be: http header location 필드에 방금 저장한 경험에 접근할 수 있는 url 값 셋팅

@seungyeonchoi seungyeonchoi added this to the v8 milestone May 7, 2023
@seungyeonchoi seungyeonchoi requested a review from cnpcnp99 May 7, 2023 07:24
@seungyeonchoi seungyeonchoi changed the title 경험 저장 API 응답값 수정 경험 저장 API 요청 시 새로 추가한 데이터에 접근할 수 있도록 수정 May 7, 2023
Copy link
Contributor

@cnpcnp99 cnpcnp99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 단순히 200 success + recordId 로 리턴하는게 아닌 201 created + location 헤더 이용으로 보다 정석적인 방법으로 리턴하는 방식에 대해 알 수 있어서 좋았습니다.
  2. Mybatis에서 Insert후 해당 Row의 Id값을 알 수 있는 방법에 대해 같이 알게 됐습니다. 감사합니다!

고생하셨습니다!

@@ -4,7 +4,7 @@

<mapper namespace="sullog.backend.record.mapper.RecordMapper">

<insert id="insertRecord" parameterType="sullog.backend.record.entity.Record">
<insert id="insertRecord" parameterType="sullog.backend.record.entity.Record" useGeneratedKeys="true" keyProperty="recordId">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert후 select로 id를 가져오는게 아니라 insert하면서 리턴 값으로 id를 받을 수 있는 방법 확인했습니다!

.path("/{recordId}")
.buildAndExpand(savedRecordId)
.toUri();
return ResponseEntity.created(location).build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTP 표준에 입각해서 location 헤더에 위치값을 리턴하는 구조 확인했습니다.

Copy link
Contributor

@cnpcnp99 cnpcnp99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 단순히 200 success + recordId 로 리턴하는게 아닌 201 created + location 헤더 이용으로 보다 정석적인 방법으로 리턴하는 방식에 대해 알 수 있어서 좋았습니다.
  2. Mybatis에서 Insert후 해당 Row의 Id값을 알 수 있는 방법에 대해 같이 알게 됐습니다. 감사합니다!

고생하셨습니다!

@seungyeonchoi
Copy link
Contributor Author

매번 자세하게 코멘트 주셔서 감사합니다 ! 의재님이 한차례 더 정리해주셔서 많이 도움됩니다 !!!

@seungyeonchoi seungyeonchoi merged commit cf22140 into dev May 7, 2023
@seungyeonchoi seungyeonchoi deleted the feature/sy/refactor-create-record-response branch May 7, 2023 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants