Skip to content

Commit

Permalink
Merge pull request #110 from HanRiverMeetup/issue-109
Browse files Browse the repository at this point in the history
closed #109 알람 관련 버그 수정
  • Loading branch information
leemy0102 authored Sep 26, 2018
2 parents 2254516 + 57b3d1b commit b53e6d7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static void sendMessage(JsonObject fcmMessage) throws IOException {
HttpURLConnection connection = getConnection();
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(fcmMessage.toString());
outputStream.write(fcmMessage.toString().getBytes("UTF-8"));
outputStream.flush();
outputStream.close();

Expand Down Expand Up @@ -138,7 +138,11 @@ public static void sendCommonMessage(String deviceToken, String title, String bo
sendMessage(notificationMessage);
}


/**
* Send notification message to FCM for delivery to specific topic.
*
* @throws IOException
*/
public static void sendTopicMessage(String topic, String title, String body) throws IOException {
JsonObject notificationMessage = buildNotificationMessage(topic, title, body);
System.out.println("FCM request body for message using common notification object:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import java.util.List;

import com.hangang.HangangRiver.meeting.model.NotificationLog;
import org.apache.ibatis.annotations.Param;

public interface NotificationLogMapper {
int insert(NotificationLog notificationLog);
int insertDetail(NotificationLog notificationLog);
int insert(@Param("user_id") String user_id,
@Param("message") String message);
List<NotificationLog> selectNotificationLogList(String user_id);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.hangang.HangangRiver.meeting.service;

import com.hangang.HangangRiver.access.dao.AccessMapper;
import com.hangang.HangangRiver.access.model.User;
import com.hangang.HangangRiver.common.web.ExceptionController;
import com.hangang.HangangRiver.common.web.MessageManager;
import com.hangang.HangangRiver.meeting.dao.CommentMapper;
import com.hangang.HangangRiver.meeting.dao.JoinDetailMapper;
import com.hangang.HangangRiver.meeting.dao.MatchingMapper;
import com.hangang.HangangRiver.meeting.dao.MeetingDetailMapper;
import com.hangang.HangangRiver.meeting.dao.NotificationLogMapper;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

public class MeetingBaseService {
Expand All @@ -22,4 +27,18 @@ public class MeetingBaseService {
public AccessMapper accessMapper;
@Autowired
public NotificationLogMapper notificationLogMapper;

private final Logger logger = LogManager.getLogger(ExceptionController.class);

public void pushMessage(String user_id, String message) {
try {
User user = accessMapper.detail(user_id);
MessageManager.sendCommonMessage(user.getFcm_token(), "심심한강", message);

notificationLogMapper.insert(user_id, message);
}
catch(Exception e) {
logger.error(user_id + " - " + message + " : " + e.getMessage(), e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
package com.hangang.HangangRiver.meeting.service;

import com.hangang.HangangRiver.access.model.User;
import com.hangang.HangangRiver.common.web.MessageManager;
import com.hangang.HangangRiver.exceptions.AlreadyContactedMeetingException;
import com.hangang.HangangRiver.exceptions.InvalidMatchingInfoException;
import com.hangang.HangangRiver.exceptions.InvalidMeetingException;
import com.hangang.HangangRiver.meeting.model.Comment;
import com.hangang.HangangRiver.meeting.model.ContactedMeeting;
import com.hangang.HangangRiver.meeting.model.JoinDetail;
import com.hangang.HangangRiver.meeting.model.MeetingDetail;
import com.hangang.HangangRiver.meeting.model.NotificationLog;

import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

@Service
public class MeetingCommService extends MeetingBaseService{
private String CONTACT_MSG = "같이 놀강~ 난누굴강 완료모임을 확인해주세요.";
private String ADD_COMMENT_MSG = "누가 내가 만든 모임에 관심을 보여요.";

public Comment createComment(Comment comment) throws InvalidMeetingException, IOException {
// 1. Check the target meeting to be valid
int meeting_seq = comment.getMeeting_seq();
MeetingDetail meetingDetail = meetingDetailMapper.detail(meeting_seq);

if (meetingDetailMapper.isExistMeetingDetail(meeting_seq)) {
commentMapper.insert(comment);
if (meetingDetail == null) {
throw new InvalidMeetingException();
}

MeetingDetail meetingDetail = meetingDetailMapper.detail(meeting_seq);
User user = accessMapper.detail(meetingDetail.getUser_id());
String message = "누가 내가 만든 모임에 관심을 보여요.";
MessageManager.sendCommonMessage(user.getFcm_token(), "심심한강", message);
commentMapper.insert(comment);

NotificationLog notificationLog = new NotificationLog();
notificationLog.setUser_id(meetingDetail.getUser_id());
notificationLog.setMessage(message);
notificationLogMapper.insert(notificationLog);
return comment;
}
else {
throw new InvalidMeetingException();
if(comment.getUser_id().compareTo(meetingDetail.getUser_id()) != 0){
pushMessage(meetingDetail.getUser_id(), ADD_COMMENT_MSG);
}

return comment;
}

public List<Comment> getCommentsByMeeting(int meeting_seq){
Expand Down Expand Up @@ -72,21 +66,8 @@ public ContactedMeeting match(ContactedMeeting meeting)
meeting.setGuest_user_id(joinDetailInfo.getUser_id());
matchingMapper.insert(meeting);

User hostUser = accessMapper.detail(meeting.getHost_user_id());
User guestUser = accessMapper.detail(meeting.getGuest_user_id());
String message = "같이 놀강~ 난누굴강 완료모임을 확인해주세요.";
MessageManager.sendCommonMessage(hostUser.getFcm_token(), "심심한강", message);
MessageManager.sendCommonMessage(guestUser.getFcm_token(), "심심한강", message);

NotificationLog hostNotificationLog = new NotificationLog();
hostNotificationLog.setUser_id(meeting.getHost_user_id());
hostNotificationLog.setMessage(message);
notificationLogMapper.insert(hostNotificationLog);

NotificationLog guestNotificationLog = new NotificationLog();
guestNotificationLog.setUser_id(meeting.getGuest_user_id());
guestNotificationLog.setMessage(message);
notificationLogMapper.insert(guestNotificationLog);
pushMessage(meeting.getHost_user_id(), CONTACT_MSG);
pushMessage(meeting.getGuest_user_id(), CONTACT_MSG);

return meeting;
}
Expand All @@ -102,12 +83,4 @@ public ContactedMeeting getContactedMeetingByMatchingInfo(int meeting_seq, int a
public void unmatch(int contact_seq){
matchingMapper.delete(contact_seq);
}

/* public List<MeetingDetail> selectMyMatchingMeetings(String user_id){
return matchingMapper.selectMyMatchingMeetings(user_id);
}
public List<MeetingDetail> selectMyMatchingApplications(String user_id){
return matchingMapper.selectMyMatchingApplications(user_id);
}*/
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.hangang.HangangRiver.meeting.service;

import com.hangang.HangangRiver.access.model.User;
import com.hangang.HangangRiver.common.web.MessageManager;
import com.hangang.HangangRiver.exceptions.ExistJoinDetailException;
import com.hangang.HangangRiver.exceptions.InvalidMeetingException;
import com.hangang.HangangRiver.exceptions.OverCountJoinDetailException;
import com.hangang.HangangRiver.meeting.model.JoinDetail;
import com.hangang.HangangRiver.meeting.model.MeetingDetail;
import com.hangang.HangangRiver.meeting.model.NotificationLog;

import org.springframework.stereotype.Service;

Expand All @@ -16,6 +13,8 @@

@Service
public class MeetingGuestService extends MeetingBaseService{
private final String JOIN_MSG = "똑똑! 내가 만든 모임에 신청자가 왔습니다!";

public JoinDetail join(JoinDetail joinDetail)
throws ExistJoinDetailException, InvalidMeetingException, OverCountJoinDetailException, IOException {

Expand All @@ -35,15 +34,10 @@ public JoinDetail join(JoinDetail joinDetail)
}

joinDetailMapper.insert(joinDetail);

MeetingDetail meetingDetail = meetingDetailMapper.detail(meeting_seq);
User user = accessMapper.detail(meetingDetail.getUser_id());
String message = "똑똑! 내가 만든 모임에 신청자가 왔습니다!";
MessageManager.sendCommonMessage(user.getFcm_token(), "모임 참여", "똑똑! 내가 만든 모임에 신청자가 왔습니다!");

NotificationLog notificationLog = new NotificationLog();
notificationLog.setUser_id(meetingDetail.getUser_id());
notificationLog.setMessage(message);
notificationLogMapper.insert(notificationLog);
pushMessage(meetingDetail.getUser_id(), JOIN_MSG);

return joinDetail;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Service
public class NotificationLogService extends MeetingBaseService{
public NotificationLog createNotificationLog(NotificationLog notificationLog){
notificationLogMapper.insert(notificationLog);
notificationLogMapper.insertDetail(notificationLog);
return notificationLog;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hangang.HangangRiver.meeting.dao.NotificationLogMapper">

<insert id="insert" parameterType="com.hangang.HangangRiver.meeting.model.NotificationLog">
<insert id="insert">
INSERT INTO
notification_log
(user_id, message, creation_time)
VALUES
(#{user_id}, #{message}, current_timestamp)
<selectKey keyProperty="notification_seq" resultType="Integer">
SELECT LAST_INSERT_ID()
</selectKey>
</insert>

<insert id="insertDetail" parameterType="com.hangang.HangangRiver.meeting.model.NotificationLog">
INSERT INTO
notification_log
(user_id, message, creation_time)
Expand Down

0 comments on commit b53e6d7

Please sign in to comment.