Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.back.web7_9_codecrete_be.domain.artists.controller;

import com.back.web7_9_codecrete_be.domain.artists.dto.request.CreateRequest;
import com.back.web7_9_codecrete_be.domain.artists.dto.request.UpdateRequest;
import com.back.web7_9_codecrete_be.domain.artists.service.ArtistService;
import com.back.web7_9_codecrete_be.global.rsData.RsData;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/admin/artists")
@RequiredArgsConstructor
public class ArtistAdminController {

private final ArtistService artistService;

@Operation(summary = "아티스트 생성", description = "아티스트를 등록합니다.")
@PostMapping()
public RsData<Void> create(
@Valid @RequestBody CreateRequest reqBody
) {
artistService.createArtist(reqBody.spotifyId(), reqBody.artistName(), reqBody.artistGroup(), reqBody.artistType(), reqBody.genreName());
return RsData.success("아티스트 생성이 완료되었습니다.", null);
}

@Operation(summary = "아티스트 정보 수정", description = "아티스트 정보를 수정합니다.")
@PatchMapping("/{id}")
public RsData<Void> update(
@PathVariable Long id,
@Valid @RequestBody UpdateRequest reqBody
) {
artistService.updateArtist(id, reqBody);
return RsData.success("아티스트 정보 수정을 완료했습니다.", null);
}

@Operation(summary = "아티스트 정보 삭제", description = "아티스트 정보를 삭제합니다.")
@DeleteMapping("/{id}")
public RsData<Void> delete(
@PathVariable Long id
) {
artistService.delete(id);
return RsData.success("아티스트 정보를 삭제했습니다.", null);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.back.web7_9_codecrete_be.domain.artists.controller;

import com.back.web7_9_codecrete_be.domain.artists.dto.response.*;
import com.back.web7_9_codecrete_be.domain.artists.entity.ArtistSort;
import com.back.web7_9_codecrete_be.domain.artists.dto.request.CreateRequest;
import com.back.web7_9_codecrete_be.domain.artists.dto.request.SearchRequest;
import com.back.web7_9_codecrete_be.domain.artists.dto.request.UpdateRequest;
import com.back.web7_9_codecrete_be.domain.artists.dto.response.ArtistListResponse;
import com.back.web7_9_codecrete_be.domain.artists.dto.response.ArtistDetailResponse;
import com.back.web7_9_codecrete_be.domain.artists.dto.response.ConcertListByArtistResponse;
import com.back.web7_9_codecrete_be.domain.artists.dto.response.SearchResponse;
import com.back.web7_9_codecrete_be.domain.artists.service.ArtistService;
import com.back.web7_9_codecrete_be.domain.artists.service.ArtistEnrichService;
import com.back.web7_9_codecrete_be.domain.users.entity.User;
Expand All @@ -18,7 +15,6 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -57,52 +53,24 @@ public RsData<Integer> fetchMusicBrainzIds(
return RsData.success("MusicBrainz ID 수집 성공", updated);
}

@Operation(summary = "아티스트 생성", description = "아티스트를 등록합니다.")
@PostMapping()
public RsData<Void> create(
@Valid @RequestBody CreateRequest reqBody
) {
artistService.createArtist(reqBody.spotifyID(), reqBody.artistName(), reqBody.artistGroup(), reqBody.artistType(), reqBody.genreName());
return RsData.success("아티스트 생성이 완료되었습니다.", null);
}

@Operation(summary = "아티스트 목록 조회",
description = "아티스트 전체 목록을 조회합니다(NAME: 이름순 / LIKE: 인기순 (좋아요 많은 순)")
@GetMapping()
public RsData<Slice<ArtistListResponse>> list(
public RsData<ArtistSliceResponse> list(
Pageable pageable,
@RequestParam(required = false) ArtistSort sort
) {
User user = rq.getUserOrNull(); // 로그인하지 않은 경우 null
return RsData.success("아티스트 전체 목록을 조회했습니다.", artistService.listArtist(pageable, user, sort));
return RsData.success("아티스트 전체 목록을 조회했습니다.",
ArtistSliceResponse.from(artistService.listArtist(pageable, user, sort)));
}

@Operation(summary = "아티스트 상세 조회", description = "아티스트의 상세 정보를 조회합니다.")
@GetMapping("/{id}")
public RsData<ArtistDetailResponse> artist(
@PathVariable Long id
) {
User user = rq.getUserOrNull(); // 로그인하지 않은 경우 null
return RsData.success("아티스트 상세 조회를 성공했습니다.", artistService.getArtistDetail(id, user));
}

@Operation(summary = "아티스트 정보 수정", description = "아티스트 정보를 수정합니다.")
@PatchMapping("/{id}")
public RsData<Void> update(
@PathVariable Long id,
@Valid @RequestBody UpdateRequest reqBody
) {
artistService.updateArtist(id, reqBody);
return RsData.success("아티스트 정보 수정을 완료했습니다.", null);
}

@Operation(summary = "아티스트 정보 삭제", description = "아티스트 정보를 삭제합니다.")
@DeleteMapping("/{id}")
public RsData<Void> delete(
@PathVariable Long id
) {
artistService.delete(id);
return RsData.success("아티스트 정보를 삭제했습니다.", null);
return RsData.success("아티스트 상세 조회를 성공했습니다.", artistService.getArtistDetail(id));
}

@Operation(summary = "아티스트 검색",
Expand Down Expand Up @@ -151,6 +119,13 @@ public RsData<List<ConcertListByArtistResponse>> concertList() {
return RsData.success("찜한 아티스트 공연 리스트 조회 성공", artistService.getConcertList(user.getId()));
}

@Operation(summary = "유저가 찜한 아티스트 목록", description = "유저 Id 를 통해 해당 유저가 찜한 아티스트 목록을 조회합니다.")
@GetMapping("/likes")
public RsData<List<LikeArtistResponse>> findLikeArtists() {
User user = rq.getUser();
return RsData.success("유저가 찜한 아티스트 목록 조회 성공", artistService.findArtistsLikeByUserId(user));
}

@Operation(summary = "아티스트 인기 순위(구현 전)", description = "Spotify 인기도를 바탕으로 아티스트 인기 순위 랭킹을 제공합니다.")
@GetMapping("/ranking")
public void artistRanking() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.back.web7_9_codecrete_be.domain.artists.controller;

import com.back.web7_9_codecrete_be.domain.artists.dto.response.GenreResponse;
import com.back.web7_9_codecrete_be.domain.artists.service.GenreService;
import com.back.web7_9_codecrete_be.global.rsData.RsData;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/genre")
@RequiredArgsConstructor
public class GenreController {

private final GenreService genreService;

@GetMapping()
public RsData<List<GenreResponse>> genreList() {
return RsData.success("전체 장르 조회 성공", genreService.genreList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record CreateRequest(
@NotBlank
@Size(max = 30, message = "Spotify ID 는 필수로 입력해야합니다.")
@Schema(description = "Spotify ID 입니다.")
String spotifyID,
String spotifyId,

@NotBlank(message = "아티스트 이름은 필수로 입력해야합니다.")
@Size(max = 200, message = "아티스트 이름은 200자를 넘길 수 없습니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
import java.util.List;

public record ArtistDetailResponse(
@Schema(description = "아티스트 아이디입니다.")
Long id,

@Schema(description = "아티스트 이름입니다.")
String artistName,

@Schema(description = "한국어 기준 아티스트 이름입니다.")
String nameKo,

@Schema(description = "아티스트 소속 그룹입니다. 아티스트 이름이 그룹인 경우, null 로 처리됩니다.")
String artistGroup,

Expand Down Expand Up @@ -37,9 +43,6 @@ public record ArtistDetailResponse(
List<TopTrackResponse> topTracks,

@Schema(description = "아티스트와 관련 있는 다른 아티스트 목록입니다.")
List<RelatedArtistResponse> relatedArtists,

@Schema(description = "로그인한 유저의 좋아요 여부입니다. 비회원인 경우 false입니다.")
Boolean isLiked
List<RelatedArtistResponse> relatedArtists
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public record ArtistListResponse(
@Schema(description = "아티스트 이름입니다.")
String artistName,

@Schema(description = "한국어 기준 아티스트 이름 입니다.")
String nameKo,

@Schema(description = "아티스트 소속 그룹입니다. 아티스트 이름이 그룹인 경우, null 로 처리됩니다.")
String artistGroup,

Expand Down Expand Up @@ -39,6 +42,7 @@ public static ArtistListResponse from(Artist artist) {
return new ArtistListResponse(
artist.getId(),
artist.getArtistName(),
artist.getNameKo(),
artist.getArtistGroup(),
genres,
artist.getLikeCount(),
Expand All @@ -52,6 +56,7 @@ public static ArtistListResponse from(Artist artist, boolean isLiked) {
return new ArtistListResponse(
artist.getId(),
artist.getArtistName(),
artist.getNameKo(),
artist.getArtistGroup(),
genres,
artist.getLikeCount(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.back.web7_9_codecrete_be.domain.artists.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.data.domain.Slice;

import java.util.List;

public record ArtistSliceResponse(
@Schema(description = "아티스트 정보입니다.")
List<ArtistListResponse> content
) {
public static ArtistSliceResponse from(Slice<ArtistListResponse> slice) {
return new ArtistSliceResponse(
slice.getContent()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.back.web7_9_codecrete_be.domain.artists.dto.response;

import com.back.web7_9_codecrete_be.domain.artists.entity.Genre;

public record GenreResponse(
Long genreId,
String genreName
) {
public static GenreResponse from(Genre genre) {
return new GenreResponse(
genre.getId(),
genre.getGenreName()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.back.web7_9_codecrete_be.domain.artists.dto.response;

import com.back.web7_9_codecrete_be.domain.artists.entity.Artist;

public record LikeArtistResponse(
Long artistId,
String artistName,
String nameKo,
String imageUrl,
boolean isLiked
) {
public static LikeArtistResponse from(Artist artist) {
return new LikeArtistResponse(
artist.getId(),
artist.getArtistName(),
artist.getNameKo(),
artist.getImageUrl(),
true
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import io.swagger.v3.oas.annotations.media.Schema;

public record RelatedArtistResponse(
@Schema(description = "아티스트 id 입니다.")
Long id,

@Schema(description = "아티스트 이름입니다.")
String artistName,

@Schema(description = "한국어 기준 아티스트 이름입니다.")
String nameKo,

@Schema(description = "아티스트 사진 URL 입니다.")
String imageUrl,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public record SearchResponse(
@Schema(description = "아티스트 이름입니다.")
String artistName,

@Schema(description = "한국어 기준 아티스트 이름입니다.")
String nameKo,

@Schema(description = "아티스트 소속 그룹입니다. 아티스트 이름이 그룹인 경우, null 로 처리됩니다.")
String artistGroup,

Expand All @@ -16,6 +19,7 @@ public record SearchResponse(
public static SearchResponse from(Artist artist) {
return new SearchResponse(
artist.getArtistName(),
artist.getNameKo(),
artist.getArtistGroup(),
artist.getLikeCount()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public interface ArtistLikeRepository extends JpaRepository<ArtistLike, Long> {
where al.user.id = :userId
""")
List<Long> findArtistIdsByUserId(@Param("userId") Long userId);
@Query("""
select al.artist
from ArtistLike al
where al.user.id = :userId
""")
List<Artist> findArtistsByUserId(@Param("userId") Long userId);
}
Loading