ужин(

This commit is contained in:
Justiks 2025-02-19 18:56:04 +03:00
parent 5ee0e95aef
commit b71d3eee7d
4 changed files with 57 additions and 29 deletions

45
.idea/workspace.xml generated
View File

@ -4,13 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="067ac1f0-be04-4fe4-85c6-f870334053b8" name="Changes" comment="промежуточные итоги :skull:"> <list default="true" id="067ac1f0-be04-4fe4-85c6-f870334053b8" name="Changes" comment="AUTHORIZATION WORK!">
<change afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/service/impl/UserDetailsServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Code.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Code.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/service/EmployeeService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/service/EmployeeService.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Employee.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Employee.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -38,7 +36,7 @@
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent"><![CDATA[{
"keyToString": { "keyToString": {
"Application.App.executor": "Debug", "Application.App.executor": "Run",
"Maven.NTO-2024 [org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean].executor": "Run", "Maven.NTO-2024 [org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean].executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true", "RunOnceActivity.git.unshallow": "true",
@ -144,7 +142,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1739968326971</updated> <updated>1739968326971</updated>
</task> </task>
<option name="localTasksCounter" value="7" /> <task id="LOCAL-00007" summary="AUTHORIZATION WORK!">
<option name="closed" value="true" />
<created>1739978089147</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1739978089147</updated>
</task>
<option name="localTasksCounter" value="8" />
<servers /> <servers />
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
@ -154,59 +160,60 @@
<MESSAGE value="migrate to postgres" /> <MESSAGE value="migrate to postgres" />
<MESSAGE value="websecurity configs" /> <MESSAGE value="websecurity configs" />
<MESSAGE value="промежуточные итоги :skull:" /> <MESSAGE value="промежуточные итоги :skull:" />
<option name="LAST_COMMIT_MESSAGE" value="промежуточные итоги :skull:" /> <MESSAGE value="AUTHORIZATION WORK!" />
<option name="LAST_COMMIT_MESSAGE" value="AUTHORIZATION WORK!" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
<breakpoints> <breakpoints>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java</url>
<line>29</line> <line>34</line>
<option name="timeStamp" value="6" /> <option name="timeStamp" value="6" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/EmployeeController.java</url>
<line>12</line> <line>15</line>
<option name="timeStamp" value="7" /> <option name="timeStamp" value="7" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>49</line> <line>51</line>
<option name="timeStamp" value="25" /> <option name="timeStamp" value="25" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>57</line> <line>59</line>
<option name="timeStamp" value="26" /> <option name="timeStamp" value="26" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>50</line> <line>52</line>
<option name="timeStamp" value="30" /> <option name="timeStamp" value="30" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>52</line> <line>54</line>
<option name="timeStamp" value="31" /> <option name="timeStamp" value="31" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>53</line> <line>55</line>
<option name="timeStamp" value="34" /> <option name="timeStamp" value="34" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>54</line> <line>56</line>
<option name="timeStamp" value="35" /> <option name="timeStamp" value="35" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>55</line> <line>57</line>
<option name="timeStamp" value="36" /> <option name="timeStamp" value="36" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>56</line> <line>58</line>
<option name="timeStamp" value="37" /> <option name="timeStamp" value="37" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>

View File

@ -5,8 +5,11 @@ import com.example.nto.repository.CodeRepository;
import com.example.nto.service.EmployeeService; import com.example.nto.service.EmployeeService;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional; import java.util.Optional;
@RestController @RestController
@ -22,11 +25,13 @@ public class EmployeeController {
/** /**
* Эндпоинт для проверки присутствия логина в емплоеееее таблице * Эндпоинт для проверки присутствия логина в емплоеееее таблице
* *
* @param login Искомый логин
* @return статус код, смотри документацию к тз * @return статус код, смотри документацию к тз
*/ */
@GetMapping("/api/{login}/auth") @GetMapping("/api/auth")
public ResponseEntity<String> authAttempt(@PathVariable String login) { public ResponseEntity<String> authAttempt(HttpServletRequest request) {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
try { try {
if (employeeService.checkEmployeeExists(login)) { if (employeeService.checkEmployeeExists(login)) {
return ResponseEntity.status(HttpStatus.ACCEPTED).build(); // Логин найден ДВЕСТИ return ResponseEntity.status(HttpStatus.ACCEPTED).build(); // Логин найден ДВЕСТИ
@ -40,15 +45,24 @@ public class EmployeeController {
} }
} }
/**
* Такой же метод, как и getEmployeeInfo, только для админов по логину
* @return
*/
@Secured("ADMIN")
@GetMapping("/api/admin/{value}/info")
public Employee getEmployeeInfoAdmin(@PathVariable String value) {
return employeeService.getEmployeeInfoById(Long.parseLong(value));
}
/** /**
* Получить информацию по емплоеееее * Получить информацию по емплоеееее
* *
* @param login логин пользователя
* @return емплоеееееее иначе 401 бан бан бан бан, а если ошибка, то 400 БАААААН * @return емплоеееееее иначе 401 бан бан бан бан, а если ошибка, то 400 БАААААН
*/ */
@GetMapping("/api/{login}/info") @GetMapping("/api/info")
public ResponseEntity<Employee> getEmployeeInfo(@PathVariable String login) { public ResponseEntity<Employee> getEmployeeInfo() {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
try { try {
Optional<Employee> employee = employeeService.getEmployeeInfo(login); Optional<Employee> employee = employeeService.getEmployeeInfo(login);
return employee.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.status(HttpStatus.UNAUTHORIZED).build()); return employee.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.status(HttpStatus.UNAUTHORIZED).build());
@ -61,13 +75,14 @@ public class EmployeeController {
/** /**
* Проверка на дверь открыть не открыть * Проверка на дверь открыть не открыть
* @param login логин входящего
* @param value код двери * @param value код двери
* @return статус код отвта * @return статус код отвта
*/ */
@PatchMapping("api/{login}/open") @PatchMapping("api/{value}/open")
public ResponseEntity<String> openDoorAttempt(@PathVariable String login, @RequestBody Long value) { public ResponseEntity<String> openDoorAttempt(@RequestBody Long value) {
try { try {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
if (!employeeService.checkEmployeeExists(login)) { if (!employeeService.checkEmployeeExists(login)) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
} }

View File

@ -9,4 +9,5 @@ public interface EmployeeService {
Optional<Employee> getEmployeeInfo(String login); Optional<Employee> getEmployeeInfo(String login);
boolean doorIsOpen(String login, long code); boolean doorIsOpen(String login, long code);
void updateLastVisit(String login); void updateLastVisit(String login);
Employee getEmployeeInfoById(Long id);
} }

View File

@ -69,4 +69,9 @@ public class EmployeeServiceImpl implements EmployeeService {
Employee employee = employeeRepository.getByLogin(login).get(); Employee employee = employeeRepository.getByLogin(login).get();
employee.setLastVisit(LocalDateTime.now()); employee.setLastVisit(LocalDateTime.now());
} }
@Override
public Employee getEmployeeInfoById(Long id) {
return employeeRepository.findById(id).get();
}
} }