채용 공고에서 특정 객체를 선택했을 때 상세 정보를 조회하는 API이다 

여기서 가산점을 주는 요소는 채용공고를 올린 회사가 올린 다른 채용공고의 id 리스트도 같이 반환하는 것이다 

 

회사 엔티티와 관련 로직이 필요해 추가했다 

- Company

위치  : /domain/company

@Table
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Company {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String companyName;
    private String country;
    private String region;


    @Builder
    public Company(String companyName, String country, String region) {
        this.companyName = companyName;
        this.country = country;
        this.region = region;
    }

    public static Company of(String companyName, String country, String region) {
        Company company = Company.builder()
                .companyName(companyName)
                .country(country)
                .region(region)
                .build();

        return company;
    }
}

-CompanyRepository

위치  : /domain/company

public interface CompanyRepository extends JpaRepository<Company, Long> {
}

- CompanyService

위치 : /service/company

@Service
@RequiredArgsConstructor
public class CompanyService {

    private final CompanyRepository companyRepository;

    public void createCompany(CreateCompanyRequest request) {

        Company created = Company.of(request.getCompanyName(), request.getCountry(), request.getRegion());

        companyRepository.save(created);
    }
}

 

- CompanyController

위치 : /web/company

@RestController
@RequiredArgsConstructor
@RequestMapping("/company")
public class CompanyController {

    private final CompanyService companyService;

    @PostMapping("/create")
    public ApiResponse<String> createCompany(@RequestBody CreateCompanyRequest request) {
        companyService.createCompany(request);
        return ApiResponse.SUCCESS;
    }
}

 

- getRecruitDetail()

위치 : /web/recruitment/RecruitmentController.class

@GetMapping("/detail/{id}")
public ApiResponse<GetRecruitDetailResponse> getRecruitDetail(@PathVariable Long id) {
    GetRecruitDetailResponse response = recruitmentService.getRecruitDetail(id);
    return ApiResponse.success(response);
}

 

-getRecruitDetail()

위치 : /service/recruitment/RecruitmentService.class

public GetRecruitDetailResponse getRecruitDetail(Long id) {
        Optional<Recruitment> findRecruit = recruitmentRepository.findById(id);
        Company company = findRecruit.get().getCompany();
        Long companyId = company.getId();

        List<Long> companyRecruits = new ArrayList<>();
        List<Recruitment> recruits = recruitmentRepository.findByCompanyId(companyId);
        for (Recruitment recruit : recruits) {
            if (!recruit.getId().equals(id)) {
                companyRecruits.add(recruit.getId());
            }
        }

        GetRecruitDetailResponse response = GetRecruitDetailResponse.of(company, findRecruit.get(), companyRecruits);

        return response;
    }

 

- GetRecruitDetailResponse

@ToString
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class GetRecruitDetailResponse {

    private Long recruitId;
    private String companyName;
    private String country;
    private String region;
    private String position;
    private Integer reward;
    private String techInfo;
    private String contents;
    private List<Long> companyRecruits = new ArrayList<>();

    @Builder
    public GetRecruitDetailResponse(Long recruitId, String companyName, String country, String region, String position, Integer reward, String techInfo, String contents, List<Long> companyRecruits) {
        this.recruitId = recruitId;
        this.companyName = companyName;
        this.country = country;
        this.region = region;
        this.position = position;
        this.reward = reward;
        this.techInfo = techInfo;
        this.contents = contents;
        this.companyRecruits = companyRecruits;
    }

    public static GetRecruitDetailResponse of(Company company, Recruitment recruitment, List<Long> companyRecruits) {
        GetRecruitDetailResponse response = GetRecruitDetailResponse.builder()
                .recruitId(recruitment.getId())
                .companyName(company.getCompanyName())
                .country(company.getCountry())
                .region(company.getRegion())
                .position(recruitment.getPosition())
                .reward(recruitment.getReward())
                .techInfo(recruitment.getTechInfo())
                .contents(recruitment.getContents())
                .companyRecruits(companyRecruits)
                .build();

        return response;
    }
}

Postman

RequestParam

ResponseBody

여기에서 조회한 채용공고까지 중복으로 포함되는데 이 부분은 수정해야할 것 같다 

{
    "data": {
        "recruitId": 1,
        "companyName": "wanted",
        "country": "korea",
        "region": "seoul",
        "position": "Backend Developer 1",
        "reward": 125000000,
        "techInfo": "Java",
        "contents": "now wanted is hiring for ,,,",
        "companyRecruits": [
            2,
            3
        ]
    }
}
{
    "data": {
        "recruitId": 5,
        "companyName": "naver",
        "country": "korea",
        "region": "seoul",
        "position": "backend junior developer",
        "reward": 25000000,
        "techInfo": "Java",
        "contents": "now naver is hiring for,,,",
        "companyRecruits": [
            4
        ]
    }
}
 

 

'개인프로젝트 > 과제' 카테고리의 다른 글

7. 사용자가 채용공고에 지원 API (가산점 요소)  (0) 2022.08.25
5-2. 채용공고 검색 API (가산점 요소)  (0) 2022.08.25
5-1. 채용공고 목록 API  (0) 2022.08.24
4. 삭제 API  (0) 2022.08.23
3. 수정 API  (0) 2022.08.23

+ Recent posts