Skip to content
Draft
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 @@ -79,7 +79,7 @@ public ChatContentsResponse saveChatLoudSpeakerContent(LoudspeakerNotificationRe
.orElseThrow(() -> new UserNotFoundException("해당 작성자는 존재하지 않는 사용자입니다."));

ChatLoudSpeakerContent chatLoudSpeakerContent = chatLoudSpeakerContentRepository.save(
ChatLoudSpeakerContent.of(request.getStartTime())
ChatLoudSpeakerContent.of(request.getStartTime().getHour())
);
ChatContents chatContents = ChatContents.createLoudspeakerContent(
ChatContentType.LOUDSPEAKER,
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/slams/server/common/dto/BaseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.slams.server.common.dto;

import java.time.LocalDateTime;

/**
* Created by yunyun on 2022/01/24.
*/
public class BaseDto {
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package org.slams.server.notification.dto.response;
package org.slams.server.common.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;
import org.slams.server.court.entity.Texture;
import org.slams.server.notification.common.ValidationMessage;

import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;

/**
* Created by yunyun on 2021/12/14.
* Created by yunyun on 2022/01/24.
*/

@Getter
public class CourtInfo {
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Court {
private final Long id;
private final String name;
private final double latitude;
Expand All @@ -22,7 +24,7 @@ public class CourtInfo {
private final Texture texture;

@Builder
public CourtInfo(
public Court(
Long id,
String name,
double latitude,
Expand All @@ -31,9 +33,9 @@ public CourtInfo(
int basketCount,
Texture texture
){
checkArgument(id != null, "userId는 null을 허용하지 않습니다.");
checkArgument(isNotEmpty(name), "농구장는 빈값을 허용하지 않습니다.");
checkArgument(basketCount >= 0, "골대 개수는 0이상만 가능합니다.");
checkArgument(id != null, ValidationMessage.NOTNULL_ID);
checkArgument(isNotEmpty(name), ValidationMessage.NOT_EMPTY_NAME);
checkArgument(basketCount > 0, ValidationMessage.MORE_THAN_ONE_BASKET_COUNT);

this.id = id;
this.name = name;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/slams/server/common/dto/Follow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.slams.server.common.dto;

/**
* Created by yunyun on 2022/01/24.
*/

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Follow extends BaseDto{
private User creator;
private User receiver;

@Builder
public Follow(
User creator,
User receiver
){
this.creator = creator;
this.receiver = receiver;
}

}
47 changes: 47 additions & 0 deletions src/main/java/org/slams/server/common/dto/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.slams.server.common.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import org.slams.server.notification.common.ValidationMessage;
import org.slams.server.user.entity.Position;
import org.slams.server.user.entity.Proficiency;

import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;

/**
* Created by yunyun on 2022/01/24.
*/

@JsonInclude(JsonInclude.Include.NON_NULL)
public class User extends BaseDto{

private Long id;
private String nickname;
private String profileImage;
private String description;
private Proficiency proficiency;
private List<Position> positions;

@Builder
public User(
Long id,
String nickname,
String profileImage,
String description,
Proficiency proficiency,
List<Position> positions
){
checkArgument(id != null, ValidationMessage.NOTNULL_ID);
checkArgument(isNotEmpty(nickname), ValidationMessage.NOT_EMPTY_NICKNAME);

this.id = id;
this.nickname = nickname;
this.profileImage = profileImage;
this.description = description;
this.positions = positions;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ public void insertExcel() throws IOException, InvalidFormatException {
}

public void insertNotificationDummy(Long userId, int dataSize){
LoudspeakerNotificationRequest request = new LoudspeakerNotificationRequest(1L, LocalDateTime.now().getHour(), 1L);
LoudspeakerNotificationRequest request = new LoudspeakerNotificationRequest(1L, LocalDateTime.now(), LocalDateTime.now().plusHours(2L), 1L);

int index = 0;
while (index < dataSize){
notificationService.saveForLoudSpeakerNotification(request, userId);
notificationService.saveForLoudSpeakerNotification(request, userId, userId);
index = index + 1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.slams.server.notification.common;

/**
* Created by yunyun on 2022/01/24.
*/
public enum ValidationMessage {
// common
NOTNULL_ID("Id는 NULL 을 허용하지 않습니다."),

// user
NOTNULL_USERID("UserId는 NULL 을 허용하지 않습니다."),
NOTNULL_USER("User 정보는 NULL 을 허용하지 않습니다."),
NOT_EMPTY_NICKNAME("nickname은 빈값을 허용하지 않습니다."),

// notification
NOTNULL_NOTIFICATION_TYPE("Notification Type 정보는 NULL 을 허용하지 않습니다."),

// court
NOTNULL_COURT("경기장 정보는 NULL 을 허용하지 않습니다."),
NOTNULL_START_TIME("경기 시작 시간의 정보는 NULL 을 허용하지 않습니다."),
NOTNULL_END_TIME("경기 끝 시간의 정보는 NULL 을 허용하지 않습니다."),
NOT_EMPTY_NAME("경기장 이름은 빈값을 허용하지 않습니다."),

MORE_THAN_ONE_BASKET_COUNT("골대의 개수는 1개 이상이어야 합니다.")
;


private String message;

ValidationMessage(String message) {
this.message = message;
}

public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ public void saveLoudSpeakerAndThenSending(
LoudspeakerNotificationRequest request,
SimpMessageHeaderAccessor headerAccessor
){
Long userId = websocketUtil.findTokenFromHeader(headerAccessor);
List<Long> bookerIds = reservationRepository.findBeakerIdByCourtId(request.getCourtId());
Long sendId = websocketUtil.findTokenFromHeader(headerAccessor);
List<Long> receiverIds = reservationRepository.findBeakerIdByCourtId(request.getCourtId());

for (Long bookId : bookerIds){
if (bookId.equals(userId)){
for (Long receiverId : receiverIds){
if (receiverId.equals(sendId)){
continue;
}
NotificationResponse notification = notificationService.saveForLoudSpeakerNotification(request, bookId);
NotificationResponse notification = notificationService.saveForLoudSpeakerNotification(request, receiverId, sendId);
websocket.convertAndSend(
String.format("/user/%d/notification", bookId),
String.format("/user/%d/notification", receiverId),
notification
);
}

ChatContentsResponse chatContentsResponse = chatContentsService.saveChatLoudSpeakerContent(request, userId);
ChatContentsResponse chatContentsResponse = chatContentsService.saveChatLoudSpeakerContent(request, sendId);
websocket.convertAndSend(
String.format("/user/%d/chat", request.getCourtId()),
chatContentsResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package org.slams.server.notification.convertor;

import org.slams.server.common.dto.Court;
import org.slams.server.common.dto.Follow;
import org.slams.server.common.dto.User;
import org.slams.server.notification.Exception.InvalidNotificationTypeException;
import org.slams.server.notification.dto.response.CourtInfo;
import org.slams.server.notification.dto.response.FollowerInfo;
import org.slams.server.notification.dto.response.LoudspeakerInfo;
import org.slams.server.notification.dto.response.Loudspeaker;
import org.slams.server.notification.dto.response.NotificationResponse;
import org.slams.server.notification.entity.FollowNotification;
import org.slams.server.notification.entity.LoudSpeakerNotification;
import org.slams.server.notification.entity.NotificationIndex;
import org.slams.server.notification.entity.Notification;
import org.slams.server.notification.entity.NotificationType;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

Expand All @@ -22,31 +20,33 @@
@Component
public class NotificationConvertor {

public List<NotificationResponse> toDtoList(List<NotificationIndex> notifications){
/** null 유효성 검사 추가 **/
// followNotificationList
public List<NotificationResponse> toDtoList(List<Notification> notifications){

if (notifications.isEmpty()){
return Collections.emptyList();
}

return notifications.stream()
.map(v -> toDto(v))
.collect(Collectors.toList());
}

public NotificationResponse toDto(NotificationIndex notification){
if (notification.getNotificationType().equals(NotificationType.LOUDSPEAKER)){
public NotificationResponse toDto(Notification notification){
if (notification.getType().equals(NotificationType.LOUDSPEAKER)){
return NotificationResponse.createForLoudspeakerNotification(
notification.getId(),
NotificationType.LOUDSPEAKER,
LoudspeakerInfo.builder()
.courtInfo(CourtInfo.builder()
.id(notification.getLoudSpeakerNotification().getCourt().getId())
.name(notification.getLoudSpeakerNotification().getCourt().getName())
.texture(notification.getLoudSpeakerNotification().getCourt().getTexture())
.longitude(notification.getLoudSpeakerNotification().getCourt().getLongitude())
.latitude(notification.getLoudSpeakerNotification().getCourt().getLatitude())
.image(notification.getLoudSpeakerNotification().getCourt().getImage())
.basketCount(notification.getLoudSpeakerNotification().getCourt().getBasketCount())
Loudspeaker.builder()
.court(Court.builder()
.id(notification.getLoudSpeaker().getCourt().getId())
.name(notification.getLoudSpeaker().getCourt().getName())
.texture(notification.getLoudSpeaker().getCourt().getTexture())
.longitude(notification.getLoudSpeaker().getCourt().getLongitude())
.latitude(notification.getLoudSpeaker().getCourt().getLatitude())
.image(notification.getLoudSpeaker().getCourt().getImage())
.basketCount(notification.getLoudSpeaker().getCourt().getBasketCount())
.build())
.startTime(notification.getLoudSpeakerNotification().getStartTime())
.startTime(notification.getLoudSpeaker().getStartTime())
.build(),
notification.isRead(),
notification.isClicked(),
Expand All @@ -55,14 +55,18 @@ public NotificationResponse toDto(NotificationIndex notification){
);
}

if (notification.getNotificationType().equals(NotificationType.FOLLOWING)){
if (notification.getType().equals(NotificationType.FOLLOW)){
return NotificationResponse.createForFollowNotification(
notification.getId(),
NotificationType.FOLLOWING,
FollowerInfo.builder()
.userId(notification.getFollowNotification().getCreator().getId())
.userImage(notification.getFollowNotification().getCreator().getProfileImage())
.userNickname(notification.getFollowNotification().getCreator().getNickname())
NotificationType.FOLLOW,
Follow.builder()
.creator(
User.builder()
.id(notification.getFollow().getFollower().getId())
.profileImage(notification.getFollow().getFollower().getProfileImage())
.nickname(notification.getFollow().getFollower().getNickname())
.build()
)
.build(),
notification.isRead(),
notification.isClicked(),
Expand All @@ -73,71 +77,6 @@ public NotificationResponse toDto(NotificationIndex notification){

throw new InvalidNotificationTypeException("존재하지 않는 공지 타입입니다.");
}
//
// public List<NotificationResponse> toDtoListForLoudspeakerNotification(List<LoudSpeakerNotification> loudSpeakerNotificationList){
// /** null 유효성 검사 추가 **/
// // followNotificationList
//
// return loudSpeakerNotificationList.stream()
// .map(v -> toDtoForLoudNotification(v))
// .collect(Collectors.toList());
// }
//
// public NotificationResponse toDtoForFollowNotification(FollowNotification followNotification){
// /** null 유효성 검사 추가 **/
// //followNotification.getNotification();
// //followNotification.getFollower();
//
// return NotificationResponse.createForFollowNotification(
// followNotification.getNotificationType(),
// FollowerInfo.builder()
// .userId(followNotification.getCreator().getId())
// .userImage(followNotification.getCreator().getProfileImage())
// .userNickname(followNotification.getCreator().getNickname())
// .build(),
// followNotification.isRead(),
// followNotification.isClicked(),
// followNotification.getCreatedAt(),
// followNotification.getUpdateAt()
// );
// }
//
// public NotificationResponse toDtoForLoudNotification(LoudSpeakerNotification loudSpeakerNotification){
//
// return NotificationResponse.createForLoudspeakerNotification(
// loudSpeakerNotification.getNotificationType(),
// LoudspeakerInfo.builder()
// .courtInfo(CourtInfo.builder()
// .id(loudSpeakerNotification.getCourt().getId())
// .basketCount(loudSpeakerNotification.getCourt().getBasketCount())
// .image(loudSpeakerNotification.getCourt().getImage())
// .latitude(loudSpeakerNotification.getCourt().getLatitude())
// .longitude(loudSpeakerNotification.getCourt().getLongitude())
// .name(loudSpeakerNotification.getCourt().getName())
// .texture(loudSpeakerNotification.getCourt().getTexture())
// .build()
// )
// .startTime(loudSpeakerNotification.getStartTime())
// .build(),
// loudSpeakerNotification.isRead(),
// loudSpeakerNotification.isClicked(),
// loudSpeakerNotification.getCreatedAt(),
// loudSpeakerNotification.getUpdateAt()
// );
// }
//
// /** created로 정렬 **/
// public List<NotificationResponse> mergeListForFollowNotificationAndLoudspeakerNotification(
// List<NotificationResponse> followNotificationList,
// List<NotificationResponse> loudSpeakerNotificationList
// ){
// followNotificationList.addAll(loudSpeakerNotificationList);
// if(followNotificationList.size() > 0){
// Collections.sort(followNotificationList);
// return followNotificationList;
// }
// return Collections.emptyList();
// }


}
Loading