Posts DEVIL: 알림 기능 구현
Post
Cancel

DEVIL: 알림 기능 구현

요구사항

다음과 같은 상황이 발생할 때 당사자에게 알림이 가도록 만든다.

  • 유저 작성 게시글에 댓글이 달릴 경우
  • 유저 작성 댓글에 대댓글이 달릴 경우
  • 타유저가 유저를 팔로할 경우
  • 유저가 뱃지를 획득했을 경우

진행현황

  • DB 구조 변경: comment, follow, badge 테이블의 PK를 FK를 갖도록 변경한다.
  • Notification 관련 Doman, Controller, Service, Dao, Mapper 파일을 만든다.

알림 생성 및 저장

  • 특정 상황이 발생했을 때 해당하는 알림을 생성하여 저장하도록 각 Service를 변경한다. 이때 트랜잭션 처리도 함께 해준다.
    • CommentService: add()
    • FollowService: add()
    • CollectService: add()
  • NotificationMapper의 insert 쿼리 작성
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
      <insert id="insert" parameterType="notification">
          insert into noti(type, cno, fwer_no, bno, uno)
          values(#{type}, #{comment.no}, #{follower.no}, #{badge.no},
          <choose>
              <when test="comment == null">
                  #{userNo}
              </when>
              <otherwise>
               <if test="type==1">
                  (select a.writer from comment c inner join article a on a.arno = c.arno where c.cno = #{comment.no})
                  </if>
                  <if test="type==2">
                  (select c.uno from comment c inner join comment c2 on c.momno = c2.cno where c.cno = #{comment.no})
                  </if>
              </otherwise>
          </choose>
          )
      </insert>
    

알림 목록 출력

  • Model: NotificatinoDao.findAll(), NotiifcationService.list()
  • Controller: NotificationController.list()
  • View
This post is licensed under CC BY 4.0 by the author.

DEVIL: DispatcherServlet에 따른 비활성 상태의 데이터 추출 여부 변경

DEVIL: 알림 목록 요청을 비동기 요청으로 전환

Loading comments from Disqus ...