Done code and user interfaces
This commit is contained in:
parent
79d3f9d1f6
commit
f7c4e0a23a
6
pom.xml
6
pom.xml
@ -25,28 +25,34 @@
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<version>1.7.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.example.nto;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class);
|
||||
}
|
||||
}
|
||||
|
18
src/main/java/com/example/nto/controller/CodeController.java
Normal file
18
src/main/java/com/example/nto/controller/CodeController.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Code;
|
||||
import com.example.nto.service.CodeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class CodeController {
|
||||
|
||||
private final CodeService codeService;
|
||||
|
||||
@PatchMapping("/api/{login}/open")
|
||||
public Code update(@PathVariable String login, @RequestBody Code newCode) {
|
||||
return codeService.update(login, newCode);
|
||||
}
|
||||
}
|
@ -1,4 +1,25 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class EmployeeController {
|
||||
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
@GetMapping("api/{login}/info")
|
||||
public Employee findByLogin(@PathVariable String login) {
|
||||
return employeeService.findByLogin(login);
|
||||
}
|
||||
|
||||
@GetMapping("api/{login}/auth")
|
||||
public boolean findExistByLogin(@PathVariable String login) {
|
||||
return employeeService.findExistByLogin(login);
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,18 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "Code")
|
||||
public class Code {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
@Column(name = "value")
|
||||
private long value;
|
||||
}
|
||||
|
@ -5,17 +5,27 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "Employee")
|
||||
public class Employee {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
@Column(name = "login")
|
||||
private String login;
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
@Column(name = "photo")
|
||||
private String photo;
|
||||
@Column(name = "position")
|
||||
private String position;
|
||||
@Column(name = "lastVisit")
|
||||
private LocalDateTime lastVisit;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.example.nto.repository;
|
||||
|
||||
import com.example.nto.entity.Code;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
public interface CodeRepository extends JpaRepository<Code, Long> {
|
||||
}
|
||||
@Repository
|
||||
public interface CodeRepository extends JpaRepository<Code, Long> {}
|
||||
|
@ -2,6 +2,15 @@ package com.example.nto.repository;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
|
||||
@Query("select e from Employee e where e.login = ?1")
|
||||
Employee findByLogin(String login);
|
||||
|
||||
@Query("select count(e) = 1 from Employee e where login = ?1")
|
||||
boolean findExistByLogin(String login);
|
||||
}
|
||||
|
9
src/main/java/com/example/nto/service/CodeService.java
Normal file
9
src/main/java/com/example/nto/service/CodeService.java
Normal file
@ -0,0 +1,9 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
|
||||
import com.example.nto.entity.Code;
|
||||
|
||||
public interface CodeService {
|
||||
|
||||
Code update(String login, Code newCode);
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
|
||||
public interface EmployeeService {
|
||||
|
||||
Employee findByLogin(String login);
|
||||
Boolean findExistByLogin(String login);
|
||||
}
|
||||
|
@ -1,6 +1,44 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.entity.Code;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.repository.CodeRepository;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.service.CodeService;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EmployeeServiceImpl implements EmployeeService, CodeService {
|
||||
|
||||
private final EmployeeRepository employeeRepository;
|
||||
private final CodeRepository codeRepository;
|
||||
|
||||
@Override
|
||||
public Employee findByLogin(String login) {
|
||||
return employeeRepository.findByLogin(login);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean findExistByLogin(String login) {
|
||||
return employeeRepository.findExistByLogin(login);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Code update(String login, Code newCode) {
|
||||
long employeeId = findByLogin(login).getId();
|
||||
|
||||
Optional<Code> codeOptional = codeRepository.findById(employeeId);
|
||||
if (codeOptional.isEmpty()) throw new RuntimeException("Code with id " + employeeId + "is not found");
|
||||
|
||||
Code code = codeOptional.get();
|
||||
code.setValue(newCode.getValue());
|
||||
|
||||
return codeRepository.save(code);
|
||||
}
|
||||
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user