add endpoints
This commit is contained in:
parent
e9642bde10
commit
f959016e8f
35
.idea/workspace.xml
generated
35
.idea/workspace.xml
generated
@ -4,14 +4,15 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<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$/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/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/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/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/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/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" />
|
||||
@ -178,7 +179,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1740043625151</updated>
|
||||
</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 />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
@ -192,34 +201,30 @@
|
||||
<MESSAGE value="create new endpoints (employee edit)" />
|
||||
<MESSAGE value="fix secure" />
|
||||
<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 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>14</line>
|
||||
<line>16</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>58</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/AdminController.java</url>
|
||||
<line>79</line>
|
||||
<line>128</line>
|
||||
<option name="timeStamp" value="42" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="java-line">
|
||||
<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" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="java-line">
|
||||
<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" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
|
@ -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<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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -10,5 +10,4 @@ public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
boolean existsByLogin(String login);
|
||||
Optional<Employee> getByLogin(String login);
|
||||
Optional<Employee> findByLogin(String login);
|
||||
|
||||
}
|
||||
|
@ -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<Employee> getEmployees();
|
||||
}
|
||||
|
@ -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<Employee> getEmployees() {
|
||||
return employeeRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user