ужин(

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" />
</component>
<component name="ChangeListManager">
<list default="true" id="067ac1f0-be04-4fe4-85c6-f870334053b8" name="Changes" comment="промежуточные итоги :skull:">
<change afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/service/impl/UserDetailsServiceImpl.java" afterDir="false" />
<list default="true" id="067ac1f0-be04-4fe4-85c6-f870334053b8" name="Changes" comment="AUTHORIZATION WORK!">
<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/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/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/websecurity/WebSecurityConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/websecurity/WebSecurityConfig.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/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/service/impl/EmployeeServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/service/impl/EmployeeServiceImpl.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -38,7 +36,7 @@
</component>
<component name="PropertiesComponent"><![CDATA[{
"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",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
@ -144,7 +142,15 @@
<option name="project" value="LOCAL" />
<updated>1739968326971</updated>
</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 />
</component>
<component name="VcsManagerConfiguration">
@ -154,59 +160,60 @@
<MESSAGE value="migrate to postgres" />
<MESSAGE value="websecurity configs" />
<MESSAGE value="промежуточные итоги :skull:" />
<option name="LAST_COMMIT_MESSAGE" value="промежуточные итоги :skull:" />
<MESSAGE value="AUTHORIZATION WORK!" />
<option name="LAST_COMMIT_MESSAGE" value="AUTHORIZATION WORK!" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<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" />
</line-breakpoint>
</breakpoints>

View File

@ -5,8 +5,11 @@ import com.example.nto.repository.CodeRepository;
import com.example.nto.service.EmployeeService;
import org.springframework.http.HttpStatus;
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 javax.servlet.http.HttpServletRequest;
import java.util.Optional;
@RestController
@ -22,11 +25,13 @@ public class EmployeeController {
/**
* Эндпоинт для проверки присутствия логина в емплоеееее таблице
*
* @param login Искомый логин
* @return статус код, смотри документацию к тз
*/
@GetMapping("/api/{login}/auth")
public ResponseEntity<String> authAttempt(@PathVariable String login) {
@GetMapping("/api/auth")
public ResponseEntity<String> authAttempt(HttpServletRequest request) {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
try {
if (employeeService.checkEmployeeExists(login)) {
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 БАААААН
*/
@GetMapping("/api/{login}/info")
public ResponseEntity<Employee> getEmployeeInfo(@PathVariable String login) {
@GetMapping("/api/info")
public ResponseEntity<Employee> getEmployeeInfo() {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
try {
Optional<Employee> employee = employeeService.getEmployeeInfo(login);
return employee.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.status(HttpStatus.UNAUTHORIZED).build());
@ -61,13 +75,14 @@ public class EmployeeController {
/**
* Проверка на дверь открыть не открыть
* @param login логин входящего
* @param value код двери
* @return статус код отвта
*/
@PatchMapping("api/{login}/open")
public ResponseEntity<String> openDoorAttempt(@PathVariable String login, @RequestBody Long value) {
@PatchMapping("api/{value}/open")
public ResponseEntity<String> openDoorAttempt(@RequestBody Long value) {
try {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
if (!employeeService.checkEmployeeExists(login)) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}

View File

@ -9,4 +9,5 @@ public interface EmployeeService {
Optional<Employee> getEmployeeInfo(String login);
boolean doorIsOpen(String login, long code);
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.setLastVisit(LocalDateTime.now());
}
@Override
public Employee getEmployeeInfoById(Long id) {
return employeeRepository.findById(id).get();
}
}