@@ -82,16 +82,13 @@ public class JwtAuthenticationController { | |||||
} | } | ||||
private ResponseEntity<?> createAuthTokenResponse(JwtRequest authenticationRequest) { | private ResponseEntity<?> createAuthTokenResponse(JwtRequest authenticationRequest) { | ||||
final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername()); | |||||
if (userDetails == null) { | |||||
final User user = userDetailsService.loadUserByUsername(authenticationRequest.getUsername()); | |||||
if (user == null) { | |||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED) | return ResponseEntity.status(HttpStatus.UNAUTHORIZED) | ||||
.body(new ExceptionResponse(authenticationRequest.getUsername() + " not yet register in the system.", null)); | .body(new ExceptionResponse(authenticationRequest.getUsername() + " not yet register in the system.", null)); | ||||
} | } | ||||
final String accessToken = jwtTokenUtil.generateToken(userDetails); | |||||
final String refreshToken = jwtTokenUtil.createRefreshToken(userDetails.getUsername()).getToken(); | |||||
User user = userRepository.findByName(authenticationRequest.getUsername()).get(0); | |||||
final String accessToken = jwtTokenUtil.generateToken(user); | |||||
final String refreshToken = jwtTokenUtil.createRefreshToken(user.getUsername()).getToken(); | |||||
Set<AbilityModel> abilities = new HashSet<>(); | Set<AbilityModel> abilities = new HashSet<>(); | ||||
userAuthorityService.getUserAuthority(user).forEach(auth -> abilities.add(new AbilityModel(auth.getAuthority()))); | userAuthorityService.getUserAuthority(user).forEach(auth -> abilities.add(new AbilityModel(auth.getAuthority()))); | ||||
@@ -6,4 +6,6 @@ import com.ffii.tsms.modules.project.entity.projections.InvoiceSearchInfo | |||||
interface MilestoneRepository : AbstractRepository<Milestone, Long> { | interface MilestoneRepository : AbstractRepository<Milestone, Long> { | ||||
fun findInvoiceSearchInfoBy(): List<InvoiceSearchInfo> | fun findInvoiceSearchInfoBy(): List<InvoiceSearchInfo> | ||||
fun findAllByProject(project: Project): List<Milestone> | |||||
} | } |
@@ -3,4 +3,5 @@ package com.ffii.tsms.modules.project.entity; | |||||
import com.ffii.core.support.AbstractRepository | import com.ffii.core.support.AbstractRepository | ||||
interface ProjectTaskRepository : AbstractRepository<ProjectTask, Long> { | interface ProjectTaskRepository : AbstractRepository<ProjectTask, Long> { | ||||
fun findAllByProject(project: Project): List<ProjectTask> | |||||
} | } |
@@ -1,6 +1,8 @@ | |||||
package com.ffii.tsms.modules.project.entity; | package com.ffii.tsms.modules.project.entity; | ||||
import com.ffii.core.support.AbstractRepository | import com.ffii.core.support.AbstractRepository | ||||
import com.ffii.tsms.modules.data.entity.Staff | |||||
interface StaffAllocationRepository : AbstractRepository<StaffAllocation, Long> { | interface StaffAllocationRepository : AbstractRepository<StaffAllocation, Long> { | ||||
fun findAssignedProjectsByStaff(staff: Staff): List<StaffAllocation> | |||||
} | } |
@@ -1,5 +1,6 @@ | |||||
package com.ffii.tsms.modules.project.service | package com.ffii.tsms.modules.project.service | ||||
import com.ffii.tsms.modules.common.SecurityUtils | |||||
import com.ffii.tsms.modules.data.entity.* | import com.ffii.tsms.modules.data.entity.* | ||||
import com.ffii.tsms.modules.data.service.CustomerContactService | import com.ffii.tsms.modules.data.service.CustomerContactService | ||||
import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo | import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo | ||||
@@ -8,11 +9,14 @@ import com.ffii.tsms.modules.data.service.GradeService | |||||
import com.ffii.tsms.modules.project.entity.* | import com.ffii.tsms.modules.project.entity.* | ||||
import com.ffii.tsms.modules.project.entity.projections.InvoiceInfoSearchInfo | import com.ffii.tsms.modules.project.entity.projections.InvoiceInfoSearchInfo | ||||
import com.ffii.tsms.modules.project.entity.projections.InvoiceSearchInfo | import com.ffii.tsms.modules.project.entity.projections.InvoiceSearchInfo | ||||
import com.ffii.tsms.modules.project.web.models.AssignedProject | |||||
import com.ffii.tsms.modules.project.web.models.MilestoneInfo | |||||
import com.ffii.tsms.modules.project.web.models.NewProjectRequest | import com.ffii.tsms.modules.project.web.models.NewProjectRequest | ||||
import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
import org.springframework.transaction.annotation.Transactional | import org.springframework.transaction.annotation.Transactional | ||||
import java.time.LocalDate | import java.time.LocalDate | ||||
import java.time.format.DateTimeFormatter | import java.time.format.DateTimeFormatter | ||||
import kotlin.jvm.optionals.getOrNull | |||||
@Service | @Service | ||||
open class ProjectsService( | open class ProjectsService( | ||||
@@ -51,6 +55,33 @@ open class ProjectsService( | |||||
return projectRepository.findInvoiceInfoSearchInfoById(id) | return projectRepository.findInvoiceInfoSearchInfoById(id) | ||||
} | } | ||||
open fun allAssignedProjects(): List<AssignedProject> { | |||||
return SecurityUtils.getUser().getOrNull()?.let { user -> | |||||
staffRepository.findByUserId(user.id).getOrNull()?.let { staff -> | |||||
staffAllocationRepository.findAssignedProjectsByStaff(staff) | |||||
.mapNotNull { it.project?.let { project -> | |||||
AssignedProject( | |||||
id = project.id!!, | |||||
code = project.code!!, | |||||
name = project.name!!, | |||||
tasks = projectTaskRepository.findAllByProject(project).mapNotNull { pt -> pt.task }, | |||||
milestones = milestoneRepository.findAllByProject(project) | |||||
.filter { milestone -> milestone.taskGroup?.id != null } | |||||
.associateBy { milestone -> milestone.taskGroup!!.id!! } | |||||
.mapValues { (_, milestone) -> MilestoneInfo( | |||||
startDate = milestone.startDate?.format(DateTimeFormatter.ISO_LOCAL_DATE), | |||||
endDate = milestone.endDate?.format(DateTimeFormatter.ISO_LOCAL_DATE) | |||||
) }, | |||||
hoursAllocated = project.totalManhour ?: 0.0, | |||||
hoursAllocatedOther = 0.0, | |||||
hoursSpent = 0.0, | |||||
hoursSpentOther = 0.0 | |||||
) | |||||
} } | |||||
} | |||||
} ?: emptyList() | |||||
} | |||||
open fun allProjectCategories(): List<ProjectCategory> { | open fun allProjectCategories(): List<ProjectCategory> { | ||||
return projectCategoryRepository.findAll() | return projectCategoryRepository.findAll() | ||||
} | } | ||||
@@ -5,6 +5,7 @@ import com.ffii.tsms.modules.project.entity.projections.ProjectSearchInfo | |||||
import com.ffii.tsms.modules.project.entity.Project | import com.ffii.tsms.modules.project.entity.Project | ||||
import com.ffii.tsms.modules.project.entity.ProjectCategory | import com.ffii.tsms.modules.project.entity.ProjectCategory | ||||
import com.ffii.tsms.modules.project.service.ProjectsService | import com.ffii.tsms.modules.project.service.ProjectsService | ||||
import com.ffii.tsms.modules.project.web.models.AssignedProject | |||||
import com.ffii.tsms.modules.project.web.models.NewProjectRequest | import com.ffii.tsms.modules.project.web.models.NewProjectRequest | ||||
import jakarta.validation.Valid | import jakarta.validation.Valid | ||||
import org.springframework.web.bind.annotation.* | import org.springframework.web.bind.annotation.* | ||||
@@ -17,6 +18,11 @@ class ProjectsController(private val projectsService: ProjectsService) { | |||||
return projectsService.allProjects() | return projectsService.allProjects() | ||||
} | } | ||||
@GetMapping("/assignedProjects") | |||||
fun assignedProjects(): List<AssignedProject> { | |||||
return projectsService.allAssignedProjects() | |||||
} | |||||
@GetMapping("/categories") | @GetMapping("/categories") | ||||
fun projectCategories(): List<ProjectCategory> { | fun projectCategories(): List<ProjectCategory> { | ||||
return projectsService.allProjectCategories() | return projectsService.allProjectCategories() | ||||
@@ -0,0 +1,22 @@ | |||||
package com.ffii.tsms.modules.project.web.models | |||||
import com.ffii.tsms.modules.project.entity.Task | |||||
data class AssignedProject( | |||||
val id: Long, | |||||
val code: String, | |||||
val name: String, | |||||
val tasks: List<Task>, | |||||
val milestones: Map<Long, MilestoneInfo>, | |||||
// Manhour info | |||||
val hoursAllocated: Double, | |||||
val hoursAllocatedOther: Double, | |||||
val hoursSpent: Double, | |||||
val hoursSpentOther: Double, | |||||
) | |||||
data class MilestoneInfo( | |||||
val startDate: String?, | |||||
val endDate: String? | |||||
) |