-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from No-Country-simulation/ale-back
Ale back
- Loading branch information
Showing
5 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Back-End/app/src/main/java/com/web/app/dto/search/db/SearchDBResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.web.app.dto.search.db; | ||
|
||
public record SearchDBResponse( | ||
String track, | ||
String album, | ||
String picture_url, | ||
String type, | ||
Long id | ||
) { | ||
// public SearchDBResponse(String track, String album, String pictureUrl, String type, Long id) { | ||
// this.track = track; | ||
// this.album = album; | ||
// this.pictureUrl = pictureUrl; | ||
// this.type = type; | ||
// this.id = id; | ||
// } | ||
} |
18 changes: 18 additions & 0 deletions
18
Back-End/app/src/main/java/com/web/app/dto/search/db/SearchDBResponseProjection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.web.app.dto.search.db; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public interface SearchDBResponseProjection { | ||
@Schema(example = "Nueva Era") | ||
String getTrack(); | ||
@Schema(example = "AMERI") | ||
String getAlbum(); | ||
@Schema(example = "DUKI") | ||
String getArtist(); | ||
@Schema(example = "https://api.deezer.com/album/664113131/image") | ||
String getPicture_url(); | ||
@Schema(example = "track") | ||
String getType(); | ||
@Schema(example = "3069012151") | ||
Long getId(); | ||
} |
53 changes: 53 additions & 0 deletions
53
Back-End/app/src/main/java/com/web/app/repository/TrackRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,63 @@ | ||
package com.web.app.repository; | ||
|
||
import com.web.app.dto.search.db.SearchDBResponseProjection; | ||
import com.web.app.model.Track; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface TrackRepository extends JpaRepository<Track, Long> { | ||
List<Track> findAllByAlbumId(Long albumId); | ||
|
||
@Query(value = """ | ||
SELECT | ||
t.name AS track, | ||
al.name AS album, | ||
ar.name AS artist, | ||
al.picture_url, | ||
'track' AS type, | ||
t.id AS id | ||
FROM | ||
Track t | ||
JOIN | ||
Album al ON t.album_id = al.id | ||
JOIN | ||
Artist ar ON al.artist_id = ar.id | ||
WHERE | ||
t.name LIKE %:searchTerm% | ||
UNION SELECT | ||
NULL AS track, | ||
al.name AS album, | ||
NULL AS artist, | ||
al.picture_url, | ||
'album' AS type, | ||
al.id AS id | ||
FROM | ||
Track t | ||
JOIN | ||
Album al ON t.album_id = al.id | ||
JOIN | ||
Artist ar ON al.artist_id = ar.id | ||
WHERE | ||
al.name LIKE %:searchTerm% | ||
UNION SELECT | ||
NULL AS track, | ||
NULL AS album, | ||
ar.name AS artist, | ||
ar.pictureUrl AS picture_url, | ||
'artist' AS type, | ||
ar.id AS id | ||
FROM | ||
Track t | ||
JOIN | ||
Album al ON t.album_id = al.id | ||
JOIN | ||
Artist ar ON al.artist_id = ar.id | ||
WHERE | ||
ar.name LIKE %:searchTerm%; | ||
""", nativeQuery = true) | ||
List<SearchDBResponseProjection> findMusicBySearchTerm(@Param("searchTerm") String searchTerm); | ||
|
||
} |
17 changes: 15 additions & 2 deletions
17
Back-End/app/src/main/java/com/web/app/service/impl/SearchServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
package com.web.app.service.impl; | ||
|
||
import com.web.app.dto.search.db.SearchDBResponse; | ||
import com.web.app.dto.search.db.SearchDBResponseProjection; | ||
import com.web.app.repository.TrackRepository; | ||
import com.web.app.service.api.DeezerClient; | ||
import com.web.app.dto.BaseResponse; | ||
import com.web.app.dto.ExtendedBaseResponse; | ||
import com.web.app.dto.search.SearchDeezerResponse; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@Service | ||
public class SearchServiceImpl { | ||
public final DeezerClient deezerClient; | ||
private final DeezerClient deezerClient; | ||
private final TrackRepository trackRepository; | ||
|
||
public ExtendedBaseResponse<SearchDeezerResponse> searchDeezaer(String artist, String track, String album) { | ||
SearchDeezerResponse response=deezerClient.searchDeezerAPI(artist, track, album); | ||
SearchDeezerResponse response = deezerClient.searchDeezerAPI(artist, track, album); | ||
return ExtendedBaseResponse.of(BaseResponse.ok("Busqueda por Deezer Exitoso"), response); | ||
} | ||
|
||
public ExtendedBaseResponse<List<SearchDBResponseProjection>> searchDB(String data) { | ||
List<SearchDBResponseProjection> response = trackRepository.findMusicBySearchTerm(data); | ||
System.out.println("canciones"+response); | ||
return ExtendedBaseResponse.of(BaseResponse.ok("Busqueda por Base de Datos Exitosa"), response); | ||
} | ||
} |