generated from kappsegla/maven-java-template
-
Notifications
You must be signed in to change notification settings - Fork 19
ItunesPlaylist #9
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
Closed
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
31af7ea
add deadline
github-classroom[bot] 149c2cf
Adds docker-compose.yml
mattknatt 53f3bad
Merge pull request #1 from ithsjava25/feature/dbsetup
mattknatt 31e5caa
Adds PersistenceManager class
mattknatt 2b06218
Adds entities
mattknatt f10da7c
Corrects mapping in Album and Artist classes.
mattknatt 99a0dd4
Merge pull request #2 from ithsjava25/feature/persistenceconfig
mattknatt 2072f52
Implements ItunesApiClient
mattknatt 7bbf493
Imports entitymanagerfactory
mattknatt 4c53813
Fixes according to CodeRabbit feedback. Corrects duplicate handling w…
mattknatt e26c8ca
Merge pull request #3 from ithsjava25/feature/itunesapiconnection
mattknatt 5733aee
repo split
jesperlarsson1910 da32a4a
repo split
jesperlarsson1910 157b3a1
Merge pull request #5 from ithsjava25/reposplit
jesperlarsson1910 583d9c9
Add implementation for AlbumRepositoryl, add implementation for Artis…
simonforsberg a822044
Merge pull request #6 from ithsjava25/artist_album_repoimpl
simonforsberg b1fc312
Implements methods from SongRepository
mattknatt b965860
Merge pull request #7 from ithsjava25/feature/songrepo
mattknatt d1a4ba8
Updated pom.xml-file with
johanbriger 054eadf
Added Stylesheet
johanbriger bc75e64
Added MyPod.java for UI
johanbriger 0a1b05a
Added MyPod.java for UI
johanbriger e032fdf
Added MyPod.java for UI
johanbriger db5bbb0
Added MyPod.java for UI
johanbriger 1c4943f
Move initialization to a background thread(CodeRabbit)
johanbriger 348ab56
Handle nullpointerexception
johanbriger 012dddb
Added RuntimeException
johanbriger ce1335a
Initialize UI components before starting the Task:
johanbriger 51bc759
New window to edit playlists(Itunes)
johanbriger 58f9e6a
New window to edit playlists(Itunes)
johanbriger e2ba577
New Icons för ScrollWheel
johanbriger 1dee24d
Moved all styling to ipod_style.css
johanbriger 4759e22
Added comments
johanbriger 8114044
Added comments
johanbriger 9cdff2a
Added comments
johanbriger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 @@ | ||
| services: | ||
| myPod: | ||
| image: mysql:9.5.0 | ||
| environment: | ||
| MYSQL_ROOT_PASSWORD: root | ||
| MYSQL_ROOT_HOST: "%" | ||
| MYSQL_DATABASE: myPodDB | ||
| MYSQL_USER: user | ||
| MYSQL_PASSWORD: pass | ||
| ports: | ||
| - "3306:3306" | ||
| volumes: | ||
| - mypod_data:/var/lib/mysql | ||
| volumes: | ||
| mypod_data: |
This file contains hidden or 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
This file contains hidden or 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,7 +1,12 @@ | ||
| package org.example; | ||
|
|
||
| import javafx.application.Application; | ||
|
|
||
|
|
||
| public class App { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello There!"); | ||
|
|
||
| Application.launch(MyPod.class, args); | ||
|
|
||
| } | ||
| } |
This file contains hidden or 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,67 @@ | ||
| package org.example; | ||
|
|
||
| import org.example.entity.Album; | ||
| import org.example.entity.Artist; | ||
| import org.example.entity.Song; | ||
| import org.example.repo.AlbumRepository; | ||
| import org.example.repo.ArtistRepository; | ||
| import org.example.repo.SongRepository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class DatabaseInitializer { | ||
|
|
||
| private final ItunesApiClient apiClient; | ||
|
|
||
| private final SongRepository songRepo; | ||
| private final AlbumRepository albumRepo; | ||
| private final ArtistRepository artistRepo; | ||
|
|
||
| public DatabaseInitializer(ItunesApiClient apiClient, SongRepository songRepo , AlbumRepository albumRepo, ArtistRepository artistRepo) { | ||
| this.apiClient = apiClient; | ||
| this.songRepo = songRepo; | ||
| this.albumRepo = albumRepo; | ||
| this.artistRepo = artistRepo; | ||
| } | ||
|
|
||
| public void init() { | ||
| if (songRepo.count() > 0) { //check if there is data already | ||
| return; | ||
| } | ||
|
|
||
| List<String> searches = List.of("the+war+on+drugs", | ||
| "refused", | ||
| "thrice", | ||
| "16+horsepower", | ||
| "viagra+boys", | ||
| "geese", | ||
| "ghost", | ||
| "run+the+jewels", | ||
| "rammstein", | ||
| "salvatore+ganacci", | ||
| "baroness" | ||
| ); | ||
| for (String term : searches) { | ||
| try { | ||
| apiClient.searchSongs(term).forEach(dto -> { | ||
| Artist ar = Artist.fromDTO(dto); | ||
| if (!artistRepo.existsByUniqueId(ar)) { | ||
| artistRepo.save(ar); | ||
| } | ||
|
|
||
| Album al = Album.fromDTO(dto, ar); | ||
| if (!albumRepo.existsByUniqueId(al)) { | ||
| albumRepo.save(al); | ||
| } | ||
|
|
||
| Song s = Song.fromDTO(dto, al); | ||
| if (!songRepo.existsByUniqueId(s)) { | ||
| songRepo.save(s); | ||
| } | ||
| }); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to fetch or persist data for search term: " + term, e); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,63 @@ | ||
| package org.example; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URLEncoder; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpRequest; | ||
| import java.net.http.HttpResponse; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class ItunesApiClient { | ||
|
|
||
| private final HttpClient client; | ||
| private final ObjectMapper mapper; | ||
|
|
||
| public ItunesApiClient() { | ||
| this.client = HttpClient.newHttpClient(); | ||
| this.mapper = new ObjectMapper(); | ||
| mapper.registerModule(new JavaTimeModule()); | ||
| } | ||
|
|
||
| public List<ItunesDTO> searchSongs(String term) throws Exception { | ||
|
|
||
| String encodedTerm = URLEncoder.encode(term, StandardCharsets.UTF_8); | ||
| String url = "https://itunes.apple.com/search?term=" + encodedTerm + "&entity=song&attribute=artistTerm&limit=8"; | ||
|
|
||
| HttpRequest request = HttpRequest.newBuilder() | ||
| .GET() | ||
| .uri(URI.create(url)) | ||
| .timeout(Duration.ofSeconds(10)) | ||
| .build(); | ||
|
|
||
| HttpResponse<String> response = | ||
| client.send(request, HttpResponse.BodyHandlers.ofString()); | ||
|
|
||
| // Kontrollera status | ||
| if (response.statusCode() != 200) { | ||
| throw new RuntimeException("API-fel: " + response.statusCode()); | ||
| } | ||
|
|
||
| // Parse JSON | ||
| JsonNode root = mapper.readTree(response.body()); | ||
| JsonNode results = root.get("results"); | ||
| if (results == null || !results.isArray()) { | ||
| return List.of(); | ||
| } | ||
|
|
||
| List<ItunesDTO> songs = new ArrayList<>(); | ||
| for (JsonNode node : results) { | ||
| ItunesDTO song = mapper.treeToValue(node, ItunesDTO.class); | ||
| songs.add(song); | ||
| } | ||
|
|
||
| return songs; | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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,23 @@ | ||
| package org.example; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public record ItunesDTO(Long artistId, | ||
| Long collectionId, | ||
| Long trackId, | ||
| String trackName, | ||
| String artistName, | ||
| String collectionName, | ||
| String country, | ||
| String primaryGenreName, | ||
| LocalDate releaseDate, | ||
| Long trackCount, | ||
| Long trackTimeMillis) { | ||
|
|
||
| public int releaseYear() { | ||
| return releaseDate != null ? releaseDate.getYear() : 0; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Swedish comments and error messages for consistency.
The codebase uses English for code and comments elsewhere, but this file contains Swedish comments ("Kontrollera status", "Parse JSON") and error messages ("API-fel: "). This creates inconsistency and may confuse international contributors.
🔎 Proposed fix
Also applies to: 47-47
🤖 Prompt for AI Agents