채용 공고 리스트를 조회하는 API이다 

채용 공고 등록할 때는 회사 정보를 입력하지 않아서 회사 엔티티를 만들지 않았는데, 목록의 각 개체에 회사정보가 있길래 회사 관련 정보도 추가해서 진행했다 

 

-getRecruitList()

위치 : /web/recruitment/RecruitmentController.class

채용공고 목록만 확인하는 것이므로 따로 requestbody가 필요하지 않다고 생각했다 

@GetMapping("/list")
public ApiResponse<List<GetRecruitListResponse>> getRecruitList() {
    List<GetRecruitListResponse> responses = recruitmentService.getRecruitList();
    return ApiResponse.success(responses);
}

-getRecruitList()

위치 : /service/RecruitmentService.class

public List<GetRecruitListResponse> getRecruitList() {

    List<Recruitment> all = recruitmentRepository.findAll();

    List<GetRecruitListResponse> recruitList = new ArrayList<>();
    for (Recruitment recruitment : all) {
        Company recruitCompany = recruitment.getCompany();

        GetRecruitListResponse response = GetRecruitListResponse.of(recruitCompany, recruitment);

        recruitList.add(response);
    }

    return recruitList;
}

 

- GetRecruitListResponse

위치 : /web/recruitment/dto/response

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

    private Long recruitId;
    private String companyName;
    private String country;
    private String region;
    private String position;
    private Integer reward;
    private String techInfo;

    @Builder
    public GetRecruitListResponse(Long recruitId, String companyName, String country, String region, String position, Integer reward, String techInfo) {
        this.recruitId = recruitId;
        this.companyName = companyName;
        this.country = country;
        this.region = region;
        this.position = position;
        this.reward = reward;
        this.techInfo = techInfo;
    }

    public static GetRecruitListResponse of(Company company, Recruitment recruitment) {
        GetRecruitListResponse response = GetRecruitListResponse.builder()
                .recruitId(recruitment.getId())
                .companyName(company.getCompanyName())
                .country(company.getCountry())
                .region(company.getRegion())
                .position(recruitment.getPosition())
                .reward(recruitment.getReward())
                .techInfo(recruitment.getTechInfo())
                .build();

        return response;
    }

Postman

company 생성 (두 개의 회사)

{
    "companyName" : "wanted",
    "country" : "korea",
    "region" : "seoul"
}
{
    "data": null
}

 

company에서 recruitment 생성 

{
    "companyId" : 2,
    "position" : "backend junior developer",
    "reward" : 225000000,
    "contents" : "now wanted is hiring for,,,",
    "techInfo" : "Java"
}
{
    "data": {
        "id": 3,
        "position": "backend junior developer",
        "reward": 225000000,
        "contents": "now wanted is hiring for,,,",
        "techInfo": "Java"
    }
}

 

사용자가 recruitment list 조회 

{
    "data": [
        {
            "recruitId": 1,
            "companyName": "naver",
            "country": "korea",
            "region": "seoul",
            "position": "backend senior developer",
            "reward": 325000000,
            "techInfo": "Java"
        },
        {
            "recruitId": 2,
            "companyName": "naver",
            "country": "korea",
            "region": "seoul",
            "position": "backend jenior developer",
            "reward": 125000000,
            "techInfo": "Java"
        },
        {
            "recruitId": 3,
            "companyName": "wanted",
            "country": "korea",
            "region": "seoul",
            "position": "backend junior developer",
            "reward": 225000000,
            "techInfo": "Java"
        }
    ]
}

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

6. 채용 상세 페이지 조회 API  (0) 2022.08.25
5-2. 채용공고 검색 API (가산점 요소)  (0) 2022.08.25
4. 삭제 API  (0) 2022.08.23
3. 수정 API  (0) 2022.08.23
2. 등록 API 생성  (0) 2022.08.23

+ Recent posts