ソースを参照

Custom Runtime Exception classes added

JaseG256 6 年 前
コミット
f8b4d4a179
共有29 個のファイルを変更した108 個の追加47 個の削除を含む
  1. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Config/AuditingConfig.java
  2. 4
    4
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Config/SecurityConfig.java
  3. 5
    5
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/ChatController.java
  4. 3
    3
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/MessageController.java
  5. 3
    3
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/UserController.java
  6. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Audit/DateAudit.java
  7. 3
    3
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Chat.java
  8. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/DateAudit.java
  9. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Message.java
  10. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Role.java
  11. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/RoleName.java
  12. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/User.java
  13. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/ApiResponse.java
  14. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/JwtAuthenticationResponse.java
  15. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/LoginRequest.java
  16. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/SignUpRequest.java
  17. 2
    2
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/ChatRepository.java
  18. 2
    2
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/MessageRepository.java
  19. 3
    3
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/RoleRepository.java
  20. 2
    2
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/UserRepository.java
  21. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/CurrentUser.java
  22. 3
    3
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/CustomUserDetailsService.java
  23. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtAuthenticationEntryPoint.java
  24. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtAuthenticationFilter.java
  25. 1
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtTokenProvider.java
  26. 2
    2
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/UserPrincipal.java
  27. 15
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/AppException.java
  28. 16
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/BadRequestException.java
  29. 30
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/ResourceNotFoundException.java

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Config/AuditingConfig.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Config;
1
+package ZipTeamOrange.config;
2 2
 
3 3
 
4 4
 import org.springframework.context.annotation.Configuration;

+ 4
- 4
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Config/SecurityConfig.java ファイルの表示

@@ -1,8 +1,8 @@
1
-package ZipTeamOrange.Config;
1
+package ZipTeamOrange.config;
2 2
 
3
-import ZipTeamOrange.Security.CustomUserDetailsService;
4
-import ZipTeamOrange.Security.JwtAuthenticationEntryPoint;
5
-import ZipTeamOrange.Security.JwtAuthenticationFilter;
3
+import ZipTeamOrange.security.CustomUserDetailsService;
4
+import ZipTeamOrange.security.JwtAuthenticationEntryPoint;
5
+import ZipTeamOrange.security.JwtAuthenticationFilter;
6 6
 import org.springframework.beans.factory.annotation.Autowired;
7 7
 import org.springframework.context.annotation.Bean;
8 8
 import org.springframework.context.annotation.Configuration;

+ 5
- 5
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/ChatController.java ファイルの表示

@@ -1,12 +1,12 @@
1
-//package ZipTeamOrange.Controller;
1
+//package ZipTeamOrange.controller;
2 2
 //
3
-//import ZipTeamOrange.Model.Chat;
4
-//import ZipTeamOrange.Repository.ChatRepository;
3
+//import ZipTeamOrange.model.Chat;
4
+//import ZipTeamOrange.repository.ChatRepository;
5 5
 //import org.springframework.beans.factory.annotation.Autowired;
6
-//import org.springframework.stereotype.Controller;
6
+//import org.springframework.stereotype.controller;
7 7
 //import org.springframework.web.bind.annotation.*;
8 8
 //
9
-//@Controller
9
+//@controller
10 10
 //@RequestMapping(path = "/chat")
11 11
 //@CrossOrigin(origins = {"http://localhost:8103"})
12 12
 //public class ChatController {

+ 3
- 3
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/MessageController.java ファイルの表示

@@ -1,7 +1,7 @@
1
-//package ZipTeamOrange.Controller;
1
+//package ZipTeamOrange.controller;
2 2
 //
3
-//import ZipTeamOrange.Model.Message;
4
-//import ZipTeamOrange.Repository.MessageRepository;
3
+//import ZipTeamOrange.model.Message;
4
+//import ZipTeamOrange.repository.MessageRepository;
5 5
 //import com.fasterxml.jackson.core.JsonProcessingException;
6 6
 //import com.fasterxml.jackson.databind.ObjectMapper;
7 7
 //import org.springframework.beans.factory.annotation.Autowired;

+ 3
- 3
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/UserController.java ファイルの表示

@@ -1,7 +1,7 @@
1
-package ZipTeamOrange.Controller;
1
+package ZipTeamOrange.controller;
2 2
 
