main #10
@@ -2,7 +2,10 @@ package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import com.example.nto.service.impl.EmployeeServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.net.http.HttpResponse;
|
||||
@@ -15,12 +18,8 @@ import java.util.List;
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("code")
|
||||
@RequestMapping("api")
|
||||
public class EmployeeController {
|
||||
// @GetMapping("/auth/{id}")
|
||||
// public int isAuth(@PathVariable int id){
|
||||
// return id;
|
||||
// }
|
||||
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
@@ -31,6 +30,12 @@ public class EmployeeController {
|
||||
|
||||
@GetMapping("/{id}/auth")
|
||||
public HttpStatus Isauth(@PathVariable long id){
|
||||
if(employeeService.isIdValid(id)){
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
else
|
||||
return HttpStatus.NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,4 +15,6 @@ public interface EmployeeService {
|
||||
List<Employee> getAll();
|
||||
|
||||
Optional<Employee> getById(long id);
|
||||
|
||||
boolean isIdValid(long id);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.example.nto.service.impl;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -20,6 +21,7 @@ import java.util.Optional;
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
private final EmployeeRepository employeeRepository;
|
||||
|
||||
@Autowired
|
||||
public EmployeeServiceImpl(EmployeeRepository employeeRepository) {
|
||||
this.employeeRepository = employeeRepository;
|
||||
}
|
||||
@@ -33,4 +35,8 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
public Optional<Employee> getById(long id) {
|
||||
return employeeRepository.findById(id);
|
||||
}
|
||||
|
||||
public boolean isIdValid(long id){
|
||||
return employeeRepository.findById(id).isPresent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user