diff --git a/src/main/java/com/api/farmingsoon/common/util/CookieUtils.java b/src/main/java/com/api/farmingsoon/common/util/CookieUtils.java index 914beb5..9a665b0 100644 --- a/src/main/java/com/api/farmingsoon/common/util/CookieUtils.java +++ b/src/main/java/com/api/farmingsoon/common/util/CookieUtils.java @@ -18,7 +18,7 @@ public class CookieUtils { public static String getViewCountCookieValue(HttpServletRequest request, HttpServletResponse response) { Cookie[] cookies = request.getCookies(); - log.info(Arrays.toString(cookies)); + //log.info(Arrays.toString(cookies)); if (cookies != null) { Optional viewCountCookie = Arrays.stream(cookies) .filter(cookie -> cookie.getName().equals("viewCountCookie")) @@ -30,7 +30,7 @@ public static String getViewCountCookieValue(HttpServletRequest request, HttpSer } public static String getAccessTokenCookieValue(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); - log.info(Arrays.toString(cookies)); + //log.info(Arrays.toString(cookies)); if (cookies != null) { Optional accessTokenCookie = Arrays.stream(cookies) .filter(cookie -> cookie.getName().equals("AccessToken")) @@ -42,7 +42,7 @@ public static String getAccessTokenCookieValue(HttpServletRequest request) { } public static String getRefreshTokenCookieValue(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); - log.info(Arrays.toString(cookies)); + //log.info(Arrays.toString(cookies)); if (cookies != null) { Optional refreshTokenCookie = Arrays.stream(cookies) .filter(cookie -> cookie.getName().equals("RefreshToken")) diff --git a/src/main/java/com/api/farmingsoon/domain/chat/repository/ChatRepositoryCustom.java b/src/main/java/com/api/farmingsoon/domain/chat/repository/ChatRepositoryCustom.java index cdc7c01..fc57960 100644 --- a/src/main/java/com/api/farmingsoon/domain/chat/repository/ChatRepositoryCustom.java +++ b/src/main/java/com/api/farmingsoon/domain/chat/repository/ChatRepositoryCustom.java @@ -8,4 +8,5 @@ public interface ChatRepositoryCustom { List findMyNotReadChatList(ChatRoom chatroom, Member member); + void readAllMyNotReadChatList(ChatRoom chatroom, Member member); } diff --git a/src/main/java/com/api/farmingsoon/domain/chat/repository/ChatRepositoryCustomImpl.java b/src/main/java/com/api/farmingsoon/domain/chat/repository/ChatRepositoryCustomImpl.java index 44608f1..354125e 100644 --- a/src/main/java/com/api/farmingsoon/domain/chat/repository/ChatRepositoryCustomImpl.java +++ b/src/main/java/com/api/farmingsoon/domain/chat/repository/ChatRepositoryCustomImpl.java @@ -5,6 +5,7 @@ import com.api.farmingsoon.domain.chatroom.model.ChatRoom; import com.api.farmingsoon.domain.member.model.Member; import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -21,6 +22,7 @@ public class ChatRepositoryCustomImpl implements ChatRepositoryCustom{ private final JPAQueryFactory queryFactory; + private final EntityManager em; @Override public List findMyNotReadChatList(ChatRoom chatRoom, Member member) { @@ -29,4 +31,15 @@ public List findMyNotReadChatList(ChatRoom chatRoom, Member member) { .fetch(); } + + @Override + public void readAllMyNotReadChatList(ChatRoom chatroom, Member member) { + queryFactory.update(chat) + .where(chat.chatRoom.eq(chatroom), chat.isRead.isFalse(), chat.sender.ne(member)) + .set(chat.isRead, true) + .execute(); + em.flush(); + em.clear(); + + } } diff --git a/src/main/java/com/api/farmingsoon/domain/chat/service/ChatService.java b/src/main/java/com/api/farmingsoon/domain/chat/service/ChatService.java index 0a7f104..ba6ddf6 100644 --- a/src/main/java/com/api/farmingsoon/domain/chat/service/ChatService.java +++ b/src/main/java/com/api/farmingsoon/domain/chat/service/ChatService.java @@ -69,7 +69,11 @@ public ChatListResponse getChats(Long chatRoomId, Pageable pageable) { public void readAllMyNotReadChatList(Long chatRoomId, Long memberId) { ChatRoom chatRoom = chatRoomService.getChatRoom(chatRoomId); Member member = memberService.getMemberById(memberId); + chatRepository.readAllMyNotReadChatList(chatRoom, member); + + /* List myNotReadChatList = chatRepository.findMyNotReadChatList(chatRoom, member); myNotReadChatList.forEach(Chat::read); + */ } } diff --git a/src/main/java/com/api/farmingsoon/domain/item/service/ItemRedisService.java b/src/main/java/com/api/farmingsoon/domain/item/service/ItemRedisService.java index c6e7c30..bb91b78 100644 --- a/src/main/java/com/api/farmingsoon/domain/item/service/ItemRedisService.java +++ b/src/main/java/com/api/farmingsoon/domain/item/service/ItemRedisService.java @@ -20,9 +20,9 @@ public void setBidEndTime(Long itemId, Integer expire){ /** * @Description - * 1. 중복된 접근이 아니라면 조회수를 증가시키고 접근 처리 - * 2. set이 없다면 만들고 만료기간 자정으로 설정 - * 3. 있다면 추가 + * 1. 중복된 접근이 아니라면 조회수를 증가시키고 접근 처리(Set 의 키 값이 없거나 set 내부에 value 가 없거나) + * 2. set 이 없다면 만들고 만료기간 자정으로 설정 + * 3. 있다면 set 에 value 추가 */ @Async("testExecutor") diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 62b7937..361aff2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,16 +11,14 @@ spring: h2: console: enabled: true -# jpa: + jpa: + open-in-view: false # show-sql: true # properties: # hibernate: # format_sql: true # highlight_sql: true - hibernate: - ddl-auto: create - # defer-datasource-initialization: true - open-in-view: false + data: redis: host: localhost diff --git a/src/test/java/com/api/farmingsoon/domain/IntegrationTest.java b/src/test/java/com/api/farmingsoon/domain/IntegrationTest.java new file mode 100644 index 0000000..a6cd391 --- /dev/null +++ b/src/test/java/com/api/farmingsoon/domain/IntegrationTest.java @@ -0,0 +1,30 @@ +package com.api.farmingsoon.domain; + + +import com.api.farmingsoon.common.clean.DatabaseCleanup; +import com.api.farmingsoon.common.util.Transaction; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.web.context.WebApplicationContext; + +@SpringBootTest +@ActiveProfiles("test") +@AutoConfigureMockMvc +public abstract class IntegrationTest { + + @Autowired + protected WebApplicationContext ctx; + + @Autowired + protected Transaction transaction; + @Autowired + protected ObjectMapper objectMapper; + @Autowired + protected MockMvc mockMvc; + @Autowired + protected DatabaseCleanup databaseCleanup; +} diff --git a/src/test/java/com/api/farmingsoon/domain/chatting/ChattingIntegrationTest.java b/src/test/java/com/api/farmingsoon/domain/chatting/ChattingIntegrationTest.java index d0cec4c..90085e1 100644 --- a/src/test/java/com/api/farmingsoon/domain/chatting/ChattingIntegrationTest.java +++ b/src/test/java/com/api/farmingsoon/domain/chatting/ChattingIntegrationTest.java @@ -3,6 +3,7 @@ import com.api.farmingsoon.common.clean.DatabaseCleanup; import com.api.farmingsoon.common.util.TimeUtils; import com.api.farmingsoon.common.util.Transaction; +import com.api.farmingsoon.domain.IntegrationTest; import com.api.farmingsoon.domain.chat.dto.ChatListResponse; import com.api.farmingsoon.domain.chat.dto.ChatMessageRequest; import com.api.farmingsoon.domain.chat.service.ChatService; @@ -50,32 +51,17 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest -@ActiveProfiles("test") -@AutoConfigureMockMvc -public class ChattingIntegrationTest { + +public class ChattingIntegrationTest extends IntegrationTest { @Autowired private ItemService itemService; @Autowired private MemberService memberService; @Autowired - private WebApplicationContext ctx; - @Autowired private ChatService chatService; @Autowired private ChatRoomService chatRoomService; - @Autowired - private ObjectMapper objectMapper; - - @Autowired - private MockMvc mockMvc; - - @Autowired - private Transaction transaction; - - @Autowired - private DatabaseCleanup databaseCleanup; private static MockMultipartFile profileImage; diff --git a/src/test/java/com/api/farmingsoon/domain/item/ItemIntegrationTest.java b/src/test/java/com/api/farmingsoon/domain/item/ItemIntegrationTest.java index 6a34dbb..f0add96 100644 --- a/src/test/java/com/api/farmingsoon/domain/item/ItemIntegrationTest.java +++ b/src/test/java/com/api/farmingsoon/domain/item/ItemIntegrationTest.java @@ -2,6 +2,7 @@ import com.api.farmingsoon.common.clean.DatabaseCleanup; import com.api.farmingsoon.common.util.TimeUtils; +import com.api.farmingsoon.domain.IntegrationTest; import com.api.farmingsoon.domain.bid.dto.BidRequest; import com.api.farmingsoon.domain.bid.service.BidService; import com.api.farmingsoon.domain.item.domain.Item; @@ -49,29 +50,17 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest -@ActiveProfiles("test") -@AutoConfigureMockMvc -class ItemIntegrationTest { + +class ItemIntegrationTest extends IntegrationTest { @Autowired private MemberService memberService; @Autowired - private WebApplicationContext ctx; - @Autowired private ItemService itemService; @Autowired private BidService bidService; - @Autowired - private ObjectMapper objectMapper; - - @Autowired - private MockMvc mockMvc; - - @Autowired - private DatabaseCleanup databaseCleanup; private static MockMultipartFile thumbnailImage; private static List images; diff --git a/src/test/java/com/api/farmingsoon/domain/like/LikeableItemIntegrationTest.java b/src/test/java/com/api/farmingsoon/domain/like/LikeableItemIntegrationTest.java index 4ab1720..d38ca45 100644 --- a/src/test/java/com/api/farmingsoon/domain/like/LikeableItemIntegrationTest.java +++ b/src/test/java/com/api/farmingsoon/domain/like/LikeableItemIntegrationTest.java @@ -3,6 +3,7 @@ import com.api.farmingsoon.common.clean.DatabaseCleanup; import com.api.farmingsoon.common.util.TimeUtils; import com.api.farmingsoon.common.util.Transaction; +import com.api.farmingsoon.domain.IntegrationTest; import com.api.farmingsoon.domain.item.domain.Item; import com.api.farmingsoon.domain.item.domain.ItemStatus; import com.api.farmingsoon.domain.item.dto.LikeableItemListResponse; @@ -46,21 +47,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest -@ActiveProfiles("test") -@AutoConfigureMockMvc -class LikeableItemIntegrationTest { - @Autowired - private Transaction transaction; - @Autowired - private ObjectMapper objectMapper; - @Autowired - private MockMvc mockMvc; - @Autowired - private WebApplicationContext ctx; - @Autowired - private DatabaseCleanup databaseCleanup; +class LikeableItemIntegrationTest extends IntegrationTest { @Autowired private MemberService memberService; @Autowired diff --git a/src/test/java/com/api/farmingsoon/domain/member/MemberIntegrationTest.java b/src/test/java/com/api/farmingsoon/domain/member/MemberIntegrationTest.java index 3faae3c..baed6f3 100644 --- a/src/test/java/com/api/farmingsoon/domain/member/MemberIntegrationTest.java +++ b/src/test/java/com/api/farmingsoon/domain/member/MemberIntegrationTest.java @@ -1,6 +1,7 @@ package com.api.farmingsoon.domain.member; import com.api.farmingsoon.common.clean.DatabaseCleanup; +import com.api.farmingsoon.domain.IntegrationTest; import com.api.farmingsoon.domain.member.dto.JoinRequest; import com.api.farmingsoon.domain.member.dto.LoginRequest; import com.api.farmingsoon.domain.member.model.Member; @@ -29,22 +30,14 @@ import java.util.Arrays; import java.util.Optional; -@SpringBootTest -@ActiveProfiles("test") -@AutoConfigureMockMvc -class MemberIntegrationTest { - @Autowired - private ObjectMapper objectMapper; + +class MemberIntegrationTest extends IntegrationTest { + @Autowired private MemberService memberService; @Autowired private PasswordEncoder passwordEncoder; - @Autowired - private MockMvc mockMvc; - - @Autowired - private DatabaseCleanup databaseCleanup; private static MockMultipartFile profileImage; @BeforeAll static void beforeAll() throws IOException { diff --git a/src/test/java/com/api/farmingsoon/domain/notification/NotificationIntegrationTest.java b/src/test/java/com/api/farmingsoon/domain/notification/NotificationIntegrationTest.java index a9744cd..52e4a7e 100644 --- a/src/test/java/com/api/farmingsoon/domain/notification/NotificationIntegrationTest.java +++ b/src/test/java/com/api/farmingsoon/domain/notification/NotificationIntegrationTest.java @@ -3,6 +3,7 @@ import com.api.farmingsoon.common.clean.DatabaseCleanup; import com.api.farmingsoon.common.util.TimeUtils; import com.api.farmingsoon.common.util.Transaction; +import com.api.farmingsoon.domain.IntegrationTest; import com.api.farmingsoon.domain.bid.dto.BidRequest; import com.api.farmingsoon.domain.bid.model.Bid; import com.api.farmingsoon.domain.bid.model.BidResult; @@ -53,21 +54,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest -@ActiveProfiles("test") -@AutoConfigureMockMvc -public class NotificationIntegrationTest { - @Autowired - private Transaction transaction; - @Autowired - private ObjectMapper objectMapper; - @Autowired - private MockMvc mockMvc; - @Autowired - private WebApplicationContext ctx; - @Autowired - private DatabaseCleanup databaseCleanup; +public class NotificationIntegrationTest extends IntegrationTest { + @Autowired private MemberService memberService; @Autowired