3
-import ZipTeamOrange.Model.User;
4
-import ZipTeamOrange.Repository.UserRepository;
3
+import ZipTeamOrange.model.User;
4
+import ZipTeamOrange.repository.UserRepository;
5 5
 import com.fasterxml.jackson.core.JsonProcessingException;
6 6
 import com.fasterxml.jackson.databind.ObjectMapper;
7 7
 import org.springframework.beans.factory.annotation.Autowired;

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Audit/DateAudit.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Model.Audit;
1
+package ZipTeamOrange.model.Audit;
2 2
 
3 3
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 4
 import org.springframework.data.annotation.CreatedDate;

+ 3
- 3
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Chat.java ファイルの表示

@@ -1,7 +1,7 @@
1
-//package ZipTeamOrange.Model;
1
+//package ZipTeamOrange.model;
2 2
 //
3
-//import ZipTeamOrange.Model.Message;
4
-//import ZipTeamOrange.Model.User;
3
+//import ZipTeamOrange.model.Message;
4
+//import ZipTeamOrange.model.User;
5 5
 //import javax.persistence.*;
6 6
 //import java.util.Set;
7 7
 //

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/DateAudit.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Model;
1
+package ZipTeamOrange.model;
2 2
 
3 3
 public class DateAudit {
4 4
 }

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Message.java ファイルの表示

@@ -1,4 +1,4 @@
1
-//package ZipTeamOrange.Model;
1
+//package ZipTeamOrange.model;
2 2
 //
3 3
 //import javax.persistence.*;
4 4
 //

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Role.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Model;
1
+package ZipTeamOrange.model;
2 2
 
3 3
 import org.hibernate.annotations.NaturalId;
4 4
 

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/RoleName.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Model;
1
+package ZipTeamOrange.model;
2 2
 
