1.uniform response status code for music component

main
Gary 11 months ago
parent e2cd163840
commit c7414e18e7

@ -14,17 +14,13 @@ public enum StatusCode implements IErrorCode {
USER_VERIFICATION_CODE_MISMATCH(10002, "验证码校验失败,请输入正确的验证码"),
USER_NAME_OR_PASSWORD_FAILED(10003, "用户名或密码错误"),
// music 模块错误码以20XXX不足5位补0;
MUSIC_COMMON_FAILED(20000, "歌曲模块失败"),
// comment 模块错误码以30XXX不足5位补0;
COMMENT_COMMON_FAILED(30000, "评论模块失败"),
// friend 模块错误码以40XXX不足5位补0;
FRIEND_COMMON_FAILED(40000, "交友模块失败"),
// tag 模块错误码以50XXX不足5位补0;
// music 模块错误码以60XXX不足5位补0;
// manage 模块错误码以70XXX不足5位补0;
MANAGE_COMMON_FAILED(70000, "管理模块失败");
TAG_COMMON_FAILED(50000, "标签模块失败");
private int code;
private String message;

@ -1,6 +1,6 @@
package com.luoo.music.client;
import entity.Result;
import api.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@ -5,19 +5,13 @@ import java.util.Map;
import com.luoo.music.client.UserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Article;
import com.luoo.music.service.ArticleService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import api.PageResult;
import api.Result;
/**
*
* @author Administrator
@ -34,33 +28,32 @@ public class ArticleController {
@Autowired
private UserClient userClient;
@RequestMapping(value = "/admin",method = RequestMethod.GET)
public Result findAdmin(){
Result result =userClient.findAll();
return result;
@GetMapping("/admin")
public Result findAdmin(){
return userClient.findAll();
}
@RequestMapping(value = "/examine/{articleId}",method = RequestMethod.PUT)
public Result examine (@PathVariable String articleId){
@PutMapping("/examine/{articleId}")
public Result<Void> examine (@PathVariable String articleId){
articleService.updateState(articleId);
return new Result(true,StatusCode.OK,"审核成功");
return Result.success();
}
@RequestMapping(value = "/thumbup/{articleId}",method = RequestMethod.PUT)
public Result thumbup (@PathVariable String articleId){
@PutMapping("/thumbup/{articleId}")
public Result<Void> thumbup (@PathVariable String articleId){
articleService.addThumbup(articleId);
return new Result(true,StatusCode.OK,"点赞成功");
return Result.success();
}
/**
*
* @return
*/
@RequestMapping(method= RequestMethod.GET)
public Result findAll(){
return new Result(true,StatusCode.OK,"查询成功",articleService.findAll());
@GetMapping
public Result<List<Article>> findAll(){
return Result.success(articleService.findAll());
}
/**
@ -68,14 +61,14 @@ public class ArticleController {
* @param id ID
* @return
*/
@RequestMapping(value="/{id}",method= RequestMethod.GET)
public Result findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",articleService.findById(id));
@GetMapping("/{id}")
public Result<Article> findById(@PathVariable String id){
return Result.success(articleService.findById(id));
}
@RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET)
public Result findByVolid(@PathVariable String volid){
return new Result(true,StatusCode.OK,"查询成功",articleService.findByVolid(volid));
@GetMapping("/findByVolid/{volid}")
public Result<Article> findByVolid(@PathVariable String volid){
return Result.success(articleService.findByVolid(volid));
}
@ -86,10 +79,10 @@ public class ArticleController {
* @param size
* @return
*/
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
@PostMapping("/search/{page}/{size}")
public Result<PageResult<Article>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Article> pageList = articleService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Article>(pageList.getTotalElements(), pageList.getContent()) );
return Result.success(new PageResult<Article>(pageList.getTotalElements(), pageList.getContent()) );
}
/**
@ -97,40 +90,40 @@ public class ArticleController {
* @param searchMap
* @return
*/
@RequestMapping(value="/search",method = RequestMethod.POST)
public Result findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",articleService.findSearch(searchMap));
@PostMapping("/search")
public Result<List<Article>> findSearch( @RequestBody Map searchMap){
return Result.success(articleService.findSearch(searchMap));
}
/**
*
* @param article
*/
@RequestMapping(method=RequestMethod.POST)
public Result add(@RequestBody Article article ){
@PostMapping
public Result<Void> add(@RequestBody Article article ){
articleService.add(article);
return new Result(true,StatusCode.OK,"增加成功");
return Result.success();
}
/**
*
* @param article
*/
@RequestMapping(value="/{id}",method= RequestMethod.PUT)
public Result update(@RequestBody Article article, @PathVariable String id ){
@PutMapping("/{id}")
public Result<Void> update(@RequestBody Article article, @PathVariable String id ){
article.setId(id);
articleService.update(article);
return new Result(true,StatusCode.OK,"修改成功");
return Result.success();
}
/**
*
* @param id
*/
@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
public Result delete(@PathVariable String id ){
@DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable String id ){
articleService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功");
return Result.success();
}
}

@ -1,12 +1,9 @@
package com.luoo.music.controller;
import entity.Result;
import entity.StatusCode;
import api.Result;
import api.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*
*/
@ -15,8 +12,8 @@ public class BaseExceptionHandler {
@ExceptionHandler(value = Exception.class)
@ResponseBody
public Result error(Exception e){
public Result<Void> error(Exception e){
e.printStackTrace();
return new Result(false, StatusCode.ERROR, "执行出错");
return Result.failed(StatusCode.MUSIC_COMMON_FAILED);
}
}

@ -4,19 +4,14 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Channel;
import com.luoo.music.service.ChannelService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import api.PageResult;
import api.Result;
/**
*
* @author Administrator
@ -35,9 +30,9 @@ public class ChannelController {
*
* @return
*/
@RequestMapping(method= RequestMethod.GET)
public Result findAll(){
return new Result(true,StatusCode.OK,"查询成功",channelService.findAll());
@GetMapping
public Result<List<Channel>> findAll(){
return Result.success(channelService.findAll());
}
/**
@ -45,9 +40,9 @@ public class ChannelController {
* @param id ID
* @return
*/
@RequestMapping(value="/{id}",method= RequestMethod.GET)
public Result findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",channelService.findById(id));
@GetMapping("/{id}")
public Result<Channel> findById(@PathVariable String id){
return Result.success(channelService.findById(id));
}
@ -58,10 +53,10 @@ public class ChannelController {
* @param size
* @return
*/
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
@PostMapping("/search/{page}/{size}")
public Result<PageResult<Channel>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Channel> pageList = channelService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Channel>(pageList.getTotalElements(), pageList.getContent()) );
return Result.success(new PageResult<Channel>(pageList.getTotalElements(), pageList.getContent()) );
}
/**
@ -69,40 +64,40 @@ public class ChannelController {
* @param searchMap
* @return
*/
@RequestMapping(value="/search",method = RequestMethod.POST)
public Result findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",channelService.findSearch(searchMap));
@PostMapping("/search")
public Result<List<Channel>> findSearch( @RequestBody Map searchMap){
return Result.success(channelService.findSearch(searchMap));
}
/**
*
* @param channel
*/
@RequestMapping(method=RequestMethod.POST)
public Result add(@RequestBody Channel channel ){
@PostMapping
public Result<Void> add(@RequestBody Channel channel ){
channelService.add(channel);
return new Result(true,StatusCode.OK,"增加成功");
return Result.success();
}
/**
*
* @param channel
*/
@RequestMapping(value="/{id}",method= RequestMethod.PUT)
public Result update(@RequestBody Channel channel, @PathVariable String id ){
@PutMapping("/{id}")
public Result<Void> update(@RequestBody Channel channel, @PathVariable String id ){
channel.setId(id);
channelService.update(channel);
return new Result(true,StatusCode.OK,"修改成功");
return Result.success();
}
/**
*
* @param id
*/
@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
public Result delete(@PathVariable String id ){
@DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable String id ){
channelService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功");
return Result.success();
}
}

@ -4,19 +4,14 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Column;
import com.luoo.music.service.ColumnService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import api.PageResult;
import api.Result;
/**
*
* @author Administrator
@ -35,9 +30,9 @@ public class ColumnController {
*
* @return
*/
@RequestMapping(method= RequestMethod.GET)
public Result findAll(){
return new Result(true,StatusCode.OK,"查询成功",columnService.findAll());
@GetMapping
public Result<List<Column>> findAll(){
return Result.success(columnService.findAll());
}
/**
@ -45,9 +40,9 @@ public class ColumnController {
* @param id ID
* @return
*/
@RequestMapping(value="/{id}",method= RequestMethod.GET)
public Result findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",columnService.findById(id));
@GetMapping("/{id}")
public Result<Column> findById(@PathVariable String id){
return Result.success(columnService.findById(id));
}
@ -58,10 +53,10 @@ public class ColumnController {
* @param size
* @return
*/
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
@PostMapping("/search/{page}/{size}")
public Result<PageResult<Column>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Column> pageList = columnService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Column>(pageList.getTotalElements(), pageList.getContent()) );
return Result.success(new PageResult<Column>(pageList.getTotalElements(), pageList.getContent()) );
}
/**
@ -69,40 +64,40 @@ public class ColumnController {
* @param searchMap
* @return
*/
@RequestMapping(value="/search",method = RequestMethod.POST)
public Result findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",columnService.findSearch(searchMap));
@PostMapping("/search")
public Result<List<Column>> findSearch( @RequestBody Map searchMap){
return Result.success(columnService.findSearch(searchMap));
}
/**
*
* @param column
*/
@RequestMapping(method=RequestMethod.POST)
public Result add(@RequestBody Column column ){
@PostMapping
public Result<Void> add(@RequestBody Column column ){
columnService.add(column);
return new Result(true,StatusCode.OK,"增加成功");
return Result.success();
}
/**
*
* @param column
*/
@RequestMapping(value="/{id}",method= RequestMethod.PUT)
public Result update(@RequestBody Column column, @PathVariable String id ){
@PutMapping("/{id}")
public Result<Void> update(@RequestBody Column column, @PathVariable String id ){
column.setId(id);
columnService.update(column);
return new Result(true,StatusCode.OK,"修改成功");
return Result.success();
}
/**
*
* @param id
*/
@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
public Result delete(@PathVariable String id ){
@DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable String id ){
columnService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功");
return Result.success();
}
}

@ -3,13 +3,11 @@ package com.luoo.music.controller;
import com.luoo.music.pojo.Article;
import com.luoo.music.pojo.Song;
import com.luoo.music.service.ArticleService;
import com.luoo.music.pojo.SongVO;
import com.luoo.music.service.SongService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import api.PageResult;
import api.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.json.JsonParser;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
@ -26,23 +24,18 @@ public class SongController {
@Autowired
private SongService songService;
/**
*
* @return
*/
@RequestMapping(method= RequestMethod.GET)
public Result findAll(){
return new Result(true, StatusCode.OK,"查询成功",songService.findAll());
@GetMapping
public Result<List<Song>> findAll(){
return Result.success(songService.findAll());
}
@RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET)
public Result findByVolid(@PathVariable String volid){
return new Result(true,StatusCode.OK,"查询成功",songService.findByVolid(volid));
@GetMapping("/findByVolid/{volid}")
public Result<List<SongVO>> findByVolid(@PathVariable String volid){
return Result.success(songService.findByVolid(volid));
}
/**
@ -50,9 +43,9 @@ public class SongController {
* @param id ID
* @return
*/
@RequestMapping(value="/{id}",method= RequestMethod.GET)
public Result findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",songService.findById(id));
@GetMapping("/{id}")
public Result<Song> findById(@PathVariable String id){
return Result.success(songService.findById(id));
}
@ -63,15 +56,15 @@ public class SongController {
* @param size
* @return
*/
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
@PostMapping("/search/{page}/{size}")
public Result<PageResult<Song>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Song> pageList = songService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Song>(pageList.getTotalElements(), pageList.getContent()) );
return Result.success(new PageResult<Song>(pageList.getTotalElements(), pageList.getContent()) );
}
@RequestMapping(value = "/init",method = RequestMethod.POST)
public Result init(@RequestBody Map map) {
@PostMapping("/init")
public Result<Void> init(@RequestBody Map map) {
List<Map> data = (List) map.get("data");
System.out.println(data.size());
Song song = new Song();
@ -112,7 +105,7 @@ public class SongController {
for (Article pojo : set) {
// articleService.add(pojo);
}
return new Result(true,StatusCode.OK,"init");
return Result.success();
}
/**
@ -120,9 +113,9 @@ public class SongController {
* @param searchMap
* @return
*/
@RequestMapping(value="/search",method = RequestMethod.POST)
public Result findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",songService.findSearch(searchMap));
@PostMapping("/search")
public Result<List<Song>> findSearch( @RequestBody Map searchMap){
return Result.success(songService.findSearch(searchMap));
}
@ -130,30 +123,30 @@ public class SongController {
*
* @param song
*/
@RequestMapping(method=RequestMethod.POST)
public Result add(@RequestBody Song song){
@PostMapping
public Result<Void> add(@RequestBody Song song){
songService.add(song);
return new Result(true,StatusCode.OK,"增加成功");
return Result.success();
}
/**
*
* @param song
*/
@RequestMapping(value="/{id}",method= RequestMethod.PUT)
public Result update(@RequestBody Song song, @PathVariable String id ){
@PutMapping("/{id}")
public Result<Void> update(@RequestBody Song song, @PathVariable String id ){
song.setId(id);
songService.update(song);
return new Result(true,StatusCode.OK,"修改成功");
return Result.success();
}
/**
*
* @param id
*/
@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
public Result delete(@PathVariable String id ){
@DeleteMapping("/{id}")
public Result<Void> delete(@PathVariable String id ){
songService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功");
return Result.success();
}
}

@ -67,7 +67,7 @@ public class AdminController {
*
* @return
*/
@GetMapping("/list")
@GetMapping
public Result<List<Admin>> findAll(){
return Result.success(adminService.findAll());
}

Loading…
Cancel
Save