| @@ -4,7 +4,11 @@ import com.ffii.core.support.AbstractRepository; | |||||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo; | import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Optional; | |||||
| public interface DepartmentRepository extends AbstractRepository<Department, Long> { | public interface DepartmentRepository extends AbstractRepository<Department, Long> { | ||||
| List<DepartmentSearchInfo> findDepartmentSearchInfoBy(); | |||||
| List<DepartmentSearchInfo> findDepartmentSearchInfoByAndDeletedFalse(); | |||||
| Optional<DepartmentSearchInfo> findDepartmentSearchInfoById(Long departmentId); | |||||
| } | } | ||||
| @@ -6,7 +6,10 @@ import com.ffii.tsms.modules.data.entity.Department | |||||
| import com.ffii.tsms.modules.data.entity.DepartmentRepository | import com.ffii.tsms.modules.data.entity.DepartmentRepository | ||||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | ||||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | ||||
| import com.ffii.tsms.modules.project.web.models.EditProjectDetails | |||||
| import org.springframework.beans.BeanUtils | |||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| import kotlin.jvm.optionals.getOrNull | |||||
| @Service | @Service | ||||
| open class DepartmentService( | open class DepartmentService( | ||||
| @@ -14,20 +17,32 @@ open class DepartmentService( | |||||
| private val jdbcDao: JdbcDao, | private val jdbcDao: JdbcDao, | ||||
| ) : AbstractBaseEntityService<Department, Long, DepartmentRepository>(jdbcDao, departmentRepository) { | ) : AbstractBaseEntityService<Department, Long, DepartmentRepository>(jdbcDao, departmentRepository) { | ||||
| open fun allDepartments(): List<DepartmentSearchInfo>{ | open fun allDepartments(): List<DepartmentSearchInfo>{ | ||||
| return departmentRepository.findDepartmentSearchInfoBy() | |||||
| return departmentRepository.findDepartmentSearchInfoByAndDeletedFalse() | |||||
| } | } | ||||
| open fun saveDepartment(request: NewDepartmentRequest): Department { | open fun saveDepartment(request: NewDepartmentRequest): Department { | ||||
| val department = | |||||
| Department().apply { | |||||
| name = request.departmentName | |||||
| code = request.departmentCode | |||||
| description = request.description | |||||
| } | |||||
| var department = Department() | |||||
| if (request.id != null && request.id > 0) { | |||||
| department = departmentRepository.findById(request.id).orElseThrow() | |||||
| BeanUtils.copyProperties(request, department) | |||||
| }else{ | |||||
| department.name = request.name | |||||
| department.code = request.code | |||||
| department.description = request.description | |||||
| } | |||||
| return departmentRepository.save(department) | return departmentRepository.save(department) | ||||
| } | } | ||||
| open fun getDepartmentDetails(departmentId: Long): DepartmentSearchInfo? { | |||||
| val department = departmentRepository.findDepartmentSearchInfoById(departmentId).orElseThrow() | |||||
| return department | |||||
| } | |||||
| open fun combo(args: Map<String, Any>): List<Map<String, Any>> { | open fun combo(args: Map<String, Any>): List<Map<String, Any>> { | ||||
| val sql = StringBuilder("select" | val sql = StringBuilder("select" | ||||
| + " d.id as id," | + " d.id as id," | ||||
| @@ -12,6 +12,7 @@ import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||||
| import com.ffii.tsms.modules.data.entity.projections.PositionSearchInfo | import com.ffii.tsms.modules.data.entity.projections.PositionSearchInfo | ||||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | ||||
| import com.ffii.tsms.modules.data.web.models.NewPositionRequest | import com.ffii.tsms.modules.data.web.models.NewPositionRequest | ||||
| import org.springframework.beans.BeanUtils | |||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| @Service | @Service | ||||
| open class PositionService( | open class PositionService( | ||||
| @@ -27,12 +28,19 @@ open class PositionService( | |||||
| } | } | ||||
| open fun savePosition(request: NewPositionRequest): Position { | open fun savePosition(request: NewPositionRequest): Position { | ||||
| val position = | |||||
| Position().apply { | |||||
| name = request.positionName | |||||
| code = request.positionCode | |||||
| description = request.description | |||||
| } | |||||
| var position = Position() | |||||
| if (request.id != null && request.id > 0 ){ | |||||
| position = positionRepository.findById(request.id).orElseThrow() | |||||
| BeanUtils.copyProperties(request, position) | |||||
| }else{ | |||||
| position.name = request.name | |||||
| position.code = request.code | |||||
| position.description = request.description | |||||
| } | |||||
| return positionRepository.save(position) | return positionRepository.save(position) | ||||
| } | } | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.ffii.tsms.modules.data.web | package com.ffii.tsms.modules.data.web | ||||
| import com.ffii.core.exception.NotFoundException | |||||
| import com.ffii.core.response.RecordsRes | import com.ffii.core.response.RecordsRes | ||||
| import com.ffii.core.utils.CriteriaArgsBuilder | import com.ffii.core.utils.CriteriaArgsBuilder | ||||
| import com.ffii.tsms.modules.data.entity.Department | import com.ffii.tsms.modules.data.entity.Department | ||||
| @@ -7,9 +8,11 @@ import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||||
| import com.ffii.tsms.modules.data.service.DepartmentService | import com.ffii.tsms.modules.data.service.DepartmentService | ||||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | ||||
| import com.ffii.tsms.modules.project.entity.Project | import com.ffii.tsms.modules.project.entity.Project | ||||
| import com.ffii.tsms.modules.project.web.models.EditProjectDetails | |||||
| import com.ffii.tsms.modules.project.web.models.NewProjectRequest | import com.ffii.tsms.modules.project.web.models.NewProjectRequest | ||||
| import jakarta.servlet.http.HttpServletRequest | import jakarta.servlet.http.HttpServletRequest | ||||
| import jakarta.validation.Valid | import jakarta.validation.Valid | ||||
| import org.springframework.http.HttpStatus | |||||
| import org.springframework.web.bind.ServletRequestBindingException | import org.springframework.web.bind.ServletRequestBindingException | ||||
| import org.springframework.web.bind.annotation.* | import org.springframework.web.bind.annotation.* | ||||
| @@ -22,11 +25,22 @@ class DepartmentController(private val departmentService: DepartmentService | |||||
| return departmentService.allDepartments() | return departmentService.allDepartments() | ||||
| } | } | ||||
| @GetMapping("/departmentDetails/{id}") | |||||
| fun departmentDetails(@PathVariable id: Long): DepartmentSearchInfo { | |||||
| return departmentService.getDepartmentDetails(id) ?: throw NotFoundException() | |||||
| } | |||||
| @PostMapping("/new") | @PostMapping("/new") | ||||
| fun saveProject(@Valid @RequestBody newDepartment: NewDepartmentRequest): Department { | fun saveProject(@Valid @RequestBody newDepartment: NewDepartmentRequest): Department { | ||||
| return departmentService.saveDepartment(newDepartment) | return departmentService.saveDepartment(newDepartment) | ||||
| } | } | ||||
| @DeleteMapping("/{id}") | |||||
| @ResponseStatus(HttpStatus.NO_CONTENT) | |||||
| fun deleteDepartment(@PathVariable id: Long) { | |||||
| departmentService.markDelete(id) | |||||
| } | |||||
| @GetMapping("/combo") | @GetMapping("/combo") | ||||
| @Throws(ServletRequestBindingException::class) | @Throws(ServletRequestBindingException::class) | ||||
| fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> { | fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> { | ||||
| @@ -14,6 +14,7 @@ import com.ffii.tsms.modules.project.entity.Project | |||||
| import com.ffii.tsms.modules.project.web.models.NewProjectRequest | import com.ffii.tsms.modules.project.web.models.NewProjectRequest | ||||
| import jakarta.servlet.http.HttpServletRequest | import jakarta.servlet.http.HttpServletRequest | ||||
| import jakarta.validation.Valid | import jakarta.validation.Valid | ||||
| import org.springframework.http.HttpStatus | |||||
| import org.springframework.web.bind.ServletRequestBindingException | import org.springframework.web.bind.ServletRequestBindingException | ||||
| import org.springframework.web.bind.annotation.* | import org.springframework.web.bind.annotation.* | ||||
| @@ -36,6 +37,12 @@ class PositionController(private val positionService: PositionService | |||||
| return positionService.savePosition(newPosition) | return positionService.savePosition(newPosition) | ||||
| } | } | ||||
| @DeleteMapping("/{id}") | |||||
| @ResponseStatus(HttpStatus.NO_CONTENT) | |||||
| fun deletePosition(@PathVariable id: Long) { | |||||
| positionService.markDelete(id) | |||||
| } | |||||
| @GetMapping("/combo") | @GetMapping("/combo") | ||||
| @Throws(ServletRequestBindingException::class) | @Throws(ServletRequestBindingException::class) | ||||
| fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> { | fun combo(request: HttpServletRequest?): RecordsRes<Map<String, Any>> { | ||||
| @@ -3,10 +3,11 @@ package com.ffii.tsms.modules.data.web.models | |||||
| import jakarta.validation.constraints.NotBlank | import jakarta.validation.constraints.NotBlank | ||||
| data class NewDepartmentRequest ( | data class NewDepartmentRequest ( | ||||
| val id: Long?, | |||||
| @field: NotBlank(message = "Department code cannot be empty") | @field: NotBlank(message = "Department code cannot be empty") | ||||
| val departmentCode: String, | |||||
| val code: String, | |||||
| @field:NotBlank(message = "Department name cannot be empty") | @field:NotBlank(message = "Department name cannot be empty") | ||||
| val departmentName: String, | |||||
| val name: String, | |||||
| val description: String | val description: String | ||||
| ) | ) | ||||
| @@ -4,12 +4,12 @@ import jakarta.validation.constraints.NotBlank | |||||
| data class NewPositionRequest ( | data class NewPositionRequest ( | ||||
| val id: Long, | |||||
| val id: Long?, | |||||
| @field: NotBlank(message = "Position code cannot be empty") | @field: NotBlank(message = "Position code cannot be empty") | ||||
| val positionCode: String, | |||||
| val code: String, | |||||
| @field:NotBlank(message = "Position name cannot be empty") | @field:NotBlank(message = "Position name cannot be empty") | ||||
| val positionName: String, | |||||
| val name: String, | |||||
| val description: String | val description: String | ||||
| ) | ) | ||||