diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index fc19531..08bc41e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,18 +4,14 @@
-
-
-
-
-
+
-
-
-
-
+
+
+
+
@@ -44,7 +40,7 @@
1740038543344
-
+
+
+ 1740043625151
+
+
+
+ 1740043625151
+
+
@@ -187,14 +191,15 @@
-
+
+
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java
- 16
+ 14
@@ -209,12 +214,12 @@
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java
- 117
+ 92
file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java
- 106
+ 80
diff --git a/src/main/java/com/example/nto/controller/AuthController.java b/src/main/java/com/example/nto/controller/AuthController.java
index 71d39e9..5d3f3ee 100644
--- a/src/main/java/com/example/nto/controller/AuthController.java
+++ b/src/main/java/com/example/nto/controller/AuthController.java
@@ -23,6 +23,18 @@ import java.util.List;
@RestController
public class AuthController {
+ class RoleResponse {
+ private String role;
+
+ public String getRole() {
+ return role;
+ }
+
+ public void setRole(String role) {
+ this.role = role;
+ }
+ }
+
@Autowired
private EmployeeRepository employeeRepository;
@@ -56,7 +68,7 @@ public class AuthController {
Эндпоинт авторизации, кинь сюда логин и пароль, и возможно я дам тебе возможность авторизоваться.
*/
@PostMapping("/api/login/")
- private ResponseEntity login(HttpServletRequest request, @RequestBody LoginBody loginBody) { //, @RequestParam String login, @RequestParam String password) {
+ private RoleResponse login(HttpServletRequest request, @RequestBody LoginBody loginBody) { //, @RequestParam String login, @RequestParam String password) {
Employee employee = employeeRepository.getByLogin(loginBody.login).get();
List authorities = new ArrayList<>();
@@ -68,7 +80,9 @@ public class AuthController {
securityContext.setAuthentication(authentication);
HttpSession session = request.getSession(true);
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
- return ResponseEntity.status(HttpStatus.OK).build();
+ RoleResponse response = new RoleResponse();
+ response.setRole(employee.getRole());
+ return response;
}
}
diff --git a/src/main/java/com/example/nto/controller/EmployeeController.java b/src/main/java/com/example/nto/controller/EmployeeController.java
index aa40fbc..d7f739c 100644
--- a/src/main/java/com/example/nto/controller/EmployeeController.java
+++ b/src/main/java/com/example/nto/controller/EmployeeController.java
@@ -11,8 +11,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
-import java.util.List;
-
@RestController
public class EmployeeController {
private final EmployeeService employeeService;
@@ -31,27 +29,6 @@ public class EmployeeController {
this.entryRepository = entryRepository;
}
- public static class EmployeeInfoBody {
- private long id;
- private List entryList;
-
- public List getEntryList() {
- return entryList;
- }
-
- public void setEntryList(List entryList) {
- this.entryList = entryList;
- }
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
- }
-
/**
* Эндпоинт для проверки присутствия логина в емплоеееее таблице
*
@@ -79,13 +56,10 @@ public class EmployeeController {
* Удален вариант получить 401 статус,так как теперь до этого эндпоинта нельзя достучаться без авторизации
*/
@GetMapping("/api/info")
- public EmployeeInfoBody getEmployeeInfo() {
+ public Employee getEmployeeInfo() {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
Employee employee = employeeService.getEmployeeInfo(login).get();
- EmployeeInfoBody employeeInfoBody = new EmployeeInfoBody();
- employeeInfoBody.setId(employee);
- employeeInfoBody.setEntryList(entryService.getEntriesByEmployee(employee));
- return employeeInfoBody;
+ return employee;
}
/**
@@ -111,6 +85,7 @@ public class EmployeeController {
Entry entry = new Entry();
Employee employee = employeeService.getEmployeeByLogin(login);
entry.setEmployee(employee);
+ entry.setPlace(codeRepository.findByValue(value));
entryRepository.save(entry);
return ResponseEntity.status(HttpStatus.ACCEPTED).build();
diff --git a/src/main/java/com/example/nto/entity/Code.java b/src/main/java/com/example/nto/entity/Code.java
index db60a73..0c063d6 100644
--- a/src/main/java/com/example/nto/entity/Code.java
+++ b/src/main/java/com/example/nto/entity/Code.java
@@ -1,11 +1,17 @@
package com.example.nto.entity;
+import com.fasterxml.jackson.annotation.JsonIdentityInfo;
+import com.fasterxml.jackson.annotation.JsonIdentityReference;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
@Entity
@Data
@@ -18,6 +24,11 @@ public class Code {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private long value;
+ private String name;
+
+ @OneToMany(mappedBy = "place")
+ @JsonIgnore
+ private List entries = new ArrayList<>();
public long getId() {
return id;
@@ -34,4 +45,12 @@ public class Code {
public void setValue(long value) {
this.value = value;
}
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
}
diff --git a/src/main/java/com/example/nto/entity/Entry.java b/src/main/java/com/example/nto/entity/Entry.java
index 02d3a9e..94e2590 100644
--- a/src/main/java/com/example/nto/entity/Entry.java
+++ b/src/main/java/com/example/nto/entity/Entry.java
@@ -1,5 +1,9 @@
package com.example.nto.entity;
+import com.fasterxml.jackson.annotation.JsonIdentityInfo;
+import com.fasterxml.jackson.annotation.JsonIdentityReference;
+import com.fasterxml.jackson.annotation.ObjectIdGenerators;
+
import javax.persistence.*;
@Entity
@@ -10,9 +14,14 @@ public class Entry {
private long id;
@ManyToOne
- @JoinColumn(name = "employee")
+ @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
+ @JsonIdentityReference(alwaysAsId = true)
private Employee employee;
+ @ManyToOne
+ @JoinColumn(name = "place")
+ private Code place;
+
public long getId() {
return id;
}
@@ -28,4 +37,12 @@ public class Entry {
public void setEmployee(Employee employee) {
this.employee = employee;
}
+
+ public Code getPlace() {
+ return place;
+ }
+
+ public void setPlace(Code place) {
+ this.place = place;
+ }
}
diff --git a/src/main/java/com/example/nto/repository/CodeRepository.java b/src/main/java/com/example/nto/repository/CodeRepository.java
index ce306de..bdb892b 100644
--- a/src/main/java/com/example/nto/repository/CodeRepository.java
+++ b/src/main/java/com/example/nto/repository/CodeRepository.java
@@ -5,4 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
public interface CodeRepository extends JpaRepository {
boolean existsByValue(Long value);
+ Code findByValue(Long value);
}
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index 8cd1fee..149120d 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -5,10 +5,10 @@ VALUES
(3, 'asemenov', '$2a$10$PRWHGoiil0XIipjWzu0MK.vMAxkdyoZQQliLtGh1TUhik7MyN2mje', 'USER', 'Семенов Анатолий Анатольевич', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Разработчик', '2024-02-13T08:31'),
(4, 'afedorov', '$2a$10$PRWHGoiil0XIipjWzu0MK.vMAxkdyoZQQliLtGh1TUhik7MyN2mje', 'USER', 'Федоров Александр Сергеевич', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Тестировщик', '2024-02-12T08:36');
-INSERT INTO code (value)
+INSERT INTO code (value, name)
VALUES
-(1234567890123456789),
-(9223372036854775807),
-(1122334455667788990),
-(998877665544332211),
-(5566778899001122334);
\ No newline at end of file
+(1234567890123456789, 'Комната Лимасова'),
+(9223372036854775807, 'Компьютерный класс'),
+(1122334455667788990, 'Туалет'),
+(998877665544332211, 'Ядерный реактор'),
+(5566778899001122334, 'Склад');
\ No newline at end of file