Skip to content

Commit

Permalink
정들었던 하우스 마지막 커밋입니다.. 고생했어요 혜정이 혁준이 !!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
orijoon98 committed Jul 2, 2024
1 parent daf46a1 commit e6de772
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package hous.api.notification;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import hous.api.service.notification.NotificationService;
import hous.api.service.notification.dto.request.NotificationSendAllRequestDto;
import hous.common.dto.SuccessResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

@Api(tags = "Todo")
@RestController
@RequestMapping("/v1")
@RequiredArgsConstructor
public class NotificationController {

private final NotificationService notificationService;

@ApiOperation(
value = "마지막 API 입니당. ㅠㅠ 혜정이 혁준이 고생했어요.",
notes = "앱 종료 푸시 알림을 전송합니다."
)
@PostMapping("/notification/all")
public ResponseEntity<SuccessResponse<String>> sendAll(@Valid @RequestBody NotificationSendAllRequestDto request) {
notificationService.sendAll(request);
return SuccessResponse.OK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.transaction.annotation.Transactional;

import hous.api.config.sqs.producer.SqsProducer;
import hous.api.service.notification.dto.request.NotificationSendAllRequestDto;
import hous.api.service.user.UserServiceUtils;
import hous.common.dto.sqs.FirebaseDto;
import hous.core.domain.badge.BadgeInfo;
import hous.core.domain.notification.Notification;
Expand All @@ -18,6 +20,7 @@
import hous.core.domain.user.PushStatus;
import hous.core.domain.user.TodoPushStatus;
import hous.core.domain.user.User;
import hous.core.domain.user.mysql.UserRepository;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
Expand All @@ -26,6 +29,7 @@
public class NotificationService {

private final NotificationRepository notificationRepository;
private final UserRepository userRepository;
private final SqsProducer sqsProducer;

public void sendNewTodoNotification(User to, Todo todo, boolean isTake) {
Expand Down Expand Up @@ -133,6 +137,13 @@ public void sendNewBadgeNotification(User to, BadgeInfo badgeInfo) {
}
}

public void sendAll(NotificationSendAllRequestDto request) {
List<User> users = UserServiceUtils.findAllUsers(userRepository);
users.forEach(user -> {
sqsProducer.produce(FirebaseDto.of(user.getFcmToken(), request.getTitle(), request.getBody()));
});
}

private String generateContent(String name, String message) {
return String.format("'%s' %s", name, message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hous.api.service.notification.dto.request;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@ToString
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder(access = AccessLevel.PRIVATE)
public class NotificationSendAllRequestDto {

private String title;
private String body;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static User findUserBySocialIdAndSocialType(UserRepository userRepository
return user;
}

public static List<User> findAllUsers(UserRepository userRepository) {
return userRepository.findAll();
}

public static User findUserById(UserRepository userRepository, Long userId) {
User user = userRepository.findUserById(userId);
if (user == null) {
Expand Down

0 comments on commit e6de772

Please sign in to comment.