From 8fa1458f6fd1704931c6a25cfada88efae074164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A8=EB=9D=BC?= Date: Wed, 14 May 2025 18:15:59 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[#43]=20Refactor:=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=ED=95=9C=20=EA=B5=90=EC=9C=A1=EC=A0=95=EB=B3=B4=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/crawling/JobInfoCrawling.java | 86 ------------------- .../crawlingService/CrawlingService.java | 8 -- .../crawlingService/CrawlingServiceImpl.java | 29 ------- .../server/util/WebDriverUtil.java | 47 ---------- .../web/controller/CrawlingController.java | 29 ------- .../specification/CrawlingSpecification.java | 23 ----- .../dto/JobCrawlingDTO/JobCrawlingDTO.java | 24 ------ 7 files changed, 246 deletions(-) delete mode 100644 src/main/java/com/parentsgowork/server/crawling/JobInfoCrawling.java delete mode 100644 src/main/java/com/parentsgowork/server/service/crawlingService/CrawlingService.java delete mode 100644 src/main/java/com/parentsgowork/server/service/crawlingService/CrawlingServiceImpl.java delete mode 100644 src/main/java/com/parentsgowork/server/util/WebDriverUtil.java delete mode 100644 src/main/java/com/parentsgowork/server/web/controller/CrawlingController.java delete mode 100644 src/main/java/com/parentsgowork/server/web/controller/specification/CrawlingSpecification.java delete mode 100644 src/main/java/com/parentsgowork/server/web/dto/JobCrawlingDTO/JobCrawlingDTO.java diff --git a/src/main/java/com/parentsgowork/server/crawling/JobInfoCrawling.java b/src/main/java/com/parentsgowork/server/crawling/JobInfoCrawling.java deleted file mode 100644 index b5bf38d..0000000 --- a/src/main/java/com/parentsgowork/server/crawling/JobInfoCrawling.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.parentsgowork.server.crawling; - -import com.parentsgowork.server.apiPayload.code.status.ErrorStatus; -import com.parentsgowork.server.apiPayload.exception.JobInfoCrawlingHandler; -import com.parentsgowork.server.util.WebDriverUtil; -import com.parentsgowork.server.web.dto.JobCrawlingDTO.JobCrawlingDTO; -import org.openqa.selenium.*; -import org.springframework.stereotype.Component; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.List; - -@Component -public class JobInfoCrawling { - - public List crawlJobs(int page) { - WebDriver driver = WebDriverUtil.getChromeDriver(); - List jobs = new ArrayList<>(); - - try { - String url = "https://www.work24.go.kr/wk/a/b/1200/retriveDtlEmpSrchList.do?" + - "basicSetupYn=&careerTo=&keywordJobCd=&occupation=&seqNo=&cloDateEndtParam=&payGbn=&templateInfo=&rot2WorkYn=&shsyWorkSecd=&resultCnt=10" + - "&keywordJobCont=" + (page > 1 ? "N" : "") + - "&cert=&moreButtonYn=Y&minPay=&codeDepth2Info=11000¤tPageNo=1&eventNo=&mode=&major=&resrDutyExcYn=&eodwYn=&sortField=DATE&staArea=&sortOrderBy=DESC&keyword=&termSearchGbn=&carrEssYns=&benefitSrchAndOr=O&disableEmpHopeGbn=&actServExcYn=" + - "&keywordStaAreaNm=" + (page > 1 ? "N" : "") + - "&maxPay=&emailApplyYn=&codeDepth1Info=11000&keywordEtcYn=®DateStdtParam=&publDutyExcYn=&keywordJobCdSeqNo=&viewType=&exJobsCd=&templateDepthNmInfo=®ion=&employGbn=&empTpGbcd=1&computerPreferential=&infaYn=&cloDateStdtParam=&siteClcd=all&searchMode=Y" + - "&birthFromYY=&indArea=&careerTypes=&subEmpHopeYn=&tlmgYn=&academicGbn=&templateDepthNoInfo=&foriegn=&entryRoute=&mealOfferClcd=&basicSetupYnChk=&station=&holidayGbn=&srcKeyword=&academicGbnoEdu=noEdu&enterPriseGbn=&cloTermSearchGbn=&birthToYY=" + - "&keywordWantedTitle=" + (page > 1 ? "N" : "") + - "&stationNm=&benefitGbn=&keywordFlag=¬SrcKeyword=&essCertChk=&depth2SelCode=" + - "&keywordBusiNm=" + (page > 1 ? "N" : "") + - "&preferentialGbn=&rot3WorkYn=®DateEndtParam=&pfMatterPreferential=B" + - "&pageIndex=" + page + - "&termContractMmcnt=&careerFrom=&laborHrShortYn=#scrollLoc"; - - - driver.get(url); - driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); - - List jobCards = driver.findElements(By.cssSelector("tr[id^='list']")); - - for (WebElement card : jobCards) { - WebElement titleElement = card.findElement(By.cssSelector("a.t3_sb")); - String title = titleElement.getText(); - String detailUrl = titleElement.getAttribute("href"); - String company = card.findElement(By.cssSelector("a.cp_name")).getText(); - String pay = card.findElement(By.cssSelector("li.dollar span.item")).getText(); - String time = card.findElement(By.cssSelector("li.time span.item.sm:nth-of-type(1)")).getText(); - String location = card.findElement(By.cssSelector("li.site p")).getText(); - - String deadline = "", registrationDate = ""; - - List dateElements = card.findElements(By.cssSelector("p[class='s1_r']")); - if (dateElements.size() >= 2) { - deadline = dateElements.get(0).getText(); - registrationDate = dateElements.get(1).getText(); - } - - jobs.add( - JobCrawlingDTO.JobInfoDTO.builder() - .companyName(company) - .jobTitle(title) - .pay(pay) - .workTime(time) - .location(location) - .deadline(deadline) - .registrationDate(registrationDate) - .detailUrl(detailUrl) - .build() - ); - } - } catch (NoSuchElementException e) { - throw new JobInfoCrawlingHandler(ErrorStatus.CRAWLING_ELEMENT_NOT_FOUND); - } catch (TimeoutException e) { - throw new JobInfoCrawlingHandler(ErrorStatus.CRAWLING_TIMEOUT); - } catch (SessionNotCreatedException e) { - throw new JobInfoCrawlingHandler(ErrorStatus.CRAWLING_SESSION_FAIL); - } catch (Exception e) { - throw new JobInfoCrawlingHandler(ErrorStatus.CRAWLING_UNKNOWN_ERROR); - } finally { - WebDriverUtil.quit(driver); - } - - return jobs; - } -} diff --git a/src/main/java/com/parentsgowork/server/service/crawlingService/CrawlingService.java b/src/main/java/com/parentsgowork/server/service/crawlingService/CrawlingService.java deleted file mode 100644 index 78befab..0000000 --- a/src/main/java/com/parentsgowork/server/service/crawlingService/CrawlingService.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.parentsgowork.server.service.crawlingService; - -import com.parentsgowork.server.web.dto.JobCrawlingDTO.JobCrawlingDTO; -import java.util.List; - -public interface CrawlingService { - List getSeniorJobs(int page); -} diff --git a/src/main/java/com/parentsgowork/server/service/crawlingService/CrawlingServiceImpl.java b/src/main/java/com/parentsgowork/server/service/crawlingService/CrawlingServiceImpl.java deleted file mode 100644 index b4decca..0000000 --- a/src/main/java/com/parentsgowork/server/service/crawlingService/CrawlingServiceImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.parentsgowork.server.service.crawlingService; - -import com.parentsgowork.server.crawling.JobInfoCrawling; -import com.parentsgowork.server.web.dto.JobCrawlingDTO.JobCrawlingDTO; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -@RequiredArgsConstructor -public class CrawlingServiceImpl implements CrawlingService { - - private final JobInfoCrawling jobPageCrawling; - - @Override - public List getSeniorJobs(int page) { - List jobs = jobPageCrawling.crawlJobs(page); - - long startId = (long) (page - 1) * jobs.size() + 1; - - for (int i = 0; i < jobs.size(); i++) { - jobs.get(i).setId(startId + i); - } - - return jobs; - } - -} diff --git a/src/main/java/com/parentsgowork/server/util/WebDriverUtil.java b/src/main/java/com/parentsgowork/server/util/WebDriverUtil.java deleted file mode 100644 index 24ba143..0000000 --- a/src/main/java/com/parentsgowork/server/util/WebDriverUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.parentsgowork.server.util; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import org.springframework.util.ObjectUtils; - -import java.time.Duration; - -@Component -public class WebDriverUtil { - - private static String WEB_DRIVER_PATH; // WebDriver 경로 - - public static WebDriver getChromeDriver() { - if (ObjectUtils.isEmpty(System.getProperty("webdriver.chrome.driver"))) { - System.setProperty("webdriver.chrome.driver", WEB_DRIVER_PATH); - } - - // webDriver 옵션 설정 - ChromeOptions chromeOptions = new ChromeOptions(); - chromeOptions.addArguments("--headless"); - chromeOptions.addArguments("--lang=ko"); - chromeOptions.addArguments("--no-sandbox"); - chromeOptions.addArguments("--disable-dev-shm-usage"); - chromeOptions.addArguments("--disable-gpu"); - - WebDriver driver = new ChromeDriver(chromeOptions); - driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30)); - - return driver; - } - - @Value("${driver.chrome.driver_path}") - public void initDriver(String path){ - WEB_DRIVER_PATH = path; - } - - public static void quit(WebDriver driver) { - if (!ObjectUtils.isEmpty(driver)) { - driver.quit(); - } - } - -} diff --git a/src/main/java/com/parentsgowork/server/web/controller/CrawlingController.java b/src/main/java/com/parentsgowork/server/web/controller/CrawlingController.java deleted file mode 100644 index e780297..0000000 --- a/src/main/java/com/parentsgowork/server/web/controller/CrawlingController.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.parentsgowork.server.web.controller; - -import com.parentsgowork.server.apiPayload.ApiResponse; -import com.parentsgowork.server.service.crawlingService.CrawlingService; -import com.parentsgowork.server.web.controller.specification.CrawlingSpecification; -import com.parentsgowork.server.web.dto.JobCrawlingDTO.JobCrawlingDTO; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import org.springframework.boot.autoconfigure.batch.BatchProperties; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@Tag(name = "Crawler", description = "크롤링 API") -@RestController -@RequiredArgsConstructor -@RequestMapping("/crawler") -public class CrawlingController implements CrawlingSpecification { - - private final CrawlingService crawlingService; - - @Override - @GetMapping("/seniorJobs") - public ApiResponse> jobCrawler(@RequestParam(defaultValue = "1") int page) { - - List response = crawlingService.getSeniorJobs(page); - return ApiResponse.onSuccess(response); - } -} diff --git a/src/main/java/com/parentsgowork/server/web/controller/specification/CrawlingSpecification.java b/src/main/java/com/parentsgowork/server/web/controller/specification/CrawlingSpecification.java deleted file mode 100644 index 56cc478..0000000 --- a/src/main/java/com/parentsgowork/server/web/controller/specification/CrawlingSpecification.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.parentsgowork.server.web.controller.specification; - -import com.parentsgowork.server.apiPayload.ApiResponse; -import com.parentsgowork.server.web.dto.JobCrawlingDTO.JobCrawlingDTO; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import java.util.List; - -public interface CrawlingSpecification { - - @GetMapping("/seniorJobs") - @Operation(summary = "채용정보 크롤링", description = "우대 조건이 50세 이상인 채용 정보를 조회합니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) - }) - ApiResponse> jobCrawler(@RequestParam(defaultValue = "1") int page); -} diff --git a/src/main/java/com/parentsgowork/server/web/dto/JobCrawlingDTO/JobCrawlingDTO.java b/src/main/java/com/parentsgowork/server/web/dto/JobCrawlingDTO/JobCrawlingDTO.java deleted file mode 100644 index 8d07c99..0000000 --- a/src/main/java/com/parentsgowork/server/web/dto/JobCrawlingDTO/JobCrawlingDTO.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.parentsgowork.server.web.dto.JobCrawlingDTO; - - -import lombok.*; - -public class JobCrawlingDTO { - - @Data - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class JobInfoDTO { - private Long id; - private String companyName; - private String jobTitle; - private String pay; - private String workTime; - private String location; - private String deadline; - private String registrationDate; - private String detailUrl; - } - -} From 58172c68a624436c8df0cbbd4bd1404bd573ec03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A8=EB=9D=BC?= Date: Wed, 14 May 2025 18:16:04 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[#43]=20Refactor:=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=ED=95=9C=20=EA=B5=90=EC=9C=A1=EC=A0=95=EB=B3=B4=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiPayload/code/status/ErrorStatus.java | 14 ++----- .../server/converter/BookmarkConverter.java | 11 ++++++ .../server/repository/BookmarkRepository.java | 5 +++ .../BookmarkCommandService.java | 2 - .../BookmarkCommandServiceImpl.java | 38 +------------------ .../bookmarkService/BookmarkQueryService.java | 5 +-- .../BookmarkQueryServiceImpl.java | 20 ++++++---- .../web/controller/BookmarkController.java | 16 ++------ .../specification/BookmarkSpecification.java | 14 ++----- .../dto/BookmarkDTO/BookmarkResponseDTO.java | 10 +++++ 10 files changed, 50 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/parentsgowork/server/apiPayload/code/status/ErrorStatus.java b/src/main/java/com/parentsgowork/server/apiPayload/code/status/ErrorStatus.java index cc6b103..30e04f7 100644 --- a/src/main/java/com/parentsgowork/server/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/com/parentsgowork/server/apiPayload/code/status/ErrorStatus.java @@ -45,18 +45,10 @@ public enum ErrorStatus implements BaseErrorCode { EMAIL_SEND_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "AUTH5001", "이메일 전송에 실패했습니다."), EMAIL_ENCODING_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "AUTH5002", "이메일 내용 인코딩에 실패했습니다."), - // 크롤링 관련 에러 - CRAWLING_DRIVER_NOT_FOUND(HttpStatus.INTERNAL_SERVER_ERROR, "CRAWLING4001", "크롬 드라이버 경로가 설정되지 않았습니다."), - CRAWLING_PAGE_LOAD_FAIL(HttpStatus.INTERNAL_SERVER_ERROR,"CRAWLING4002", "페이지 로딩 중 오류가 발생했습니다."), - CRAWLING_ELEMENT_NOT_FOUND(HttpStatus.NOT_FOUND,"CRAWLING4003", "요소를 찾을 수 없습니다."), - CRAWLING_TIMEOUT(HttpStatus.INTERNAL_SERVER_ERROR,"CRAWLING4004", "페이지 로딩 시간이 초과되었습니다."), - CRAWLING_SESSION_FAIL(HttpStatus.INTERNAL_SERVER_ERROR,"CRAWLING4005", "크롬 드라이버 세션을 시작할 수 없습니다."), - CRAWLING_INVALID_SELECTOR(HttpStatus.BAD_REQUEST,"CRAWLING4006", "유효하지 않은 셀렉터입니다."), - CRAWLING_NO_RESULTS(HttpStatus.NOT_FOUND,"CRAWLING4007", "크롤링 결과가 존재하지 않습니다."), - CRAWLING_UNKNOWN_ERROR(HttpStatus.INTERNAL_SERVER_ERROR,"CRAWLING4008", "알 수 없는 크롤링 오류가 발생했습니다."), - // 북마크 관련 에러 - BOOKMARK_NOT_FOUND(HttpStatus.NOT_FOUND, "BOOKMARK4001", "북마크가 존재하지 않습니다."); + EDUCATION_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "BOOKMARK4001", "북마크한 교육정보가 존재하지 않습니다."), + POLICY_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "BOOKMARK4002", "북마크한 정책정보가 존재하지 않습니다."); + diff --git a/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java b/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java index 33a48b8..34a4f94 100644 --- a/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java +++ b/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java @@ -1,6 +1,7 @@ package com.parentsgowork.server.converter; import com.parentsgowork.server.domain.Bookmark; +import com.parentsgowork.server.domain.EducationInfo; import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; @@ -56,6 +57,16 @@ public static List getBookmarkListDTO(List< .collect(Collectors.toList()); } + public static List getEducationInfoListDTO(List educationInfos) { + return educationInfos.stream() + .map(education -> BookmarkResponseDTO.EducationInfoListDTO.builder() + .id(education.getId()) + .title(education.getTitle()) + .url(education.getUrl()) + .build()) + .collect(Collectors.toList()); + } + public static BookmarkResponseDTO.DeleteBookmarkDTO toDeletedBookmark(Bookmark bookmark) { return BookmarkResponseDTO.DeleteBookmarkDTO.builder() .id(bookmark.getId()) diff --git a/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java b/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java index 0eb9b92..210fca6 100644 --- a/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java +++ b/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java @@ -1,6 +1,7 @@ package com.parentsgowork.server.repository; import com.parentsgowork.server.domain.Bookmark; +import com.parentsgowork.server.domain.EducationInfo; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -14,5 +15,9 @@ public interface BookmarkRepository extends JpaRepository { "WHERE b. user.id = :userId") List findBookmarkList(@Param("userId") Long userId); + @Query("SELECT ei FROM EducationInfo ei " + + "WHERE ei. user.id = :userId") + List findEducationInfoList(@Param("userId") Long userId); + Optional findByIdAndUserId(@Param("bookmarkId") Long bookmarkId, @Param("userId") Long userId); } diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandService.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandService.java index 09c4cea..978fffc 100644 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandService.java +++ b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandService.java @@ -4,7 +4,5 @@ import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; public interface BookmarkCommandService { - BookmarkRequestDTO.SaveBookmarkDTO bookmarkJob(Long userId, Long jobId, int page); - BookmarkResponseDTO.DeleteBookmarkDTO delete(Long userId, Long bookmarkId); } diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandServiceImpl.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandServiceImpl.java index d024fa3..f23a83a 100644 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandServiceImpl.java +++ b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandServiceImpl.java @@ -8,55 +8,19 @@ import com.parentsgowork.server.domain.User; import com.parentsgowork.server.repository.BookmarkRepository; import com.parentsgowork.server.repository.UserRepository; -import com.parentsgowork.server.service.crawlingService.CrawlingService; import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; -import com.parentsgowork.server.web.dto.JobCrawlingDTO.JobCrawlingDTO.JobInfoDTO; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.List; @Service @RequiredArgsConstructor public class BookmarkCommandServiceImpl implements BookmarkCommandService { private final BookmarkRepository bookmarkRepository; - private final CrawlingService crawlingService; private final UserRepository userRepository; - @Override - public BookmarkRequestDTO.SaveBookmarkDTO bookmarkJob(Long userId, Long jobId, int page) { - - // 해당 페이지의 크롤링 결과 불러오기 - List crawledJobs = crawlingService.getSeniorJobs(page); - - // 해당 ID의 채용 정보 찾기 - JobInfoDTO job = crawledJobs.stream() - .filter(j -> j.getId().equals(jobId)) - .findFirst() - .orElseThrow(() -> new BookmarkHandler(ErrorStatus.CRAWLING_NO_RESULTS)); - - User user = userRepository.findById(userId) - .orElseThrow(() -> new UserHandler(ErrorStatus.USER_NOT_FOUND)); - - Bookmark bookmark = Bookmark.builder() - .user(user) - .jobId(jobId) - .companyName(job.getCompanyName()) - .jobTitle(job.getJobTitle()) - .pay(job.getPay()) - .time(job.getWorkTime()) - .location(job.getLocation()) - .deadline(job.getDeadline()) - .registrationDate(job.getRegistrationDate()) - .detailUrl(job.getDetailUrl()) - .build(); - - Bookmark savedBookmark = bookmarkRepository.save(bookmark); - return BookmarkConverter.toSaveBookmarkDTO(savedBookmark); - } - @Override public BookmarkResponseDTO.DeleteBookmarkDTO delete(Long userId, Long bookmarkId) { @@ -64,7 +28,7 @@ public BookmarkResponseDTO.DeleteBookmarkDTO delete(Long userId, Long bookmarkId .orElseThrow(() -> new UserHandler(ErrorStatus.USER_NOT_FOUND)); Bookmark bookmark = bookmarkRepository.findByIdAndUserId(bookmarkId, userId) - .orElseThrow(() -> new BookmarkHandler(ErrorStatus.BOOKMARK_NOT_FOUND)); + .orElseThrow(() -> new BookmarkHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND)); bookmarkRepository.deleteById(bookmarkId); diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java index d601c64..6efca8d 100644 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java +++ b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java @@ -1,12 +1,11 @@ package com.parentsgowork.server.service.bookmarkService; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; import java.util.List; public interface BookmarkQueryService { - List getBookmarkList(Long userId); - BookmarkResponseDTO.BookmarkDetailInfoDTO getBookmarkDetails(Long userId, Long bookmarkId); + + List getEducationInfoList(Long userId); } diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java index 0d39790..a3a86e1 100644 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java +++ b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java @@ -4,8 +4,8 @@ import com.parentsgowork.server.apiPayload.exception.BookmarkHandler; import com.parentsgowork.server.converter.BookmarkConverter; import com.parentsgowork.server.domain.Bookmark; +import com.parentsgowork.server.domain.EducationInfo; import com.parentsgowork.server.repository.BookmarkRepository; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,19 +19,23 @@ public class BookmarkQueryServiceImpl implements BookmarkQueryService { private final BookmarkRepository bookmarkRepository; @Override - public List getBookmarkList(Long userId) { + public BookmarkResponseDTO.BookmarkDetailInfoDTO getBookmarkDetails(Long userId, Long bookmarkId) { - List bookmarks = bookmarkRepository.findBookmarkList(userId); + Bookmark bookmark = bookmarkRepository.findByIdAndUserId(bookmarkId, userId) + .orElseThrow(() -> new BookmarkHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND)); - return BookmarkConverter.getBookmarkListDTO(bookmarks); + return BookmarkConverter.toDetailDTO(bookmark); } @Override - public BookmarkResponseDTO.BookmarkDetailInfoDTO getBookmarkDetails(Long userId, Long bookmarkId) { + public List getEducationInfoList(Long userId) { - Bookmark bookmark = bookmarkRepository.findByIdAndUserId(bookmarkId, userId) - .orElseThrow(() -> new BookmarkHandler(ErrorStatus.BOOKMARK_NOT_FOUND)); + List educationInfos = bookmarkRepository.findEducationInfoList(userId); - return BookmarkConverter.toDetailDTO(bookmark); + if(educationInfos == null || educationInfos.isEmpty()) { + throw new BookmarkHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND); + } + + return BookmarkConverter.getEducationInfoListDTO(educationInfos); } } diff --git a/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java b/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java index 5427e45..e94380c 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java +++ b/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java @@ -4,7 +4,6 @@ import com.parentsgowork.server.service.bookmarkService.BookmarkCommandService; import com.parentsgowork.server.service.bookmarkService.BookmarkQueryService; import com.parentsgowork.server.web.controller.specification.BookmarkSpecification; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -23,21 +22,12 @@ public class BookmarkController implements BookmarkSpecification { private final BookmarkCommandService bookmarkCommandService; private final BookmarkQueryService bookmarkQueryService; - @PostMapping("") - public ApiResponse bookmarkJob(@RequestBody BookmarkRequestDTO.jobInfoBookmarkDTO request) { + @GetMapping("/educationInfo") + public ApiResponse> getEducationInfoList() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Long userId = (Long) authentication.getPrincipal(); - BookmarkRequestDTO.SaveBookmarkDTO response = bookmarkCommandService.bookmarkJob(userId, request.getJobId(), request.getPage()); - return ApiResponse.onSuccess(response); - } - - @GetMapping("") - public ApiResponse> getBookmarkList() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - Long userId = (Long) authentication.getPrincipal(); - - List response = bookmarkQueryService.getBookmarkList(userId); + List response = bookmarkQueryService.getEducationInfoList(userId); return ApiResponse.onSuccess(response); } diff --git a/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java b/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java index e5bc7fc..f57014b 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java +++ b/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java @@ -14,21 +14,13 @@ public interface BookmarkSpecification { - @PostMapping("/") - @Operation(summary = "채용 정보 북마크", description = "저장하고 싶은 채용 정보를 북마크합니다.
" + "job 아이디와 페이지 값을 보내주세요.") + @GetMapping("") + @Operation(summary = "내가 저장한 교육정보 리스트 조회", description = "내가 저장한 교육정보 리스트를 조회합니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) - ApiResponse bookmarkJob(@RequestBody BookmarkRequestDTO.jobInfoBookmarkDTO request); - - @GetMapping("/") - @Operation(summary = "내가 저장한 북마크 리스트 조회", description = "내가 저장한 북마크 리스트를 조회합니다.") - @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) - }) - ApiResponse> getBookmarkList(); + ApiResponse> getEducationInfoList(); @GetMapping("{bookmarkId}") @Operation(summary = "특정 북마크 조회", description = "내가 저장한 북마크 중 특정 북마크를 조회합니다. bookmark 아이디 값을 보내주세요.") diff --git a/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java b/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java index c45bd27..bbf2f62 100644 --- a/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java +++ b/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java @@ -49,4 +49,14 @@ public static class DeleteBookmarkDTO { private String message; // ex) 북마크 삭제가 완료되었습니다. } + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class EducationInfoListDTO { + private Long id; + private String title; + private String url; + } + } From d9c17041a3189d01c25005eefff91ff51fbbf601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A8=EB=9D=BC?= Date: Wed, 14 May 2025 18:26:58 +0900 Subject: [PATCH 3/7] =?UTF-8?q?Refactor:=20=EB=82=B4=EA=B0=80=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=9C=20=EA=B5=90=EC=9C=A1=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/converter/BookmarkConverter.java | 56 +++---------------- .../server/repository/BookmarkRepository.java | 6 +- .../bookmarkService/BookmarkQueryService.java | 2 +- .../BookmarkQueryServiceImpl.java | 18 +++--- .../web/controller/BookmarkController.java | 6 +- .../specification/BookmarkSpecification.java | 8 +-- .../dto/BookmarkDTO/BookmarkResponseDTO.java | 38 +++---------- 7 files changed, 36 insertions(+), 98 deletions(-) diff --git a/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java b/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java index 34a4f94..8ef7a49 100644 --- a/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java +++ b/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java @@ -10,53 +10,6 @@ public class BookmarkConverter { - public static BookmarkRequestDTO.SaveBookmarkDTO toSaveBookmarkDTO(Bookmark bookmark) { - return BookmarkRequestDTO.SaveBookmarkDTO.builder() - .id(bookmark.getId()) - .jobId(bookmark.getJobId()) - .companyName(bookmark.getCompanyName()) - .jobTitle(bookmark.getJobTitle()) - .pay(bookmark.getPay()) - .time(bookmark.getTime()) - .location(bookmark.getLocation()) - .deadline(bookmark.getDeadline()) - .registrationDate(bookmark.getRegistrationDate()) - .detailUrl(bookmark.getDetailUrl()) - .build(); - } - - public static BookmarkResponseDTO.BookmarkDetailInfoDTO toDetailDTO(Bookmark bookmark) { - return BookmarkResponseDTO.BookmarkDetailInfoDTO.builder() - .id(bookmark.getId()) - .jobTitle(bookmark.getJobTitle()) - .companyName(bookmark.getCompanyName()) - .pay(bookmark.getPay()) - .time(bookmark.getTime()) - .location(bookmark.getLocation()) - .deadline(bookmark.getDeadline()) - .registrationDate(bookmark.getRegistrationDate()) - .detailUrl(bookmark.getDetailUrl()) - .build(); - } - - - public static List getBookmarkListDTO(List bookmarks) { - return bookmarks.stream() - .map(bookmark -> BookmarkResponseDTO.BookmarkListDTO.builder() - .id(bookmark.getId()) - .jobId(bookmark.getJobId()) - .companyName(bookmark.getCompanyName()) - .jobTitle(bookmark.getJobTitle()) - .pay(bookmark.getPay()) - .time(bookmark.getTime()) - .location(bookmark.getLocation()) - .deadline(bookmark.getDeadline()) - .registrationDate(bookmark.getRegistrationDate()) - .detailUrl(bookmark.getDetailUrl()) - .build()) - .collect(Collectors.toList()); - } - public static List getEducationInfoListDTO(List educationInfos) { return educationInfos.stream() .map(education -> BookmarkResponseDTO.EducationInfoListDTO.builder() @@ -67,6 +20,15 @@ public static List getEducationInfoLis .collect(Collectors.toList()); } + public static BookmarkResponseDTO.EducationInfoDetailDTO getEducationInfoDetailDTO(EducationInfo educationInfo) { + return BookmarkResponseDTO.EducationInfoDetailDTO.builder() + .id(educationInfo.getId()) + .title(educationInfo.getTitle()) + .url(educationInfo.getUrl()) + .build(); + } + + public static BookmarkResponseDTO.DeleteBookmarkDTO toDeletedBookmark(Bookmark bookmark) { return BookmarkResponseDTO.DeleteBookmarkDTO.builder() .id(bookmark.getId()) diff --git a/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java b/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java index 210fca6..319901a 100644 --- a/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java +++ b/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java @@ -11,13 +11,9 @@ public interface BookmarkRepository extends JpaRepository { - @Query("SELECT b FROM Bookmark b " + - "WHERE b. user.id = :userId") - List findBookmarkList(@Param("userId") Long userId); - @Query("SELECT ei FROM EducationInfo ei " + "WHERE ei. user.id = :userId") List findEducationInfoList(@Param("userId") Long userId); - Optional findByIdAndUserId(@Param("bookmarkId") Long bookmarkId, @Param("userId") Long userId); + Optional findByIdAndUserId(@Param("educationInfoId") Long educationInfoId, @Param("userId") Long userId); } diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java index 6efca8d..c7c396b 100644 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java +++ b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java @@ -5,7 +5,7 @@ import java.util.List; public interface BookmarkQueryService { - BookmarkResponseDTO.BookmarkDetailInfoDTO getBookmarkDetails(Long userId, Long bookmarkId); List getEducationInfoList(Long userId); + BookmarkResponseDTO.EducationInfoDetailDTO getEducationInfoDetails(Long userId, Long educationInfoId); } diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java index a3a86e1..2166ad8 100644 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java +++ b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java @@ -18,15 +18,6 @@ public class BookmarkQueryServiceImpl implements BookmarkQueryService { private final BookmarkRepository bookmarkRepository; - @Override - public BookmarkResponseDTO.BookmarkDetailInfoDTO getBookmarkDetails(Long userId, Long bookmarkId) { - - Bookmark bookmark = bookmarkRepository.findByIdAndUserId(bookmarkId, userId) - .orElseThrow(() -> new BookmarkHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND)); - - return BookmarkConverter.toDetailDTO(bookmark); - } - @Override public List getEducationInfoList(Long userId) { @@ -38,4 +29,13 @@ public List getEducationInfoList(Long return BookmarkConverter.getEducationInfoListDTO(educationInfos); } + + @Override + public BookmarkResponseDTO.EducationInfoDetailDTO getEducationInfoDetails(Long userId, Long educationInfoId) { + + EducationInfo educationInfo = bookmarkRepository.findByIdAndUserId(educationInfoId, userId) + .orElseThrow(() -> new BookmarkHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND)); + + return BookmarkConverter.getEducationInfoDetailDTO(educationInfo); + } } diff --git a/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java b/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java index e94380c..af9cb07 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java +++ b/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java @@ -31,12 +31,12 @@ public ApiResponse> getEducationI return ApiResponse.onSuccess(response); } - @GetMapping("{bookmarkId}") - public ApiResponse getBookmarkDetails(@PathVariable Long bookmarkId) { + @GetMapping("/educationInfo/{educationInfoId}") + public ApiResponse getEducationInfoDetails(@PathVariable Long educationInfoId) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Long userId = (Long) authentication.getPrincipal(); - BookmarkResponseDTO.BookmarkDetailInfoDTO response = bookmarkQueryService.getBookmarkDetails(userId, bookmarkId); + BookmarkResponseDTO.EducationInfoDetailDTO response = bookmarkQueryService.getEducationInfoDetails(userId, educationInfoId); return ApiResponse.onSuccess(response); } diff --git a/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java b/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java index f57014b..6392c92 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java +++ b/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java @@ -14,7 +14,7 @@ public interface BookmarkSpecification { - @GetMapping("") + @GetMapping("/educationInfo") @Operation(summary = "내가 저장한 교육정보 리스트 조회", description = "내가 저장한 교육정보 리스트를 조회합니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @@ -22,13 +22,13 @@ public interface BookmarkSpecification { }) ApiResponse> getEducationInfoList(); - @GetMapping("{bookmarkId}") - @Operation(summary = "특정 북마크 조회", description = "내가 저장한 북마크 중 특정 북마크를 조회합니다. bookmark 아이디 값을 보내주세요.") + @GetMapping("/educationInfo/{educationInfoId}") + @Operation(summary = "특정 교육정보 조회", description = "내가 저장한 교육정보 중 특정 교육정보를 조회합니다. bookmark 아이디 값을 보내주세요.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) - ApiResponse getBookmarkDetails(@PathVariable Long bookmarkId); + ApiResponse getEducationInfoDetails(@PathVariable Long educationInfoId); @DeleteMapping("{bookmarkId}") @Operation(summary = "내가 저장한 북마크 삭제", description = "내가 저장한 북마크 리스트를 삭제합니다.") diff --git a/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java b/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java index bbf2f62..d1f3008 100644 --- a/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java +++ b/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java @@ -7,37 +7,27 @@ public class BookmarkResponseDTO { + + // 저장한 교육정보 리스트 dto @Getter @Builder @NoArgsConstructor @AllArgsConstructor - public static class BookmarkListDTO { + public static class EducationInfoListDTO { private Long id; - private Long jobId; - private String companyName; - private String jobTitle; - private String pay; - private String time; - private String location; - private String deadline; - private String registrationDate; - private String detailUrl; + private String title; + private String url; } + // 저장한 교육정보 상세페이지 dto @Getter @Builder @NoArgsConstructor @AllArgsConstructor - public static class BookmarkDetailInfoDTO { + public static class EducationInfoDetailDTO { private Long id; - private String jobTitle; - private String companyName; - private String pay; - private String time; - private String location; - private String deadline; - private String registrationDate; - private String detailUrl; + private String title; + private String url; } @Getter @@ -49,14 +39,4 @@ public static class DeleteBookmarkDTO { private String message; // ex) 북마크 삭제가 완료되었습니다. } - @Getter - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class EducationInfoListDTO { - private Long id; - private String title; - private String url; - } - } From c5caa61540097811f1fe0b2c33164d65de3c04b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A8=EB=9D=BC?= Date: Wed, 14 May 2025 18:55:42 +0900 Subject: [PATCH 4/7] =?UTF-8?q?Refactor:=20=EA=B5=90=EC=9C=A1=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EA=B4=80=EB=A0=A8=20Bookmark=20->=20EducaitonInfo?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20=EB=B0=8F=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiPayload/exception/BookmarkHandler.java | 10 ----- .../server/converter/BookmarkConverter.java | 38 ----------------- .../server/repository/BookmarkRepository.java | 19 --------- .../BookmarkCommandService.java | 8 ---- .../BookmarkCommandServiceImpl.java | 37 ---------------- .../bookmarkService/BookmarkQueryService.java | 11 ----- .../BookmarkQueryServiceImpl.java | 41 ------------------ ...ller.java => EducationInfoController.java} | 6 +-- ...n.java => EducationInfoSpecification.java} | 6 +-- .../dto/BookmarkDTO/BookmarkRequestDTO.java | 35 ---------------- .../dto/BookmarkDTO/BookmarkResponseDTO.java | 42 ------------------- 11 files changed, 6 insertions(+), 247 deletions(-) delete mode 100644 src/main/java/com/parentsgowork/server/apiPayload/exception/BookmarkHandler.java delete mode 100644 src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java delete mode 100644 src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java delete mode 100644 src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandService.java delete mode 100644 src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandServiceImpl.java delete mode 100644 src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java delete mode 100644 src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java rename src/main/java/com/parentsgowork/server/web/controller/{BookmarkController.java => EducationInfoController.java} (91%) rename src/main/java/com/parentsgowork/server/web/controller/specification/{BookmarkSpecification.java => EducationInfoSpecification.java} (88%) delete mode 100644 src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkRequestDTO.java delete mode 100644 src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java diff --git a/src/main/java/com/parentsgowork/server/apiPayload/exception/BookmarkHandler.java b/src/main/java/com/parentsgowork/server/apiPayload/exception/BookmarkHandler.java deleted file mode 100644 index cce4d2a..0000000 --- a/src/main/java/com/parentsgowork/server/apiPayload/exception/BookmarkHandler.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.parentsgowork.server.apiPayload.exception; - -import com.parentsgowork.server.apiPayload.code.BaseErrorCode; - -public class BookmarkHandler extends GeneralException { - public BookmarkHandler(BaseErrorCode code) { - super(code); - } - -} diff --git a/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java b/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java deleted file mode 100644 index 8ef7a49..0000000 --- a/src/main/java/com/parentsgowork/server/converter/BookmarkConverter.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.parentsgowork.server.converter; - -import com.parentsgowork.server.domain.Bookmark; -import com.parentsgowork.server.domain.EducationInfo; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; - -import java.util.List; -import java.util.stream.Collectors; - -public class BookmarkConverter { - - public static List getEducationInfoListDTO(List educationInfos) { - return educationInfos.stream() - .map(education -> BookmarkResponseDTO.EducationInfoListDTO.builder() - .id(education.getId()) - .title(education.getTitle()) - .url(education.getUrl()) - .build()) - .collect(Collectors.toList()); - } - - public static BookmarkResponseDTO.EducationInfoDetailDTO getEducationInfoDetailDTO(EducationInfo educationInfo) { - return BookmarkResponseDTO.EducationInfoDetailDTO.builder() - .id(educationInfo.getId()) - .title(educationInfo.getTitle()) - .url(educationInfo.getUrl()) - .build(); - } - - - public static BookmarkResponseDTO.DeleteBookmarkDTO toDeletedBookmark(Bookmark bookmark) { - return BookmarkResponseDTO.DeleteBookmarkDTO.builder() - .id(bookmark.getId()) - .message("북마크를 삭제했습니다.") - .build(); - } -} diff --git a/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java b/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java deleted file mode 100644 index 319901a..0000000 --- a/src/main/java/com/parentsgowork/server/repository/BookmarkRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.parentsgowork.server.repository; - -import com.parentsgowork.server.domain.Bookmark; -import com.parentsgowork.server.domain.EducationInfo; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; -import java.util.Optional; - -public interface BookmarkRepository extends JpaRepository { - - @Query("SELECT ei FROM EducationInfo ei " + - "WHERE ei. user.id = :userId") - List findEducationInfoList(@Param("userId") Long userId); - - Optional findByIdAndUserId(@Param("educationInfoId") Long educationInfoId, @Param("userId") Long userId); -} diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandService.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandService.java deleted file mode 100644 index 978fffc..0000000 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandService.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.parentsgowork.server.service.bookmarkService; - -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; - -public interface BookmarkCommandService { - BookmarkResponseDTO.DeleteBookmarkDTO delete(Long userId, Long bookmarkId); -} diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandServiceImpl.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandServiceImpl.java deleted file mode 100644 index f23a83a..0000000 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkCommandServiceImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.parentsgowork.server.service.bookmarkService; - -import com.parentsgowork.server.apiPayload.code.status.ErrorStatus; -import com.parentsgowork.server.apiPayload.exception.BookmarkHandler; -import com.parentsgowork.server.apiPayload.exception.UserHandler; -import com.parentsgowork.server.converter.BookmarkConverter; -import com.parentsgowork.server.domain.Bookmark; -import com.parentsgowork.server.domain.User; -import com.parentsgowork.server.repository.BookmarkRepository; -import com.parentsgowork.server.repository.UserRepository; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - - -@Service -@RequiredArgsConstructor -public class BookmarkCommandServiceImpl implements BookmarkCommandService { - - private final BookmarkRepository bookmarkRepository; - private final UserRepository userRepository; - - @Override - public BookmarkResponseDTO.DeleteBookmarkDTO delete(Long userId, Long bookmarkId) { - - userRepository.findById(userId) - .orElseThrow(() -> new UserHandler(ErrorStatus.USER_NOT_FOUND)); - - Bookmark bookmark = bookmarkRepository.findByIdAndUserId(bookmarkId, userId) - .orElseThrow(() -> new BookmarkHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND)); - - bookmarkRepository.deleteById(bookmarkId); - - return BookmarkConverter.toDeletedBookmark(bookmark); - } -} diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java deleted file mode 100644 index c7c396b..0000000 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.parentsgowork.server.service.bookmarkService; - -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; - -import java.util.List; - -public interface BookmarkQueryService { - - List getEducationInfoList(Long userId); - BookmarkResponseDTO.EducationInfoDetailDTO getEducationInfoDetails(Long userId, Long educationInfoId); -} diff --git a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java b/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java deleted file mode 100644 index 2166ad8..0000000 --- a/src/main/java/com/parentsgowork/server/service/bookmarkService/BookmarkQueryServiceImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.parentsgowork.server.service.bookmarkService; - -import com.parentsgowork.server.apiPayload.code.status.ErrorStatus; -import com.parentsgowork.server.apiPayload.exception.BookmarkHandler; -import com.parentsgowork.server.converter.BookmarkConverter; -import com.parentsgowork.server.domain.Bookmark; -import com.parentsgowork.server.domain.EducationInfo; -import com.parentsgowork.server.repository.BookmarkRepository; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -@RequiredArgsConstructor -public class BookmarkQueryServiceImpl implements BookmarkQueryService { - - private final BookmarkRepository bookmarkRepository; - - @Override - public List getEducationInfoList(Long userId) { - - List educationInfos = bookmarkRepository.findEducationInfoList(userId); - - if(educationInfos == null || educationInfos.isEmpty()) { - throw new BookmarkHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND); - } - - return BookmarkConverter.getEducationInfoListDTO(educationInfos); - } - - @Override - public BookmarkResponseDTO.EducationInfoDetailDTO getEducationInfoDetails(Long userId, Long educationInfoId) { - - EducationInfo educationInfo = bookmarkRepository.findByIdAndUserId(educationInfoId, userId) - .orElseThrow(() -> new BookmarkHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND)); - - return BookmarkConverter.getEducationInfoDetailDTO(educationInfo); - } -} diff --git a/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java b/src/main/java/com/parentsgowork/server/web/controller/EducationInfoController.java similarity index 91% rename from src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java rename to src/main/java/com/parentsgowork/server/web/controller/EducationInfoController.java index af9cb07..5e8b6ea 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/BookmarkController.java +++ b/src/main/java/com/parentsgowork/server/web/controller/EducationInfoController.java @@ -40,12 +40,12 @@ public ApiResponse getEducationInfoD return ApiResponse.onSuccess(response); } - @DeleteMapping("{bookmarkId}") - public ApiResponse deleteBookmark(@PathVariable("bookmarkId") Long bookmarkId) { + @DeleteMapping("/educationInfo/{educationInfoId}") + public ApiResponse deleteBookmark(@PathVariable("educationInfoId") Long educationInfoId) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Long userId = (Long) authentication.getPrincipal(); - BookmarkResponseDTO.DeleteBookmarkDTO deleteBookmark = bookmarkCommandService.delete(bookmarkId, userId); + BookmarkResponseDTO.DeleteBookmarkDTO deleteBookmark = bookmarkCommandService.delete(educationInfoId, userId); return ApiResponse.onSuccess(deleteBookmark); } } diff --git a/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java b/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java similarity index 88% rename from src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java rename to src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java index 6392c92..1809428 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/specification/BookmarkSpecification.java +++ b/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java @@ -30,12 +30,12 @@ public interface BookmarkSpecification { }) ApiResponse getEducationInfoDetails(@PathVariable Long educationInfoId); - @DeleteMapping("{bookmarkId}") - @Operation(summary = "내가 저장한 북마크 삭제", description = "내가 저장한 북마크 리스트를 삭제합니다.") + @DeleteMapping("/educationInfo/{educationInfoId}") + @Operation(summary = "내가 저장한 교육정보 삭제", description = "내가 저장한 교육정보 리스트 중 특정 교육정보를 삭제합니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) - ApiResponse deleteBookmark(@PathVariable("bookmarkId") Long bookmarkId); + ApiResponse deleteBookmark(@PathVariable("educationInfoId") Long educationInfoId); } diff --git a/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkRequestDTO.java b/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkRequestDTO.java deleted file mode 100644 index 1ab0724..0000000 --- a/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkRequestDTO.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.parentsgowork.server.web.dto.BookmarkDTO; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -public class BookmarkRequestDTO { - @Getter - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class jobInfoBookmarkDTO { - private Long jobId; - private Integer page; - } - - @Getter - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class SaveBookmarkDTO { - private Long id; - private Long jobId; - private String companyName; - private String jobTitle; - private String pay; - private String time; - private String location; - private String deadline; - private String registrationDate; - private String detailUrl; - } - -} diff --git a/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java b/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java deleted file mode 100644 index d1f3008..0000000 --- a/src/main/java/com/parentsgowork/server/web/dto/BookmarkDTO/BookmarkResponseDTO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.parentsgowork.server.web.dto.BookmarkDTO; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -public class BookmarkResponseDTO { - - - // 저장한 교육정보 리스트 dto - @Getter - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class EducationInfoListDTO { - private Long id; - private String title; - private String url; - } - - // 저장한 교육정보 상세페이지 dto - @Getter - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class EducationInfoDetailDTO { - private Long id; - private String title; - private String url; - } - - @Getter - @Builder - @NoArgsConstructor - @AllArgsConstructor - public static class DeleteBookmarkDTO { - private Long id; - private String message; // ex) 북마크 삭제가 완료되었습니다. - } - -} From 8fd1694be2b6f951ba81023a6aee429b0cdc96de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A8=EB=9D=BC?= Date: Wed, 14 May 2025 18:55:46 +0900 Subject: [PATCH 5/7] =?UTF-8?q?Refactor:=20=EA=B5=90=EC=9C=A1=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EA=B4=80=EB=A0=A8=20Bookmark=20->=20EducaitonInfo?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20=EB=B0=8F=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiPayload/code/status/ErrorStatus.java | 2 +- .../exception/EducationInfoHandler.java | 9 ++++ .../converter/EducationInfoConverter.java | 36 ++++++++++++++++ .../repository/EducationInfoRepository.java | 17 ++++++++ .../EducationInfoCommandService.java | 8 ++++ .../EducationInfoCommandServiceImpl.java | 34 +++++++++++++++ .../EducationInfoQueryService.java | 10 +++++ .../EducationInfoQueryServiceImpl.java | 40 ++++++++++++++++++ .../controller/EducationInfoController.java | 38 ++++++++--------- .../EducationInfoSpecification.java | 18 ++++---- .../EducationInfoRequestDTO.java | 4 ++ .../EducationInfoResponseDTO.java | 41 +++++++++++++++++++ 12 files changed, 227 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/parentsgowork/server/apiPayload/exception/EducationInfoHandler.java create mode 100644 src/main/java/com/parentsgowork/server/converter/EducationInfoConverter.java create mode 100644 src/main/java/com/parentsgowork/server/repository/EducationInfoRepository.java create mode 100644 src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoCommandService.java create mode 100644 src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoCommandServiceImpl.java create mode 100644 src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoQueryService.java create mode 100644 src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoQueryServiceImpl.java create mode 100644 src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoRequestDTO.java create mode 100644 src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoResponseDTO.java diff --git a/src/main/java/com/parentsgowork/server/apiPayload/code/status/ErrorStatus.java b/src/main/java/com/parentsgowork/server/apiPayload/code/status/ErrorStatus.java index 30e04f7..dc3fa6d 100644 --- a/src/main/java/com/parentsgowork/server/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/com/parentsgowork/server/apiPayload/code/status/ErrorStatus.java @@ -17,7 +17,7 @@ public enum ErrorStatus implements BaseErrorCode { _FORBIDDEN(HttpStatus.FORBIDDEN, "COMMON403", "금지된 요청입니다."), //멤버 관련 에러 - USER_NOT_FOUND(HttpStatus.UNAUTHORIZED, "USER4001", "이메일 또는 패스워드가 일치하지 않습니다."), + USER_NOT_FOUND(HttpStatus.NOT_FOUND, "USER4001", "회원을 찾을 수 없습니다."), EMAIL_ALREADY_EXISTS(HttpStatus.CONFLICT, "USER4002", "이미 존재하는 이메일입니다."), USER_STATUS_INACTIVE(HttpStatus.FORBIDDEN, "USER4003", "탈퇴한 회원입니다."), diff --git a/src/main/java/com/parentsgowork/server/apiPayload/exception/EducationInfoHandler.java b/src/main/java/com/parentsgowork/server/apiPayload/exception/EducationInfoHandler.java new file mode 100644 index 0000000..45be984 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/apiPayload/exception/EducationInfoHandler.java @@ -0,0 +1,9 @@ +package com.parentsgowork.server.apiPayload.exception; + +import com.parentsgowork.server.apiPayload.code.BaseErrorCode; + +public class EducationInfoHandler extends GeneralException { + public EducationInfoHandler(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/parentsgowork/server/converter/EducationInfoConverter.java b/src/main/java/com/parentsgowork/server/converter/EducationInfoConverter.java new file mode 100644 index 0000000..bed2075 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/converter/EducationInfoConverter.java @@ -0,0 +1,36 @@ +package com.parentsgowork.server.converter; + +import com.parentsgowork.server.domain.EducationInfo; +import com.parentsgowork.server.web.dto.EducationInfoDTO.EducationInfoResponseDTO; + +import java.util.List; +import java.util.stream.Collectors; + +public class EducationInfoConverter { + + public static List getEducationInfoListDTO(List educationInfos) { + return educationInfos.stream() + .map(education -> EducationInfoResponseDTO.EducationInfoListDTO.builder() + .id(education.getId()) + .title(education.getTitle()) + .url(education.getUrl()) + .build()) + .collect(Collectors.toList()); + } + + public static EducationInfoResponseDTO.EducationInfoDetailDTO getEducationInfoDetailDTO(EducationInfo educationInfo) { + return EducationInfoResponseDTO.EducationInfoDetailDTO.builder() + .id(educationInfo.getId()) + .title(educationInfo.getTitle()) + .url(educationInfo.getUrl()) + .build(); + } + + + public static EducationInfoResponseDTO.DeleteEducationInfoDTO DeleteEducationInfoDTO(EducationInfo educationInfo) { + return EducationInfoResponseDTO.DeleteEducationInfoDTO.builder() + .id(educationInfo.getId()) + .message("저장한 교육정보를 삭제하였습니다.") + .build(); + } +} diff --git a/src/main/java/com/parentsgowork/server/repository/EducationInfoRepository.java b/src/main/java/com/parentsgowork/server/repository/EducationInfoRepository.java new file mode 100644 index 0000000..dbb383b --- /dev/null +++ b/src/main/java/com/parentsgowork/server/repository/EducationInfoRepository.java @@ -0,0 +1,17 @@ +package com.parentsgowork.server.repository; + +import com.parentsgowork.server.domain.EducationInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; +import java.util.Optional; + +public interface EducationInfoRepository extends JpaRepository { + @Query("SELECT ei FROM EducationInfo ei " + + "WHERE ei. user.id = :userId") + List findEducationInfoList(@Param("userId") Long userId); + + Optional findByIdAndUserId(@Param("educationInfoId") Long educationInfoId, @Param("userId") Long userId); +} diff --git a/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoCommandService.java b/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoCommandService.java new file mode 100644 index 0000000..9f41423 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoCommandService.java @@ -0,0 +1,8 @@ +package com.parentsgowork.server.service.educationInfoService; + +import com.parentsgowork.server.web.dto.EducationInfoDTO.EducationInfoResponseDTO; + +public interface EducationInfoCommandService { + EducationInfoResponseDTO.DeleteEducationInfoDTO delete(Long userId, Long educationInfoId); + +} diff --git a/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoCommandServiceImpl.java b/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoCommandServiceImpl.java new file mode 100644 index 0000000..a6653c6 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoCommandServiceImpl.java @@ -0,0 +1,34 @@ +package com.parentsgowork.server.service.educationInfoService; + +import com.parentsgowork.server.apiPayload.code.status.ErrorStatus; +import com.parentsgowork.server.apiPayload.exception.EducationInfoHandler; +import com.parentsgowork.server.apiPayload.exception.UserHandler; +import com.parentsgowork.server.converter.EducationInfoConverter; +import com.parentsgowork.server.domain.EducationInfo; +import com.parentsgowork.server.repository.EducationInfoRepository; +import com.parentsgowork.server.repository.UserRepository; +import com.parentsgowork.server.web.dto.EducationInfoDTO.EducationInfoResponseDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class EducationInfoCommandServiceImpl implements EducationInfoCommandService { + + private final EducationInfoRepository educationInfoRepository; + private final UserRepository userRepository; + + @Override + public EducationInfoResponseDTO.DeleteEducationInfoDTO delete(Long userId, Long educationInfoId) { + + userRepository.findById(userId) + .orElseThrow(() -> new UserHandler(ErrorStatus.USER_NOT_FOUND)); + + EducationInfo educationInfo = educationInfoRepository.findByIdAndUserId(educationInfoId, userId) + .orElseThrow(() -> new EducationInfoHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND)); + + educationInfoRepository.deleteById(educationInfoId); + + return EducationInfoConverter.DeleteEducationInfoDTO(educationInfo); + } +} diff --git a/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoQueryService.java b/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoQueryService.java new file mode 100644 index 0000000..83d304a --- /dev/null +++ b/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoQueryService.java @@ -0,0 +1,10 @@ +package com.parentsgowork.server.service.educationInfoService; + +import com.parentsgowork.server.web.dto.EducationInfoDTO.EducationInfoResponseDTO; + +import java.util.List; + +public interface EducationInfoQueryService { + List getEducationInfoList(Long userId); + EducationInfoResponseDTO.EducationInfoDetailDTO getEducationInfoDetails(Long userId, Long educationInfoId); +} diff --git a/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoQueryServiceImpl.java b/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoQueryServiceImpl.java new file mode 100644 index 0000000..c96440c --- /dev/null +++ b/src/main/java/com/parentsgowork/server/service/educationInfoService/EducationInfoQueryServiceImpl.java @@ -0,0 +1,40 @@ +package com.parentsgowork.server.service.educationInfoService; + +import com.parentsgowork.server.apiPayload.code.status.ErrorStatus; +import com.parentsgowork.server.apiPayload.exception.EducationInfoHandler; +import com.parentsgowork.server.converter.EducationInfoConverter; +import com.parentsgowork.server.domain.EducationInfo; +import com.parentsgowork.server.repository.EducationInfoRepository; +import com.parentsgowork.server.web.dto.EducationInfoDTO.EducationInfoResponseDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class EducationInfoQueryServiceImpl implements EducationInfoQueryService { + + private final EducationInfoRepository educationInfoRepository; + + @Override + public List getEducationInfoList(Long userId) { + + List educationInfos = educationInfoRepository.findEducationInfoList(userId); + + if(educationInfos == null || educationInfos.isEmpty()) { + throw new EducationInfoHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND); + } + + return EducationInfoConverter.getEducationInfoListDTO(educationInfos); + } + + @Override + public EducationInfoResponseDTO.EducationInfoDetailDTO getEducationInfoDetails(Long userId, Long educationInfoId) { + + EducationInfo educationInfo = educationInfoRepository.findByIdAndUserId(educationInfoId, userId) + .orElseThrow(() -> new EducationInfoHandler(ErrorStatus.EDUCATION_INFO_NOT_FOUND)); + + return EducationInfoConverter.getEducationInfoDetailDTO(educationInfo); + } +} \ No newline at end of file diff --git a/src/main/java/com/parentsgowork/server/web/controller/EducationInfoController.java b/src/main/java/com/parentsgowork/server/web/controller/EducationInfoController.java index 5e8b6ea..be49453 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/EducationInfoController.java +++ b/src/main/java/com/parentsgowork/server/web/controller/EducationInfoController.java @@ -1,10 +1,10 @@ package com.parentsgowork.server.web.controller; import com.parentsgowork.server.apiPayload.ApiResponse; -import com.parentsgowork.server.service.bookmarkService.BookmarkCommandService; -import com.parentsgowork.server.service.bookmarkService.BookmarkQueryService; -import com.parentsgowork.server.web.controller.specification.BookmarkSpecification; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; +import com.parentsgowork.server.service.educationInfoService.EducationInfoCommandService; +import com.parentsgowork.server.service.educationInfoService.EducationInfoQueryService; +import com.parentsgowork.server.web.controller.specification.EducationInfoSpecification; +import com.parentsgowork.server.web.dto.EducationInfoDTO.EducationInfoResponseDTO; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.security.core.Authentication; @@ -13,39 +13,39 @@ import java.util.List; -@Tag(name = "Bookmark", description = "북마크 API") +@Tag(name = "EducationInfo", description = "교육정보 API") @RestController @RequiredArgsConstructor -@RequestMapping("/bookmark") -public class BookmarkController implements BookmarkSpecification { +@RequestMapping("/educationInfo") +public class EducationInfoController implements EducationInfoSpecification { - private final BookmarkCommandService bookmarkCommandService; - private final BookmarkQueryService bookmarkQueryService; + private final EducationInfoCommandService educationInfoCommandService; + private final EducationInfoQueryService educationInfoQueryService; - @GetMapping("/educationInfo") - public ApiResponse> getEducationInfoList() { + @GetMapping("") + public ApiResponse> getEducationInfoList() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Long userId = (Long) authentication.getPrincipal(); - List response = bookmarkQueryService.getEducationInfoList(userId); + List response = educationInfoQueryService.getEducationInfoList(userId); return ApiResponse.onSuccess(response); } - @GetMapping("/educationInfo/{educationInfoId}") - public ApiResponse getEducationInfoDetails(@PathVariable Long educationInfoId) { + @GetMapping("/{educationInfoId}") + public ApiResponse getEducationInfoDetails(@PathVariable Long educationInfoId) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Long userId = (Long) authentication.getPrincipal(); - BookmarkResponseDTO.EducationInfoDetailDTO response = bookmarkQueryService.getEducationInfoDetails(userId, educationInfoId); + EducationInfoResponseDTO.EducationInfoDetailDTO response = educationInfoQueryService.getEducationInfoDetails(userId, educationInfoId); return ApiResponse.onSuccess(response); } - @DeleteMapping("/educationInfo/{educationInfoId}") - public ApiResponse deleteBookmark(@PathVariable("educationInfoId") Long educationInfoId) { + @DeleteMapping("/{educationInfoId}") + public ApiResponse deleteEducationInfo(@PathVariable("educationInfoId") Long educationInfoId) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Long userId = (Long) authentication.getPrincipal(); - BookmarkResponseDTO.DeleteBookmarkDTO deleteBookmark = bookmarkCommandService.delete(educationInfoId, userId); - return ApiResponse.onSuccess(deleteBookmark); + EducationInfoResponseDTO.DeleteEducationInfoDTO response = educationInfoCommandService.delete(educationInfoId, userId); + return ApiResponse.onSuccess(response); } } diff --git a/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java b/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java index 1809428..fec14a3 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java +++ b/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java @@ -1,9 +1,7 @@ package com.parentsgowork.server.web.controller.specification; import com.parentsgowork.server.apiPayload.ApiResponse; -import com.parentsgowork.server.domain.Bookmark; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkRequestDTO; -import com.parentsgowork.server.web.dto.BookmarkDTO.BookmarkResponseDTO; +import com.parentsgowork.server.web.dto.EducationInfoDTO.EducationInfoResponseDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -12,30 +10,30 @@ import java.util.List; -public interface BookmarkSpecification { +public interface EducationInfoSpecification { - @GetMapping("/educationInfo") + @GetMapping("") @Operation(summary = "내가 저장한 교육정보 리스트 조회", description = "내가 저장한 교육정보 리스트를 조회합니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) - ApiResponse> getEducationInfoList(); + ApiResponse> getEducationInfoList(); - @GetMapping("/educationInfo/{educationInfoId}") + @GetMapping("/{educationInfoId}") @Operation(summary = "특정 교육정보 조회", description = "내가 저장한 교육정보 중 특정 교육정보를 조회합니다. bookmark 아이디 값을 보내주세요.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) - ApiResponse getEducationInfoDetails(@PathVariable Long educationInfoId); + ApiResponse getEducationInfoDetails(@PathVariable Long educationInfoId); - @DeleteMapping("/educationInfo/{educationInfoId}") + @DeleteMapping("/{educationInfoId}") @Operation(summary = "내가 저장한 교육정보 삭제", description = "내가 저장한 교육정보 리스트 중 특정 교육정보를 삭제합니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) - ApiResponse deleteBookmark(@PathVariable("educationInfoId") Long educationInfoId); + ApiResponse deleteEducationInfo(@PathVariable("educationInfoId") Long educationInfoId); } diff --git a/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoRequestDTO.java b/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoRequestDTO.java new file mode 100644 index 0000000..c041537 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoRequestDTO.java @@ -0,0 +1,4 @@ +package com.parentsgowork.server.web.dto.EducationInfoDTO; + +public class EducationInfoRequestDTO { +} diff --git a/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoResponseDTO.java b/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoResponseDTO.java new file mode 100644 index 0000000..2bbcfc0 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoResponseDTO.java @@ -0,0 +1,41 @@ +package com.parentsgowork.server.web.dto.EducationInfoDTO; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class EducationInfoResponseDTO { + + // 저장한 교육정보 리스트 dto + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class EducationInfoListDTO { + private Long id; + private String title; + private String url; + } + + // 저장한 교육정보 상세페이지 dto + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class EducationInfoDetailDTO { + private Long id; + private String title; + private String url; + } + + // 저장한 교육정보 삭제 dto + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class DeleteEducationInfoDTO { + private Long id; + private String message; + } +} From dc81c470fae0cfdb0f4844ce7239b123b63fddd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A8=EB=9D=BC?= Date: Wed, 14 May 2025 19:39:11 +0900 Subject: [PATCH 6/7] =?UTF-8?q?Refactor:=20=EB=82=B4=EA=B0=80=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=9C=20=EA=B3=A0=EC=9A=A9=20=EC=A0=95=EC=B1=85/?= =?UTF-8?q?=EB=B3=B5=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/dto/EducationInfoDTO/EducationInfoRequestDTO.java | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoRequestDTO.java diff --git a/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoRequestDTO.java b/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoRequestDTO.java deleted file mode 100644 index c041537..0000000 --- a/src/main/java/com/parentsgowork/server/web/dto/EducationInfoDTO/EducationInfoRequestDTO.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.parentsgowork.server.web.dto.EducationInfoDTO; - -public class EducationInfoRequestDTO { -} From e514e686f2886e6286f2f5db8a6594162753c73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B2=A8=EB=9D=BC?= Date: Wed, 14 May 2025 19:39:21 +0900 Subject: [PATCH 7/7] =?UTF-8?q?Refactor:=20=EB=82=B4=EA=B0=80=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=9C=20=EA=B3=A0=EC=9A=A9=20=EC=A0=95=EC=B1=85/?= =?UTF-8?q?=EB=B3=B5=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/PolicyInfoHandler.java | 9 ++++ .../server/converter/PolicyInfoConverter.java | 35 +++++++++++++ .../repository/PolicyInfoRepository.java | 18 +++++++ .../PolicyInfoCommandService.java | 9 ++++ .../PolicyInfoCommandServiceImpl.java | 34 +++++++++++++ .../PolicyInfoQueryService.java | 10 ++++ .../PolicyInfoQueryServiceImpl.java | 40 +++++++++++++++ .../web/controller/PolicyInfoController.java | 51 +++++++++++++++++++ .../EducationInfoSpecification.java | 4 +- .../PolicyInfoSpecification.java | 41 +++++++++++++++ .../PolicyInfoDTO/PolicyInfoResponseDTO.java | 41 +++++++++++++++ 11 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/parentsgowork/server/apiPayload/exception/PolicyInfoHandler.java create mode 100644 src/main/java/com/parentsgowork/server/converter/PolicyInfoConverter.java create mode 100644 src/main/java/com/parentsgowork/server/repository/PolicyInfoRepository.java create mode 100644 src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoCommandService.java create mode 100644 src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoCommandServiceImpl.java create mode 100644 src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoQueryService.java create mode 100644 src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoQueryServiceImpl.java create mode 100644 src/main/java/com/parentsgowork/server/web/controller/PolicyInfoController.java create mode 100644 src/main/java/com/parentsgowork/server/web/controller/specification/PolicyInfoSpecification.java create mode 100644 src/main/java/com/parentsgowork/server/web/dto/PolicyInfoDTO/PolicyInfoResponseDTO.java diff --git a/src/main/java/com/parentsgowork/server/apiPayload/exception/PolicyInfoHandler.java b/src/main/java/com/parentsgowork/server/apiPayload/exception/PolicyInfoHandler.java new file mode 100644 index 0000000..6e4fbd3 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/apiPayload/exception/PolicyInfoHandler.java @@ -0,0 +1,9 @@ +package com.parentsgowork.server.apiPayload.exception; + +import com.parentsgowork.server.apiPayload.code.BaseErrorCode; + +public class PolicyInfoHandler extends GeneralException { + public PolicyInfoHandler(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/parentsgowork/server/converter/PolicyInfoConverter.java b/src/main/java/com/parentsgowork/server/converter/PolicyInfoConverter.java new file mode 100644 index 0000000..6dfcf8f --- /dev/null +++ b/src/main/java/com/parentsgowork/server/converter/PolicyInfoConverter.java @@ -0,0 +1,35 @@ +package com.parentsgowork.server.converter; + +import com.parentsgowork.server.domain.PolicyInfo; +import com.parentsgowork.server.web.dto.PolicyInfoDTO.PolicyInfoResponseDTO; + +import java.util.List; +import java.util.stream.Collectors; + +public class PolicyInfoConverter { + public static List getPolicyInfoListDTO(List policyInfos) { + return policyInfos.stream() + .map(policy -> PolicyInfoResponseDTO.PolicyInfoListDTO.builder() + .id(policy.getId()) + .title(policy.getTitle()) + .url(policy.getUrl()) + .build()) + .collect(Collectors.toList()); + } + + public static PolicyInfoResponseDTO.PolicyInfoDetailDTO getPolicyInfoDetailDTO(PolicyInfo policyInfo) { + return PolicyInfoResponseDTO.PolicyInfoDetailDTO.builder() + .id(policyInfo.getId()) + .title(policyInfo.getTitle()) + .url(policyInfo.getUrl()) + .build(); + } + + + public static PolicyInfoResponseDTO.DeletePolicyInfoDTO DeletePolicyInfoDTO(PolicyInfo policyInfo) { + return PolicyInfoResponseDTO.DeletePolicyInfoDTO.builder() + .id(policyInfo.getId()) + .message("저장한 정책정보를 삭제하였습니다.") + .build(); + } +} diff --git a/src/main/java/com/parentsgowork/server/repository/PolicyInfoRepository.java b/src/main/java/com/parentsgowork/server/repository/PolicyInfoRepository.java new file mode 100644 index 0000000..1ea18cb --- /dev/null +++ b/src/main/java/com/parentsgowork/server/repository/PolicyInfoRepository.java @@ -0,0 +1,18 @@ +package com.parentsgowork.server.repository; + +import com.parentsgowork.server.domain.PolicyInfo; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; +import java.util.Optional; + +public interface PolicyInfoRepository extends JpaRepository { + + @Query("SELECT pi FROM PolicyInfo pi " + + "WHERE pi. user.id = :userId") + List findPolicyInfoList(@Param("userId") Long userId); + + Optional findByIdAndUserId(@Param("policyInfoId") Long policyInfoId, @Param("userId") Long userId); +} diff --git a/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoCommandService.java b/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoCommandService.java new file mode 100644 index 0000000..66e3257 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoCommandService.java @@ -0,0 +1,9 @@ +package com.parentsgowork.server.service.policyInfoService; + + +import com.parentsgowork.server.web.dto.PolicyInfoDTO.PolicyInfoResponseDTO; + +public interface PolicyInfoCommandService { + PolicyInfoResponseDTO.DeletePolicyInfoDTO delete(Long userId, Long policyInfoId); + +} diff --git a/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoCommandServiceImpl.java b/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoCommandServiceImpl.java new file mode 100644 index 0000000..de80741 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoCommandServiceImpl.java @@ -0,0 +1,34 @@ +package com.parentsgowork.server.service.policyInfoService; + +import com.parentsgowork.server.apiPayload.code.status.ErrorStatus; +import com.parentsgowork.server.apiPayload.exception.PolicyInfoHandler; +import com.parentsgowork.server.apiPayload.exception.UserHandler; +import com.parentsgowork.server.converter.PolicyInfoConverter; +import com.parentsgowork.server.domain.PolicyInfo; +import com.parentsgowork.server.repository.PolicyInfoRepository; +import com.parentsgowork.server.repository.UserRepository; +import com.parentsgowork.server.web.dto.PolicyInfoDTO.PolicyInfoResponseDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PolicyInfoCommandServiceImpl implements PolicyInfoCommandService { + + private final PolicyInfoRepository policyInfoRepository; + private final UserRepository userRepository; + + @Override + public PolicyInfoResponseDTO.DeletePolicyInfoDTO delete(Long userId, Long policyInfoId) { + + userRepository.findById(userId) + .orElseThrow(() -> new UserHandler(ErrorStatus.USER_NOT_FOUND)); + + PolicyInfo policyInfo = policyInfoRepository.findByIdAndUserId(policyInfoId, userId) + .orElseThrow(() -> new PolicyInfoHandler(ErrorStatus.POLICY_INFO_NOT_FOUND)); + + policyInfoRepository.deleteById(policyInfoId); + + return PolicyInfoConverter.DeletePolicyInfoDTO(policyInfo); + } +} diff --git a/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoQueryService.java b/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoQueryService.java new file mode 100644 index 0000000..6e433ca --- /dev/null +++ b/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoQueryService.java @@ -0,0 +1,10 @@ +package com.parentsgowork.server.service.policyInfoService; + +import com.parentsgowork.server.web.dto.PolicyInfoDTO.PolicyInfoResponseDTO; + +import java.util.List; + +public interface PolicyInfoQueryService { + List getPolicyInfoList(Long userId); + PolicyInfoResponseDTO.PolicyInfoDetailDTO getPolicyInfoDetails(Long userId, Long policyInfoId); +} diff --git a/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoQueryServiceImpl.java b/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoQueryServiceImpl.java new file mode 100644 index 0000000..dee36e1 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/service/policyInfoService/PolicyInfoQueryServiceImpl.java @@ -0,0 +1,40 @@ +package com.parentsgowork.server.service.policyInfoService; + +import com.parentsgowork.server.apiPayload.code.status.ErrorStatus; +import com.parentsgowork.server.apiPayload.exception.PolicyInfoHandler; +import com.parentsgowork.server.converter.PolicyInfoConverter; +import com.parentsgowork.server.domain.PolicyInfo; +import com.parentsgowork.server.repository.PolicyInfoRepository; +import com.parentsgowork.server.web.dto.PolicyInfoDTO.PolicyInfoResponseDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class PolicyInfoQueryServiceImpl implements PolicyInfoQueryService { + + private final PolicyInfoRepository policyInfoRepository; + + @Override + public List getPolicyInfoList(Long userId) { + + List policyInfos = policyInfoRepository.findPolicyInfoList(userId); + + if(policyInfos == null || policyInfos.isEmpty()) { + throw new PolicyInfoHandler(ErrorStatus.POLICY_INFO_NOT_FOUND); + } + + return PolicyInfoConverter.getPolicyInfoListDTO(policyInfos); + } + + @Override + public PolicyInfoResponseDTO.PolicyInfoDetailDTO getPolicyInfoDetails(Long userId, Long policyInfoId) { + + PolicyInfo policyInfo = policyInfoRepository.findByIdAndUserId(policyInfoId, userId) + .orElseThrow(() -> new PolicyInfoHandler(ErrorStatus.POLICY_INFO_NOT_FOUND)); + + return PolicyInfoConverter.getPolicyInfoDetailDTO(policyInfo); + } +} diff --git a/src/main/java/com/parentsgowork/server/web/controller/PolicyInfoController.java b/src/main/java/com/parentsgowork/server/web/controller/PolicyInfoController.java new file mode 100644 index 0000000..6e48433 --- /dev/null +++ b/src/main/java/com/parentsgowork/server/web/controller/PolicyInfoController.java @@ -0,0 +1,51 @@ +package com.parentsgowork.server.web.controller; + +import com.parentsgowork.server.apiPayload.ApiResponse; +import com.parentsgowork.server.service.policyInfoService.PolicyInfoCommandService; +import com.parentsgowork.server.service.policyInfoService.PolicyInfoQueryService; +import com.parentsgowork.server.web.controller.specification.PolicyInfoSpecification; +import com.parentsgowork.server.web.dto.PolicyInfoDTO.PolicyInfoResponseDTO; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Tag(name = "PolicyInfo", description = "정책정보 API") +@RestController +@RequiredArgsConstructor +@RequestMapping("/policyInfo") +public class PolicyInfoController implements PolicyInfoSpecification { + + private final PolicyInfoCommandService policyInfoCommandService; + private final PolicyInfoQueryService policyInfoQueryService; + + @GetMapping("") + public ApiResponse> getPolicyInfoList() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + Long userId = (Long) authentication.getPrincipal(); + + List response = policyInfoQueryService.getPolicyInfoList(userId); + return ApiResponse.onSuccess(response); + } + + @GetMapping("/{policyInfoId}") + public ApiResponse getPolicyInfoDetails(@PathVariable Long policyInfoId) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + Long userId = (Long) authentication.getPrincipal(); + + PolicyInfoResponseDTO.PolicyInfoDetailDTO response = policyInfoQueryService.getPolicyInfoDetails(userId, policyInfoId); + return ApiResponse.onSuccess(response); + } + + @DeleteMapping("/{policyInfoId}") + public ApiResponse deletePolicyInfo(@PathVariable("policyInfoId") Long policyInfoId) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + Long userId = (Long) authentication.getPrincipal(); + + PolicyInfoResponseDTO.DeletePolicyInfoDTO response = policyInfoCommandService.delete(policyInfoId, userId); + return ApiResponse.onSuccess(response); + } +} diff --git a/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java b/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java index fec14a3..c5237b2 100644 --- a/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java +++ b/src/main/java/com/parentsgowork/server/web/controller/specification/EducationInfoSpecification.java @@ -21,7 +21,7 @@ public interface EducationInfoSpecification { ApiResponse> getEducationInfoList(); @GetMapping("/{educationInfoId}") - @Operation(summary = "특정 교육정보 조회", description = "내가 저장한 교육정보 중 특정 교육정보를 조회합니다. bookmark 아이디 값을 보내주세요.") + @Operation(summary = "특정 교육정보 조회", description = "내가 저장한 특정 교육정보를 조회합니다. 교육정보 아이디 값을 보내주세요.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) @@ -29,7 +29,7 @@ public interface EducationInfoSpecification { ApiResponse getEducationInfoDetails(@PathVariable Long educationInfoId); @DeleteMapping("/{educationInfoId}") - @Operation(summary = "내가 저장한 교육정보 삭제", description = "내가 저장한 교육정보 리스트 중 특정 교육정보를 삭제합니다.") + @Operation(summary = "내가 저장한 교육정보 삭제", description = "내가 저장한 특정 교육정보를 삭제합니다.") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) diff --git a/src/main/java/com/parentsgowork/server/web/controller/specification/PolicyInfoSpecification.java b/src/main/java/com/parentsgowork/server/web/controller/specification/PolicyInfoSpecification.java new file mode 100644 index 0000000..9b81aba --- /dev/null +++ b/src/main/java/com/parentsgowork/server/web/controller/specification/PolicyInfoSpecification.java @@ -0,0 +1,41 @@ +package com.parentsgowork.server.web.controller.specification; + +import com.parentsgowork.server.apiPayload.ApiResponse; +import com.parentsgowork.server.web.dto.PolicyInfoDTO.PolicyInfoResponseDTO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +import java.util.List; + +public interface PolicyInfoSpecification { + + @GetMapping("") + @Operation(summary = "내가 저장한 고용 정책/복지 리스트 조회", description = "내가 저장한 고용 정책/복지 리스트를 조회합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + ApiResponse> getPolicyInfoList(); + + @GetMapping("/{policyInfoId}") + @Operation(summary = "특정 고용 정책/복지 조회", description = "내가 저장한 특정 고용 정책/복지를 조회합니다. 고용 정책/복지 아이디 값을 보내주세요.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + ApiResponse getPolicyInfoDetails(@PathVariable Long policyInfoId); + + @DeleteMapping("/{policyInfoId}") + @Operation(summary = "내가 저장한 고용 정책/복지 삭제", description = "내가 저장한 특정 고용 정책/복지를 삭제합니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "⭕ SUCCESS, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "❌ BAD, 잘못된 요청", content = @Content(schema = @Schema(implementation = ApiResponse.class))) + }) + ApiResponse deletePolicyInfo(@PathVariable("policyInfoId") Long policyInfoId); + +} diff --git a/src/main/java/com/parentsgowork/server/web/dto/PolicyInfoDTO/PolicyInfoResponseDTO.java b/src/main/java/com/parentsgowork/server/web/dto/PolicyInfoDTO/PolicyInfoResponseDTO.java new file mode 100644 index 0000000..71d292b --- /dev/null +++ b/src/main/java/com/parentsgowork/server/web/dto/PolicyInfoDTO/PolicyInfoResponseDTO.java @@ -0,0 +1,41 @@ +package com.parentsgowork.server.web.dto.PolicyInfoDTO; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class PolicyInfoResponseDTO { + + // 저장한 정책정보 리스트 dto + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class PolicyInfoListDTO { + private Long id; + private String title; + private String url; + } + + // 저장한 정책정보 상세페이지 dto + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class PolicyInfoDetailDTO { + private Long id; + private String title; + private String url; + } + + // 저장한 정책정보 삭제 dto + @Getter + @Builder + @NoArgsConstructor + @AllArgsConstructor + public static class DeletePolicyInfoDTO { + private Long id; + private String message; + } +}