-
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/#31 Log를 저장하는 API 구현 #34
Conversation
- AllArgsConstructor에서 RequiredArgsConstructor로 변경
- Service 요청을 담당하는 CreateLogServiceRequest를 추가했습니다ㅏ.
- Log를 만들고 저장하는 LogService를 추가했습니다. - AppId 검증 로직이 이후에 추가되어야 합니다.
- Log를 만들고 저장하는 LogService에 대한 테스트를 추가했습니다. - AppId 검증 로직에 대한 테스트가 추가되어야 합니다.
- logLevel은 `@NotBlank`를 통해 검증했습니다. - logData를 `@NotBlank`를 통해 검증했습니다. - LocalDateTime을 `@NotNull`를 통해 검증했습니다.
- Header에서 받아온 applicationId와 Controller Request를 파라미터로 받아서 만들도록 구현
- CreateLogRequest를 레코드로 변경했습니다. - CreateLogServiceRequest의 of메서드를 파라미터 변경
- applicationId에 대해 Positive, NotNull Validation 추가 - CreateLogRequest에 대해 Validation 추가
- 유효한 입력 값으로 로그 생성 성공 테스트. - app_id 누락 시 400 Bad Request 반환 테스트. - 음수 app_id에 대한 400 Bad Request 반환 테스트. - logLevel 및 logData 필드에 대한 null 및 빈 문자열 입력 시 400 Bad Request 반환 테스트. - timestamp 누락 시 400 Bad Request 반환 테스트.
...rc/main/java/info/logbat/domain/log/application/payload/request/CreateLogServiceRequest.java
Show resolved
Hide resolved
logbat/src/main/java/info/logbat/domain/log/presentation/LogController.java
Show resolved
Hide resolved
logbat/src/main/java/info/logbat/domain/log/presentation/payload/request/CreateLogRequest.java
Show resolved
Hide resolved
logbat/src/main/java/info/logbat/domain/log/repository/LogRepository.java
Show resolved
Hide resolved
logbat/src/test/java/info/logbat/domain/common/ControllerTestSupport.java
Show resolved
Hide resolved
logbat/src/test/java/info/logbat/domain/log/application/LogServiceTest.java
Show resolved
Hide resolved
logbat/src/test/java/info/logbat/domain/log/presentation/LogControllerTest.java
Show resolved
Hide resolved
logbat/src/test/java/info/logbat/domain/log/repository/LogRepositoryTest.java
Show resolved
Hide resolved
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.
리뷰 확인해주세요!
logbat/src/main/java/info/logbat/domain/log/application/LogService.java
Outdated
Show resolved
Hide resolved
|
||
private final LogService logService; | ||
|
||
@PostMapping("/logs") |
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.
@RequestMapping
으로 처리하는게 좋아보입니다.
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.
좋아요!!
@RequestHeader("app_id") @NotNull @Positive Long applicationId, | ||
@Valid @RequestBody CreateLogRequest request |
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.
API 문서화 해주세여!
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.
완료했습니당
@NotBlank | ||
String logLevel, | ||
|
||
@NotBlank | ||
String logData, | ||
|
||
@NotNull |
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.
예외 메시지도 써주면 좋을 것 같습니다 :D
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.
반영했습니다~~
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.
👍🏻
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@SpringBootTest |
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.
@WebMVCTest
vs @SpringBootTest
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.
Service 레이어는 DB붙여서 테스트하는 것이 더 좋다고 생각해서 @SpringBootTest
를 이용해야 하지 않을까 생각됩니다!!
- `@RequestMapping("/logs")`와 `@PostMapping`을 사용하게 수정
- LogController의 applicationId에 메세지 추가 - CreateLogRequest의 Validation에 메세지 추가
logbat/src/main/java/info/logbat/domain/log/presentation/LogController.java
Show resolved
Hide resolved
logbat/src/main/java/info/logbat/domain/log/presentation/payload/request/CreateLogRequest.java
Show resolved
Hide resolved
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.
조아요
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.
승인입니다! 일단 논의 내용에 대해 더 이야기해봐요
logbat/src/main/java/info/logbat/domain/log/application/LogService.java
Outdated
Show resolved
Hide resolved
public ResponseEntity<Void> saveLog( | ||
@RequestHeader("app_id") | ||
@NotNull(message = "Application ID가 비어있습니다.") | ||
@Positive(message = "Application ID는 양수여야 합니다.") Long applicationId, |
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.
어플리케이션 ID를 어떤 형식으로 해야할지 더 논의해보면 좋겠어요!
난수 String이 더 안전하지 않을까 생각이 듭니다 🥹
private LogService logService; | ||
|
||
@Autowired | ||
private LogRepository logRepository; |
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.
이부분도 서비스 테스트에서 데이터베이스는 모킹 안되어 있는데 어떤 방식으로 하면 좋을지 더 논의해봐요!
repository layer는 저도 이렇게 주입받아 쓰는면이 유지보수도 용이하고 테스트 컨테이너를 사용할 예정이라 좋아보여요!
- LogService에서 Log를 생성 시 of 팩터리 메서드를 이용하도록 변경
* chore: LogRepository에 잘못 사용한 생성자 변경 - AllArgsConstructor에서 RequiredArgsConstructor로 변경 * feat: CreateLogServiceRequest 레코드 추가 - Service 요청을 담당하는 CreateLogServiceRequest를 추가했습니다ㅏ. * feat: Log를 저장하는 LogService 추가 - Log를 만들고 저장하는 LogService를 추가했습니다. - AppId 검증 로직이 이후에 추가되어야 합니다. * test: Log를 저장하는 LogService에 대한 테스트 추가 - Log를 만들고 저장하는 LogService에 대한 테스트를 추가했습니다. - AppId 검증 로직에 대한 테스트가 추가되어야 합니다. * feat: Controller의 요청을 받기 위해 CreateLogRequest를 추가했습니다. - logLevel은 `@NotBlank`를 통해 검증했습니다. - logData를 `@NotBlank`를 통해 검증했습니다. - LocalDateTime을 `@NotNull`를 통해 검증했습니다. * feat: 컨트롤러 Request에서 CreateLogServiceRequest변환하는 정적 팩토리 메서드 추가 - Header에서 받아온 applicationId와 Controller Request를 파라미터로 받아서 만들도록 구현 * refactor: CreateLogRequest를 레코드를 사용하도록 변경 - CreateLogRequest를 레코드로 변경했습니다. - CreateLogServiceRequest의 of메서드를 파라미터 변경 * config: build.gradle에 validation 추가 * feat: LogController 추가 - applicationId에 대해 Positive, NotNull Validation 추가 - CreateLogRequest에 대해 Validation 추가 * test: Cntroller 테스트 환경 통합을 위해 ControllerTestSupport 추가 * test: LogController에 대한 단위 테스트 추가 - 유효한 입력 값으로 로그 생성 성공 테스트. - app_id 누락 시 400 Bad Request 반환 테스트. - 음수 app_id에 대한 400 Bad Request 반환 테스트. - logLevel 및 logData 필드에 대한 null 및 빈 문자열 입력 시 400 Bad Request 반환 테스트. - timestamp 누락 시 400 Bad Request 반환 테스트. * refactor: Transactional import를 jakarta에서 springframework로 변경 * refactor: logController에서 prefix logs는 RequestMapping을 사용하도록 수정 - `@RequestMapping("/logs")`와 `@PostMapping`을 사용하게 수정 * feat: Validation에서 message 추가하도록 변경 - LogController의 applicationId에 메세지 추가 - CreateLogRequest의 Validation에 메세지 추가 * feat: Log를 생성하는 of 정적 팩터리 메서드 추가 - LogService에서 Log를 생성 시 of 팩터리 메서드를 이용하도록 변경
🚀 개발 사항
1. Log 저장 기능 구현
2. LogService 구현 (Log 생성 및 저장 기능)
3. Controller 구현
4. 테스트 환경 구성
기타
이슈 번호
특이 사항 🫶
ControllerTestSuport
를 만들어 두었습니다. 주석을 참고하여 앞으로 사용하시면 됩니다!