diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 08bc41e..608fbcc 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,14 +4,15 @@
-
+
+
-
-
-
+
+
+
@@ -178,7 +179,15 @@
1740043625151
-
+
+
+ 1740045412863
+
+
+
+ 1740045412863
+
+
@@ -192,34 +201,30 @@
-
+
+
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java
- 14
+ 16
-
- file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java
- 58
-
-
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AdminController.java
- 79
+ 128
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java
- 92
+ 95
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java
- 80
+ 82
diff --git a/src/main/java/com/example/nto/controller/AdminController.java b/src/main/java/com/example/nto/controller/AdminController.java
index d74b914..46b7c50 100644
--- a/src/main/java/com/example/nto/controller/AdminController.java
+++ b/src/main/java/com/example/nto/controller/AdminController.java
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed;
+import java.util.List;
@Controller
@RequestMapping("/api/admin/")
@@ -19,6 +20,54 @@ public class AdminController {
@Autowired
private EmployeeService employeeService;
+ public static class NewEmployeeRequest {
+ private String login;
+ private String name;
+ private String password;
+ private String photo;
+ private String position;
+
+ public String getLogin() {
+ return login;
+ }
+
+ public void setLogin(String login) {
+ this.login = login;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getPhoto() {
+ return photo;
+ }
+
+ public void setPhoto(String photo) {
+ this.photo = photo;
+ }
+
+ public String getPosition() {
+ return position;
+ }
+
+ public void setPosition(String position) {
+ this.position = position;
+ }
+ }
+
public static class DeleteEmployeeRequest {
private Long id;
@@ -94,4 +143,30 @@ public class AdminController {
employeeService.updateEmployeePosition(updateEmployeeRequest.id, updateEmployeeRequest.field);
return ResponseEntity.status(HttpStatus.OK).build();
}
+
+ @RolesAllowed("ADMIN")
+ @GetMapping("/employee/info/{id}/")
+ public Employee getInfo(@PathVariable Long id) {
+ return employeeService.getEmployeeInfoById(id);
+ }
+
+ @RolesAllowed("ADMIN")
+ @GetMapping("/employee/info/all/")
+ public List getEmployees() {
+ return employeeService.getEmployees();
+ }
+
+ @RolesAllowed("ADMIN")
+ @PostMapping("/employee/new/")
+ public ResponseEntity newEmployee(@RequestBody NewEmployeeRequest newEmployeeRequest) {
+ Employee employee = new Employee();
+ employee.setLogin(newEmployeeRequest.getLogin());
+ employee.setPhoto(newEmployeeRequest.getPhoto());
+ employee.setPosition(newEmployeeRequest.getPosition());
+ employee.setName(newEmployeeRequest.getName());
+ employee.setPassword(newEmployeeRequest.getPassword());
+ return ResponseEntity.status(HttpStatus.OK).build();
+ }
+
+
}
diff --git a/src/main/java/com/example/nto/controller/AuthController.java b/src/main/java/com/example/nto/controller/AuthController.java
index 5d3f3ee..8a0861f 100644
--- a/src/main/java/com/example/nto/controller/AuthController.java
+++ b/src/main/java/com/example/nto/controller/AuthController.java
@@ -4,8 +4,6 @@ import com.example.nto.entity.Employee;
import com.example.nto.repository.EmployeeRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
diff --git a/src/main/java/com/example/nto/controller/EmployeeController.java b/src/main/java/com/example/nto/controller/EmployeeController.java
index d7f739c..d3c3f5d 100644
--- a/src/main/java/com/example/nto/controller/EmployeeController.java
+++ b/src/main/java/com/example/nto/controller/EmployeeController.java
@@ -11,6 +11,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
+import java.time.LocalDateTime;
+
@RestController
public class EmployeeController {
private final EmployeeService employeeService;
@@ -85,6 +87,7 @@ public class EmployeeController {
Entry entry = new Entry();
Employee employee = employeeService.getEmployeeByLogin(login);
entry.setEmployee(employee);
+ entry.setTime(LocalDateTime.now());
entry.setPlace(codeRepository.findByValue(value));
entryRepository.save(entry);
return ResponseEntity.status(HttpStatus.ACCEPTED).build();
diff --git a/src/main/java/com/example/nto/entity/Entry.java b/src/main/java/com/example/nto/entity/Entry.java
index 94e2590..6782500 100644
--- a/src/main/java/com/example/nto/entity/Entry.java
+++ b/src/main/java/com/example/nto/entity/Entry.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*;
+import java.time.LocalDateTime;
@Entity
@Table(name = "entry")
@@ -18,6 +19,9 @@ public class Entry {
@JsonIdentityReference(alwaysAsId = true)
private Employee employee;
+ private LocalDateTime time;
+
+
@ManyToOne
@JoinColumn(name = "place")
private Code place;
@@ -45,4 +49,12 @@ public class Entry {
public void setPlace(Code place) {
this.place = place;
}
+
+ public LocalDateTime getTime() {
+ return time;
+ }
+
+ public void setTime(LocalDateTime time) {
+ this.time = time;
+ }
}
diff --git a/src/main/java/com/example/nto/repository/EmployeeRepository.java b/src/main/java/com/example/nto/repository/EmployeeRepository.java
index a64bebc..2cf302a 100644
--- a/src/main/java/com/example/nto/repository/EmployeeRepository.java
+++ b/src/main/java/com/example/nto/repository/EmployeeRepository.java
@@ -10,5 +10,4 @@ public interface EmployeeRepository extends JpaRepository {
boolean existsByLogin(String login);
Optional getByLogin(String login);
Optional findByLogin(String login);
-
}
diff --git a/src/main/java/com/example/nto/service/EmployeeService.java b/src/main/java/com/example/nto/service/EmployeeService.java
index 496bd01..c23f380 100644
--- a/src/main/java/com/example/nto/service/EmployeeService.java
+++ b/src/main/java/com/example/nto/service/EmployeeService.java
@@ -2,6 +2,7 @@ package com.example.nto.service;
import com.example.nto.entity.Employee;
+import java.util.List;
import java.util.Optional;
public interface EmployeeService {
@@ -15,4 +16,5 @@ public interface EmployeeService {
Employee updateEmployeeAvatar(Long id, String newAvatar);
Employee updateEmployeePosition(Long id, String newPosition);
Employee getEmployeeByLogin(String login);
+ List getEmployees();
}
diff --git a/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java b/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java
index 68976c2..ed413f2 100644
--- a/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java
+++ b/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
+import java.util.List;
import java.util.Optional;
@Service
@@ -108,4 +109,9 @@ public class EmployeeServiceImpl implements EmployeeService {
public Employee getEmployeeByLogin(String login) {
return employeeRepository.getByLogin(login).get();
}
+
+ @Override
+ public List getEmployees() {
+ return employeeRepository.findAll();
+ }
}