Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.5.6 #232

Merged
merged 15 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private Message buildMessage(String token, Alert alert, Map<String, String> data
.setToken(token)
.setNotification(buildNotification(alert))
.setAndroidConfig(buildAndroidConfig(alert))
.putData("title", alert.getTitle())
.putData("body", alert.getBody())
.putData("publishedAt", alert.getCreatedAt().toString())
.putData("userId", alert.getUserId().toString())
.putData("type", alert.getType().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.teumteum.meeting.domain.Topic;
import net.teumteum.meeting.domain.request.CreateMeetingRequest;
import net.teumteum.meeting.domain.request.UpdateMeetingRequest;
import net.teumteum.meeting.domain.response.MeetingParticipantsResponse;
import net.teumteum.meeting.domain.response.MeetingParticipantResponse;
import net.teumteum.meeting.domain.response.MeetingResponse;
import net.teumteum.meeting.domain.response.MeetingsResponse;
import net.teumteum.meeting.model.PageDto;
Expand Down Expand Up @@ -43,14 +43,14 @@ public class MeetingController {
public MeetingResponse createMeeting(
@RequestPart @Valid CreateMeetingRequest meetingRequest,
@RequestPart List<MultipartFile> images) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
return meetingService.createMeeting(images, meetingRequest, userId);
}

@GetMapping("/{meetingId}")
@ResponseStatus(HttpStatus.OK)
public MeetingResponse getMeetingById(@PathVariable("meetingId") Long meetingId) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
return meetingService.getMeetingById(meetingId, userId);
}

Expand All @@ -64,7 +64,7 @@ public PageDto<MeetingsResponse> getMeetingsByCondition(
@RequestParam(value = "participantUserId", required = false) Long participantUserId,
@RequestParam(value = "isBookmarked", required = false) Boolean isBookmarked,
@RequestParam(value = "searchWord", required = false) String searchWord) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
return meetingService.getMeetingsBySpecification(pageable, topic, meetingAreaStreet, participantUserId,
searchWord, isBookmarked, isOpen, userId);
}
Expand All @@ -74,55 +74,56 @@ public PageDto<MeetingsResponse> getMeetingsByCondition(
public MeetingResponse updateMeeting(@PathVariable Long meetingId,
@RequestPart @Valid UpdateMeetingRequest request,
@RequestPart List<MultipartFile> images) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
return meetingService.updateMeeting(meetingId, images, request, userId);
}

@DeleteMapping("/{meetingId}")
@ResponseStatus(HttpStatus.OK)
public void deleteMeeting(@PathVariable("meetingId") Long meetingId) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
meetingService.deleteMeeting(meetingId, userId);
}

@PostMapping("/{meetingId}/participants")
@ResponseStatus(HttpStatus.CREATED)
public MeetingResponse addParticipant(@PathVariable("meetingId") Long meetingId) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
return meetingService.addParticipant(meetingId, userId);
}

@DeleteMapping("/{meetingId}/participants")
@ResponseStatus(HttpStatus.OK)
public void deleteParticipant(@PathVariable("meetingId") Long meetingId) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
meetingService.cancelParticipant(meetingId, userId);
}

@GetMapping("/{meetingId}/participants")
@ResponseStatus(HttpStatus.OK)
public List<MeetingParticipantsResponse> getParticipants(@PathVariable("meetingId") Long meetingId) {
return meetingService.getParticipants(meetingId);
public List<MeetingParticipantResponse> getParticipants(@PathVariable("meetingId") Long meetingId) {
Long userId = getCurrentUserId();
return meetingService.getParticipants(meetingId, userId);
}

@PostMapping("/{meetingId}/reports")
@ResponseStatus(HttpStatus.CREATED)
public void reportMeeting(@PathVariable("meetingId") Long meetingId) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
meetingService.reportMeeting(meetingId, userId);
}

@PostMapping("/{meetingId}/bookmarks")
@ResponseStatus(HttpStatus.CREATED)
public void addBookmark(@PathVariable("meetingId") Long meetingId) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
meetingService.addBookmark(meetingId, userId);
}

@DeleteMapping("/{meetingId}/bookmarks")
@ResponseStatus(HttpStatus.OK)
public void deleteBookmark(@PathVariable("meetingId") Long meetingId) {
Long userId = securityService.getCurrentUserId();
Long userId = getCurrentUserId();
meetingService.cancelBookmark(meetingId, userId);
}

Expand All @@ -132,4 +133,8 @@ public ErrorResponse handleIllegalArgumentException(IllegalArgumentException ill
Sentry.captureException(illegalArgumentException);
return ErrorResponse.of(illegalArgumentException);
}

