[Sproutist 고민의 흔적] 작가 신청 다중 데이터 문제
![[Sproutist 고민의 흔적] 작가 신청 다중 데이터 문제](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1731944342113%2F8eb7cac6-d9a0-473d-9891-8af691bb797b.png&w=3840&q=75)
🤔상황
작가 신청 현황 조회 기능 정의
회원은 작가 신청을 한 뒤에 회원가입 시 입력했던 아이디와 이름으로 승인 현황을 조회할 수 있다.
아이디를 입력한 후 [조회] 버튼을 클릭한다.
해당 아이디가 신청 목록에 없다면 "해당 아이디는 신청 목록에 존재하지 않습니다. " 알림 창 .
해당 아이디가 신청 목록에 있다면 "해당 아이디는 현재 ( 대기, 승인, 거절 ) 상태입니다." 알림 창.
프로세스

- 작가 신청 상태를 확인하여
승인인 경우 다시 버튼을 눌러 신청할 수 없다.
- 작가 신청 상태를 확인하여
$.ajax({
type: 'POST',
url: '/user/rqcheck',
data: { mid: midval },
// contentType : 'application/json',
dataType: 'text',
success: function(result) {
console.log(result);
if (result == null || result =='' || result == '거절') {
// 신청상태가 아니거나 또는 거절이거나
artFrm.attr('action','/user/request');
artFrm.submit();
}else {
Swal.fire(
'이미 신청상태 입니다!',
'',
'info'
)
return;
}
},
error: function(xhr, status, er) {
// 오류 처리
console.error(er);
}
});
REQUEST 테이블

🫢원인
기획 당시 작가 신청이
거절된다면 REQUEST 테이블에서 삭제하도록 설정.- 하지만 그렇게 되면 관리자가 승인/거절 신청 현황을 관리할 수 없다.
그래서 거절 상태를 추가했더니 거절당한 회원이 여러 번 신청할 경우 아이디로 STATE 값을 가져올 때 여러 개의 STATE 값을 가져온다.
😊해결
UserMapper.xml
- 아이디(mid) 값으로 조회한 후 가져오는 값들을 신청 날짜를 기준으로 내림차순 정렬(최신순)
<select id="artSearch" resultMap="requestMap">
SELECT state
FROM REQUEST
WHERE mid = #{mid}
ORDER BY request_date DESC
</select>
-
- 작가 신청 상태를 담은 RequestVO 객체의 리스트
public List<RequestVO> artSearch(String mid); // 작가 신청 정보 조회 select
-
@PostMapping(value ="rqcheck" , produces = "application/text; charset=utf8") @ResponseBody @PreAuthorize("hasAnyRole('ROLE_ARTIST','ROLE_ADMIN','ROLE_USER')") public String rqcheck (String mid) { log.info("rqcheck...."); // 신청이 거절일때 또 신청하면 아이디가 겹친다. // 그럼 아이디에 대한 상태가 2개이상 넘어올 수 있다. // 그래서 신청날짜를 기준으로 최신순 정렬한뒤 첫번째 값만 가져오기 List<RequestVO> results = us.artSearch(mid); String state = ""; if (results != null && !results.isEmpty()) { RequestVO first = results.get(0); state = first.getState(); System.out.println(state); } return state; }
![[혼공컴운] 6주차_책 한 권을 끝내다니(Ch 14~ 15)](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1755441066842%2F4d3a042e-e395-4e14-84c2-725aeabc56ed.png&w=3840&q=75)
![[혼공컴운] 5주차_끝이 보인다(Ch 12 ~ 13)](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1754833767926%2F85ea771d-0416-409a-82d9-bcc62b92cf17.png&w=3840&q=75)
![[혼공컴운] 4주차_운영체제 시작(Ch 09 ~ 11)](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1753626546414%2F943e9f66-8c81-4bac-83b6-5797bd83293c.png&w=3840&q=75)
![[혼공컴운] 3주차_컴퓨터 구조 끝(Ch 06 ~ 08)](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1753020566648%2Fc2832934-e4d5-45c1-87c8-a1d5f27b2169.png&w=3840&q=75)