add endpoints

This commit is contained in:
Justiks 2025-02-20 13:59:39 +03:00
parent e9642bde10
commit f959016e8f
8 changed files with 118 additions and 18 deletions

35
.idea/workspace.xml generated
View File

@ -4,14 +4,15 @@
<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="add Entiries table and bugfix"> <list default="true" id="067ac1f0-be04-4fe4-85c6-f870334053b8" name="Changes" comment="bugfix">
<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/AdminController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/controller/AdminController.java" 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/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/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/entity/Entry.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Entry.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Entry.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/entity/Entry.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/repository/CodeRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/repository/CodeRepository.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/com/example/nto/repository/EmployeeRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/nto/repository/EmployeeRepository.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/data.sql" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/data.sql" 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> </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" />
@ -178,7 +179,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1740043625151</updated> <updated>1740043625151</updated>
</task> </task>
<option name="localTasksCounter" value="11" /> <task id="LOCAL-00011" summary="bugfix">
<option name="closed" value="true" />
<created>1740045412863</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1740045412863</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers /> <servers />
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
@ -192,34 +201,30 @@
<MESSAGE value="create new endpoints (employee edit)" /> <MESSAGE value="create new endpoints (employee edit)" />
<MESSAGE value="fix secure" /> <MESSAGE value="fix secure" />
<MESSAGE value="add Entiries table and bugfix" /> <MESSAGE value="add Entiries table and bugfix" />
<option name="LAST_COMMIT_MESSAGE" value="add Entiries table and bugfix" /> <MESSAGE value="bugfix" />
<option name="LAST_COMMIT_MESSAGE" value="bugfix" />
</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>14</line> <line>16</line>
<option name="timeStamp" value="7" /> <option name="timeStamp" value="7" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AuthController.java</url>
<line>58</line>
<option name="timeStamp" value="25" />
</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/AdminController.java</url> <url>file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AdminController.java</url>
<line>79</line> <line>128</line>
<option name="timeStamp" value="42" /> <option name="timeStamp" value="42" />
</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>92</line> <line>95</line>
<option name="timeStamp" value="43" /> <option name="timeStamp" value="43" />
</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>80</line> <line>82</line>
<option name="timeStamp" value="44" /> <option name="timeStamp" value="44" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>

View File

@ -11,6 +11,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import java.util.List;
@Controller @Controller
@RequestMapping("/api/admin/") @RequestMapping("/api/admin/")
@ -19,6 +20,54 @@ public class AdminController {
@Autowired @Autowired
private EmployeeService employeeService; 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 { public static class DeleteEmployeeRequest {
private Long id; private Long id;
@ -94,4 +143,30 @@ public class AdminController {
employeeService.updateEmployeePosition(updateEmployeeRequest.id, updateEmployeeRequest.field); employeeService.updateEmployeePosition(updateEmployeeRequest.id, updateEmployeeRequest.field);
return ResponseEntity.status(HttpStatus.OK).build(); 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<Employee> getEmployees() {
return employeeService.getEmployees();
}
@RolesAllowed("ADMIN")
@PostMapping("/employee/new/")
public ResponseEntity<String> 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();
}
} }

View File

@ -4,8 +4,6 @@ import com.example.nto.entity.Employee;
import com.example.nto.repository.EmployeeRepository; import com.example.nto.repository.EmployeeRepository;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; 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.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;

View File

@ -11,6 +11,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
@RestController @RestController
public class EmployeeController { public class EmployeeController {
private final EmployeeService employeeService; private final EmployeeService employeeService;
@ -85,6 +87,7 @@ public class EmployeeController {
Entry entry = new Entry(); Entry entry = new Entry();
Employee employee = employeeService.getEmployeeByLogin(login); Employee employee = employeeService.getEmployeeByLogin(login);
entry.setEmployee(employee); entry.setEmployee(employee);
entry.setTime(LocalDateTime.now());
entry.setPlace(codeRepository.findByValue(value)); entry.setPlace(codeRepository.findByValue(value));
entryRepository.save(entry); entryRepository.save(entry);
return ResponseEntity.status(HttpStatus.ACCEPTED).build(); return ResponseEntity.status(HttpStatus.ACCEPTED).build();

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*; import javax.persistence.*;
import java.time.LocalDateTime;
@Entity @Entity
@Table(name = "entry") @Table(name = "entry")
@ -18,6 +19,9 @@ public class Entry {
@JsonIdentityReference(alwaysAsId = true) @JsonIdentityReference(alwaysAsId = true)
private Employee employee; private Employee employee;
private LocalDateTime time;
@ManyToOne @ManyToOne
@JoinColumn(name = "place") @JoinColumn(name = "place")
private Code place; private Code place;
@ -45,4 +49,12 @@ public class Entry {
public void setPlace(Code place) { public void setPlace(Code place) {
this.place = place; this.place = place;
} }
public LocalDateTime getTime() {
return time;
}
public void setTime(LocalDateTime time) {
this.time = time;
}
} }

View File

@ -10,5 +10,4 @@ public interface EmployeeRepository extends JpaRepository<Employee, Long> {
boolean existsByLogin(String login); boolean existsByLogin(String login);
Optional<Employee> getByLogin(String login); Optional<Employee> getByLogin(String login);
Optional<Employee> findByLogin(String login); Optional<Employee> findByLogin(String login);
} }

View File

@ -2,6 +2,7 @@ package com.example.nto.service;
import com.example.nto.entity.Employee; import com.example.nto.entity.Employee;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public interface EmployeeService { public interface EmployeeService {
@ -15,4 +16,5 @@ public interface EmployeeService {
Employee updateEmployeeAvatar(Long id, String newAvatar); Employee updateEmployeeAvatar(Long id, String newAvatar);
Employee updateEmployeePosition(Long id, String newPosition); Employee updateEmployeePosition(Long id, String newPosition);
Employee getEmployeeByLogin(String login); Employee getEmployeeByLogin(String login);
List<Employee> getEmployees();
} }

View File

@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional; import java.util.Optional;
@Service @Service
@ -108,4 +109,9 @@ public class EmployeeServiceImpl implements EmployeeService {
public Employee getEmployeeByLogin(String login) { public Employee getEmployeeByLogin(String login) {
return employeeRepository.getByLogin(login).get(); return employeeRepository.getByLogin(login).get();
} }
@Override
public List<Employee> getEmployees() {
return employeeRepository.findAll();
}
} }