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/#31 Log를 저장하는 API 구현 #34

Merged
merged 15 commits into from
Aug 13, 2024
Merged

Feat/#31 Log를 저장하는 API 구현 #34

merged 15 commits into from
Aug 13, 2024

Conversation

miiiinju1
Copy link
Member

@miiiinju1 miiiinju1 commented Aug 13, 2024

🚀 개발 사항

1. Log 저장 기능 구현

  • LogRepository 생성자 변경 (AllArgsConstructor → RequiredArgsConstructor)
  • CreateLogServiceRequest 레코드 추가

2. LogService 구현 (Log 생성 및 저장 기능)

  • LogService 단위 테스트 추가

3. Controller 구현

  • CreateLogRequest DTO 추가 (validation 포함)
  • CreateLogServiceRequest로 변환하는 정적 팩토리 메서드 구현
  • LogController 구현 (applicationId 및 CreateLogRequest validation 포함)
  • LogController 단위 테스트 추가

4. 테스트 환경 구성

  • ControllerTestSupport 추가로 Controller 테스트 환경 통합

기타

  • build.gradle에 validation 의존성 추가

이슈 번호

특이 사항 🫶

  • aee7b31: Controller Test 환경 통합용 ControllerTestSuport를 만들어 두었습니다. 주석을 참고하여 앞으로 사용하시면 됩니다!

- 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 반환 테스트.
@miiiinju1 miiiinju1 self-assigned this Aug 13, 2024
@miiiinju1 miiiinju1 requested a review from a team August 13, 2024 05:36
Copy link
Member

@tidavid1 tidavid1 left a comment

Choose a reason for hiding this comment

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

리뷰 확인해주세요!


private final LogService logService;

@PostMapping("/logs")
Copy link
Member

Choose a reason for hiding this comment

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

@RequestMapping 으로 처리하는게 좋아보입니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

좋아요!!

Comment on lines 24 to 25
@RequestHeader("app_id") @NotNull @Positive Long applicationId,
@Valid @RequestBody CreateLogRequest request
Copy link
Member

Choose a reason for hiding this comment

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

API 문서화 해주세여!

Copy link
Member Author

Choose a reason for hiding this comment

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

완료했습니당

Comment on lines 8 to 14
@NotBlank
String logLevel,

@NotBlank
String logData,

@NotNull
Copy link
Member

Choose a reason for hiding this comment

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

예외 메시지도 써주면 좋을 것 같습니다 :D

Copy link
Member Author

Choose a reason for hiding this comment

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

반영했습니다~~

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

@WebMVCTest vs @SpringBootTest

Copy link
Member Author

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에 메세지 추가
Copy link
Member

@tidavid1 tidavid1 left a comment

Choose a reason for hiding this comment

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

조아요

Copy link
Member

@LuizyHub LuizyHub left a comment

Choose a reason for hiding this comment

The 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,
Copy link
Member

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;
Copy link
Member

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 팩터리 메서드를 이용하도록 변경
@miiiinju1 miiiinju1 merged commit c4e8a1f into dev Aug 13, 2024
1 check passed
@miiiinju1 miiiinju1 deleted the feat/#31 branch August 13, 2024 06:27
miiiinju1 added a commit that referenced this pull request Aug 13, 2024
* 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 팩터리 메서드를 이용하도록 변경
@miiiinju1 miiiinju1 added the ⭐️ Feat 새로운 기능이나 요청 label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐️ Feat 새로운 기능이나 요청
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants