Skip to content

Commit 3d1ccf8

Browse files
Merge branch 'main' into feat/#57
2 parents 602ff03 + 7df4e03 commit 3d1ccf8

23 files changed

Lines changed: 1427 additions & 29 deletions

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ dependencies {
7272

7373
// 정적 HTML 문서 기준 크롤링
7474
implementation("org.jsoup:jsoup:1.21.2")
75+
76+
// Spotify
77+
implementation("se.michaelthelin.spotify:spotify-web-api-java:8.4.1")
7578
}
7679

7780
tasks.withType<Test> {
Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
package com.back.web7_9_codecrete_be.domain.artists.controller;
22

3-
import com.back.web7_9_codecrete_be.domain.artists.service.ArtistsService;
3+
import com.back.web7_9_codecrete_be.domain.artists.service.ArtistService;
4+
import com.back.web7_9_codecrete_be.domain.artists.service.ArtistEnrichService;
5+
import com.back.web7_9_codecrete_be.global.rsData.RsData;
6+
import io.swagger.v3.oas.annotations.Operation;
7+
import io.swagger.v3.oas.annotations.tags.Tag;
48
import lombok.RequiredArgsConstructor;
5-
import org.springframework.web.bind.annotation.RequestMapping;
6-
import org.springframework.web.bind.annotation.RestController;
9+
import org.springframework.web.bind.annotation.*;
710

811
@RestController
912
@RequestMapping("/api/v1/artists")
1013
@RequiredArgsConstructor
14+
@Tag(name = "Artists", description = "공연에 대한 정보를 제공하는 API 입니다.")
1115
public class ArtistsController {
12-
private final ArtistsService artistsService;
16+
private final ArtistService artistService;
17+
private final ArtistEnrichService enrichService;
18+
19+
@Operation(summary = "아티스트 저장", description = "임의의 가수 300명(or 팀)을 DB에 저장합니다.")
20+
@GetMapping("/saved")
21+
public RsData<Integer> saveArtist() {
22+
int saved = artistService.setArtist();
23+
return RsData.success("아티스트 저장에 성공하였습니다.", saved);
24+
}
25+
26+
@Operation(summary = "아티스트 정보 보완", description = "아티스트 한국어 이름, 그룹 여부, 소속 그룹 정보 보완")
27+
@PostMapping("/enrich")
28+
public RsData<Integer> enrich(
29+
@RequestParam(required = false, defaultValue = "100") int limit
30+
) {
31+
int updated = enrichService.enrichArtist(limit);
32+
return RsData.success("enrich 성공", updated);
33+
}
1334
}

src/main/java/com/back/web7_9_codecrete_be/domain/artists/dto/dummy.txt

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.back.web7_9_codecrete_be.domain.artists.dto.request;
2+
3+
import com.back.web7_9_codecrete_be.domain.artists.entity.Genre;
4+
5+
6+
public record CreateRequest(
7+
String artistName,
8+
String artistGroup,
9+
String artistType,
10+
Genre genre
11+
) {
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.back.web7_9_codecrete_be.domain.artists.dto.request;
2+
3+
import com.back.web7_9_codecrete_be.domain.artists.entity.Genre;
4+
5+
6+
public record UpdateRequest(
7+
String artistName,
8+
String artistGroup,
9+
String artistType,
10+
Genre genre
11+
) {
12+
}
Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,54 @@
11
package com.back.web7_9_codecrete_be.domain.artists.entity;
22

33
import jakarta.persistence.*;
4+
import lombok.AccessLevel;
45
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
59

610
@Entity
711
@Getter
8-
@Table(name = "arist")
12+
@Setter
13+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
14+
@Table(name = "artist")
915
public class Artist {
1016
@Id
1117
@GeneratedValue(strategy = GenerationType.IDENTITY)
1218
@Column(name = "artist_id")
1319
private long id;
1420

15-
@Column(name = "artist_name", nullable = false, length = 30)
21+
@Column(name = "artist_name", nullable = false)
1622
private String artistName;
1723

18-
@Column(name = "artist_group", length = 30)
24+
@Column(name = "artist_group")
1925
private String artistGroup;
2026

21-
@Column(name = "artist_type", nullable = false, length = 20)
27+
@Column(name = "artist_type")
2228
private String artistType;
2329

2430
@ManyToOne(fetch = FetchType.LAZY)
2531
private Genre genre;
2632

33+
@Column(name = "spotify_artist_id", unique = true)
34+
private String spotifyArtistId;
35+
36+
@Column(name = "name_ko", length = 200)
37+
private String nameKo;
38+
39+
public Artist(String spotifyArtistId, String artistName, String artistGroup, String artistType, Genre genre) {
40+
this.spotifyArtistId = spotifyArtistId;
41+
this.artistName = artistName;
42+
this.artistGroup = artistGroup; // 옵션 B: seed에서는 null
43+
this.artistType = artistType; // 옵션 B: seed에서는 "SINGER"
44+
this.genre = genre;
45+
}
46+
47+
public void updateProfile(String nameKo, String artistGroup, String artistType) {
48+
this.nameKo = nameKo;
49+
this.artistGroup = artistGroup; // nullable
50+
this.artistType = artistType; // "SOLO" / "GROUP"
51+
}
52+
53+
2754
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.back.web7_9_codecrete_be.domain.artists.entity;
22

33
import jakarta.persistence.*;
4+
import lombok.AccessLevel;
45
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
57

68
@Entity
79
@Getter
10+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
811
@Table(name = "genre")
912
public class Genre {
1013
@Id
@@ -19,4 +22,10 @@ public class Genre {
1922

2023
@Column(name = "genre_memo")
2124
private String genreMemo;
25+
26+
public Genre(String genreName, String genreGroup, String genreMemo) {
27+
this.genreName = genreName;
28+
this.genreGroup = genreGroup;
29+
this.genreMemo = genreMemo;
30+
}
2231
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package com.back.web7_9_codecrete_be.domain.artists.repository;
22

33
import com.back.web7_9_codecrete_be.domain.artists.entity.Artist;
4+
import org.springframework.data.domain.Pageable;
45
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.data.jpa.repository.Query;
57
import org.springframework.stereotype.Repository;
68

9+
import java.util.List;
10+
711
@Repository
812
public interface ArtistRepository extends JpaRepository<Artist, Long> {
13+
boolean existsBySpotifyArtistId(String spotifyArtistId);
14+
15+
@Query("SELECT a FROM Artist a WHERE a.nameKo IS NULL ORDER BY a.id ASC")
16+
List<Artist> findByNameKoIsNullOrderByIdAsc(Pageable pageable);
917
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.springframework.data.jpa.repository.JpaRepository;
55
import org.springframework.stereotype.Repository;
66

7+
import java.util.Optional;
8+
79
@Repository
810
public interface GenreRepository extends JpaRepository<Genre, Long> {
11+
Optional<Genre> findByGenreName(String genreName);
912
}

0 commit comments

Comments
 (0)