게시글 상세보기 쿼리

김지원·2023년 8월 8일
0

select
b.id board_id,
b.content board_content,
b.title board_title,
b.user_id board_user_id,
r.id reply_id,
r.comment reply_comment,
r.user_id reply_user_id,
ru.username reply_user_username
from board_tb b left outer join reply_tb r
on b.id = r.board_id
inner join user_tb ru
on r.user_id = ru.id
where b.id = 1;

select
b.id board_id,
b.content board_content,
b.title board_title,
b.user_id board_user_id,
r.id reply_id,
r.comment reply_comment,
r.user_id reply_user_id,
ru.username reply_user_username,
case when r.user_id = 2 then true else false end reply_owner
from board_tb b left outer join reply_tb r
on b.id = r.board_id
left outer join user_tb ru
on r.user_id = ru.id
where b.id = 1;

        {{#replyOwner}}
        <div class="replyDelete col-auto">

          <form action="/reply/{{replyId}}/delete" method="post">
            <button type="submit" class="btn btn-danger text-white">삭제</button>
          </form>

        </div>
        {{/replyOwner}}

          <form class="replyAll" sessionUserId={{sessionUserId}} replyUserId={{replyUserId}} action="/reply/{{replyId}}/delete" method="post">
            <button type="submit" class="btn btn-danger text-white">삭제</button>
          </form>
        
        
        
<!--
<script>
  let replyAll = document.querySelectorAll('.replyAll');

  replyAll.forEach(element => {
    let sessionUserId = element.getAttribute('sessionUserId');
    let replyUserId = element.getAttribute('replyUserId');
    console.log("로그인한아이디:"+sessionUserId+" 리플쓴아이디:"+replyUserId);
    if(sessionUserId != replyUserId){
      element.style.display = 'none';
    }
  });
</script>
-->

로그인했을때/안했을때 상황따라 동적쿼리를 만들어도 되고
그냥 리포지토리에 2개를 만들어서 상황따라 다르게 써도 됨

profile
https://github.com/k7850

0개의 댓글