Skip to content

Commit

Permalink
[CHORE] 코드 스타일 리뷰 반영
Browse files Browse the repository at this point in the history
[참고 PR](#306)
  • Loading branch information
yummygyudon committed Jan 18, 2025
1 parent 42ffa6a commit 4eeb48c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ public class AlarmServiceImpl implements AlarmService {
public AlarmCreateResponse sendInstantAlarm(AlarmInstantSendRequest request) {
val alarm = request.toEntity();
val alarmTarget = alarm.getTarget();

alarmTarget.setTargetIds(extractTargetIds(alarmTarget));
val savedAlarm = alarmRepository.save(alarm);

val savedAlarm = alarmRepository.save(alarm);
val alarmRequest = InstantAlarmRequest.of(savedAlarm);
alarmManager.sendInstant(alarmRequest);

alarmManager.sendInstant(alarmRequest);
return AlarmCreateResponse.of(savedAlarm);
}

Expand Down Expand Up @@ -93,6 +94,7 @@ public void deleteAlarm(long alarmId) {
}

@Override
@Transactional
public void updateScheduleAlarm(long alarmId, AlarmScheduleStatusUpdateRequest request) {
val alarm = findAlarm(alarmId);
alarm.updateStatusToComplete(request.sendAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class WebLectureServiceImpl implements WebLectureService {
public static final String NULL = "null";
public static final String WHITE_SPACE = " ";

private final LectureRepository lectureRepository;
private final SubLectureRepository subLectureRepository;
private final AttendanceRepository attendanceRepository;
private final SubAttendanceRepository subAttendanceRepository;
private final MemberRepository memberRepository;

private final AlarmManager alarmSender;
private final AlarmManager alarmManager;
private final ValueConfig valueConfig;

@Override
Expand Down Expand Up @@ -177,14 +179,14 @@ private Lecture getLectureReadyToEnd(long lectureId) {
}

private void sendAlarm(Lecture lecture) {
val alarmMessageTitle = lecture.getName() + " " + valueConfig.getALARM_MESSAGE_TITLE();
val alarmMessageTitle = String.join(WHITE_SPACE, lecture.getName(), valueConfig.getALARM_MESSAGE_TITLE());
val alarmMessageContent = valueConfig.getALARM_MESSAGE_CONTENT();
val targets = lecture.getAttendances().stream()
.map(attendance -> String.valueOf(attendance.getMember().getPlaygroundId()))
.filter(id -> !id.equals("null"))
.filter(id -> !id.equals(NULL))
.toList();
val alarmRequest = InstantAlarmRequest.of(alarmMessageTitle, alarmMessageContent, targets);
alarmSender.sendInstant(alarmRequest);
alarmManager.sendInstant(alarmRequest);
}

private Lecture getLectureToDelete(long lectureId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InstantAlarmSender implements AlarmSender{

@Override
public void sendAlarm(AlarmRequest alarmRequest) {
InstantAlarmRequest instantRequest = (InstantAlarmRequest) alarmRequest;
val instantRequest = (InstantAlarmRequest) alarmRequest;
try {
val host = valueConfig.getNOTIFICATION_URL();
val body = generateBody(instantRequest);
Expand All @@ -46,10 +46,8 @@ public void sendAlarm(AlarmRequest alarmRequest) {

private Map<Object, Object> generateBody(InstantAlarmRequest instantRequest) {
val body = new HashMap<>();

putRequiredAttributes(instantRequest, body);
putOptionalAttributes(instantRequest, body);

return body;
}

Expand All @@ -60,30 +58,32 @@ private static void putRequiredAttributes(InstantAlarmRequest instantRequest, Ha
}

private static void putOptionalAttributes(InstantAlarmRequest instantRequest, HashMap<Object, Object> body) {
if (!instantRequest.targetType().equals(AlarmTargetType.ALL)) {
val isTargetAll = instantRequest.targetType().equals(AlarmTargetType.ALL);
val isWebLink = instantRequest.linkType().equals(AlarmLinkType.WEB);
val isAppLink = instantRequest.linkType().equals(AlarmLinkType.APP);

if (!isTargetAll) {
body.put("userIds", instantRequest.targets());
}

if (instantRequest.linkType().equals(AlarmLinkType.WEB)) {
if (isWebLink) {
body.put("webLink", instantRequest.link());
} else if (instantRequest.linkType().equals(AlarmLinkType.APP)) {
} else if (isAppLink) {
body.put("appLink", instantRequest.link());
}
}

private HttpHeaders generateHeader(InstantAlarmRequest instantRequest) {
val headers = new HttpHeaders();
val apiKey = valueConfig.getNOTIFICATION_KEY();
val actionValue = instantRequest.targetType().getAction().getValue();

headers.setContentType(APPLICATION_JSON);
headers.setAccept(Collections.singletonList(APPLICATION_JSON));

String actionValue = instantRequest.targetType().getAction().getValue();
headers.add("action", actionValue);
headers.add("transactionId", randomUUID().toString());
headers.add("service", "operation");
headers.add("x-api-key", apiKey);

return headers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import java.time.format.DateTimeFormatter;
import java.util.UUID;

import static org.sopt.makers.operation.constant.AlarmConstant.ALARM_REQUEST_DATE_FORMAT;
import static org.sopt.makers.operation.constant.AlarmConstant.ALARM_REQUEST_TIME_FORMAT;

@Component
@RequiredArgsConstructor
class ScheduleAlarmSender implements AlarmSender{
Expand All @@ -52,7 +55,6 @@ public void sendAlarm(AlarmRequest alarmRequest) {
try {
val name = generateEventName(scheduleRequest);
val cronExpression = generateScheduleCronExpression(scheduleRequest);

val eventJson = generateEventJson(scheduleRequest);
val target = generateEventTarget(eventJson);

Expand Down Expand Up @@ -85,9 +87,8 @@ private Target generateEventTarget(String eventJson) {
}

private String generateEventName(ScheduleAlarmRequest request) {
val dateData = request.scheduleDateTime().toLocalDate().format(DateTimeFormatter.ISO_DATE);
val timeData = request.scheduleDateTime().toLocalTime().format(DateTimeFormatter.ofPattern("HH-mm"));

val dateData = request.scheduleDateTime().toLocalDate().format(DateTimeFormatter.ofPattern(ALARM_REQUEST_DATE_FORMAT));
val timeData = request.scheduleDateTime().toLocalTime().format(DateTimeFormatter.ofPattern(ALARM_REQUEST_TIME_FORMAT));
return String.format("%s_%s_%d", dateData, timeData, request.alarmId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public record InstantAlarmRequest(
AlarmLinkType linkType

) implements AlarmRequest {

public static InstantAlarmRequest of(Alarm alarm) {
val content = alarm.getContent();
return InstantAlarmRequest.builder()
Expand Down

0 comments on commit 4eeb48c

Please sign in to comment.