Skip to content
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 @@ -25,6 +25,7 @@
import com.ourmenu.backend.domain.user.exception.NotFoundUserException;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -187,6 +188,13 @@ private MenuInfoOnMapDto getMenuInfo(Menu menu) {
* @param menu
*/
private void saveOwnedMenuSearchHistory(Long userId, Menu menu) {
Optional<OwnedMenuSearch> searchHistory = ownedMenuSearchRepository.findByUserIdAndMenuId(userId, menu.getId());

if (searchHistory.isPresent()) {
searchHistory.get().updateModifiedAt();
return;
}

OwnedMenuSearch ownedMenuSearch = OwnedMenuSearch.builder()
.menuId(menu.getId())
.menuTitle(menu.getTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ public interface MenuRepository extends JpaRepository<Menu, Long> {

boolean existsByStore(Store store);

List<Menu> findMenusByUserId(Long userId);
@Query("""
SELECT m
FROM Menu m
JOIN FETCH m.store s
JOIN FETCH s.map map
WHERE m.userId = :userId
""")
List<Menu> findMenusByUserId(@Param("userId") Long userId);

List<Menu> findMenusByStoreIdAndUserId(Long storeId, Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface OwnedMenuSearchRepository extends JpaRepository<OwnedMenuSearch, Long> {

Page<OwnedMenuSearch> findByUserId(Long userId, Pageable pageable);
@Query("""
SELECT oms
FROM OwnedMenuSearch oms
WHERE oms.userId = :userId
""")
Page<OwnedMenuSearch> findByUserId(@Param("userId") Long userId, Pageable pageable);

Optional<OwnedMenuSearch> findByUserIdAndMenuId(Long userId, Long menuId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@

import org.locationtech.jts.geom.Point;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface MapRepository extends JpaRepository<Map, Long> {

Optional<Map> findByLocation(Point location);

@Query("""
SELECT mp
FROM Map mp
JOIN FETCH mp.stores st
WHERE mp.id = :mapId
""")
Optional<Map> findMapById(Long mapId);
}
Loading