-
Notifications
You must be signed in to change notification settings - Fork 1
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 #17 from No-Country-simulation/ale-back
buscador desde la API de deezer
- Loading branch information
Showing
9 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
26 changes: 26 additions & 0 deletions
26
Back-End/app/src/main/java/com/web/app/client/DeezerClient.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,26 @@ | ||
package com.web.app.client; | ||
|
||
import com.web.app.dto.search.SearchDeezerResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
public class DeezerClient { | ||
|
||
private final String url = "https://api.deezer.com/"; | ||
|
||
public SearchDeezerResponse searchDeezerAPI(String artist, String track, String album) { | ||
RestTemplate template = new RestTemplate(); | ||
return template.getForObject(url + "search?q=" | ||
// con comillas o que las agreguen al hacer la peticion | ||
// creo que al hacer las peticiones son un buen indicador de | ||
+ "artist:" + artist | ||
+ " track:" + track | ||
+ " album:" + album | ||
|
||
// + "artist:" + "\"" + artist + "\"" | ||
// + " track:" + "\"" + track + "\"" | ||
// + " album:" + "\"" + album + "\"" | ||
, SearchDeezerResponse.class); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Back-End/app/src/main/java/com/web/app/controllers/SearchController.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,41 @@ | ||
package com.web.app.controllers; | ||
|
||
import com.web.app.dto.ExtendedBaseResponse; | ||
import com.web.app.dto.search.SearchDeezerResponse; | ||
import com.web.app.service.impl.SearchServiceImpl; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Tag(name = "Buscador", description = "Buscar canciones, album, artist tanto desde la API de Deezar como la nuestra") | ||
@RestController | ||
@RequestMapping("/search") | ||
@RequiredArgsConstructor | ||
public class SearchController { | ||
public final SearchServiceImpl searchService; | ||
// Implementación de los métodos para buscar canciones, albums y artistas | ||
@Operation(summary = "Buscador", | ||
description = "Al Buscar canciones, album, artist, hacerlo entre comillas" | ||
) | ||
@ApiResponses( value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "Busqueda por API Deezer Exitoso.", | ||
content = { | ||
@Content(mediaType = "application/json", | ||
schema = @Schema(implementation = ExtendedBaseResponse.class)) | ||
}) | ||
}) | ||
@GetMapping | ||
public ExtendedBaseResponse<SearchDeezerResponse> findTracksByAlbumId( | ||
@RequestParam(required = false) String artist, | ||
@RequestParam(required = false) String track, | ||
@RequestParam(required = false) String album) { | ||
return searchService.searchDeezaer(artist,track,album); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Back-End/app/src/main/java/com/web/app/dto/search/AlbumResponseBySearch.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,15 @@ | ||
package com.web.app.dto.search; | ||
|
||
public record AlbumResponseBySearch( | ||
long id, | ||
String title, | ||
String cover, | ||
String cover_small, | ||
String cover_medium, | ||
String cover_big, | ||
String cover_xl, | ||
String md5_image, | ||
String tracklist | ||
// String type | ||
) { | ||
} |
15 changes: 15 additions & 0 deletions
15
Back-End/app/src/main/java/com/web/app/dto/search/ArtistResponseBySearch.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,15 @@ | ||
package com.web.app.dto.search; | ||
|
||
public record ArtistResponseBySearch( | ||
String id, | ||
String name, | ||
// String link, | ||
String picture, | ||
String picture_small, | ||
String picture_medium, | ||
String picture_big, | ||
String picture_xl, | ||
String tracklist | ||
// String type | ||
) { | ||
} |
22 changes: 22 additions & 0 deletions
22
Back-End/app/src/main/java/com/web/app/dto/search/DataResponseBySearch.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,22 @@ | ||
package com.web.app.dto.search; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
public record DataResponseBySearch( | ||
long id, | ||
// boolean readable, | ||
String title, | ||
String title_short, | ||
// String title_version, | ||
// String link, | ||
int duration, | ||
// int rank, | ||
// boolean explicit_lyrics, | ||
// int explicit_content_lyrics, | ||
// int explicit_content_cover, | ||
String preview, | ||
String md5_image, | ||
ArtistResponseBySearch artist, | ||
AlbumResponseBySearch album | ||
) { | ||
} |
10 changes: 10 additions & 0 deletions
10
Back-End/app/src/main/java/com/web/app/dto/search/SearchDeezerResponse.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,10 @@ | ||
package com.web.app.dto.search; | ||
|
||
import java.util.ArrayList; | ||
|
||
public record SearchDeezerResponse( | ||
ArrayList<DataResponseBySearch> data, | ||
int total, | ||
String next | ||
) { | ||
} |
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
18 changes: 18 additions & 0 deletions
18
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.web.app.service.impl; | ||
|
||
import com.web.app.client.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; | ||
|
||
@AllArgsConstructor | ||
@Service | ||
public class SearchServiceImpl { | ||
public final DeezerClient deezerClient; | ||
public ExtendedBaseResponse<SearchDeezerResponse> searchDeezaer(String artist, String track, String album) { | ||
SearchDeezerResponse response=deezerClient.searchDeezerAPI(artist, track, album); | ||
return ExtendedBaseResponse.of(BaseResponse.ok("Busqueda por Deezer Exitoso"), response); | ||
} | ||
} |