release-只有本人可以删除/修改专辑内容

release-2024-08-08
pikaqiudeshujia 7 months ago
parent d209cc9b4f
commit ba2dd5043f

@ -69,7 +69,7 @@ public class AlbumController {
@RequestMapping(value = "/delete", method = RequestMethod.POST) @RequestMapping(value = "/delete", method = RequestMethod.POST)
public Result<Void> delete(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, public Result<Void> delete(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "专辑id", required = true) String id) { @ApiParam(value = "专辑id", required = true) String id) {
albumService.deleteAlbum(id); albumService.deleteAlbum(token, id);
return Result.success(); return Result.success();
} }
@ -77,7 +77,7 @@ public class AlbumController {
@RequestMapping(value = "/delete/song", method = RequestMethod.POST) @RequestMapping(value = "/delete/song", method = RequestMethod.POST)
public Result<Void> deleteAlbumSong(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token, public Result<Void> deleteAlbumSong(@ApiParam(value = "Header中的token信息", required = true) @RequestHeader("Authorization") String token,
@ApiParam(value = "专辑歌曲绑定的id", required = true) String id) { @ApiParam(value = "专辑歌曲绑定的id", required = true) String id) {
albumService.deleteAlbumSong(id); albumService.deleteAlbumSong(token, id);
return Result.success(); return Result.success();
} }

@ -222,6 +222,9 @@ public class AlbumService {
UserLoginDto user = jwtUtil.getUserLoginDto(token); UserLoginDto user = jwtUtil.getUserLoginDto(token);
if (user != null) { if (user != null) {
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
throw new RuntimeException("只允许本人操作!");
}
artistAlbum.setUpdateUser(user.getUserId()); artistAlbum.setUpdateUser(user.getUserId());
} else { } else {
throw new RuntimeException("用户校验失败,请重新登录"); throw new RuntimeException("用户校验失败,请重新登录");
@ -236,8 +239,10 @@ public class AlbumService {
* @param id id * @param id id
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteAlbum(String id) { public void deleteAlbum(String token, String id) {
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
ArtistAlbum artistAlbum = checkAlbum(token, id);
artistAlbumDao.delete(artistAlbum); artistAlbumDao.delete(artistAlbum);
artistAlbumSongDao.deleteByAlbumId(id); artistAlbumSongDao.deleteByAlbumId(id);
@ -249,14 +254,39 @@ public class AlbumService {
* @param id -id * @param id -id
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteAlbumSong(String id) { public void deleteAlbumSong(String token, String id) {
ArtistAlbumSong artistAlbumSong = artistAlbumSongDao.findById(id).get(); ArtistAlbumSong artistAlbumSong = artistAlbumSongDao.findById(id).get();
if (artistAlbumSong.getId() == null) { if (artistAlbumSong.getId() == null) {
throw new RuntimeException("该专辑不存在此歌曲"); throw new RuntimeException("该专辑不存在此歌曲");
} }
checkAlbum(token, artistAlbumSong.getAlbumId());
artistAlbumSongDao.delete(artistAlbumSong); artistAlbumSongDao.delete(artistAlbumSong);
} }
/**
* /
*
* @param token token
* @param id id
* @return
*/
private ArtistAlbum checkAlbum(String token, String id) {
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get();
UserLoginDto user = jwtUtil.getUserLoginDto(token);
if (user != null) {
if (ObjectUtils.notEqual(user.getUserId(), artistAlbum.getCreateUser())) {
throw new RuntimeException("只允许本人操作!");
}
} else {
throw new RuntimeException("用户校验失败,请重新登录");
}
return artistAlbum;
}
/** /**
* *
* *
@ -267,7 +297,7 @@ public class AlbumService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void addNewSong(String token, String id, AlbumSongAddDTO albumSongAddDTO) { public void addNewSong(String token, String id, AlbumSongAddDTO albumSongAddDTO) {
UserLoginDto user = jwtUtil.getUserLoginDto(token); UserLoginDto user = jwtUtil.getUserLoginDto(token);
ArtistAlbum artistAlbum = artistAlbumDao.findById(id).get(); ArtistAlbum artistAlbum = checkAlbum(token, id);
addSongForAlbum(albumSongAddDTO, user, artistAlbum); addSongForAlbum(albumSongAddDTO, user, artistAlbum);
} }

Loading…
Cancel
Save