Skip to content

Commit

Permalink
Merge branch 'develop' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
jud1thDev committed Aug 8, 2024
2 parents 1f64a83 + 3e76a58 commit 930f0e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

public interface PinRepository extends JpaRepository <Pin, Long> {
List<Pin> findBySong(Song song);
Page<Pin> findAllBySong(Song song, Pageable pageable);

int countBySong(Song song);
int countByPlace(Place place);
@Query("SELECT p FROM Pin p WHERE p.song = :song ORDER BY p.listenedDate DESC, p.pinId DESC")
Page<Pin> findAllBySong(@Param("song") Song song, Pageable pageable);
@Query("SELECT p FROM Pin p WHERE p.song = :song AND p.creator = :creator ORDER BY p.listenedDate DESC, p.pinId DESC")
Page<Pin> findAllBySongAndCreator(@Param("song") Song song, @Param("creator") Member creator, Pageable pageable);

// 노래 상세보기 페이지에서 "들은날짜" = 등록한 핀 중 가장 최신의 listenedDate
Optional<Pin> findTopBySongAndCreatorOrderByListenedDateDesc(Song song, Member member);
Page<Pin> findAllBySongAndCreator(Song song, Member creator, Pageable pageable);
@Query("SELECT p.pinId, p.song.songId, p.song.title, p.song.artist, p.song.imgPath, p.listenedDate, p.place.placeName, p.place.latitude, p.place.longitude, g.genreName, p.memo, p.visibility " +
"FROM Pin p " +
"LEFT JOIN p.genre g " +
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/sws/songpin/domain/pin/service/PinService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sws.songpin.domain.pin.entity.Pin;
import sws.songpin.domain.pin.repository.PinRepository;
import sws.songpin.domain.place.entity.Place;
import sws.songpin.domain.place.repository.PlaceRepository;
import sws.songpin.domain.place.service.PlaceService;
import sws.songpin.domain.playlist.entity.Playlist;
import sws.songpin.domain.playlistpin.entity.PlaylistPin;
Expand All @@ -40,6 +41,7 @@
public class PinService {
private final PinRepository pinRepository;
private final SongRepository songRepository;
private final PlaceRepository placeRepository;
private final PlaylistPinRepository playlistPinRepository;
private final MemberService memberService;
private final SongService songService;
Expand Down Expand Up @@ -88,8 +90,12 @@ public void deletePin(Long pinId) {
playlist.removePlaylistPin(playlistPin);
}
playlistPinRepository.deleteAll(playlistPins);
Place place = pin.getPlace();
pinRepository.delete(pin);
updateSongAvgGenreName(pin.getSong());
if (place != null && pinRepository.countByPlace(place) == 0) {
placeRepository.delete(place);
}
}

public void updateSongAvgGenreName(Song song) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public interface PlaceRepository extends JpaRepository<Place, Long> {
Optional<Place> findByProviderAddressId(Long providerAddressId);

//// 장소 검색 (페이징 방식)

@Query(value = "SELECT p.place_id, p.place_name, COUNT(pin.pin_id) AS pin_count " +
"FROM place p " +
"LEFT JOIN pin pin ON p.place_id = pin.place_id " +
Expand Down Expand Up @@ -58,4 +57,4 @@ public interface PlaceRepository extends JpaRepository<Place, Long> {

@Query(value = "SELECT * FROM place p ORDER BY p.place_id DESC LIMIT 3", nativeQuery = true)
List<Place> findTop3ByOrderByPlaceIdDesc();
}
}

0 comments on commit 930f0e5

Please sign in to comment.