|
@@ -66,19 +66,20 @@ public class PosterController {
|
|
|
@Transactional
|
|
|
@RequestMapping(method = RequestMethod.POST)
|
|
|
public APIResult<Poster> create(@Valid @RequestBody PosterDTO posterDTO) {
|
|
|
- try{
|
|
|
- // 创建海报
|
|
|
- Poster result = posterService.create(posterDTO);
|
|
|
- if (null == result) {
|
|
|
- return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
- }
|
|
|
- setProductInfo(result);
|
|
|
- return APIResult.ok(result);
|
|
|
- }catch(Exception e){
|
|
|
- log.info("poster create error: message={}",e.getMessage());
|
|
|
+ if(isExist(posterDTO)){
|
|
|
return APIResult.error(APICode.ALREADY_EXISTS);
|
|
|
}
|
|
|
+ // 创建海报
|
|
|
+ Poster result = posterService.create(posterDTO);
|
|
|
+ if (null == result) {
|
|
|
+ return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
+ }
|
|
|
+ setProductInfo(result);
|
|
|
+ return APIResult.ok(result);
|
|
|
+ }
|
|
|
|
|
|
+ private boolean isExist(PosterDTO posterDTO) {
|
|
|
+ return posterService.isExist(posterDTO);
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@@ -88,19 +89,18 @@ public class PosterController {
|
|
|
if (Id == null) {
|
|
|
return APIResult.error(APICode.error("参数错误: id不能为空"));
|
|
|
}
|
|
|
-
|
|
|
- try{
|
|
|
- Poster result = posterService.update(posterDTO);
|
|
|
- if (null == result) {
|
|
|
- return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
- }
|
|
|
-
|
|
|
- setProductInfo(result);
|
|
|
- return APIResult.ok(result);
|
|
|
- }catch(Exception e){
|
|
|
- log.info("poster update error: message={}",e.getMessage());
|
|
|
+ if(isExist(posterDTO)){
|
|
|
return APIResult.error(APICode.ALREADY_EXISTS);
|
|
|
}
|
|
|
+
|
|
|
+ Poster result = posterService.update(posterDTO);
|
|
|
+ if (null == result) {
|
|
|
+ return APIResult.error(APICode.OPERATE_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ setProductInfo(result);
|
|
|
+ return APIResult.ok(result);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|