Compare commits

..

2 Commits

Author SHA1 Message Date
4ab23b99c8 controller變更 2025-05-14 14:19:51 +09:00
31639a6e98 CONTROLLER變更 2025-05-14 14:17:03 +09:00
16 changed files with 40 additions and 29 deletions

View File

@ -1,6 +1,5 @@
package co.jp.app.common;
import co.jp.app.common.ResultCode;
public class ApiResponse<T> {
private boolean success;

View File

@ -1,6 +1,9 @@
package co.jp.app.config.security;
<<<<<<< HEAD
=======
import co.jp.app.config.security.filter.JwtAuthenticationFilter;
>>>>>>> 2aae88278c46cf937380317aae1f9d229bcb3c37
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
@ -10,12 +13,12 @@ import org.springframework.security.authentication.dao.DaoAuthenticationProvider
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import co.jp.app.config.security.filter.JwtAuthenticationFilter;
@Configuration
public class SecurityConfig {

View File

@ -1,12 +1,7 @@
package co.jp.app.config.security.filter;
import co.jp.app.service.JwtService;
import java.io.IOException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Lazy;
import org.springframework.lang.NonNull;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
@ -16,6 +11,16 @@ import org.springframework.security.web.authentication.WebAuthenticationDetailsS
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
<<<<<<< HEAD
import co.jp.app.service.JwtService;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
=======
>>>>>>> 2aae88278c46cf937380317aae1f9d229bcb3c37
@Component
public class JwtAuthenticationFilter extends OncePerRequestFilter {

View File

@ -3,21 +3,23 @@ package co.jp.app.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import co.jp.app.entity.PetEntity;
import co.jp.app.service.PetService;
@Controller
@RestController
public class DownloadController {
@Autowired
private PetService service;
@GetMapping("/api/dogs/download")
public String downloadById(@RequestParam List<Integer> id) {
service.getPetByID(id);
return "download";
public ResponseEntity<?> downloadById(@RequestParam List<Integer> id) {
List<PetEntity> list = service.getPetByID(id);
return ResponseEntity.ok(list);
}
}

View File

@ -3,13 +3,15 @@ package co.jp.app.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import co.jp.app.entity.PetEntity;
import co.jp.app.service.PetService;
@Controller
@RestController
public class PetController {
@ -17,8 +19,9 @@ public class PetController {
private PetService service;
@GetMapping("/api/dogs/pet")
public String getListByEntities(@RequestParam List<Integer> id) {
service.getPetByID(id);
return "pet";
public ResponseEntity<?> getListByEntities(@RequestParam List<Integer> id) {
List<PetEntity> list = service.getPetByID(id);
return ResponseEntity.ok(list);
}
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
@ -19,12 +20,12 @@ public class UploadController {
private UploadService service;
@PostMapping("/api/dogs/upload")
public String upload() {
public ResponseEntity<?> upload() {
List<PetEntity> list = new ArrayList<PetEntity>();
service.saveAllPets(list);
List<PetEntity> pets = service.saveAllPets(list);
return "upload";
return ResponseEntity.ok(pets);
}

View File

@ -1,14 +1,11 @@
package co.jp.app.exception;
import co.jp.app.common.ApiResponse;
import co.jp.app.common.ResultCode;
import co.jp.app.exception.BusinessException;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@ -18,7 +15,8 @@ import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.stream.Collectors;
import co.jp.app.common.ApiResponse;
import co.jp.app.common.ResultCode;
@RestControllerAdvice
public class GlobalExceptionHandler {

View File

@ -1,6 +1,6 @@
#Generated by Maven Integration for Eclipse
#Mon May 12 15:57:02 JST 2025
m2e.projectLocation=C\:\\Users\\Administrator\\git\\Dog-1
#Wed May 14 11:48:45 JST 2025
m2e.projectLocation=C\:\\Users\\ichbi\\OneDrive\\\u30C7\u30B9\u30AF\u30C8\u30C3\u30D7\\dog-1
m2e.projectName=dog-1
groupId=co.jp.app
artifactId=dog-2