Changeset 0808ef2
- Timestamp:
- 02/10/26 13:53:31 (5 months ago)
- Branches:
- main
- Children:
- 1579b4f
- Parents:
- 890e036
- Location:
- finkwave/src/main/java/com/ukim/finki/develop/finkwave
- Files:
-
- 8 edited
-
controller/UserController.java (modified) (1 diff)
-
service/AlbumService.java (modified) (2 diffs)
-
service/ArtistService.java (modified) (1 diff)
-
service/AuthService.java (modified) (2 diffs)
-
service/FollowService.java (modified) (1 diff)
-
service/NonAdminUserService.java (modified) (3 diffs)
-
service/PlaylistService.java (modified) (1 diff)
-
service/SongService.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
finkwave/src/main/java/com/ukim/finki/develop/finkwave/controller/UserController.java
r890e036 r0808ef2 32 32 return ResponseEntity.ok(usersService.search(userType, searchTerm, limit)); 33 33 } 34 34 35 } -
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/AlbumService.java
r890e036 r0808ef2 26 26 throw new AlbumNotFoundException(id); 27 27 } 28 Long currentUserId=authService.getCurrentUserID ();28 Long currentUserId=authService.getCurrentUserIDOptional().orElse(null); 29 29 30 30 Album album=albumRepository.findById(id).orElseThrow(()->new AlbumNotFoundException(id)); … … 44 44 45 45 public List<MusicalEntityDto> searchAlbums(String searchTerm){ 46 return albumRepository.searchAlbums(authService.getCurrentUserID (), searchTerm);46 return albumRepository.searchAlbums(authService.getCurrentUserIDOptional().orElse(null), searchTerm); 47 47 } 48 48 -
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/ArtistService.java
r890e036 r0808ef2 9 9 10 10 import java.util.List; 11 import java.util.stream.Collectors;12 11 13 12 @Service 14 13 @AllArgsConstructor 15 14 public class ArtistService { 16 17 15 private final ArtistContributionRepository artistContributionRepository; 18 private final AuthService authService;19 16 20 17 21 18 @Transactional(readOnly=true) 22 public List<ArtistContributionDto> getArtistContributions(Long artistId){ 23 Long currentUserId=authService.getCurrentUserID(); 19 public List<ArtistContributionDto> getArtistContributions(Long artistId, Long currentUserId){ 24 20 return artistContributionRepository.findContributionsByArtistId(currentUserId,artistId); 25 21 } -
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/AuthService.java
r890e036 r0808ef2 5 5 import java.nio.file.Path; 6 6 import java.nio.file.Paths; 7 import java.util.List; 8 import java.util.Optional; 7 9 import java.util.UUID; 8 10 … … 123 125 } 124 126 127 public Optional<Long> getCurrentUserIDOptional(){ 128 Authentication authentication= SecurityContextHolder.getContext().getAuthentication(); 129 if (authentication == null || !authentication.isAuthenticated()) { 130 return Optional.empty(); 131 } 132 String username=authentication.getName(); 133 return userRepository.findByUsername(username).map(User::getId); 134 } 125 135 126 136 private User createNonAdminUser(AuthRequestDto authRequestDto) throws IOException { -
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/FollowService.java
r890e036 r0808ef2 55 55 Long id=nonAdminUser.getId(); 56 56 List<Follow> followers = followRepository.findFollowersWithProfile(id); 57 Long currentUserId=authService.getCurrentUserID ();57 Long currentUserId=authService.getCurrentUserIDOptional().orElse(null); 58 58 59 59 -
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/NonAdminUserService.java
r890e036 r0808ef2 41 41 @Transactional(readOnly = true) 42 42 public NonAdminUserDto getNonAdminUserProfile(String username) { 43 44 Long currentUserId= authService.getCurrentUserID(); 45 43 Long currentUserId = authService.getCurrentUserIDOptional().orElse(null); 46 44 47 45 Optional<Artist>artistOptional=artistRepository.findByUsername(username); … … 63 61 64 62 private FollowStatusDto getFollowingInfo(Long id,Long currentUserId){ 63 65 64 Long followers = followRepository.countByFolloweeId(id); 66 65 Long following = followRepository.countByFollowerId(id); 67 boolean isFollowing = followRepository.isFollowing(currentUserId, id);66 boolean isFollowing = currentUserId != null && followRepository.isFollowing(currentUserId, id); 68 67 return new FollowStatusDto(isFollowing,followers,following); 69 68 } … … 72 71 Long artistId=artist.getId(); 73 72 74 List<ArtistContributionDto>artistContributionDtos=artistService.getArtistContributions(artistId );73 List<ArtistContributionDto>artistContributionDtos=artistService.getArtistContributions(artistId, currentUserId); 75 74 FollowStatusDto followStatusDto=getFollowingInfo(artistId,currentUserId); 76 75 -
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/PlaylistService.java
r890e036 r0808ef2 35 35 36 36 public PlaylistDto getPlaylist(Long id){ 37 Long currentUserId=authService.getCurrentUserID ();37 Long currentUserId=authService.getCurrentUserIDOptional().orElse(null); 38 38 Playlist playlist = playlistRepository.findById(id).orElseThrow(()-> new PlaylistNotFoundException(id)); 39 39 List<MusicalEntityDto>songsInPlaylist=songRepository.findSongsByPlaylistId(id,currentUserId); -
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/SongService.java
r890e036 r0808ef2 27 27 28 28 public List<SongDto> searchSongs(String searchTerm){ 29 Long userId = authService.getCurrentUserID ();29 Long userId = authService.getCurrentUserIDOptional().orElse(null); 30 30 return songRepository.searchSongs(userId, searchTerm); 31 31 } … … 36 36 } 37 37 38 public MusicalEntityDto getSongById(Long songId){39 Long userId = null;40 try {41 userId = authService.getCurrentUserID();42 } catch (Exception ignored) {}43 return songRepository.getSongById(songId, userId);44 }38 // public MusicalEntityDto getSongById(Long songId){ 39 // Long userId = null; 40 // try { 41 // userId = authService.getCurrentUserID(); 42 // } catch (Exception ignored) {} 43 // return songRepository.getSongById(songId, userId); 44 // } 45 45 46 46 public SongDetailsDto getSongDetails(Long songId){
Note:
See TracChangeset
for help on using the changeset viewer.
