Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,18 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>jakarta.validation</groupId>-->
<!-- <artifactId>jakarta.validation-api</artifactId>-->
<!-- <version>3.0.2</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.passay</groupId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/heftyb/dms/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.FormLoginConfigurer;
Expand All @@ -13,6 +14,7 @@

@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class WebSecurityConfig {

// private final UserDetailsService userDetailsService;
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/heftyb/dms/controllers/AdminController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.heftyb.dms.controllers;

import com.heftyb.dms.crm.Employee;
import com.heftyb.dms.crm.JobTitle;
import com.heftyb.dms.crm.services.EmployeeService;
import com.heftyb.dms.users.RoleDepartment;
import com.heftyb.dms.users.User;
import com.heftyb.dms.users.services.RoleService;
import com.heftyb.dms.users.services.UserService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
Expand All @@ -17,15 +22,19 @@

@Controller
@RequestMapping("admin")
@PreAuthorize("hasRole('ADMIN')")
public class AdminController {

private final UserService userService;
private final EmployeeService employeeService;
private final RoleService roleService;

public AdminController(final UserService userService,
final EmployeeService employeeService) {
final EmployeeService employeeService,
final RoleService roleService) {
this.userService = userService;
this.employeeService = employeeService;
this.roleService = roleService;
}

@GetMapping({"/", ""})
Expand All @@ -36,6 +45,9 @@ public String adminHome(HttpServletRequest request, Model model, Principal princ
List<User> users = userService.findAll();
model.addAttribute("users", users);
model.addAttribute("username", principal.getName());
model.addAttribute("roles", roleService.findAll());
model.addAttribute("deptRoles", RoleDepartment.values());
model.addAttribute("jobTitles", JobTitle.values());
return "hr_administrator";
}

Expand All @@ -47,7 +59,7 @@ public String create_employee_form(Principal principal, ModelMap map) {
}

@PostMapping({"/create_employee", "/create_employee/"})
public String create_employee(Employee employee) {
public String create_employee(@Valid Employee employee) {


employeeService.save(employee);
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/heftyb/dms/crm/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import com.heftyb.dms.users.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

@Entity
Expand All @@ -19,9 +22,11 @@ public class Employee extends Auditable {
private boolean isActive = true;

@NotNull
@Size(min = 1)
private String firstName;

@NotNull
@Size(min = 1)
private String lastName;

@NotNull
Expand All @@ -46,7 +51,7 @@ public class Employee extends Auditable {

private JobTitle jobTitle;

private Date hiredDate;
private LocalDateTime hiredDate;


// private Employee manager;
Expand Down Expand Up @@ -83,7 +88,7 @@ public Employee() {
jobInProgress = false;
}

public Employee(String firstName, String lastName, String preferredName, Address address, ContactInformation contactInformation, String taxId, JobTitle jobTitle, Date hiredDate) {
public Employee(String firstName, String lastName, String preferredName, Address address, ContactInformation contactInformation, String taxId, JobTitle jobTitle, LocalDateTime hiredDate) {
this.firstName = firstName;
this.lastName = lastName;
this.preferredName = preferredName;
Expand Down Expand Up @@ -174,11 +179,11 @@ public void setJobTitle(JobTitle jobTitle) {
this.jobTitle = jobTitle;
}

public Date getHiredDate() {
public LocalDateTime getHiredDate() {
return hiredDate;
}

public void setHiredDate(Date hiredDate) {
public void setHiredDate(LocalDateTime hiredDate) {
this.hiredDate = hiredDate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public Employee findById(long id) {

@Override
public Employee save(Employee employee) {
Employee e = new Employee();
Employee e;
if (employee.getId() != 0) {
e = findById(employee.getId());
} else {
e = new Employee();
}
e.setActive(employee.isActive());
e.setFirstName(employee.getFirstName());
e.setLastName(employee.getLastName());
e.setPreferredName(employee.getPreferredName());
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/heftyb/dms/repairorder/RepairOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -68,8 +67,7 @@ public class RepairOrder extends Auditable {
private boolean isActive;

@NotNull
@Size(max = 1)
@Pattern(regexp = "/([0-9])+/g")
@Pattern(regexp = "[0-9]")
private String priority = "0";


Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/heftyb/dms/users/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Role {

private String role;

@Enumerated(EnumType.STRING)
private RoleDepartment department;

@OneToMany(mappedBy = "role",
cascade = CascadeType.ALL,
Expand Down Expand Up @@ -58,11 +60,20 @@ public void setUsers(Set<UserRole> users) {
this.users = users;
}

public RoleDepartment getDepartment() {
return department;
}

public void setDepartment(RoleDepartment department) {
this.department = department;
}

@Override
public String toString() {
return "Role{" +
"id=" + id +
", role='" + role + '\'' +
", department=" + department +
'}';
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/heftyb/dms/users/RoleDepartment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.heftyb.dms.users;

public enum RoleDepartment {
SHARED, OFFICE, SALES, SERVICE, PARTS, TECH_DEV
}
39 changes: 39 additions & 0 deletions src/main/java/com/heftyb/dms/users/controllers/RoleController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.heftyb.dms.users.controllers;

import com.heftyb.dms.users.Role;
import com.heftyb.dms.users.RoleDepartment;
import com.heftyb.dms.users.services.RoleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/admin/roles")
@PreAuthorize("hasRole('ADMIN')")
public class RoleController {

private final RoleService roleService;

public RoleController(final RoleService roleService) {
this.roleService = roleService;
}

@PostMapping({"/create", "/create/"})
public String createNewRole(@RequestParam String role, @RequestParam RoleDepartment department) {
Role r = new Role();
r.setRole(role);
r.setDepartment(department);
roleService.save(r);

return "redirect:/admin";
}

@PostMapping({"/delete", "/delete/"})
public String deleteRole(@RequestParam long roleId) {
roleService.delete(roleId);

return "redirect:/admin";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface RoleService {

Role save(Role role);

void Delete(long id);
void delete(long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public Role save(Role role) {
}
Role r = new Role();
r.setRole(role.getRole());

r.setDepartment(role.getDepartment());
return roleRepo.save(r);
}

@Override
public void Delete(long id) {
public void delete(long id) {
findById(id);
roleRepo.deleteById(id);
}
Expand Down
23 changes: 18 additions & 5 deletions src/main/resources/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,17 @@ body {
display: flex;
flex-direction: column;
justify-content: space-evenly;
color: white;
background-color: black;
/*color: white;*/
/*background-color: black;*/
height: 100vh;
position: sticky;
top: 0;
}

.side-navbar-open {
width: 20%;
opacity: 30%;
/*width: 20%;*/
/*opacity: 30%;*/
/*position: sticky;*/
}

.side-navbar-closed {
Expand Down Expand Up @@ -365,7 +369,7 @@ td a {
justify-content: center;
}

.edit-button-wrapper {
.edit-button-wrapper, .flex-between {
display: flex;
justify-content: space-between;
}
Expand Down Expand Up @@ -810,4 +814,13 @@ td a {
/*overflow: hidden;*/
/*text-decoration: underline;*/
/*text-underline: black;*/
}

.flex-col {
display: flex;
flex-direction: column;
}

.just-cent {
justify-content: center;
}
Loading
Loading