Skip to content

Commit

Permalink
SpotifyPlayList-dev-018-be-add-unit-tests (#181)
Browse files Browse the repository at this point in the history
* move to tests to dev test, add service test

* fix test pkg name, add AuthService test

* fix AuthServiceTest.java

* add UserDataServiceTest.java

* fix ec2 deploy cmd (#183)

* SpotifyPlayList-dev-019-recommend-with-playlist (#182)

* BE service add getSongFeatureByPlayList, add recommend with playList

* controller add getSongFeatureWithPlayList endpoint, service fix res init

* implement getRecommendationWithPlayList, move nb, update readme

* update

* update attr in dto, refactor RecommendationsService, add getRecommendWithPlaylist endpoint

* FE add GetRecommendationWithPlaylist view, update router, app.vue

* update FE view, add logging at FE, BE

* FE fix view naming, placeholder name

* FE fix v-model, naming

* BE fix spotify client init, fix recommend reqeust set seed features

* FE fix playlist hardcode, remove no need code

* recommend get seed song from random song, PlayListService clean code

* BE remove no need log, commented code

* add service test

* add SearchServiceTest.java

* add UserDataServiceTest.java

* format all BE code

* add RecommendationsServiceTest.java

* remove no need code

* add sptofy playlist github action

* fix CI name

* update
  • Loading branch information
yennanliu authored Oct 31, 2024
1 parent 131cda7 commit 4ceddda
Show file tree
Hide file tree
Showing 40 changed files with 790 additions and 474 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/maven_spotifyPlaylist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: (SpotifyPlayList service) Java CI with Maven

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: rm -rf ~/.m2 && cd springSpotifyPlayList/backend/SpotifyPlayList && mvn -DskipTests=true package #&& mvn -Dtest=com.yen.SpotifyPlayList.service.* test
7 changes: 7 additions & 0 deletions springSpotifyPlayList/backend/SpotifyPlayList/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>5.2.0</version> <!-- Use the latest version -->
<scope>test</scope>
</dependency>

<!-- Spotify Libraray -->
<dependency>
<groupId>se.michaelthelin.spotify</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
@SpringBootApplication
public class SpotifyPlayListApplication {

public static void main(String[] args) {

SpringApplication.run(SpotifyPlayListApplication.class, args);
}
public static void main(String[] args) {

SpringApplication.run(SpotifyPlayListApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
// 1) enable CORS 2) show swagger 2.x UI properly
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*") // SpringBoot2.4.0 [allowedOriginPatterns]代替[allowedOrigins]
.allowedMethods("*")
.maxAge(3600)
.allowCredentials(true);
}

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS");
}
};

}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOriginPatterns("*") // SpringBoot2.4.0 [allowedOriginPatterns]代替[allowedOrigins]
.allowedMethods("*")
.maxAge(3600)
.allowCredentials(true);
}

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "PUT", "POST", "PATCH", "DELETE", "OPTIONS");
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,34 @@
import se.michaelthelin.spotify.model_objects.specification.Paging;
import se.michaelthelin.spotify.model_objects.specification.TrackSimplified;