3 3
 public enum  RoleName {
4 4
     ROLE_USER,

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/User.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Model;
1
+package ZipTeamOrange.model;
2 2
 
3 3
 import org.hibernate.annotations.NaturalId;
4 4
 

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/ApiResponse.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Payload;
1
+package ZipTeamOrange.payload;
2 2
 
3 3
 public class ApiResponse {
4 4
     private Boolean success;

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/JwtAuthenticationResponse.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Payload;
1
+package ZipTeamOrange.payload;
2 2
 
3 3
 public class JwtAuthenticationResponse {
4 4
     private String accessToken;

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/LoginRequest.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Payload;
1
+package ZipTeamOrange.payload;
2 2
 
3 3
 import javax.validation.constraints.NotBlank;
4 4
 

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Payload/SignUpRequest.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Payload;
1
+package ZipTeamOrange.payload;
2 2
 
3 3
 import javax.validation.constraints.Email;
4 4
 import javax.validation.constraints.NotBlank;

+ 2
- 2
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/ChatRepository.java ファイルの表示

@@ -1,6 +1,6 @@
1
-//package ZipTeamOrange.Repository;
1
+//package ZipTeamOrange.repository;
2 2
 //
3
-//import ZipTeamOrange.Model.Chat;
3
+//import ZipTeamOrange.model.Chat;
4 4
 //import org.springframework.data.jpa.repository.JpaRepository;
5 5
 //
6 6
 //public interface ChatRepository extends JpaRepository<Chat, Long> {

+ 2
- 2
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/MessageRepository.java ファイルの表示

@@ -1,6 +1,6 @@
1
-//package ZipTeamOrange.Repository;
1
+//package ZipTeamOrange.repository;
2 2
 //
3
-//import ZipTeamOrange.Model.Message;
3
+//import ZipTeamOrange.model.Message;
4 4
 //import org.springframework.data.jpa.repository.JpaRepository;
5 5
 //
6 6
 //public interface MessageRepository extends JpaRepository<Message, Long> {

+ 3
- 3
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/RoleRepository.java ファイルの表示

@@ -1,7 +1,7 @@
1
-package ZipTeamOrange.Repository;
1
+package ZipTeamOrange.repository;
2 2
 
3
-import ZipTeamOrange.Model.Role;
4
-import ZipTeamOrange.Model.RoleName;
3
+import ZipTeamOrange.model.Role;
4
+import ZipTeamOrange.model.RoleName;
5 5
 import org.springframework.data.jpa.repository.JpaRepository;
6 6
 import org.springframework.stereotype.Repository;
7 7
 

+ 2
- 2
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/UserRepository.java ファイルの表示

@@ -1,6 +1,6 @@
1
-package ZipTeamOrange.Repository;
1
+package ZipTeamOrange.repository;
2 2
 
3
-import ZipTeamOrange.Model.User;
3
+import ZipTeamOrange.model.User;
4 4
 import org.springframework.data.jpa.repository.JpaRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/CurrentUser.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Security;
1
+package ZipTeamOrange.security;
2 2
 
3 3
 import org.springframework.security.core.annotation.AuthenticationPrincipal;
4 4
 

+ 3
- 3
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/CustomUserDetailsService.java ファイルの表示

@@ -1,7 +1,7 @@
1
-package ZipTeamOrange.Security;
1
+package ZipTeamOrange.security;
2 2
 
3
-import ZipTeamOrange.Model.User;
4
-import ZipTeamOrange.Repository.UserRepository;
3
+import ZipTeamOrange.model.User;
4
+import ZipTeamOrange.repository.UserRepository;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.security.core.userdetails.UserDetails;
7 7
 import org.springframework.security.core.userdetails.UserDetailsService;

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtAuthenticationEntryPoint.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Security;
1
+package ZipTeamOrange.security;
2 2
 
3 3
 import org.slf4j.Logger;
4 4
 import org.slf4j.LoggerFactory;

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtAuthenticationFilter.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Security;
1
+package ZipTeamOrange.security;
2 2
 
3 3
 import org.slf4j.Logger;
4 4
 import org.slf4j.LoggerFactory;

+ 1
- 1
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtTokenProvider.java ファイルの表示

@@ -1,4 +1,4 @@
1
-package ZipTeamOrange.Security;
1
+package ZipTeamOrange.security;
2 2
 
3 3
 import io.jsonwebtoken.*;
4 4
 import org.slf4j.Logger;

+ 2
- 2
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/UserPrincipal.java ファイルの表示

@@ -1,6 +1,6 @@
1
-package ZipTeamOrange.Security;
1
+package ZipTeamOrange.security;
2 2
 
3
-import ZipTeamOrange.Model.User;
3
+import ZipTeamOrange.model.User;
4 4
 import com.fasterxml.jackson.annotation.JsonIgnore;
5 5
 import org.springframework.security.core.GrantedAuthority;
6 6
 import org.springframework.security.core.authority.SimpleGrantedAuthority;

+ 15
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/AppException.java ファイルの表示

@@ -0,0 +1,15 @@
1
+package ZipTeamOrange.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
7
+public class AppException extends RuntimeException {
8
+    public AppException(String message) {
9
+        super(message);
10
+    }
11
+
12
+    public AppException(String message, Throwable cause) {
13
+        super(message, cause);
14
+    }
15
+}

+ 16
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/BadRequestException.java ファイルの表示

@@ -0,0 +1,16 @@
1
+package ZipTeamOrange.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.BAD_REQUEST)
7
+public class BadRequestException extends RuntimeException {
8
+
9
+    public BadRequestException(String message) {
10
+        super(message);
11
+    }
12
+
13
+    public BadRequestException(String message, Throwable cause) {
14
+        super(message, cause);
15
+    }
16
+}

+ 30
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/ResourceNotFoundException.java ファイルの表示

@@ -0,0 +1,30 @@
1
+package ZipTeamOrange.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.NOT_FOUND)
7
+public class ResourceNotFoundException extends RuntimeException {
8
+    private String resourceName;
9
+    private String fieldName;
10
+    private Object fieldValue;
11
+
12
+    public ResourceNotFoundException( String resourceName, String fieldName, Object fieldValue) {
13
+        super(String.format("%s not found with %s : '%s'", resourceName, fieldName, fieldValue));
14
+        this.resourceName = resourceName;
15
+        this.fieldName = fieldName;
16
+        this.fieldValue = fieldValue;
17
+    }
18
+
19
+    public String getResourceName() {
20
+        return resourceName;
21
+    }
22
+
23
+    public String getFieldName() {
24
+        return fieldName;
25
+    }
26
+
27
+    public Object getFieldValue() {
28
+        return fieldValue;
29
+    }
30
+}