Skip to content

Commit 697d54e

Browse files
Merge pull request #80 from prgrms-web-devcourse-final-project/feat/#66
[Artist] CRUD 구현
2 parents bbb805a + 6aa1fb7 commit 697d54e

17 files changed

Lines changed: 502 additions & 23 deletions

src/main/java/com/back/web7_9_codecrete_be/domain/artists/controller/ArtistsController.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.back.web7_9_codecrete_be.domain.artists.controller;
22

3+
import com.back.web7_9_codecrete_be.domain.artists.dto.request.CreateRequest;
4+
import com.back.web7_9_codecrete_be.domain.artists.dto.request.UpdateRequest;
5+
import com.back.web7_9_codecrete_be.domain.artists.dto.response.ArtistListResponse;
6+
import com.back.web7_9_codecrete_be.domain.artists.dto.response.ArtistDetailResponse;
37
import com.back.web7_9_codecrete_be.domain.artists.service.ArtistService;
48
import com.back.web7_9_codecrete_be.domain.artists.service.ArtistEnrichService;
59
import com.back.web7_9_codecrete_be.global.rsData.RsData;
@@ -8,10 +12,12 @@
812
import lombok.RequiredArgsConstructor;
913
import org.springframework.web.bind.annotation.*;
1014

15+
import java.util.List;
16+
1117
@RestController
1218
@RequestMapping("/api/v1/artists")
1319
@RequiredArgsConstructor
14-
@Tag(name = "Artists", description = "공연에 대한 정보를 제공하는 API 입니다.")
20+
@Tag(name = "Artists", description = "아티스트에 대한 정보를 제공하는 API 입니다.")
1521
public class ArtistsController {
1622
private final ArtistService artistService;
1723
private final ArtistEnrichService enrichService;
@@ -23,12 +29,54 @@ public RsData<Integer> saveArtist() {
2329
return RsData.success("아티스트 저장에 성공하였습니다.", saved);
2430
}
2531

26-
@Operation(summary = "아티스트 정보 보완", description = "아티스트 한국어 이름, 그룹 여부, 소속 그룹 정보 보완")
32+
@Operation(summary = "아티스트 정보 보완", description = "아티스트 한국어 이름, 그룹 여부, 소속 그룹 정보를 보완합니다.")
2733
@PostMapping("/enrich")
2834
public RsData<Integer> enrich(
2935
@RequestParam(required = false, defaultValue = "100") int limit
3036
) {
3137
int updated = enrichService.enrichArtist(limit);
3238
return RsData.success("enrich 성공", updated);
3339
}
40+
41+
@Operation(summary = "아티스트 생성", description = "아티스트를 등록합니다.")
42+
@PostMapping()
43+
public RsData<Void> create(
44+
@RequestBody CreateRequest reqBody
45+
) {
46+
artistService.createArtist(reqBody.artistName(), reqBody.artistGroup(), reqBody.artistGroup(), reqBody.genreName());
47+
return RsData.success("아티스트 생성이 완료되었습니다.", null);
48+
}
49+
50+
@Operation(summary = "아티스트 목록 조회", description = "아티스트 전체 목록을 조회합니다.")
51+
@GetMapping()
52+
public RsData<List<ArtistListResponse>> list() {
53+
return RsData.success("아티스트 전체 목록을 조회했습니다.", artistService.listArtist());
54+
}
55+
56+
@Operation(summary = "아티스트 상세 조회", description = "아티스트의 상세 정보를 조회합니다.")
57+
@GetMapping("/{id}")
58+
public RsData<ArtistDetailResponse> artist(
59+
@PathVariable Long id
60+
) {
61+
return RsData.success("아티스트 상세 조회를 성공했습니다.", artistService.getArtistDetail(id));
62+
}
63+
64+
@Operation(summary = "아티스트 정보 수정", description = "아티스트 정보를 수정합니다.")
65+
@PatchMapping("/{id}")
66+
public RsData<Void> update(
67+
@PathVariable Long id,
68+
@RequestBody UpdateRequest reqBody
69+
) {
70+
artistService.updateArtist(id, reqBody);
71+
return RsData.success("아티스트 정보 수정을 완료했습니다.", null);
72+
}
73+
74+
@Operation(summary = "아티스트 정보 삭제", description = "아티스트 정보를 삭제합니다.")
75+
@DeleteMapping("/{id}")
76+
public RsData<Void> delete(
77+
@PathVariable Long id
78+
) {
79+
artistService.delete(id);
80+
return RsData.success("아티스트 정보를 삭제했습니다.", null);
81+
}
3482
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package com.back.web7_9_codecrete_be.domain.artists.dto.request;
22

3-
import com.back.web7_9_codecrete_be.domain.artists.entity.Genre;
4-
5-
63
public record CreateRequest(
74
String artistName,
85
String artistGroup,
96
String artistType,
10-
Genre genre
7+
String genreName
118
) {
129
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package com.back.web7_9_codecrete_be.domain.artists.dto.request;
22

3-
import com.back.web7_9_codecrete_be.domain.artists.entity.Genre;
4-
5-
63
public record UpdateRequest(
74
String artistName,
85
String artistGroup,
96
String artistType,
10-
Genre genre
7+
String genreName
118
) {
129
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.back.web7_9_codecrete_be.domain.artists.dto.response;
2+
3+
public record AlbumResponse(
4+
String albumName,
5+
String releaseDate,
6+
String albumType, // album / single / ep
7+
String imageUrl,
8+
String spotifyUrl
9+
) {
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.back.web7_9_codecrete_be.domain.artists.dto.response;
2+
3+
import java.util.List;
4+
5+
public record ArtistDetailResponse(
6+
String artistName,
7+
String artistGroup,
8+
String artistType,
9+
String profileImageUrl,
10+
long likeCount,
11+
int totalAlbums,
12+
double popularityRating,
13+
String description,
14+
List<AlbumResponse> albums,
15+
List<TopTrackResponse> topTracks,
16+
List<RelatedArtistResponse> relatedArtists
17+
) {
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.back.web7_9_codecrete_be.domain.artists.dto.response;
2+
3+
import com.back.web7_9_codecrete_be.domain.artists.entity.Artist;
4+
5+
public record ArtistListResponse(
6+
String artistName,
7+
String artistGroup,
8+
String genreName
9+
) {
10+
public static ArtistListResponse from(Artist artist) {
11+
return new ArtistListResponse(
12+
artist.getArtistName(),
13+
artist.getArtistGroup(),
14+
artist.getGenre().getGenreName()
15+
);
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.back.web7_9_codecrete_be.domain.artists.dto.response;
2+
3+
public record RelatedArtistResponse(
4+
String artistName,
5+
String imageUrl,
6+
String spotifyArtistId
7+
) {
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.back.web7_9_codecrete_be.domain.artists.dto.response;
2+
3+
public record TopTrackResponse(
4+
String trackName,
5+
String spotifyUrl
6+
) {
7+
}

src/main/java/com/back/web7_9_codecrete_be/domain/artists/entity/Artist.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,34 @@ public Artist(String spotifyArtistId, String artistName, String artistGroup, Str
4444
this.genre = genre;
4545
}
4646

47+
public Artist(String artistName, String artistGroup, String artistType, Genre genre) {
48+
this.artistName = artistName;
49+
this.artistGroup = artistGroup;
50+
this.artistType = artistType;
51+
this.genre = genre;
52+
}
53+
4754
public void updateProfile(String nameKo, String artistGroup, String artistType) {
4855
this.nameKo = nameKo;
4956
this.artistGroup = artistGroup; // nullable
5057
this.artistType = artistType; // "SOLO" / "GROUP"
5158
}
5259

60+
public void changeName(String name) {
61+
this.artistName = name;
62+
}
63+
64+
public void changeGroup(String group) {
65+
this.artistGroup = group;
66+
}
67+
68+
public void changeType(String type) {
69+
this.artistType = type;
70+
}
71+
72+
public void changeGenre(Genre genre) {
73+
this.genre = genre;
74+
}
75+
5376

5477
}

src/main/java/com/back/web7_9_codecrete_be/domain/artists/repository/ArtistLikeRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66

77
@Repository
88
public interface ArtistLikeRepository extends JpaRepository<ArtistLike, Long> {
9+
long countByArtistId(Long artistId);
910
}

0 commit comments

Comments
 (0)