-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 크롬 익스텐션 공고 수집 API 추가 #107
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ava/com/jobdri/jobdri_api/domain/jobposting/controller/JobPostingExtensionController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.jobdri.jobdri_api.domain.jobposting.controller; | ||
|
|
||
| import com.jobdri.jobdri_api.domain.jobposting.dto.request.JobPostingExtensionIngestRequest; | ||
| import com.jobdri.jobdri_api.domain.jobposting.dto.response.JobPostingExtensionIngestResponse; | ||
| import com.jobdri.jobdri_api.domain.jobposting.service.JobPostingExtensionIngestService; | ||
| import com.jobdri.jobdri_api.domain.user.service.UserService; | ||
| import com.jobdri.jobdri_api.global.apiPayload.ApiResponse; | ||
| import com.jobdri.jobdri_api.global.security.UserDetailsImpl; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/job-postings/extension") | ||
| @Tag(name = "JobPosting Extension", description = "크롬 익스텐션 채용 공고 연계 API") | ||
| public class JobPostingExtensionController { | ||
|
|
||
| private final JobPostingExtensionIngestService jobPostingExtensionIngestService; | ||
| private final UserService userService; | ||
|
|
||
| @Operation( | ||
| summary = "크롬 익스텐션 공고 수집 및 모의 서류 생성", | ||
| description = "크롬 익스텐션이 크롤링한 채용 공고 원문을 기반으로 공고를 저장하고 모의 서류 지원을 생성합니다." | ||
| ) | ||
| @PostMapping(value = "/ingest", consumes = MediaType.APPLICATION_JSON_VALUE) | ||
| public ApiResponse<JobPostingExtensionIngestResponse> ingestFromExtension( | ||
| @AuthenticationPrincipal UserDetailsImpl userDetails, | ||
| @Valid @RequestBody JobPostingExtensionIngestRequest request | ||
| ) { | ||
| var user = userService.validateUser(userDetails == null ? null : userDetails.getUser()); | ||
| return ApiResponse.onSuccess( | ||
| "크롬 익스텐션 공고 수집에 성공했습니다.", | ||
| jobPostingExtensionIngestService.ingest(user, request) | ||
| ); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...com/jobdri/jobdri_api/domain/jobposting/dto/request/JobPostingExtensionIngestRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.jobdri.jobdri_api.domain.jobposting.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record JobPostingExtensionIngestRequest( | ||
| String sourceUrl, | ||
| String sourceSite, | ||
|
|
||
| @NotBlank(message = "크롤링한 공고 내용은 필수입니다.") | ||
| String rawText | ||
| ) { | ||
| } |
28 changes: 28 additions & 0 deletions
28
...m/jobdri/jobdri_api/domain/jobposting/dto/response/JobPostingExtensionIngestResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.jobdri.jobdri_api.domain.jobposting.dto.response; | ||
|
|
||
| import com.jobdri.jobdri_api.domain.mockapply.dto.response.MockApplyCreateResponse; | ||
|
|
||
| public record JobPostingExtensionIngestResponse( | ||
| String sourceUrl, | ||
| String sourceSite, | ||
| boolean savedToDatabase, | ||
| String message, | ||
| JobPostingIngestResponse ingest, | ||
| MockApplyCreateResponse mockApply | ||
| ) { | ||
| public static JobPostingExtensionIngestResponse of( | ||
| String sourceUrl, | ||
| String sourceSite, | ||
| JobPostingIngestResponse ingest, | ||
| MockApplyCreateResponse mockApply | ||
| ) { | ||
| return new JobPostingExtensionIngestResponse( | ||
| sourceUrl, | ||
| sourceSite, | ||
| ingest.isSavedToDatabase(), | ||
| ingest.getMessage(), | ||
| ingest, | ||
| mockApply | ||
| ); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
...ava/com/jobdri/jobdri_api/domain/jobposting/service/JobPostingExtensionIngestService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.jobdri.jobdri_api.domain.jobposting.service; | ||
|
|
||
| import com.jobdri.jobdri_api.domain.jobposting.dto.request.JobPostingExtensionIngestRequest; | ||
| import com.jobdri.jobdri_api.domain.jobposting.dto.request.JobPostingIngestRequest; | ||
| import com.jobdri.jobdri_api.domain.jobposting.dto.response.JobPostingExtensionIngestResponse; | ||
| import com.jobdri.jobdri_api.domain.jobposting.dto.response.JobPostingIngestResponse; | ||
| import com.jobdri.jobdri_api.domain.mockapply.dto.response.MockApplyCreateResponse; | ||
| import com.jobdri.jobdri_api.domain.mockapply.service.MockApplyService; | ||
| import com.jobdri.jobdri_api.domain.user.entity.User; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class JobPostingExtensionIngestService { | ||
|
|
||
| private final JobPostingIngestService jobPostingIngestService; | ||
| private final MockApplyService mockApplyService; | ||
|
|
||
| public JobPostingExtensionIngestResponse ingest(User user, JobPostingExtensionIngestRequest request) { | ||
| JobPostingIngestResponse ingest = jobPostingIngestService.ingestAndCreate( | ||
| user, | ||
| new JobPostingIngestRequest(request.rawText(), null) | ||
| ); | ||
|
|
||
| MockApplyCreateResponse mockApply = null; | ||
| if (ingest.isSavedToDatabase() && ingest.getSaved() != null) { | ||
| mockApply = mockApplyService.createMockApplyFromJobPosting( | ||
| user, | ||
| ingest.getSaved().getJobPostingId() | ||
| ); | ||
| } | ||
|
|
||
| return JobPostingExtensionIngestResponse.of( | ||
| request.sourceUrl(), | ||
| request.sourceSite(), | ||
| ingest, | ||
| mockApply | ||
| ); | ||
| } | ||
| } | ||
121 changes: 121 additions & 0 deletions
121
...com/jobdri/jobdri_api/domain/jobposting/service/JobPostingExtensionIngestServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package com.jobdri.jobdri_api.domain.jobposting.service; | ||
|
|
||
| import com.jobdri.jobdri_api.domain.jobposting.dto.request.JobPostingExtensionIngestRequest; | ||
| import com.jobdri.jobdri_api.domain.jobposting.dto.request.JobPostingIngestRequest; | ||
| import com.jobdri.jobdri_api.domain.jobposting.dto.response.JobPostingExtensionIngestResponse; | ||
| import com.jobdri.jobdri_api.domain.jobposting.dto.response.JobPostingIngestResponse; | ||
| import com.jobdri.jobdri_api.domain.jobposting.dto.response.JobPostingResponse; | ||
| import com.jobdri.jobdri_api.domain.mockapply.dto.response.MockApplyCreateResponse; | ||
| import com.jobdri.jobdri_api.domain.mockapply.entity.ApplyType; | ||
| import com.jobdri.jobdri_api.domain.mockapply.service.MockApplyService; | ||
| import com.jobdri.jobdri_api.domain.user.entity.User; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.springframework.test.util.ReflectionTestUtils; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class JobPostingExtensionIngestServiceTest { | ||
|
|
||
| @Mock | ||
| private JobPostingIngestService jobPostingIngestService; | ||
|
|
||
| @Mock | ||
| private MockApplyService mockApplyService; | ||
|
|
||
| @InjectMocks | ||
| private JobPostingExtensionIngestService jobPostingExtensionIngestService; | ||
|
|
||
| private User user; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| user = User.signup("테스트 사용자", "extension@example.com", "encoded-password"); | ||
| ReflectionTestUtils.setField(user, "id", 1L); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("익스텐션 공고 수집 성공 시 공고 저장 후 모의 서류 지원을 생성한다") | ||
| void ingestCreatesMockApplyWhenJobPostingSaved() { | ||
| JobPostingExtensionIngestRequest request = new JobPostingExtensionIngestRequest( | ||
| "https://www.wanted.co.kr/wd/123", | ||
| "WANTED", | ||
| "채용 공고 원문" | ||
| ); | ||
| JobPostingResponse saved = JobPostingResponse.builder() | ||
| .jobPostingId(10L) | ||
| .userId(1L) | ||
| .companyId(2L) | ||
| .companyName("테스트 회사") | ||
| .detailClassificationId(3L) | ||
| .detailClassificationName("백엔드 개발") | ||
| .task("주요 업무") | ||
| .requirement("자격 요건") | ||
| .preferred("우대 사항") | ||
| .build(); | ||
| JobPostingIngestResponse ingest = new JobPostingIngestResponse( | ||
| true, | ||
| "저장 성공", | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| saved | ||
| ); | ||
| MockApplyCreateResponse mockApply = new MockApplyCreateResponse(10L, 20L, ApplyType.MOCK, 1); | ||
|
|
||
| when(jobPostingIngestService.ingestAndCreate(eq(user), org.mockito.ArgumentMatchers.any(JobPostingIngestRequest.class))) | ||
| .thenReturn(ingest); | ||
| when(mockApplyService.createMockApplyFromJobPosting(user, 10L)) | ||
| .thenReturn(mockApply); | ||
|
|
||
| JobPostingExtensionIngestResponse response = jobPostingExtensionIngestService.ingest(user, request); | ||
|
|
||
| ArgumentCaptor<JobPostingIngestRequest> ingestRequestCaptor = ArgumentCaptor.forClass(JobPostingIngestRequest.class); | ||
| verify(jobPostingIngestService).ingestAndCreate(eq(user), ingestRequestCaptor.capture()); | ||
| assertThat(ingestRequestCaptor.getValue().rawText()).isEqualTo("채용 공고 원문"); | ||
| assertThat(ingestRequestCaptor.getValue().imageObjectKey()).isNull(); | ||
| assertThat(response.sourceUrl()).isEqualTo("https://www.wanted.co.kr/wd/123"); | ||
| assertThat(response.sourceSite()).isEqualTo("WANTED"); | ||
| assertThat(response.mockApply()).isEqualTo(mockApply); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("공고 저장이 보류되면 모의 서류 지원을 생성하지 않는다") | ||
| void ingestSkipsMockApplyWhenJobPostingNotSaved() { | ||
| JobPostingExtensionIngestRequest request = new JobPostingExtensionIngestRequest( | ||
| "https://www.wanted.co.kr/wd/123", | ||
| "WANTED", | ||
| "채용 공고 원문" | ||
| ); | ||
| JobPostingIngestResponse ingest = new JobPostingIngestResponse( | ||
| false, | ||
| "저장 보류", | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| null | ||
| ); | ||
|
|
||
| when(jobPostingIngestService.ingestAndCreate(eq(user), org.mockito.ArgumentMatchers.any(JobPostingIngestRequest.class))) | ||
| .thenReturn(ingest); | ||
|
|
||
| JobPostingExtensionIngestResponse response = jobPostingExtensionIngestService.ingest(user, request); | ||
|
|
||
| verify(mockApplyService, never()).createMockApplyFromJobPosting(org.mockito.ArgumentMatchers.any(), org.mockito.ArgumentMatchers.any()); | ||
| assertThat(response.savedToDatabase()).isFalse(); | ||
| assertThat(response.mockApply()).isNull(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🗄️ Data Integrity & Integration | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
Repository: JobDri-Developer/BackEnd
Length of output: 3872
Atomicity risk: Two write operations have no common transaction boundary.
ingest()triggers a persistence action viajobPostingIngestService.ingestAndCreate(...)followed bymockApplyService.createMockApplyFromJobPosting(...).Verification confirms that neither the orchestrator method nor the callee
ingestAndCreatehave a@Transactionalannotation. Furthermore,createMockApplyFromJobPostingis explicitly annotated with@Transactional(propagation = Propagation.NOT_SUPPORTED), forcing it to execute outside any transaction.This sequence lacks an atomic context: if the mock-apply creation fails after the job posting is saved, the system is left in an inconsistent state with the posting persisted but no associated mock application.
Enclose the orchestration in
@Transactionaland ensure the downstream service methods respect the transaction (or removePropagation.NOT_SUPPORTEDif the mock-apply step should participate in the caller's transaction).🤖 Prompt for AI Agents