Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public enum ErrorStatus implements BaseErrorCode {
EMAIL_ENCODING_FAIL(HttpStatus.INTERNAL_SERVER_ERROR, "AUTH5002", "이메일 내용 인코딩에 실패했습니다."),

// 북마크 관련 에러
EDUCATION_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "BOOKMARK4001", "북마크한 교육정보가 존재하지 않습니다."),
POLICY_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "BOOKMARK4002", "북마크한 정책정보가 존재하지 않습니다.");
EDUCATION_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "BOOKMARK4001", "교육정보가 존재하지 않습니다."),
POLICY_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "BOOKMARK4002", "정책정보가 존재하지 않습니다."),
JOB_INFO_NOT_FOUND(HttpStatus.NOT_FOUND, "BOOKMARK4003", "구직정보가 존재하지 않습니다.");



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.parentsgowork.server.apiPayload.code.BaseErrorCode;

public class JobInfoCrawlingHandler extends GeneralException {
public JobInfoCrawlingHandler(BaseErrorCode code) {
public class JobInfoHandler extends GeneralException {
public JobInfoHandler(BaseErrorCode code) {
super(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.parentsgowork.server.converter;

import com.parentsgowork.server.domain.JobInfo;
import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoResponseDTO;

import java.util.List;
import java.util.stream.Collectors;

public class JobInfoConverter {

public static JobInfoResponseDTO.AddJobResultDTO toAddJobResultDTO(JobInfo jobInfo) {
return JobInfoResponseDTO.AddJobResultDTO.builder()
.title(jobInfo.getTitle())
.content(jobInfo.getContent())
.build();
}

public static List<JobInfoResponseDTO.JobInfoResultDTO> getJobInfoListDTO(List<JobInfo> jobInfos) {
return jobInfos.stream()
.map(job -> JobInfoResponseDTO.JobInfoResultDTO.builder()
.title(job.getTitle())
.content(job.getContent())
.build())
.collect(Collectors.toList());
}

public static JobInfoResponseDTO.JobInfoDetailDTO getJobInfoDetailDTO(JobInfo jobInfo) {
return JobInfoResponseDTO.JobInfoDetailDTO.builder()
.title(jobInfo.getTitle())
.content(jobInfo.getContent())
.build();
}


public static JobInfoResponseDTO.DeleteJobInfoDTO DeleteJobInfoDTO(JobInfo jobInfo) {
return JobInfoResponseDTO.DeleteJobInfoDTO.builder()
.id(jobInfo.getId())
.message("저장한 구직정보를 삭제하였습니다.")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Bookmark extends BaseEntity {
public class JobInfo extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -23,30 +23,12 @@ public class Bookmark extends BaseEntity {
private User user;

@Column
private Long jobId;
private String title;

@Column
private String companyName;
private String content;

@Column
private String jobTitle;

@Column
private String pay;

@Column
private String time;

@Column
private String location;

@Column
private String deadline;

@Column
private String registrationDate;

@Column(columnDefinition = "TEXT")
private String detailUrl;
// @Column(columnDefinition = "TEXT")
// private String url;

}
2 changes: 1 addition & 1 deletion src/main/java/com/parentsgowork/server/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class User extends BaseEntity {
private RefreshToken refreshToken;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Bookmark> bookmarks;
private List<JobInfo> bookmarks;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<PolicyInfo> policyInfos;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.parentsgowork.server.repository;

import com.parentsgowork.server.domain.JobInfo;
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 JobInfoRepository extends JpaRepository<JobInfo, Long> {
@Query("SELECT ji FROM JobInfo ji " +
"WHERE ji. user.id = :userId")
List<JobInfo> findJobInfoList(@Param("userId") Long userId);

Optional<JobInfo> findByIdAndUserId(@Param("jobInfoId") Long jobInfoId, @Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.parentsgowork.server.service.jobInfoService;

import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoRequestDTO;
import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoResponseDTO;

import java.util.List;

public interface JobInfoCommandService {

List<JobInfoResponseDTO.AddJobResultDTO> addJobInfo(Long userId, List<JobInfoRequestDTO.SaveJobInfoDTO> saveJobInfoDTOList);

JobInfoResponseDTO.DeleteJobInfoDTO delete(Long userId, Long jobInfoId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.parentsgowork.server.service.jobInfoService;

import com.parentsgowork.server.apiPayload.code.status.ErrorStatus;
import com.parentsgowork.server.apiPayload.exception.JobInfoHandler;
import com.parentsgowork.server.converter.JobInfoConverter;
import com.parentsgowork.server.domain.JobInfo;
import com.parentsgowork.server.domain.User;
import com.parentsgowork.server.repository.JobInfoRepository;
import com.parentsgowork.server.repository.UserRepository;
import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoRequestDTO;
import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoResponseDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Slf4j
public class JobInfoCommandServiceImpl implements JobInfoCommandService {

private final UserRepository userRepository;
private final JobInfoRepository jobInfoRepository;

@Override
public List<JobInfoResponseDTO.AddJobResultDTO> addJobInfo(Long userId, List<JobInfoRequestDTO.SaveJobInfoDTO> saveJobInfoDTOList) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new JobInfoHandler(ErrorStatus.USER_NOT_FOUND));

List<JobInfo> jobInfos = saveJobInfoDTOList.stream()
.map(dto -> JobInfo.builder()
.title(dto.getTitle())
.content(dto.getContent())
.user(user)
.build())
.collect(Collectors.toList());

jobInfoRepository.saveAll(jobInfos);

return jobInfos.stream()
.map(JobInfoConverter::toAddJobResultDTO)
.collect(Collectors.toList());
}

@Override
public JobInfoResponseDTO.DeleteJobInfoDTO delete(Long userId, Long jobInfoId) {

userRepository.findById(userId)
.orElseThrow(() -> new JobInfoHandler(ErrorStatus.USER_NOT_FOUND));

JobInfo jobInfo = jobInfoRepository.findByIdAndUserId(jobInfoId, userId)
.orElseThrow(() -> new JobInfoHandler(ErrorStatus.JOB_INFO_NOT_FOUND));

jobInfoRepository.deleteById(jobInfoId);

return JobInfoConverter.DeleteJobInfoDTO(jobInfo);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.parentsgowork.server.service.jobInfoService;

import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoResponseDTO;

import java.util.List;

public interface JobInfoQueryService {

List<JobInfoResponseDTO.JobInfoResultDTO> getJobInfoList(Long userId);
JobInfoResponseDTO.JobInfoDetailDTO getJobInfoDetails(Long userId, Long jobInfoId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.parentsgowork.server.service.jobInfoService;

import com.parentsgowork.server.apiPayload.code.status.ErrorStatus;
import com.parentsgowork.server.apiPayload.exception.JobInfoHandler;
import com.parentsgowork.server.converter.JobInfoConverter;
import com.parentsgowork.server.domain.JobInfo;
import com.parentsgowork.server.repository.JobInfoRepository;
import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class JobInfoQueryServiceImpl implements JobInfoQueryService {

private final JobInfoRepository jobInfoRepository;

@Override
public List<JobInfoResponseDTO.JobInfoResultDTO> getJobInfoList(Long userId) {

List<JobInfo> jobInfos = jobInfoRepository.findJobInfoList(userId);

if(jobInfos == null || jobInfos.isEmpty()) {
throw new JobInfoHandler(ErrorStatus.JOB_INFO_NOT_FOUND);
}

return JobInfoConverter.getJobInfoListDTO(jobInfos);
}

@Override
public JobInfoResponseDTO.JobInfoDetailDTO getJobInfoDetails(Long userId, Long jobInfoId) {

JobInfo jobInfo = jobInfoRepository.findByIdAndUserId(jobInfoId, userId)
.orElseThrow(() -> new JobInfoHandler(ErrorStatus.JOB_INFO_NOT_FOUND));

return JobInfoConverter.getJobInfoDetailDTO(jobInfo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.parentsgowork.server.web.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.parentsgowork.server.apiPayload.ApiResponse;
import com.parentsgowork.server.service.jobInfoService.JobInfoCommandService;
import com.parentsgowork.server.service.jobInfoService.JobInfoQueryService;
import com.parentsgowork.server.web.controller.specification.JobInfoSpecification;
import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoRequestDTO;
import com.parentsgowork.server.web.dto.JobInfoDTO.JobInfoResponseDTO;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.stream.Collectors;

@Tag(name = "JobInfo", description = "구직정보 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/jobInfo")
public class JobInfoController implements JobInfoSpecification {

@Value("${seoul.openapi.key}")
private String apiKey;

private final RestTemplate restTemplate = new RestTemplate();
private final ObjectMapper objectMapper = new ObjectMapper();

private final JobInfoCommandService jobInfoCommandService;
private final JobInfoQueryService jobInfoQueryService;

@GetMapping("/search")
public ResponseEntity<List<JobInfoResponseDTO.JobInfoResultDTO>> getParsedJobInfo() {
int start = 1;
int end = 3;
String url = String.format(
"http://openapi.seoul.go.kr:8088/%s/json/GetJobInfo/%d/%d/",
apiKey, start, end
);

String rawJson = restTemplate.getForObject(url, String.class);

try {
JobInfoResponseDTO response = objectMapper.readValue(rawJson, JobInfoResponseDTO.class);

List<JobInfoResponseDTO.JobInfoResultDTO> resultList =
response.getJobInfo().getRow().stream()
.map(row -> JobInfoResponseDTO.JobInfoResultDTO.builder()
.title(row.getTitle())
.content(row.getContent())
.build())
.collect(Collectors.toList());


return ResponseEntity.ok(resultList);

} catch (Exception e) {
return ResponseEntity.status(500).build();
}
}

@PostMapping("/add")
public ApiResponse<List<JobInfoResponseDTO.AddJobResultDTO>> addJobInfo(@RequestBody List<JobInfoRequestDTO.SaveJobInfoDTO> saveJobInfoDTOList) {

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Long userId = (Long) authentication.getPrincipal();

List<JobInfoResponseDTO.AddJobResultDTO> response = jobInfoCommandService.addJobInfo(userId, saveJobInfoDTOList);
return ApiResponse.onSuccess(response);
}

@GetMapping("")
public ApiResponse<List<JobInfoResponseDTO.JobInfoResultDTO>> getJobInfoList() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Long userId = (Long) authentication.getPrincipal();

List<JobInfoResponseDTO.JobInfoResultDTO> response = jobInfoQueryService.getJobInfoList(userId);
return ApiResponse.onSuccess(response);
}

@GetMapping("/{jobInfoId}")
public ApiResponse<JobInfoResponseDTO.JobInfoDetailDTO> getJobInfoDetails(@PathVariable Long jobInfoId) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Long userId = (Long) authentication.getPrincipal();

JobInfoResponseDTO.JobInfoDetailDTO response = jobInfoQueryService.getJobInfoDetails(userId, jobInfoId);
return ApiResponse.onSuccess(response);
}

@DeleteMapping("/{jobInfoId}")
public ApiResponse<JobInfoResponseDTO.DeleteJobInfoDTO> deleteJobInfo(@PathVariable("jobInfoId") Long jobInfoId) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Long userId = (Long) authentication.getPrincipal();

JobInfoResponseDTO.DeleteJobInfoDTO response = jobInfoCommandService.delete(jobInfoId, userId);
return ApiResponse.onSuccess(response);
}

}
Loading