Entities added, changed database
This commit is contained in:
parent
caf100cc9a
commit
0cfe30a008
@ -1,14 +1,18 @@
|
||||
package com.indexzero.finals.controller;
|
||||
|
||||
import com.indexzero.finals.entity.Code;
|
||||
import com.indexzero.finals.entity.Employee;
|
||||
import com.indexzero.finals.entity.OpenRequestBody;
|
||||
import com.indexzero.finals.entity.Visit;
|
||||
import com.indexzero.finals.repository.CodeRepository;
|
||||
import com.indexzero.finals.repository.EmployeeRepository;
|
||||
import com.indexzero.finals.repository.VisitRepository;
|
||||
import com.indexzero.finals.service.EmployeeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
@ -22,6 +26,9 @@ public class EmployeeController {
|
||||
@Autowired
|
||||
EmployeeService employeeService;
|
||||
|
||||
@Autowired
|
||||
VisitRepository visitRepository;
|
||||
|
||||
@GetMapping("/{login}/auth")
|
||||
public ResponseEntity<Object> Auth(@PathVariable String login) {
|
||||
return employeeService.checkIfUserExists(login);
|
||||
|
19
src/main/java/com/indexzero/finals/entity/Authority.java
Normal file
19
src/main/java/com/indexzero/finals/entity/Authority.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.indexzero.finals.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "authority")
|
||||
public class Authority {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
Long id;
|
||||
|
||||
@Column(name = "authority", nullable = false)
|
||||
String authority;
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.indexzero.finals.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@ -19,5 +16,10 @@ public class Code {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@Column(name = "value")
|
||||
private long value;
|
||||
|
||||
@Column(name = "is_active")
|
||||
boolean isActive;
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.indexzero.finals.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@ -15,10 +16,29 @@ import java.time.LocalDateTime;
|
||||
@AllArgsConstructor
|
||||
public class Employee {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
private long id;
|
||||
|
||||
@Column(name = "login", nullable = false, unique = true)
|
||||
private String login;
|
||||
|
||||
@Column(name = "password", nullable = false)
|
||||
private String password;
|
||||
|
||||
@Column(name = "name", nullable = false)
|
||||
private String name;
|
||||
private String photo;
|
||||
|
||||
@Column(name = "position", nullable = false)
|
||||
private String position;
|
||||
private LocalDateTime lastVisit;
|
||||
|
||||
@Column(name = "photo_url")
|
||||
private String photoUrl;
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
Set<Authority> authorities;
|
||||
|
||||
@OneToMany(mappedBy = "id")
|
||||
List<Visit> visits;
|
||||
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
package com.indexzero.finals.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OpenRequestBody {
|
||||
Long value;
|
||||
}
|
24
src/main/java/com/indexzero/finals/entity/Visit.java
Normal file
24
src/main/java/com/indexzero/finals/entity/Visit.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.indexzero.finals.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import org.apache.catalina.User;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "employee_visits")
|
||||
public class Visit {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@Column(name = "visit_time")
|
||||
private Date visitTime;
|
||||
|
||||
@Column(name = "type")
|
||||
private String type;
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.indexzero.finals.repository;
|
||||
|
||||
import com.indexzero.finals.entity.Authority;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface AuthorityRepository extends JpaRepository<Authority, Long> {
|
||||
}
|
@ -5,5 +5,4 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CodeRepository extends JpaRepository<Code, Long> {
|
||||
boolean existsByValue(Long value);
|
||||
Code findByValue(Long value);
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.indexzero.finals.repository;
|
||||
|
||||
import com.indexzero.finals.entity.Visit;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface VisitRepository extends JpaRepository<Visit, Long> {
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.indexzero.finals.service;
|
||||
|
||||
import com.indexzero.finals.entity.Employee;
|
||||
import com.indexzero.finals.entity.OpenRequestBody;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
public interface EmployeeService {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.indexzero.finals.service.impl;
|
||||
|
||||
import com.indexzero.finals.entity.Employee;
|
||||
import com.indexzero.finals.entity.OpenRequestBody;
|
||||
import com.indexzero.finals.repository.CodeRepository;
|
||||
import com.indexzero.finals.repository.EmployeeRepository;
|
||||
import com.indexzero.finals.service.EmployeeService;
|
||||
@ -56,7 +55,7 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
LocalDateTime time = LocalDateTime.now();
|
||||
String formatted = time.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||
formatted = formatted.split("\\.")[0];
|
||||
employee.setLastVisit(LocalDateTime.parse(formatted));
|
||||
// employee.setLastVisit(LocalDateTime.parse(formatted));
|
||||
|
||||
employeeRepository.save(employee);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
@ -23,6 +23,9 @@
|
||||
<column name="value" type="bigint">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="is_active" type="bool">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
|
||||
</changeSet>
|
||||
|
@ -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="2025-02-18--0005-employee-visits" author="okalugin">
|
||||
<changeSet id="2025-02-18--0005-visits" author="okalugin">
|
||||
<preConditions>
|
||||
<not>
|
||||
<tableExists tableName="employee_visits"/>
|
||||
|
@ -1,6 +1,6 @@
|
||||
id;value
|
||||
1;1234567890123456789
|
||||
2;9223372036854775807
|
||||
3;1122334455667788990
|
||||
4;998877665544332211
|
||||
5;5566778899001122334
|
||||
id;value;is_active
|
||||
1;1234567890123456789;true
|
||||
2;9223372036854775807;true
|
||||
3;1122334455667788990;false
|
||||
4;998877665544332211;false
|
||||
5;5566778899001122334;true
|
|
@ -8,12 +8,12 @@
|
||||
<include file="db.changelog/1.0/2024-10-20--0002-employee.xml"/>
|
||||
<include file="db.changelog/1.0/2025-02-18--0003-authority.xml"/>
|
||||
<include file="db.changelog/1.0/2025-02-18--0004-employee-authorities.xml"/>
|
||||
<include file="db.changelog/1.0/2025-02-18--0005-employee-visits.xml"/>
|
||||
<include file="/db.changelog/1.0/2025-02-18--0005-employee-visits.xml"/>
|
||||
|
||||
<include file="db.changelog/data/2024-10-20--0001-code-data.xml"/>
|
||||
<include file="db.changelog/data/2024-10-20--0002-employee-data.xml"/>
|
||||
<include file="db.changelog/data/2025-02-18--0003-authority-data.xml"/>
|
||||
<include file="db.changelog/data/2025-02-18--0004-employee-authorities-data.xml"/>
|
||||
<include file="db.changelog/data/2025-02-18--0005-employee-visits-data.xml"/>
|
||||
<include file="/db.changelog/data/2025-02-18--0005-employee-visits-data.xml"/>
|
||||
|
||||
</databaseChangeLog>
|
Loading…
x
Reference in New Issue
Block a user