Skip to content

Commit

Permalink
Merge pull request #78 from connecSWUn/fix/my-page
Browse files Browse the repository at this point in the history
Fix/my page
  • Loading branch information
ehBeak authored Nov 23, 2023
2 parents 72a6be7 + caca437 commit 9c06699
Show file tree
Hide file tree
Showing 44 changed files with 590 additions and 77 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ src/main/resources/import.sql

.jqwik-database

swulab-firebase-adminsdk.jsonapplication-fcm-dev.yml
application-fcm-loc.yml
application-fcm-dev.yml
swulab-firebase-adminsdk.json
2 changes: 1 addition & 1 deletion scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ chmod +x $JAR_NAME

echo "> $JAR_NAME 실행"
nohup java -jar \
-Dspring.config.location=classpath:/application.yml,/home/ubuntu/swulab/application-devdb.yml,/home/ubuntu/swulab/application-s3.yml,/home/ubuntu/swulab/application-jwt-dev.yml \
-Dspring.config.location=classpath:/application.yml,/home/ubuntu/swulab/application-devdb.yml,/home/ubuntu/swulab/application-fcm-dev.yml,/home/ubuntu/swulab/application-s3.yml,/home/ubuntu/swulab/application-jwt-dev.yml \
-Dspring.profile.active=dev \
$JAR_NAME > $REPOSITORY/nohup.out 2>&1 &
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public class GetChatMessagesResponse {

private List<ChatMessageResponse> messages;

private Integer chat_room_number;

public GetChatMessagesResponse(GetChatMessagesCommand command) {
public GetChatMessagesResponse(GetChatMessagesCommand command, Integer chat_room_number) {
this.recruitStatus = command.getRecruitStatus();
this.recruit_title = command.getRecruitTitle();
this.recruit_spot = command.getRecruitSpot();
Expand All @@ -34,6 +35,7 @@ public GetChatMessagesResponse(GetChatMessagesCommand command) {
this.sender_name = command.getSenderName();

this.messages = command.getCommandList().stream().map(ChatMessageResponse::new).toList();
this.chat_room_number = chat_room_number;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.swulab.eatswunee.domain.chatroom.adapter.in.dto.response.GetChatMessagesResponse;
import com.swulab.eatswunee.domain.chatroom.application.port.in.GetChatMessagesUseCase;
import com.swulab.eatswunee.domain.chatroom.application.port.in.GetUserChatRoomListUseCase;
import com.swulab.eatswunee.domain.chatroom.application.port.in.command.GetChatMessagesCommand;
import com.swulab.eatswunee.global.common.adapter.web.in.dto.SuccessResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -17,15 +18,17 @@
public class GetChatMessagesController {

private final GetChatMessagesUseCase getChatMessagesUseCase;
private final GetUserChatRoomListUseCase getUserChatRoomListUseCase;


@GetMapping("/chat/enter/{chatRoomId}")
public ResponseEntity getChatMessages2UseCase(@AuthenticationPrincipal UserDetails userDetails, @PathVariable String chatRoomId) {

long guestId = Long.parseLong(userDetails.getUsername());


GetChatMessagesCommand command = getChatMessagesUseCase.getChatMessages(guestId, chatRoomId);
GetChatMessagesResponse response = new GetChatMessagesResponse(command);
GetChatMessagesResponse response = new GetChatMessagesResponse(command, getUserChatRoomListUseCase.getUserChatRoomList(guestId).size());

return ResponseEntity.ok(SuccessResponse.create200SuccessResponse(response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
@RequiredArgsConstructor
public class NotificationMapper {

public Notification mapToDomainEntity(NotificationJpaEntity notificationJpaEntity) {
return Notification.builder()
.notificationId(notificationJpaEntity.getId())
.notificationContent(notificationJpaEntity.getNotificationContent())
.notificationIsRead(notificationJpaEntity.getNotificationIsRead())
.notificationCreatedAt(notificationJpaEntity.getCreatedAt())
.build();
}
public Notification mapToDomainEntity(NotificationJpaEntity notificationJpaEntity) {
return Notification.builder()
.notificationId(notificationJpaEntity.getId())
.notificationContent(notificationJpaEntity.getNotificationContent())
.notificationIsRead(notificationJpaEntity.getNotificationIsRead())
.notificationCreatedAt(notificationJpaEntity.getCreatedAt())
.notificationCategory(notificationJpaEntity.getNotificationCategory())
.build();
}

public NotificationJpaEntity mapToJpaEntity(Notification notification) {
return NotificationJpaEntity.builder()
.id(notification.getNotificationId())
.notificationContent(notification.getNotificationContent())
.notificationIsRead(notification.getNotificationIsRead())
.createdAt(notification.getNotificationCreatedAt())
.build();
}
public NotificationJpaEntity mapToJpaEntity(Notification notification) {
return NotificationJpaEntity.builder()
.id(notification.getNotificationId())
.notificationContent(notification.getNotificationContent())
.notificationIsRead(notification.getNotificationIsRead())
.createdAt(notification.getNotificationCreatedAt())
.notificationCategory(notification.getNotificationCategory())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.swulab.eatswunee.domain.notification.adapter.out.persistence;

import com.swulab.eatswunee.domain.notification.application.port.in.command.GetRevenueCommand;
import com.swulab.eatswunee.domain.notification.adapter.out.persistence.jpa.OrderNotificationJpaRepository;
import com.swulab.eatswunee.domain.notification.adapter.out.persistence.jpa.model.OrderNotificationJpaEntity;
import com.swulab.eatswunee.domain.notification.application.port.in.SaveOrderNotificationPort;
import com.swulab.eatswunee.domain.notification.application.port.out.ExistNotificationByOrderIdPort;
import com.swulab.eatswunee.domain.notification.application.port.out.FindOrderNotificationPort;
import com.swulab.eatswunee.domain.notification.application.port.out.FindRestaurantNotificationPort;
Expand All @@ -16,9 +18,12 @@
@Component
@RequiredArgsConstructor
public class NotificationPersistenceAdapter implements FindRestaurantNotificationPort,
ExistNotificationByOrderIdPort, FindRevenuePort, FindOrderNotificationPort {
ExistNotificationByOrderIdPort, FindRevenuePort, FindOrderNotificationPort, SaveOrderNotificationPort {

private final NotificationQueryRepository notificationQueryRepository;
private final OrderNotificationJpaRepository notificationJpaRepository;

private final OrderNotificationMapper orderNotificationMapper;

@Override
public List<FindRestaurantNotificationCommand> findRestaurantNotification(Long restaurantId) {
Expand All @@ -40,7 +45,18 @@ public List<FindRevenueCommand> findRevenue(Long restaurantId) {
@Override
public FindIdAndIsReadCommand findOrderNotificationByOrderIdAndRestaurantId(Long orderId,
Long restaurantId) {
notificationQueryRepository.findOrderNotificationByOrderIdAndRestaurantId(orderId, restaurantId).stream().forEach(
entity -> System.out.println(entity.getNotificationId())
);
return notificationQueryRepository.findOrderNotificationByOrderIdAndRestaurantId(orderId, restaurantId).get(0);
}

@Override
public void saveAll(List<OrderNotification> orderNotifications) {

return notificationQueryRepository.findOrderNotificationByOrderIdAndRestaurantId(orderId, restaurantId);
List<OrderNotificationJpaEntity> orderNotificationJpaEntities = orderNotifications.stream()
.map(orderNotificationMapper::mapToJpaEntity)
.toList();
notificationJpaRepository.saveAll(orderNotificationJpaEntities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public List<FindRevenueCommand> findRevenue(Long restaurantId) {
.fetch();
}

public FindIdAndIsReadCommand findOrderNotificationByOrderIdAndRestaurantId(Long orderId, Long restaurantId) {
public List<FindIdAndIsReadCommand> findOrderNotificationByOrderIdAndRestaurantId(Long orderId, Long restaurantId) {
return jpaQueryFactory
.select(Projections.constructor(FindIdAndIsReadCommand.class,
orderNotificationJpaEntity.id.as("notificationId"),
Expand All @@ -85,7 +85,7 @@ public FindIdAndIsReadCommand findOrderNotificationByOrderIdAndRestaurantId(Long
orderNotificationJpaEntity.orderJpaEntity.id.eq(orderId),
orderNotificationJpaEntity.restaurantJpaEntity.restaurantId.eq(restaurantId)
)
.fetchOne();
.fetch();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.swulab.eatswunee.domain.notification.adapter.out.persistence;

import com.swulab.eatswunee.domain.notification.adapter.out.persistence.jpa.model.OrderNotificationJpaEntity;
import com.swulab.eatswunee.domain.notification.domain.model.NotificationCategory;
import com.swulab.eatswunee.domain.notification.domain.model.OrderNotification;
import com.swulab.eatswunee.domain.order.adapter.out.persistence.OrderMapper;
import com.swulab.eatswunee.domain.restaurant.adapter.out.persistence.RestaurantMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class OrderNotificationMapper {

private final OrderMapper orderMapper;
private final RestaurantMapper restaurantMapper;

public OrderNotification mapToDomainEntity(OrderNotificationJpaEntity notificationJpaEntity) {
return new OrderNotification(notificationJpaEntity.getId(),
notificationJpaEntity.getNotificationContent(),
notificationJpaEntity.getNotificationIsRead(),
notificationJpaEntity.getCreatedAt(),
"",
orderMapper.mapToDomainEntity(notificationJpaEntity.getOrderJpaEntity()),
restaurantMapper.mapToDomainEntity(notificationJpaEntity.getRestaurantJpaEntity()),
NotificationCategory.REQUEST_ORDER);
}

public OrderNotificationJpaEntity mapToJpaEntity(OrderNotification notification) {
return new OrderNotificationJpaEntity(notification.getNotificationId(),
"주문", "", true, null,
orderMapper.mapToJpaEntity(notification.getOrder()),
restaurantMapper.mapToJpaEntity(notification.getRestaurant()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.swulab.eatswunee.domain.notification.adapter.out.persistence.jpa;

import com.swulab.eatswunee.domain.notification.adapter.out.persistence.jpa.model.OrderNotificationJpaEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface OrderNotificationJpaRepository extends JpaRepository<OrderNotificationJpaEntity, Long> {

@Override
<S extends OrderNotificationJpaEntity> S save(S entity);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.swulab.eatswunee.domain.notification.adapter.out.persistence.jpa.model;

import com.swulab.eatswunee.domain.notification.domain.model.NotificationCategory;
import com.swulab.eatswunee.global.common.domain.BaseEntity;
import jakarta.persistence.AttributeOverride;
import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.Table;
Expand All @@ -32,6 +35,9 @@ public class NotificationJpaEntity extends BaseEntity {
private String notificationContent;
private Boolean notificationIsRead;

@Enumerated(EnumType.STRING)
private NotificationCategory notificationCategory;

public NotificationJpaEntity(Long notificationId, String notificationTitle,
String notificationContent, Boolean notificationIsRead,
LocalDateTime notificationCreatedAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

Expand All @@ -18,6 +19,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SuperBuilder
@Table(name = "notification_order")
@Getter
public class OrderNotificationJpaEntity extends NotificationJpaEntity {

@ManyToOne
Expand All @@ -29,11 +31,13 @@ public class OrderNotificationJpaEntity extends NotificationJpaEntity {
private RestaurantJpaEntity restaurantJpaEntity;

public OrderNotificationJpaEntity(Long notificationId, String notificationTitle,
String notificationContent, Boolean notificationIsRead,
LocalDateTime notificationCreatedAt,
OrderJpaEntity orderJpaEntity) {
String notificationContent, Boolean notificationIsRead,
LocalDateTime notificationCreatedAt,
OrderJpaEntity orderJpaEntity, RestaurantJpaEntity restaurantJpaEntity) {

super(notificationId, notificationTitle, notificationContent, notificationIsRead,
notificationCreatedAt);
notificationCreatedAt);
this.orderJpaEntity = orderJpaEntity;
this.restaurantJpaEntity = restaurantJpaEntity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.swulab.eatswunee.domain.notification.application.port.in;

import com.swulab.eatswunee.domain.notification.domain.model.OrderNotification;
import java.util.List;

public interface SaveOrderNotificationPort {

void saveAll(List<OrderNotification> orderNotifications);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.swulab.eatswunee.domain.notification.application.port.out;

import com.swulab.eatswunee.domain.notification.application.port.out.command.FindIdAndIsReadCommand;
import com.swulab.eatswunee.domain.notification.domain.model.OrderNotification;

public interface FindOrderNotificationPort {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class ChatNotification extends Notification {

public ChatNotification(Long notificationId, String notificationContent,
Boolean notificationIsRead, LocalDateTime notificationCreatedAt,
String notificationType, ChatRoom chatRoom) {
String notificationType, ChatRoom chatRoom, NotificationCategory notificationCategory) {
super(notificationId, notificationContent, notificationIsRead, notificationCreatedAt,
notificationType);
notificationType, notificationCategory);
this.chatRoom = chatRoom;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -15,16 +16,19 @@ public class Notification {
private Boolean notificationIsRead;
private LocalDateTime notificationCreatedAt;
private String notificationType;
private NotificationCategory notificationCategory;


@Builder
public Notification(Long notificationId,
String notificationContent, Boolean notificationIsRead,
LocalDateTime notificationCreatedAt, String notificationType) {
LocalDateTime notificationCreatedAt, String notificationType,
NotificationCategory notificationCategory) {
this.notificationId = notificationId;
this.notificationContent = notificationContent;
this.notificationIsRead = notificationIsRead;
this.notificationCreatedAt = notificationCreatedAt;
this.notificationType = notificationType;
this.notificationCategory = notificationCategory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.swulab.eatswunee.domain.notification.domain.model;

import lombok.Getter;

@Getter
public enum NotificationCategory {

REQUEST_ORDER("주문번호 %d"),
ORDER_ARRIVED("음식 준비가 완료되었습니다."),
PLACING_ORDER("주문번호 %d"),
CHAT_ARRIVE("%s님이 메시지를 보냈습니다.");

private String message;

NotificationCategory(String message) {
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
import com.swulab.eatswunee.domain.restaurant.domain.model.Restaurant;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class OrderNotification extends Notification {

private Order order;

private Restaurant restaurant;

public OrderNotification(Long notificationId, String notificationContent,
Boolean notificationIsRead, LocalDateTime notificationCreatedAt,
String notificationType, Order order, Restaurant restaurant) {
String notificationType, Order order, Restaurant restaurant, NotificationCategory notificationCategory) {
super(notificationId, notificationContent, notificationIsRead, notificationCreatedAt,
notificationType);
notificationType, notificationCategory);
this.order = order;
this.restaurant = restaurant;
}
Expand Down
Loading

0 comments on commit 9c06699

Please sign in to comment.