-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 공고 저장, 저장취소 API 구현 #22
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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b058f41
[Comment] #20 LocalDate->OffsetDateTime으로 TODO 추가
jihoonkim501 9bf864a
[Feat] #20 JPA TimeProvider 추가
jihoonkim501 eed177f
[Fix] #20 크롤링 데이터 필요한 필드 수정
jihoonkim501 5f93567
[Feat] #20 공고 저장, 저장취소 API 기능 구현
jihoonkim501 e78cd0c
Merge branch 'develop' of https://github.com/Leets-Official/Job-is-BE…
jihoonkim501 5e995ed
[Fix] #20 TOCTOU 경쟁 조건 오류 수정
jihoonkim501 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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/leets7th/job_is_be/domain/job/controller/JobController.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,36 @@ | ||
| package com.leets7th.job_is_be.domain.job.controller; | ||
|
|
||
| import com.leets7th.job_is_be.domain.job.service.JobService; | ||
| import com.leets7th.job_is_be.global.response.ApiResponse; | ||
| import com.leets7th.job_is_be.global.status.SuccessStatus; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/jobs") | ||
| @RequiredArgsConstructor | ||
| public class JobController { | ||
|
|
||
| private final JobService jobService; | ||
|
|
||
| // TODO 인증 세팅 후 @AuthenticationPrincipal로 교체 | ||
| @PostMapping("/{jobId}/save") | ||
| public ResponseEntity<ApiResponse<Void>> saveJob( | ||
| @PathVariable Long jobId, | ||
| @RequestParam Long userId | ||
| ) { | ||
| jobService.saveJob(userId, jobId); | ||
| return ApiResponse.success(SuccessStatus.JOB_SAVE_SUCCESS); | ||
| } | ||
|
|
||
| // TODO 인증 세팅 후 @AuthenticationPrincipal로 교체 | ||
| @DeleteMapping("/{jobId}/save") | ||
| public ResponseEntity<ApiResponse<Void>> unsaveJob( | ||
| @PathVariable Long jobId, | ||
| @RequestParam Long userId | ||
| ) { | ||
| jobService.unsaveJob(userId, jobId); | ||
| return ApiResponse.success(SuccessStatus.JOB_UNSAVE_SUCCESS); | ||
| } | ||
| } | ||
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
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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/com/leets7th/job_is_be/domain/job/repository/SavedJobRepository.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,15 @@ | ||
| package com.leets7th.job_is_be.domain.job.repository; | ||
|
|
||
| import com.leets7th.job_is_be.domain.job.entity.SavedJob; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface SavedJobRepository extends JpaRepository<SavedJob, Long> { | ||
|
|
||
| boolean existsByUserIdAndJobId(Long userId, Long jobId); | ||
|
|
||
| Optional<SavedJob> findByUserIdAndJobId(Long userId, Long jobId); | ||
|
|
||
| void deleteByUserIdAndJobId(Long userId, Long jobId); | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/leets7th/job_is_be/domain/job/service/JobService.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,56 @@ | ||
| package com.leets7th.job_is_be.domain.job.service; | ||
|
|
||
| import com.leets7th.job_is_be.domain.job.entity.Job; | ||
| import com.leets7th.job_is_be.domain.job.entity.SavedJob; | ||
| import com.leets7th.job_is_be.domain.job.repository.JobRepository; | ||
| import com.leets7th.job_is_be.domain.job.repository.SavedJobRepository; | ||
| import com.leets7th.job_is_be.domain.user.entity.User; | ||
| import com.leets7th.job_is_be.domain.user.repository.UserRepository; | ||
| import com.leets7th.job_is_be.global.exception.GeneralException; | ||
| import com.leets7th.job_is_be.global.status.ErrorStatus; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.dao.DataIntegrityViolationException; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.OffsetDateTime; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class JobService { | ||
|
|
||
| private final JobRepository jobRepository; | ||
| private final SavedJobRepository savedJobRepository; | ||
| private final UserRepository userRepository; | ||
|
|
||
| @Transactional | ||
| public void saveJob(Long userId, Long jobId) { | ||
| if (savedJobRepository.existsByUserIdAndJobId(userId, jobId)) { | ||
| throw new GeneralException(ErrorStatus.JOB_ALREADY_SAVED); | ||
| } | ||
|
|
||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND)); | ||
| Job job = jobRepository.findById(jobId) | ||
| .orElseThrow(() -> new GeneralException(ErrorStatus.JOB_NOT_FOUND)); | ||
|
|
||
| try { | ||
| savedJobRepository.save(SavedJob.builder() | ||
| .user(user) | ||
| .job(job) | ||
| .savedAt(OffsetDateTime.now()) | ||
| .build()); | ||
| } catch (DataIntegrityViolationException e) { | ||
| throw new GeneralException(ErrorStatus.JOB_ALREADY_SAVED); | ||
| } | ||
| } | ||
|
jihoonkim501 marked this conversation as resolved.
|
||
|
|
||
| @Transactional | ||
| public void unsaveJob(Long userId, Long jobId) { | ||
| if (!savedJobRepository.existsByUserIdAndJobId(userId, jobId)) { | ||
| throw new GeneralException(ErrorStatus.JOB_NOT_SAVED); | ||
| } | ||
|
|
||
| savedJobRepository.deleteByUserIdAndJobId(userId, jobId); | ||
| } | ||
| } | ||
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
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
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
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
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
13 changes: 11 additions & 2 deletions
13
src/main/java/com/leets7th/job_is_be/global/config/JpaConfig.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 |
|---|---|---|
| @@ -1,10 +1,19 @@ | ||
| package com.leets7th.job_is_be.global.config; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.auditing.DateTimeProvider; | ||
| import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
|
||
| // BaseEntity의 @CreatedDate, @LastModifiedDate 활성화 | ||
| import java.time.OffsetDateTime; | ||
| import java.util.Optional; | ||
|
|
||
| @Configuration | ||
| @EnableJpaAuditing | ||
| @EnableJpaAuditing(dateTimeProviderRef = "offsetDateTimeProvider") | ||
| public class JpaConfig { | ||
|
|
||
| @Bean | ||
| public DateTimeProvider offsetDateTimeProvider() { | ||
| return () -> Optional.of(OffsetDateTime.now()); | ||
| } | ||
| } |
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
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
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.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
userId를@RequestParam으로 수신하면 IDOR 취약점이 발생합니다.TODO로 인증 적용 후
@AuthenticationPrincipal로 교체 예정인 것은 확인했습니다. 하지만 현재 상태로 배포하면 임의의userId를 쿼리 파라미터로 전달하여 다른 사용자의 공고 저장/취소를 조작할 수 있습니다. 인증 설정 전까지는 최소한 컨트롤러 단에서 세션/토큰 기반 사용자 검증을 수행하거나, 해당 엔드포인트를 비활성화하는 것을 권장합니다.🤖 Prompt for AI Agents