Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buscador desde la API de deezer #17

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Back-End/app/downloaded_song.mp3
Binary file not shown.
26 changes: 26 additions & 0 deletions Back-End/app/src/main/java/com/web/app/client/DeezerClient.java
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);
}
}
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);
}
}
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
) {
}
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
) {
}
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
) {
}
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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.authorizeHttpRequests( auth -> auth
.requestMatchers("/auth/**")
.permitAll()
.requestMatchers("/search/**")
.permitAll()
.requestMatchers("/api-docs/**", "api-docs.yaml")
.permitAll()
.requestMatchers("/swagger-ui-custom.html", "/swagger-ui/**", "/swagger-ui/")
Expand Down
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);
}
}