mirror of https://github.com/halo-dev/halo
Rename ErrorResponse into BaseResponse
parent
6f18c6c5ba
commit
b0b852a803
|
@ -12,7 +12,7 @@ import lombok.*;
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ErrorResponse {
|
public class BaseResponse {
|
||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package cc.ryanc.halo.security.handler;
|
package cc.ryanc.halo.security.handler;
|
||||||
|
|
||||||
import cc.ryanc.halo.exception.HaloException;
|
import cc.ryanc.halo.exception.HaloException;
|
||||||
import cc.ryanc.halo.model.support.ErrorResponse;
|
import cc.ryanc.halo.model.support.BaseResponse;
|
||||||
import cc.ryanc.halo.utils.ExceptionUtils;
|
import cc.ryanc.halo.utils.ExceptionUtils;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
@ -36,7 +36,7 @@ public class DefaultAuthenticationFailureHandler implements AuthenticationFailur
|
||||||
public void onFailure(HttpServletRequest request, HttpServletResponse response, HaloException exception) throws IOException, ServletException {
|
public void onFailure(HttpServletRequest request, HttpServletResponse response, HaloException exception) throws IOException, ServletException {
|
||||||
log.warn("Handle unsuccessful authentication, ip: [{}]", ServletUtil.getClientIP(request));
|
log.warn("Handle unsuccessful authentication, ip: [{}]", ServletUtil.getClientIP(request));
|
||||||
|
|
||||||
ErrorResponse errorDetail = new ErrorResponse();
|
BaseResponse errorDetail = new BaseResponse();
|
||||||
|
|
||||||
errorDetail.setMessage(exception.getMessage());
|
errorDetail.setMessage(exception.getMessage());
|
||||||
|
|
||||||
|
|
|
@ -18,5 +18,5 @@ public interface CommentService extends CrudService<Comment, Long> {
|
||||||
* @param top top number must not be less than 0
|
* @param top top number must not be less than 0
|
||||||
* @return a page of comments
|
* @return a page of comments
|
||||||
*/
|
*/
|
||||||
Page<CommentVO> listLatest(int top);
|
Page<CommentVO> pageLatest(int top);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,5 @@ public interface LogService extends CrudService<Log, Long> {
|
||||||
* @param top top number must not be less than 0
|
* @param top top number must not be less than 0
|
||||||
* @return a page of latest logs
|
* @return a page of latest logs
|
||||||
*/
|
*/
|
||||||
Page<LogOutputDTO> listLatest(int top);
|
Page<LogOutputDTO> pageLatest(int top);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public interface PostService extends CrudService<Post, Integer> {
|
||||||
* @return latest posts
|
* @return latest posts
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Page<PostSimpleOutputDTO> listLatest(int top);
|
Page<PostSimpleOutputDTO> pageLatest(int top);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List by status and type
|
* List by status and type
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class CommentServiceImpl extends AbstractCrudService<Comment, Long> imple
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<CommentVO> listLatest(int top) {
|
public Page<CommentVO> pageLatest(int top) {
|
||||||
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
||||||
|
|
||||||
// Build page request
|
// Build page request
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class LogServiceImpl extends AbstractCrudService<Log, Long> implements Lo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<LogOutputDTO> listLatest(int top) {
|
public Page<LogOutputDTO> pageLatest(int top) {
|
||||||
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
||||||
|
|
||||||
// Build page request
|
// Build page request
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save one option
|
* Saves one option
|
||||||
*
|
*
|
||||||
* @param key key
|
* @param key key
|
||||||
* @param value value
|
* @param value value
|
||||||
|
@ -45,24 +45,24 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Option options = optionRepository.findByOptionKey(key).map(option -> {
|
Option option = optionRepository.findByOptionKey(key).map(anOption -> {
|
||||||
// Exist
|
// Exist
|
||||||
option.setOptionValue(value);
|
anOption.setOptionValue(value);
|
||||||
return option;
|
return anOption;
|
||||||
}).orElseGet(() -> {
|
}).orElseGet(() -> {
|
||||||
// Not exist
|
// Not exist
|
||||||
Option option = new Option();
|
Option anOption = new Option();
|
||||||
option.setOptionKey(key);
|
anOption.setOptionKey(key);
|
||||||
option.setOptionValue(value);
|
anOption.setOptionValue(value);
|
||||||
return option;
|
return anOption;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save or update the options
|
// Save or update the options
|
||||||
optionRepository.save(options);
|
optionRepository.save(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save multiple options
|
* Saves multiple options
|
||||||
*
|
*
|
||||||
* @param options options
|
* @param options options
|
||||||
*/
|
*/
|
||||||
|
@ -74,7 +74,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all options
|
* Gets all options
|
||||||
*
|
*
|
||||||
* @return Map
|
* @return Map
|
||||||
*/
|
*/
|
||||||
|
@ -84,7 +84,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get option by key
|
* Gets option by key
|
||||||
*
|
*
|
||||||
* @param key key
|
* @param key key
|
||||||
* @return String
|
* @return String
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PostSimpleOutputDTO> listLatest(int top) {
|
public Page<PostSimpleOutputDTO> pageLatest(int top) {
|
||||||
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
||||||
|
|
||||||
PageRequest latestPageable = PageRequest.of(0, top, Sort.by(Sort.Direction.DESC, "editTime"));
|
PageRequest latestPageable = PageRequest.of(0, top, Sort.by(Sort.Direction.DESC, "editTime"));
|
||||||
|
|
|
@ -52,11 +52,11 @@ public class AdminController {
|
||||||
@GetMapping(value = {"", "index"})
|
@GetMapping(value = {"", "index"})
|
||||||
public String admin(Model model) {
|
public String admin(Model model) {
|
||||||
|
|
||||||
Page<PostSimpleOutputDTO> postPage = postService.listLatest(5);
|
Page<PostSimpleOutputDTO> postPage = postService.pageLatest(5);
|
||||||
|
|
||||||
Page<CommentVO> commentPage = commentService.listLatest(5);
|
Page<CommentVO> commentPage = commentService.pageLatest(5);
|
||||||
|
|
||||||
Page<LogOutputDTO> logPage = logService.listLatest(5);
|
Page<LogOutputDTO> logPage = logService.pageLatest(5);
|
||||||
|
|
||||||
model.addAttribute("postsCount", postPage.getTotalElements());
|
model.addAttribute("postsCount", postPage.getTotalElements());
|
||||||
model.addAttribute("commentsCount", commentPage.getTotalElements());
|
model.addAttribute("commentsCount", commentPage.getTotalElements());
|
||||||
|
|
|
@ -18,7 +18,7 @@ spring:
|
||||||
|
|
||||||
# H2database 配置
|
# H2database 配置
|
||||||
driver-class-name: org.h2.Driver
|
driver-class-name: org.h2.Driver
|
||||||
url: jdbc:h2:file:~/halo/db/halo
|
url: jdbc:h2:file:~/halo-dev/db/halo
|
||||||
username: admin
|
username: admin
|
||||||
password: 123456
|
password: 123456
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue