국비/Project-3 채용박람회

2023.07.08~09 주말 Team Project - 2 채용박람회

춘핑이 2023. 7. 28. 22:24

주말

1. 상세페이지

상세페이지는 평소와 같으니 넘어가도록 하겠다.

2. 상태 변경

수정시에 파일을 수정하거 나 그럴 것은 아니기 때문에 patch요청을 받을 것이다.
수정시에는 put요청과 patch요청을 사용할수 있는데 모든 값을 바꾸는 것은 put요청 특정 값만 바꾸는 것은 patch요청을 받아서 처리할 수 있다고 한다.
상태값만 변경할 것이기 때문에 patch요청을 사용할 것이다.

2.1 view ajax요청

보류 반려 승인 버튼을 만들었다.
각 버튼의 클릭에 따라서 status에 값을 담아서 changeStatus함수를 실행시킨다.
json으로 값을 포장해서 요청경로에 patch요청을 하게된다.
헤더에 "Content-Type": "application/json" json으로 담아서 본다는 것을 설정해야한다.

const holdBtn = document.querySelector('#hold-btn');
const rejectBtn = document.querySelector('#reject-btn');
const approveBtn = document.querySelector('#approve-btn');

holdBtn.addEventListener('click', function () {
    data = {
        "status": "hold"
    }
    changeStatus(data);
});

rejectBtn.addEventListener('click', function () {
    data = {
        "status": "rejected"
    }
    changeStatus(data);
});

approveBtn.addEventListener('click', function () {
    data = {
        "status": "approved"
    }
    changeStatus(data);
});

function changeStatus(data) {
    const url = window.location.href;
    const companyId = url.substring(url.lastIndexOf("/") + 1);
    JSON.stringify(data);

    fetch(`/api/admin/recruiter/${companyId}`, {
        method: "PATCH",
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify(data)
    })
        .then(response => {
            if (response.status === 200) {
                // 수정이 성공한 경우
                location.href = `/admin/recruiter/${companyId}`;
                alert("처리 완료되었습니다.");
            } else {
                location.href = `/admin/recruiter/${companyId}`;
                alert("처리 실패하였습니다.");
            }
        })
}

2.2 컨트롤러

status 상태를 위한 domain을 만들어두었다.
JSON으로 view에서 보내기 때문에 Map<String, String>으로 받는다.

 @PatchMapping("{companyId}")
    public ResponseEntity<Void> modify(
            @PathVariable("companyId") Integer companyId,
            @RequestBody Map<String, String> statusMap) {
        boolean success = recruiterService.changeStatus(companyId, statusMap);
        if (success) {
            return ResponseEntity.ok().build(); // 200 OK 응답
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); // 500 내부 서버 오류 응답
        }
    }

2.3 서비스

approved 승인일때와 아닐때를 나누어서 처리한다.
승인일때는 company등급의 회원을 채용담당자로 변경해주어야하기 때문이다.

@Override
public boolean changeStatus(Integer companyId, Map<String, String> status) {
    String statusValue = status.get("status");

    Integer cnt = 0;

    if (statusValue.equals("approved")) {
        cnt = companyMapper.changeStatusWithMemberType(companyId, statusValue);
    } else {
        cnt = companyMapper.changeStatus(companyId, statusValue);
    }

    return cnt != 0;
}

2.4 매퍼

승인요청이면 mebmertype을 같이 변경해준다.
JOIN을 통해서 동시에 두 테이블의 값을 변경할 수 있는 것을 알게 되었다.

  <update id="changeStatus">
    UPDATE TB_COMPANIES SET status = #{statusValue}
    WHERE company_id = #{companyId}
</update>

<update id="changeStatusWithMemberType">
    UPDATE TB_COMPANIES t
    JOIN TB_MEMBERS m ON t.member_id = m.member_id
    SET t.status = #{statusValue}, m.member_type = 'recruiter'
    WHERE t.company_id = #{companyId}
</update>

3. 참여신청 목록

3.1 컨트롤러

검색대신 view에서 회차별로 보기위해 roundValue을 받아온다.
회차에 따라 목록에 보여주는 리스트를 다르게 할것이다.

@GetMapping
public ResponseEntity<Map<String, Object>> getList(
        @RequestParam(value = "roundValue", required = false) String roundValue,
        Authentication authentication) {
    Map<String, Object> result = recruiterService.getList(roundValue, authentication.getName());
    return ResponseEntity.ok(result);
}

3.2 서비스

@Override
public Map<String, Object> getList(String roundValue, String memberId) {
    Integer round = exhibitionInfoService.getCurrentRound();

    List<Company> companyList = companyMapper.getListByName(roundValue, memberId, round);

    return Map.of("companyList", companyList);
}

3.3 매퍼

회차가 all이면 전체 회차
now면 현재회차
past면 현재회차보다 작은 것들을 불러온다.

 <select id="getListByName" resultMap="companyMap">
        SELECT * FROM TB_COMPANIES
        <where>
            <if test="roundValue eq 'all'">
                member_id = #{memberId}
            </if>
            <if test="roundValue eq 'now'">
                member_id = #{memberId} and round = #{round}
            </if>
            <if test="roundValue eq 'past'">
                member_id = #{memberId} and round &lt; #{round}
            </if>
        </where>
        ORDER BY company_id DESC
    </select>

2023.07.28

신청목록을 만들었다.