@Slf4j
@RestController
@RequestMapping("/album")
public class AlbumController {

@Autowired
private AlbumService albumService;
@Autowired private AlbumService albumService;

@GetMapping("/{albumId}")
public ResponseEntity getAlbumWithId(@PathVariable("albumId") String albumId) {
@GetMapping("/{albumId}")
public ResponseEntity getAlbumWithId(@PathVariable("albumId") String albumId) {

try {
Album album = albumService.getAlbum(albumId);
return ResponseEntity.status(HttpStatus.OK).body(album);
} catch (Exception e) {
log.error("getAlbumWithId error : " + e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}
try {
Album album = albumService.getAlbum(albumId);
return ResponseEntity.status(HttpStatus.OK).body(album);
} catch (Exception e) {
log.error("getAlbumWithId error : " + e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}
}

@GetMapping("/track/{albumId}")
public ResponseEntity getAlbumTrackWithId(@PathVariable("albumId") String albumId) {
try {
@GetMapping("/track/{albumId}")
public ResponseEntity getAlbumTrackWithId(@PathVariable("albumId") String albumId) {
try {

Paging<TrackSimplified> trackSimplifiedPaging = albumService.getAlbumTrack(albumId);
return ResponseEntity.status(HttpStatus.OK).body(trackSimplifiedPaging);
} catch (Exception e) {
log.error("getAlbumTrackWithId error : " + e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}
Paging<TrackSimplified> trackSimplifiedPaging = albumService.getAlbumTrack(albumId);
return ResponseEntity.status(HttpStatus.OK).body(trackSimplifiedPaging);
} catch (Exception e) {
log.error("getAlbumTrackWithId error : " + e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.yen.SpotifyPlayList.model.dto.CreatePlayListDto;
import com.yen.SpotifyPlayList.service.PlayListService;
import com.yen.SpotifyPlayList.service.ProfileService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@
@RequestMapping("/profile")
public class ProfileController {

@Autowired
private ProfileService profileService;
@Autowired private ProfileService profileService;

@GetMapping("/")
public ResponseEntity getCurrentUserId(@PathVariable String authCode) {
UserProfileResp profile = null;
try {
//userId = profileService.getCurrentUserId(authCode);
profile = profileService.getUserProfile();
return ResponseEntity.status(HttpStatus.OK).body(profile);
} catch (Exception e) {
log.error("getCurrentUserId error : " + e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}
@GetMapping("/")
public ResponseEntity getCurrentUserId(@PathVariable String authCode) {
UserProfileResp profile = null;
try {
// userId = profileService.getCurrentUserId(authCode);
profile = profileService.getUserProfile();
return ResponseEntity.status(HttpStatus.OK).body(profile);
} catch (Exception e) {
log.error("getCurrentUserId error : " + e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ public ResponseEntity getRecommendationWithPlayList(@PathVariable("playListId")
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//package com.yen.SpotifyPlayList.controller;
// package com.yen.SpotifyPlayList.controller;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
// import lombok.extern.slf4j.Slf4j;
// import org.springframework.web.bind.annotation.GetMapping;
// import org.springframework.web.bind.annotation.RequestMapping;
// import org.springframework.web.bind.annotation.RestController;
//
///**
/// **
// *
// * https://developer.spotify.com/documentation/web-api/tutorials/code-flow
// * https://developer.spotify.com/documentation/web-api/concepts/apps
// */
//@Slf4j
//@RestController
//@RequestMapping("/")
//public class RedirectController {
// @Slf4j
// @RestController
// @RequestMapping("/")
// public class RedirectController {
//
// @GetMapping("/hello")
// public String hello(){
Expand All @@ -27,4 +27,4 @@
// return "redirect";
// }
//
//}
// }
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
@RequestMapping("/search")
public class SearchController {

@Autowired
private SearchService searchService;
@Autowired private SearchService searchService;

@GetMapping("/album")
public AlbumSimplified[] searchAlbum(String keyword){
return searchService.searchAlbum(keyword);
}

@GetMapping("/artist")
public Artist[] searchArtist(String keyword){
return searchService.searchArtist(keyword);
}
@GetMapping("/album")
public AlbumSimplified[] searchAlbum(String keyword) {
return searchService.searchAlbum(keyword);
}

@GetMapping("/artist")
public Artist[] searchArtist(String keyword) {
return searchService.searchArtist(keyword);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yen.SpotifyPlayList.controller;

import com.yen.SpotifyPlayList.model.dto.Response.RedirectResp;
import java.net.URI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.neo4j.Neo4jProperties.Authentication;
Expand All @@ -12,8 +13,6 @@
import se.michaelthelin.spotify.SpotifyHttpManager;
import se.michaelthelin.spotify.requests.authorization.authorization_code.AuthorizationCodeUriRequest;

import java.net.URI;

@Slf4j
@RestController
public class SpotifyOAuthController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
@RequestMapping("/user_data")
public class UserDataController {

@Value("${spotify.userId}")
private String userId;
@Value("${spotify.userId}")
private String userId;

@Autowired
private UserDataService userDataService;
@Autowired private UserDataService userDataService;

@GetMapping("/playlist")
public PlaylistSimplified[] getUserPlayList(){
//String userId = "62kytpy7jswykfjtnjn9zv3ou";
return userDataService.getUserAllPlaylists(userId);
}
@GetMapping("/playlist")
public PlaylistSimplified[] getUserPlayList() {
// String userId = "62kytpy7jswykfjtnjn9zv3ou";
return userDataService.getUserAllPlaylists(userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.yen.SpotifyPlayList.model.dto;

import java.io.Serializable;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

@ToString
@Data
public class AddSongToPlayListDto implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@Data
public class CreatePlayListDto {

private String userId;
private String name;
// TODO : remove below
private String authCode;
private String userId;
private String name;
// TODO : remove below
private String authCode;
}
Loading

0 comments on commit 4ceddda

Please sign in to comment.