Compare commits
3 Commits
master
...
IAmATeapot
Author | SHA1 | Date | |
---|---|---|---|
4d78738b84 | |||
bcf9b00a2f | |||
eb9e702545 |
@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'com.index'
|
||||
version = '1.0.0-RELEASE'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
|
@ -1,5 +1,5 @@
|
||||
FROM eclipse-temurin:21
|
||||
LABEL authors="indx"
|
||||
|
||||
COPY ./build/libs/S-Pass-Backend-1.0.0-RELEASE.jar /opt/app/
|
||||
CMD ["java", "-jar", "/opt/app/S-Pass-Backend-1.0.0-RELEASE.jar"]
|
||||
COPY ./build/libs/S-QR-Backend-0.0.1-SNAPSHOT.jar /opt/app/
|
||||
CMD ["java", "-jar", "/opt/app/S-QR-Backend-0.0.1-SNAPSHOT.jar"]
|
@ -1 +1 @@
|
||||
rootProject.name = 'S-Pass-Backend'
|
||||
rootProject.name = 'S-QR-Backend'
|
||||
|
@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.authentication.ProviderManager;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
import org.springframework.security.config.Customizer;
|
||||
@ -41,7 +42,6 @@ public class SecurityConfig {
|
||||
.requestMatchers("/api/employee/{login}/{state}").hasAuthority("ADMIN")
|
||||
.requestMatchers("/api/employee/{login}").hasAuthority("ADMIN")
|
||||
.requestMatchers("/api/employee/all").hasAuthority("ADMIN")
|
||||
.requestMatchers("/api/employee/{login}/update").hasAuthority("ADMIN")
|
||||
|
||||
// Entrance for everyone
|
||||
.requestMatchers("/api/entrance").authenticated()
|
||||
|
@ -30,7 +30,7 @@ public class EmployeeController {
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||
})
|
||||
public ResponseEntity<Object> login() {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/profile")
|
||||
@ -68,17 +68,17 @@ public class EmployeeController {
|
||||
return employeeService.deleteEmployee(login);
|
||||
}
|
||||
|
||||
@PatchMapping("/{login}/change_state")
|
||||
@Operation(description = "Enable/Disable user's ability to use QR code entrance. (ADMIN only)", summary = "Enable/Disable QR")
|
||||
@PatchMapping("/{login}/{state}")
|
||||
@Operation(description = "Enable/Disable user's ability to use QR code entrance. (ADMIN only) States: active / blocked", summary = "Enable/Disable QR")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Modification Successful"),
|
||||
@ApiResponse(responseCode = "412", description = "User you're trying to block has ADMIN privileges"),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden"),
|
||||
@ApiResponse(responseCode = "404", description = "User not found"),
|
||||
@ApiResponse(responseCode = "400", description = "State doesn't exist"),
|
||||
})
|
||||
public ResponseEntity<HttpStatusCode> changeState(@PathVariable String login) {
|
||||
return employeeService.changeState(login);
|
||||
public ResponseEntity<HttpStatusCode> changeState(@PathVariable String login, @PathVariable String state) {
|
||||
return employeeService.changeState(login, state);
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
@ -96,7 +96,7 @@ public class EmployeeController {
|
||||
@GetMapping("/{login}")
|
||||
@Operation(description = "Get user's profile by login (ADMIN only)", summary = "Get user's profile by login")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Request Successful"),
|
||||
@ApiResponse(responseCode = "200", description = "Modification Successful"),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden"),
|
||||
@ApiResponse(responseCode = "404", description = "User not found"),
|
||||
@ -105,16 +105,14 @@ public class EmployeeController {
|
||||
return employeeService.getEmployeeByLogin(login);
|
||||
}
|
||||
|
||||
@PatchMapping("/{login}/update")
|
||||
@Operation(description = "Update user's profile (ADMIN only). Accepts name, position and photo_url properties", summary = "Update user's profile")
|
||||
@GetMapping("/coffee")@Operation(description = "I Am A Teapot", summary = "I Am A Teapot")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Modification Successful"),
|
||||
@ApiResponse(responseCode = "418", description = "I Am A Teapot"),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden"),
|
||||
@ApiResponse(responseCode = "404", description = "User not found"),
|
||||
})
|
||||
public ResponseEntity<EmployeeDTO> updateEmployee(@PathVariable String login, @RequestBody EmployeeDTO updateDTO) {
|
||||
return employeeService.updateEmployee(updateDTO, login);
|
||||
|
||||
public ResponseEntity<String> coffee() {
|
||||
return new ResponseEntity<>("<center><h1>I Am A Teapot</h1></center>", HttpStatus.I_AM_A_TEAPOT);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ public class EntranceController {
|
||||
@Operation(description = "Get user's last entries. Username is taken from Authentication", summary = "Get user's last entry")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Request Successful."),
|
||||
@ApiResponse(responseCode = "204", description = "No Entrances."),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||
})
|
||||
public ResponseEntity<EntranceDTO> getLastEntrance() {
|
||||
|
@ -13,8 +13,7 @@ public interface EmployeeService {
|
||||
ResponseEntity<EmployeeDTO> getUserInfo(Authentication auth);
|
||||
ResponseEntity<Object> openTheDoor(Long code, Authentication auth);
|
||||
ResponseEntity<HttpStatusCode> deleteEmployee(String login);
|
||||
ResponseEntity<HttpStatusCode> changeState(String login);
|
||||
ResponseEntity<HttpStatusCode> changeState(String login, String state);
|
||||
ResponseEntity<Page<EmployeeDTO>> getAllEmployees(Pageable pageable);
|
||||
ResponseEntity<EmployeeDTO> getEmployeeByLogin(String login);
|
||||
ResponseEntity<EmployeeDTO> updateEmployee(EmployeeDTO updateDTO, String login);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
public ResponseEntity<Object> openTheDoor(Long code, Authentication auth) {
|
||||
try {
|
||||
if (codeRepository.existsByValue(code)) {
|
||||
if (codeRepository.existsByValue(Long.valueOf(code))) {
|
||||
Employee employee = employeeRepository.findByLogin(auth.getName());
|
||||
if(employee.getIsQREnabled()) {
|
||||
Entrance entrance = new Entrance();
|
||||
@ -86,16 +86,26 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<HttpStatusCode> changeState(String login) {
|
||||
public ResponseEntity<HttpStatusCode> changeState(String login, String state) {
|
||||
Employee e = employeeRepository.findByLogin(login);
|
||||
if(e != null) {
|
||||
if (Objects.equals(e.getAuthorities().iterator().next().getAuthority(), "ADMIN")) {
|
||||
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
else {
|
||||
e.setIsQREnabled(!e.getIsQREnabled());
|
||||
employeeRepository.save(e);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
if(state.equals("active")) {
|
||||
e.setIsQREnabled(true);
|
||||
employeeRepository.save(e);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
else if(state.equals("blocked")) {
|
||||
e.setIsQREnabled(false);
|
||||
employeeRepository.save(e);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
else {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -118,25 +128,4 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<EmployeeDTO> updateEmployee(EmployeeDTO updateDTO, String login) {
|
||||
Employee e = employeeRepository.findByLogin(login);
|
||||
if(e != null) {
|
||||
if(updateDTO.getName() != null) {
|
||||
e.setName(updateDTO.getName());
|
||||
}
|
||||
if (updateDTO.getPosition() != null) {
|
||||
e.setPosition(updateDTO.getPosition());
|
||||
}
|
||||
if (updateDTO.getPhotoUrl() != null) {
|
||||
e.setPhotoUrl(updateDTO.getPhotoUrl());
|
||||
}
|
||||
employeeRepository.save(e);
|
||||
return new ResponseEntity<>(EmployeeMapper.convertToDTO(e), HttpStatus.OK);
|
||||
}
|
||||
else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,8 @@ public class EntranceServiceImpl implements EntranceService {
|
||||
public ResponseEntity<EntranceDTO> getLastEntrance(Authentication auth) {
|
||||
Employee employee = employeeRepository.findByLogin(auth.getName());
|
||||
List<EntranceDTO> entrances = employee.getEntrances().stream().map(EntranceMapper::convertToDTO).toList();
|
||||
if(entrances.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
else {
|
||||
return new ResponseEntity<>(entrances.getLast(), HttpStatus.OK);
|
||||
}
|
||||
System.out.println(entrances.getLast());
|
||||
return new ResponseEntity<>(entrances.getLast(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,7 +5,7 @@
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
|
||||
|
||||
<changeSet id="2024-10-20--0002-employee-02" author="okalugin">
|
||||
<changeSet id="2024-10-20--0002-employee" author="okalugin">
|
||||
|
||||
<preConditions onFail="MARK_RAN">
|
||||
<not>
|
||||
@ -37,7 +37,7 @@
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
|
||||
<column name="photo_url" type="VARCHAR(250)">
|
||||
<column name="photo_url" type="VARCHAR(100)">
|
||||
<constraints nullable="true"/>
|
||||
</column>
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
value;name;entry_type
|
||||
820962709643279872;Главный Вход;Вход
|
||||
353264154792598510;Главный Выход;Выход
|
||||
269199677577482211;Задний вход;Вход
|
||||
393339578854043555;Задний выход;Выход
|
||||
106684466846571407;Вход на парковку;Вход
|
||||
604595281495436727;Выход с парковки;Выход
|
||||
440569142882630461;Вход с улицы Пушкина;Вход
|
||||
615262283026725501;Выход с улицы Пушкина;Выход
|
||||
id;value;name;entry_type
|
||||
1;1234567890123456789;Главный Вход;Вход
|
||||
2;9223372036854775807;Главный Выход;Выход
|
||||
3;1122334455667788990;Задний вход;Вход
|
||||
4;998877665544332211;Выход с парковки;Выход
|
||||
5;5566778899001122334;Вход с улицы Пушкина;Вход
|
|
@ -2,7 +2,4 @@ login;password;name;photo_url;position;is_enabled
|
||||
pivanov;$2a$10$Jzb9I5eeHC0UIn/q5Rhq..wkI7KicBEZKB2u5BvnH8.n12d4alTOK;Иванов Петр Федорович;https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg;Разработчик;true
|
||||
ipetrov;$2a$10$Jzb9I5eeHC0UIn/q5Rhq..wkI7KicBEZKB2u5BvnH8.n12d4alTOK;Петров Иван Константинович;https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg;Аналитик;false
|
||||
asemenov;$2a$10$Jzb9I5eeHC0UIn/q5Rhq..wkI7KicBEZKB2u5BvnH8.n12d4alTOK;Семенов Анатолий Анатольевич;https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg;Разработчик;true
|
||||
afedorov;$2a$10$Jzb9I5eeHC0UIn/q5Rhq..wkI7KicBEZKB2u5BvnH8.n12d4alTOK;Федоров Александр Сергеевич;https://i.postimg.cc/R0tz9yFr/skala.jpg;Тестировщик;true
|
||||
alimasov;$2a$10$Jzb9I5eeHC0UIn/q5Rhq..wkI7KicBEZKB2u5BvnH8.n12d4alTOK;Андрей Лимасов;https://i.postimg.cc/L5zBsbnP/IMG-20250220-101919.jpg;Разработчик;true
|
||||
admin12345;$2a$10$whV2pS0u.zGocamf2NdEEeBB2GylZxAA2ACz6RVCSrFxz1PJqnnEG;Админ Админов Админович;https://i.postimg.cc/R0tz9yFr/skala.jpg;Админ;true
|
||||
user12345;$2a$10$mtmczxpEx7iZIEAvh8UrSOVUoJurFCIcuNXMTu5IpNnIyBR9uAV16;Райан Гослинг;https://i.postimg.cc/15kwCVL9/347817.jpg;Пользователь;true
|
||||
afedorov;$2a$10$Jzb9I5eeHC0UIn/q5Rhq..wkI7KicBEZKB2u5BvnH8.n12d4alTOK;Федоров Александр Сергеевич;https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg;Тестировщик;true
|
|
@ -2,7 +2,4 @@ employee_id;authorities_id
|
||||
1;2
|
||||
2;1
|
||||
3;1
|
||||
4;1
|
||||
5;2
|
||||
6;2
|
||||
7;1
|
||||
4;1
|
|
@ -42,7 +42,7 @@ class EmployeeControllerTests {
|
||||
void doorOpen() throws Exception {
|
||||
this.mockMvc.perform(
|
||||
patch("/api/employee/open")
|
||||
.param("code", "820962709643279872")
|
||||
.param("code", "1234567890123456789")
|
||||
.with(httpBasic("pivanov", "HelloWorld1234")))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
@ -61,12 +61,12 @@ class EmployeeControllerTests {
|
||||
@Test
|
||||
void lockAndUnlockUser() throws Exception {
|
||||
this.mockMvc.perform(
|
||||
patch("/api/employee/ipetrov/change_state")
|
||||
patch("/api/employee/ipetrov/blocked")
|
||||
.with(httpBasic("pivanov", "HelloWorld1234")))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
this.mockMvc.perform(
|
||||
patch("/api/employee/ipetrov/change_state")
|
||||
patch("/api/employee/ipetrov/active")
|
||||
.with(httpBasic("pivanov", "HelloWorld1234")))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
@ -75,12 +75,12 @@ class EmployeeControllerTests {
|
||||
@Test
|
||||
void lockAndUnlockUserNotFound() throws Exception {
|
||||
this.mockMvc.perform(
|
||||
patch("/api/employee/PetrTestovich/change_state")
|
||||
patch("/api/employee/PetrTestovich/blocked")
|
||||
.with(httpBasic("pivanov", "HelloWorld1234")))
|
||||
.andDo(print())
|
||||
.andExpect(status().isNotFound());
|
||||
this.mockMvc.perform(
|
||||
patch("/api/employee/PetrTestovich/change_state")
|
||||
patch("/api/employee/PetrTestovich/active")
|
||||
.with(httpBasic("pivanov", "HelloWorld1234")))
|
||||
.andDo(print())
|
||||
.andExpect(status().isNotFound());
|
||||
|
Loading…
x
Reference in New Issue
Block a user