main #9

Closed
student-20690 wants to merge 26 commits from (deleted):main into main
3 changed files with 19 additions and 6 deletions
Showing only changes of commit 4a22c9d466 - Show all commits

View File

@@ -2,7 +2,10 @@ package com.example.nto.controller;
import com.example.nto.entity.Employee; import com.example.nto.entity.Employee;
import com.example.nto.service.EmployeeService; 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.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
@@ -15,12 +18,8 @@ import java.util.List;
* НЕЛЬЗЯ: Изменять название класса и пакета * НЕЛЬЗЯ: Изменять название класса и пакета
*/ */
@RestController @RestController
@RequestMapping("code") @RequestMapping("api")
public class EmployeeController { public class EmployeeController {
// @GetMapping("/auth/{id}")
// public int isAuth(@PathVariable int id){
// return id;
// }
private final EmployeeService employeeService; private final EmployeeService employeeService;
@@ -31,6 +30,12 @@ public class EmployeeController {
@GetMapping("/{id}/auth") @GetMapping("/{id}/auth")
public HttpStatus Isauth(@PathVariable long id){ public HttpStatus Isauth(@PathVariable long id){
if(employeeService.isIdValid(id)){
return HttpStatus.OK; return HttpStatus.OK;
} }
else
return HttpStatus.NOT_FOUND;
}
} }

View File

@@ -15,4 +15,6 @@ public interface EmployeeService {
List<Employee> getAll(); List<Employee> getAll();
Optional<Employee> getById(long id); Optional<Employee> getById(long id);
boolean isIdValid(long id);
} }

View File

@@ -3,6 +3,7 @@ package com.example.nto.service.impl;
import com.example.nto.entity.Employee; import com.example.nto.entity.Employee;
import com.example.nto.repository.EmployeeRepository; import com.example.nto.repository.EmployeeRepository;
import com.example.nto.service.EmployeeService; import com.example.nto.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -20,6 +21,7 @@ import java.util.Optional;
public class EmployeeServiceImpl implements EmployeeService { public class EmployeeServiceImpl implements EmployeeService {
private final EmployeeRepository employeeRepository; private final EmployeeRepository employeeRepository;
@Autowired
public EmployeeServiceImpl(EmployeeRepository employeeRepository) { public EmployeeServiceImpl(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
} }
@@ -33,4 +35,8 @@ public class EmployeeServiceImpl implements EmployeeService {
public Optional<Employee> getById(long id) { public Optional<Employee> getById(long id) {
return employeeRepository.findById(id); return employeeRepository.findById(id);
} }
public boolean isIdValid(long id){
return employeeRepository.findById(id).isPresent();
}
} }