- save - get the list (name, code, description) 2. Add Position API - save - get the list (name, code, description)tags/Baseline_30082024_BACKEND_UAT
| @@ -1,6 +1,10 @@ | |||||
| package com.ffii.tsms.modules.data.entity; | package com.ffii.tsms.modules.data.entity; | ||||
| import com.ffii.core.support.AbstractRepository; | import com.ffii.core.support.AbstractRepository; | ||||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo; | |||||
| import java.util.List; | |||||
| public interface DepartmentRepository extends AbstractRepository<Department, Long> { | public interface DepartmentRepository extends AbstractRepository<Department, Long> { | ||||
| List<DepartmentSearchInfo> findDepartmentSearchInfoBy(); | |||||
| } | } | ||||
| @@ -1,6 +1,11 @@ | |||||
| package com.ffii.tsms.modules.data.entity; | package com.ffii.tsms.modules.data.entity; | ||||
| import com.ffii.core.support.AbstractRepository; | import com.ffii.core.support.AbstractRepository; | ||||
| import com.ffii.tsms.modules.data.entity.projections.PositionSearchInfo; | |||||
| import java.util.List; | |||||
| public interface PositionRepository extends AbstractRepository<Position, Long> { | public interface PositionRepository extends AbstractRepository<Position, Long> { | ||||
| List<PositionSearchInfo> findPositionSearchInfoBy(); | |||||
| } | } | ||||
| @@ -0,0 +1,12 @@ | |||||
| package com.ffii.tsms.modules.data.entity.projections; | |||||
| /** | |||||
| * Projection for {@link com.ffii.tsms.modules.data.entity.Company} | |||||
| */ | |||||
| public interface DepartmentSearchInfo { | |||||
| Long getId(); | |||||
| String getCode(); | |||||
| String getName(); | |||||
| String getDescription(); | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.ffii.tsms.modules.data.entity.projections; | |||||
| /** | |||||
| * Projection for {@link com.ffii.tsms.modules.data.entity.Company} | |||||
| */ | |||||
| public interface PositionSearchInfo { | |||||
| Long getId(); | |||||
| String getCode(); | |||||
| String getName(); | |||||
| String getDescription(); | |||||
| } | |||||
| @@ -0,0 +1,28 @@ | |||||
| package com.ffii.tsms.modules.data.service | |||||
| import com.ffii.tsms.modules.data.entity.CompanyRepository | |||||
| import com.ffii.tsms.modules.data.entity.Department | |||||
| import com.ffii.tsms.modules.data.entity.DepartmentRepository | |||||
| import com.ffii.tsms.modules.data.entity.projections.CompanySearchInfo | |||||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | |||||
| import org.springframework.stereotype.Service | |||||
| @Service | |||||
| class DepartmentService( | |||||
| private val departmentRepository: DepartmentRepository | |||||
| ) { | |||||
| fun allDepartments(): List<DepartmentSearchInfo>{ | |||||
| return departmentRepository.findDepartmentSearchInfoBy() | |||||
| } | |||||
| fun saveDepartment(request: NewDepartmentRequest): Department { | |||||
| val department = | |||||
| Department().apply { | |||||
| name = request.departmentName | |||||
| code = request.departmentCode | |||||
| description = request.description | |||||
| } | |||||
| return departmentRepository.save(department) | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,32 @@ | |||||
| package com.ffii.tsms.modules.data.service | |||||
| import com.ffii.tsms.modules.data.entity.CompanyRepository | |||||
| import com.ffii.tsms.modules.data.entity.Department | |||||
| import com.ffii.tsms.modules.data.entity.DepartmentRepository | |||||
| import com.ffii.tsms.modules.data.entity.Position | |||||
| import com.ffii.tsms.modules.data.entity.PositionRepository | |||||
| import com.ffii.tsms.modules.data.entity.projections.CompanySearchInfo | |||||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||||
| 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.NewPositionRequest | |||||
| import org.springframework.stereotype.Service | |||||
| @Service | |||||
| class PositionService( | |||||
| private val positionRepository: PositionRepository | |||||
| ) { | |||||
| fun allPositions(): List<PositionSearchInfo>{ | |||||
| return positionRepository.findPositionSearchInfoBy() | |||||
| } | |||||
| fun savePosition(request: NewPositionRequest): Position { | |||||
| val position = | |||||
| Position().apply { | |||||
| name = request.positionName | |||||
| code = request.positionCode | |||||
| description = request.description | |||||
| } | |||||
| return positionRepository.save(position) | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,25 @@ | |||||
| package com.ffii.tsms.modules.data.web | |||||
| import com.ffii.tsms.modules.data.entity.Department | |||||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||||
| import com.ffii.tsms.modules.data.service.DepartmentService | |||||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | |||||
| import com.ffii.tsms.modules.project.entity.Project | |||||
| import com.ffii.tsms.modules.project.web.models.NewProjectRequest | |||||
| import jakarta.validation.Valid | |||||
| import org.springframework.web.bind.annotation.* | |||||
| @RestController | |||||
| @RequestMapping("/departments") | |||||
| class DepartmentController(private val departmentService: DepartmentService | |||||
| ) { | |||||
| @GetMapping | |||||
| fun allDepartments(): List<DepartmentSearchInfo>{ | |||||
| return departmentService.allDepartments() | |||||
| } | |||||
| @PostMapping("/new") | |||||
| fun saveProject(@Valid @RequestBody newDepartment: NewDepartmentRequest): Department { | |||||
| return departmentService.saveDepartment(newDepartment) | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,29 @@ | |||||
| package com.ffii.tsms.modules.data.web | |||||
| import com.ffii.tsms.modules.data.entity.Department | |||||
| import com.ffii.tsms.modules.data.entity.Position | |||||
| import com.ffii.tsms.modules.data.entity.projections.DepartmentSearchInfo | |||||
| import com.ffii.tsms.modules.data.entity.projections.PositionSearchInfo | |||||
| import com.ffii.tsms.modules.data.service.DepartmentService | |||||
| import com.ffii.tsms.modules.data.service.PositionService | |||||
| import com.ffii.tsms.modules.data.web.models.NewDepartmentRequest | |||||
| import com.ffii.tsms.modules.data.web.models.NewPositionRequest | |||||
| import com.ffii.tsms.modules.project.entity.Project | |||||
| import com.ffii.tsms.modules.project.web.models.NewProjectRequest | |||||
| import jakarta.validation.Valid | |||||
| import org.springframework.web.bind.annotation.* | |||||
| @RestController | |||||
| @RequestMapping("/positions") | |||||
| class PositionController(private val positionService: PositionService | |||||
| ) { | |||||
| @GetMapping | |||||
| fun allPositions(): List<PositionSearchInfo>{ | |||||
| return positionService.allPositions() | |||||
| } | |||||
| @PostMapping("/new") | |||||
| fun saveProject(@Valid @RequestBody newPosition: NewPositionRequest): Position { | |||||
| return positionService.savePosition(newPosition) | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.ffii.tsms.modules.data.web.models | |||||
| import jakarta.validation.constraints.NotBlank | |||||
| data class NewDepartmentRequest ( | |||||
| @field: NotBlank(message = "Department code cannot be empty") | |||||
| val departmentCode: String, | |||||
| @field:NotBlank(message = "Department name cannot be empty") | |||||
| val departmentName: String, | |||||
| val description: String | |||||
| ) | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.ffii.tsms.modules.data.web.models | |||||
| import jakarta.validation.constraints.NotBlank | |||||
| data class NewPositionRequest ( | |||||
| @field: NotBlank(message = "Department code cannot be empty") | |||||
| val positionCode: String, | |||||
| @field:NotBlank(message = "Department name cannot be empty") | |||||
| val positionName: String, | |||||
| val description: String | |||||
| ) | |||||