private Long getCurrentUserId() {
return securityService.getCurrentUserId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import net.teumteum.user.domain.User;

public record MeetingParticipantsResponse(
public record MeetingParticipantResponse(
Long id,
Long characterId,
String name,
String job
) {

public static MeetingParticipantsResponse of(
public static MeetingParticipantResponse of(
User user
) {
return new MeetingParticipantsResponse(
return new MeetingParticipantResponse(
user.getId(),
user.getCharacterId(),
user.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@Transactional(readOnly = true)
public class MeetingAlertPublisher {

private static final String KR_TIME_ZONE = "Asia/Seoul";
private static final String EVERY_ONE_MINUTES = "0 * * * * *";
private static final String EVERY_12PM = "0 0 12 * * *";

Expand All @@ -24,18 +25,20 @@ public class MeetingAlertPublisher {

@Scheduled(cron = EVERY_ONE_MINUTES)
public void alertBeforeMeeting() {
var alertStart = LocalDateTime.now(ZoneId.of("Asia/Seoul")).plusMinutes(5).withNano(0).withSecond(0);
var alertStart = LocalDateTime.now(ZoneId.of(KR_TIME_ZONE)).plusMinutes(5).withNano(0).withSecond(0);
var alertEnd = alertStart.plusMinutes(1).withNano(0).withSecond(0);
var alertTargets = meetingRepository.findAlertMeetings(alertStart, alertEnd);
alertTargets.forEach(meeting -> eventPublisher.publishEvent(
new BeforeMeetingAlerted(meeting.getParticipantUserIds())
)
);
alertTargets.stream()
.filter(alertTarget -> alertTarget.getParticipantUserIds().size() > 2)
.forEach(meeting -> eventPublisher.publishEvent(
new BeforeMeetingAlerted(meeting.getParticipantUserIds())
)
);
}

@Scheduled(cron = EVERY_12PM)
public void alertEndMeeting() {
var today = LocalDateTime.now(ZoneId.of("Asia/Seoul"))
var today = LocalDateTime.now(ZoneId.of(KR_TIME_ZONE))
.withNano(0)
.withSecond(0)
.withMinute(0)
Expand All @@ -44,14 +47,16 @@ public void alertEndMeeting() {
var yesterday = today.minusDays(1);

var alertTargets = meetingRepository.findAlertMeetings(yesterday, today);
alertTargets.forEach(meeting -> eventPublisher.publishEvent(
new EndMeetingAlerted(meeting.getId(), meeting.getTitle(), meeting.getParticipantUserIds())
));
alertTargets.stream()
.filter(alertTarget -> alertTarget.getParticipantUserIds().size() > 2)
.forEach(meeting -> eventPublisher.publishEvent(
new EndMeetingAlerted(meeting.getId(), meeting.getTitle(), meeting.getParticipantUserIds())
));
}

@Scheduled(cron = EVERY_ONE_MINUTES)
public void alertEndMeetingForQa() {
var today = LocalDateTime.now(ZoneId.of("Asia/Seoul"))
var today = LocalDateTime.now(ZoneId.of(KR_TIME_ZONE))
.withNano(0)
.withSecond(0)
.withMinute(0)
Expand All @@ -61,8 +66,10 @@ public void alertEndMeetingForQa() {
var yesterday = today.minusDays(365);

var alertTargets = meetingRepository.findAlertMeetings(yesterday, future);
alertTargets.forEach(meeting -> eventPublisher.publishEvent(
new EndMeetingAlerted(meeting.getId(), meeting.getTitle(), meeting.getParticipantUserIds())
));
alertTargets.stream()
.filter(alertTarget -> alertTarget.getParticipantUserIds().size() > 2)
.forEach(meeting -> eventPublisher.publishEvent(
new EndMeetingAlerted(meeting.getId(), meeting.getTitle(), meeting.getParticipantUserIds())
));
}
}
18 changes: 14 additions & 4 deletions src/main/java/net/teumteum/meeting/service/MeetingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.teumteum.meeting.domain.Topic;
import net.teumteum.meeting.domain.request.CreateMeetingRequest;
import net.teumteum.meeting.domain.request.UpdateMeetingRequest;
import net.teumteum.meeting.domain.response.MeetingParticipantsResponse;
import net.teumteum.meeting.domain.response.MeetingParticipantResponse;
import net.teumteum.meeting.domain.response.MeetingResponse;
import net.teumteum.meeting.domain.response.MeetingsResponse;
import net.teumteum.meeting.model.PageDto;
Expand Down Expand Up @@ -94,7 +94,8 @@ public void deleteMeeting(Long meetingId, Long userId) {
}

@Transactional(readOnly = true)
public PageDto<MeetingsResponse> getMeetingsBySpecification(Pageable pageable, Topic topic, String meetingAreaStreet,
public PageDto<MeetingsResponse> getMeetingsBySpecification(Pageable pageable, Topic topic,
String meetingAreaStreet,
Long participantUserId, String searchWord, Boolean isBookmarked, Boolean isOpen, Long userId) {

Specification<Meeting> spec = MeetingSpecification.withIsOpen(isOpen);
Expand Down Expand Up @@ -153,13 +154,16 @@ public void cancelParticipant(Long meetingId, Long userId) {
}

@Transactional(readOnly = true)
public List<MeetingParticipantsResponse> getParticipants(Long meetingId) {
public List<MeetingParticipantResponse> getParticipants(Long meetingId, Long userId) {
var existMeeting = getMeeting(meetingId);

checkMeetingContainUser(existMeeting, userId);

return existMeeting.getParticipantUserIds().stream()
.filter(id -> !id.equals(userId))
.map(userConnector::findUserById)
.flatMap(Optional::stream)
.map(MeetingParticipantsResponse::of)
.map(MeetingParticipantResponse::of)
.toList();
}

Expand Down Expand Up @@ -207,4 +211,10 @@ public void reportMeeting(Long meetingId, Long userId) {
throw new IllegalArgumentException("모임 개설자는 모임을 신고할 수 없습니다.");
}
}

private void checkMeetingContainUser(Meeting meeting, Long userId) {
if (!meeting.getParticipantUserIds().contains(userId)) {
throw new IllegalArgumentException("모임에 참여하지 않은 회원입니다.");
}
}
}
Loading
Loading