Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ public RsData<Void> artistLikes(

@Operation(summary = "아티스트 찜 해체", description = "id 에 해당하는 아티스트에게 등록했던 찜을 해제합니다.")
@DeleteMapping("/likes/{id}")
public void deleteArtistLikes(
public RsData<Void> deleteArtistLikes(
@PathVariable Long id
) {}
) {
artistService.deleteLikeArtist(id);
return RsData.success("아티스트 찜 해제 성공", null);
}

@Operation(summary = "개인화된 공연 리스트 생성", description = "유저가 찜한 아티스트를 기반으로 공연 리스트를 생성합니다.")
@PostMapping("/list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.back.web7_9_codecrete_be.domain.users.entity.User;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Entity
@Getter
@NoArgsConstructor
@Table(name = "artist_like")
public class ArtistLike {
@Id
Expand All @@ -27,6 +29,7 @@ public class ArtistLike {
private Artist artist;

public ArtistLike(Artist artist, User user) {
this.createdDate = LocalDateTime.now();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auditing 사용중이라서 위에 칼럼쪽에 createdate 어노테이션 사용하시면 자동으로 주입될 것 같습니다!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정하겠습니다!!

this.artist = artist;
this.user = user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ArtistLikeRepository extends JpaRepository<ArtistLike, Long> {
long countByArtistId(Long artistId);
boolean existsByArtistAndUser(Artist artist, User user);
Optional<ArtistLike> findByArtistAndUser(Artist artist, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import com.back.web7_9_codecrete_be.global.error.code.ArtistErrorCode;
import com.back.web7_9_codecrete_be.global.error.exception.BusinessException;
import com.back.web7_9_codecrete_be.global.rq.Rq;
import lombok.AccessLevel;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class ArtistService {

private final SpotifyService spotifyService;
Expand Down Expand Up @@ -141,4 +142,15 @@ public void likeArtist(Long artistId) {
artist.increaseLikeCount();
}

@Transactional
public void deleteLikeArtist(Long artistId) {
User user = rq.getUser();
Artist artist = artistRepository.findById(artistId)
.orElseThrow(() -> new BusinessException(ArtistErrorCode.ARTIST_NOT_FOUND));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artist 찾아오는 부분은 좋아요 / 좋아요 삭제 부분에서 공통적으로 처리되는 부분이니 메소드로 빼도 좋을 것 같습니다.

  • 이미 알고 있는 미세팁일 수 있지만 해당 부분 드래그하고 export->method 하면 알아서 추출되고 이름만 쳐주면 적용됩니다(중복부분도 같이 바꿔주더라고요)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정하겠습니다!! 팁 알려주셔서 감사합니당

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artist 찾아오는 부분은 좋아요 / 좋아요 삭제 부분에서 공통적으로 처리되는 부분이니 메소드로 빼도 좋을 것 같습니다.

  • 이미 알고 있는 미세팁일 수 있지만 해당 부분 드래그하고 export->method 하면 알아서 추출되고 이름만 쳐주면 적용됩니다(중복부분도 같이 바꿔주더라고요)

저도 꿀팁 하나 얻어갑니다!

ArtistLike likes = artistLikeRepository.findByArtistAndUser(artist, user)
.orElseThrow(() -> new BusinessException(ArtistErrorCode.LIKES_NOT_FOUND));
artistLikeRepository.delete(likes);
artist.decreaseLikeCount();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public enum ArtistErrorCode implements ErrorCode {
SPOTIFY_NOT_FOUND(HttpStatus.NOT_FOUND, "AT-104", "존재하지 않는 Spotify Artist Key 입니다."),
INVALID_UPDATE_REQUEST(HttpStatus.BAD_REQUEST, "AT-105", "수정할 내용이 없습니다."),
INVALID_SEARCH_KEYWORD(HttpStatus.BAD_REQUEST, "AT-106", "입력 값이 없습니다."),
LIKES_ALREADY_EXISTS(HttpStatus.CONFLICT, "AT-107", "이미 좋아요를 눌렀습니다.");
LIKES_ALREADY_EXISTS(HttpStatus.CONFLICT, "AT-107", "이미 찜한 아티스트입니다."),
LIKES_NOT_FOUND(HttpStatus.NOT_FOUND, "AT-108", "찜한 아티스트가 아닙니다.");

private final HttpStatus status;
private final String code;
Expand Down