-
Notifications
You must be signed in to change notification settings - Fork 1
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/#51 로그 관련 도메인와 로그 API 요청의 필드명 변경 #53
Changes from all commits
a2a77ab
cd4a25e
27ecf1d
4a48953
ac1b255
5fb8113
e44b77a
a07a86c
b70a3ff
8d54562
511f16d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package info.logbat.common.util; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.UUID; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class UUIDUtil { | ||
|
||
private static final int UUID_BYTE_LENGTH = 16; | ||
|
||
public static byte[] uuidStringToBytes(String uuidStr) { | ||
UUID uuid = UUID.fromString(uuidStr); | ||
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[UUID_BYTE_LENGTH]); | ||
byteBuffer.putLong(uuid.getMostSignificantBits()); | ||
byteBuffer.putLong(uuid.getLeastSignificantBits()); | ||
return byteBuffer.array(); | ||
} | ||
|
||
public static String bytesToUuidString(byte[] bytes) { | ||
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); | ||
long high = byteBuffer.getLong(); | ||
long low = byteBuffer.getLong(); | ||
UUID uuid = new UUID(high, low); | ||
return uuid.toString(); | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 성공 실패 응답만 주면 되니까 201로 주는건 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반영하겠습니다~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 노션 API 문서도 업데이트 했습니다~ |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,14 +4,14 @@ | |||||||||||
import info.logbat.domain.log.application.payload.request.CreateLogServiceRequest; | ||||||||||||
import info.logbat.domain.log.presentation.payload.request.CreateLogRequest; | ||||||||||||
import jakarta.validation.Valid; | ||||||||||||
import jakarta.validation.constraints.NotNull; | ||||||||||||
import jakarta.validation.constraints.Positive; | ||||||||||||
import jakarta.validation.constraints.NotBlank; | ||||||||||||
import lombok.RequiredArgsConstructor; | ||||||||||||
import org.springframework.http.ResponseEntity; | ||||||||||||
import org.springframework.http.HttpStatus; | ||||||||||||
import org.springframework.web.bind.annotation.PostMapping; | ||||||||||||
import org.springframework.web.bind.annotation.RequestBody; | ||||||||||||
import org.springframework.web.bind.annotation.RequestHeader; | ||||||||||||
import org.springframework.web.bind.annotation.RequestMapping; | ||||||||||||
import org.springframework.web.bind.annotation.ResponseStatus; | ||||||||||||
import org.springframework.web.bind.annotation.RestController; | ||||||||||||
|
||||||||||||
@RestController | ||||||||||||
|
@@ -22,18 +22,15 @@ public class LogController { | |||||||||||
private final LogService logService; | ||||||||||||
|
||||||||||||
@PostMapping | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 응답 status를 정하는건 어떤가요?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 하면 함수 리턴타입을 void로 해야할 것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반영했어요!! |
||||||||||||
public ResponseEntity<Void> saveLog( | ||||||||||||
@RequestHeader("app-id") | ||||||||||||
@NotNull(message = "Application ID가 비어있습니다.") | ||||||||||||
@Positive(message = "Application ID는 양수여야 합니다.") Long applicationId, | ||||||||||||
@ResponseStatus(HttpStatus.CREATED) | ||||||||||||
public void saveLog( | ||||||||||||
@RequestHeader("appKey") | ||||||||||||
@NotBlank(message = "appKey가 비어있습니다.") String appKey, | ||||||||||||
|
||||||||||||
@Valid @RequestBody CreateLogRequest request | ||||||||||||
) { | ||||||||||||
|
||||||||||||
logService.saveLog(CreateLogServiceRequest.of(applicationId, request)); | ||||||||||||
|
||||||||||||
return ResponseEntity.ok() | ||||||||||||
.build(); | ||||||||||||
logService.saveLog(CreateLogServiceRequest.of(appKey, request)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package info.logbat.common.util; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
miiiinju1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@DisplayName("UUIDUtil에서 ") | ||
public class UUIDUtilTest { | ||
|
||
@ParameterizedTest | ||
@DisplayName("UUID 문자열은 byte 배열로 변환할 수 있다.") | ||
@MethodSource("validUUIDProvider") | ||
void uuidToBytes_ShouldConvertUUIDStringToByteArray(String uuidStr, byte[] expectedBytes) { | ||
// when | ||
byte[] bytes = UUIDUtil.uuidStringToBytes(uuidStr); | ||
|
||
assertAll( | ||
() -> assertThat(bytes).isNotNull(), | ||
() -> assertThat(bytes.length).isEqualTo(16), | ||
() -> assertThat(bytes).isEqualTo(expectedBytes) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@DisplayName("bytesToUUIDString은 byte 배열을 UUID 문자열로 정확하게 변환해야 한다.") | ||
@MethodSource("validUUIDProvider") | ||
void bytesToUUIDString_ShouldConvertByteArrayToUUIDString(String expectedUUIDStr, byte[] bytes) { | ||
// when | ||
String resultUUIDStr = UUIDUtil.bytesToUuidString(bytes); | ||
|
||
// then | ||
assertThat(resultUUIDStr).isEqualTo(expectedUUIDStr); | ||
} | ||
|
||
|
||
private static Stream<Arguments> validUUIDProvider() { | ||
return Stream.of( | ||
Arguments.of("550e8400-e29b-41d4-a716-446655440000", | ||
new byte[]{85, 14, -124, 0, -30, -101, 65, -44, -89, 22, 68, 102, 85, 68, 0, 0}), | ||
Arguments.of("123e4567-e89b-12d3-a456-426614174000", | ||
new byte[]{18, 62, 69, 103, -24, -101, 18, -45, -92, 86, 66, 102, 20, 23, 64, 0}), | ||
Arguments.of("00000000-0000-0000-0000-000000000000", | ||
new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 항상 고민인 부분인데, 컨트롤러에서도 이것에 대한 검사를 하는것 같아서 두번해도 괜찮나 생각듭니다...!
각자 맡아야 할 책임이 달라서 두군데 모두 있는면이 자연스럽다고 생각합니다!