-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
9a47205
commit ce2c4f7
Showing
9 changed files
with
219 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
server/src/main/java/io/flexwork/modules/teams/service/TeamRequestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.flexwork.modules.teams.service; | ||
|
||
import io.flexwork.modules.teams.domain.TeamRequest; | ||
import io.flexwork.modules.teams.repository.TeamRequestRepository; | ||
import io.flexwork.modules.teams.service.dto.TeamRequestDTO; | ||
import io.flexwork.modules.teams.service.mapper.TeamRequestMapper; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.jclouds.rest.ResourceNotFoundException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
public class TeamRequestService { | ||
|
||
private final TeamRequestRepository teamRequestRepository; | ||
private final TeamRequestMapper teamRequestMapper; // Assume a MapStruct mapper | ||
|
||
@Autowired | ||
public TeamRequestService( | ||
TeamRequestRepository teamRequestRepository, TeamRequestMapper teamRequestMapper) { | ||
this.teamRequestRepository = teamRequestRepository; | ||
this.teamRequestMapper = teamRequestMapper; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<TeamRequestDTO> getAllTeamRequests() { | ||
return teamRequestRepository.findAll().stream() | ||
.map(teamRequestMapper::toDto) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public TeamRequestDTO getTeamRequestById(Long id) { | ||
TeamRequest teamRequest = | ||
teamRequestRepository | ||
.findById(id) | ||
.orElseThrow( | ||
() -> | ||
new ResourceNotFoundException( | ||
"TeamRequest not found with id: " + id)); | ||
return teamRequestMapper.toDto(teamRequest); | ||
} | ||
|
||
@Transactional | ||
public TeamRequestDTO createTeamRequest(TeamRequestDTO teamRequestDTO) { | ||
TeamRequest teamRequest = teamRequestMapper.toEntity(teamRequestDTO); | ||
teamRequest.setCreatedDate(LocalDateTime.now()); // Example of setting default value | ||
teamRequest = teamRequestRepository.save(teamRequest); | ||
return teamRequestMapper.toDto(teamRequest); | ||
} | ||
|
||
@Transactional | ||
public TeamRequestDTO updateTeamRequest(Long id, TeamRequestDTO teamRequestDTO) { | ||
TeamRequest existingTeamRequest = | ||
teamRequestRepository | ||
.findById(id) | ||
.orElseThrow( | ||
() -> | ||
new ResourceNotFoundException( | ||
"TeamRequest not found with id: " + id)); | ||
|
||
teamRequestMapper.updateEntity(teamRequestDTO, existingTeamRequest); // Update fields | ||
existingTeamRequest = teamRequestRepository.save(existingTeamRequest); | ||
return teamRequestMapper.toDto(existingTeamRequest); | ||
} | ||
|
||
@Transactional | ||
public void deleteTeamRequest(Long id) { | ||
if (!teamRequestRepository.existsById(id)) { | ||
throw new ResourceNotFoundException("TeamRequest not found with id: " + id); | ||
} | ||
teamRequestRepository.deleteById(id); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
server/src/main/java/io/flexwork/modules/teams/service/dto/TeamRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.flexwork.modules.teams.service.dto; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class TeamRequestDTO { | ||
private Long id; | ||
private Long teamId; | ||
private String teamName; | ||
private Long workflowId; | ||
private String workflowName; | ||
private Long requestUserId; | ||
private String requestUserName; | ||
private Long assignUserId; | ||
private String assignUserName; | ||
private String requestTitle; | ||
private String requestDescription; | ||
private LocalDateTime createdDate; | ||
private String currentState; | ||
} |
43 changes: 43 additions & 0 deletions
43
server/src/main/java/io/flexwork/modules/teams/service/mapper/TeamRequestMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.flexwork.modules.teams.service.mapper; | ||
|
||
import io.flexwork.modules.teams.domain.TeamRequest; | ||
import io.flexwork.modules.teams.domain.Workflow; | ||
import io.flexwork.modules.teams.service.dto.TeamRequestDTO; | ||
import io.flexwork.modules.usermanagement.domain.Team; | ||
import io.flexwork.modules.usermanagement.domain.User; | ||
import org.mapstruct.BeanMapping; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.MappingTarget; | ||
import org.mapstruct.Named; | ||
import org.mapstruct.NullValuePropertyMappingStrategy; | ||
|
||
@Mapper(componentModel = "spring") | ||
public interface TeamRequestMapper { | ||
|
||
TeamRequestDTO toDto(TeamRequest teamRequest); | ||
|
||
@Mapping(target = "team", source = "teamId", qualifiedByName = "toTeam") | ||
@Mapping(target = "workflow", source = "workflowId", qualifiedByName = "toWorkflow") | ||
@Mapping(target = "requestUser", source = "requestUserId", qualifiedByName = "toUser") | ||
@Mapping(target = "assignUser", source = "assignUserId", qualifiedByName = "toUser") | ||
TeamRequest toEntity(TeamRequestDTO teamRequestDTO); | ||
|
||
@Named("toTeam") | ||
default Team toTeam(Long teamId) { | ||
return (teamId == null) ? null : Team.builder().id(teamId).build(); | ||
} | ||
|
||
@Named("toWorkflow") | ||
default Workflow toWorkflow(Long workflowId) { | ||
return (workflowId == null) ? null : Workflow.builder().id(workflowId).build(); | ||
} | ||
|
||
@Named("toUser") | ||
default User toUser(Long userId) { | ||
return (userId == null) ? null : User.builder().id(userId).build(); | ||
} | ||
|
||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) | ||
void updateEntity(TeamRequestDTO dto, @MappingTarget TeamRequest entity); | ||
} |
48 changes: 48 additions & 0 deletions
48
server/src/main/java/io/flexwork/modules/teams/web/rest/TeamRequestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.flexwork.modules.teams.web.rest; | ||
|
||
import io.flexwork.modules.teams.service.TeamRequestService; | ||
import io.flexwork.modules.teams.service.dto.TeamRequestDTO; | ||
import java.util.List; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/api/team-requests") | ||
public class TeamRequestController { | ||
|
||
private final TeamRequestService teamRequestService; | ||
|
||
public TeamRequestController(TeamRequestService teamRequestService) { | ||
this.teamRequestService = teamRequestService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<TeamRequestDTO>> getAllTeamRequests() { | ||
return ResponseEntity.ok(teamRequestService.getAllTeamRequests()); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<TeamRequestDTO> getTeamRequestById(@PathVariable Long id) { | ||
return ResponseEntity.ok(teamRequestService.getTeamRequestById(id)); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<TeamRequestDTO> createTeamRequest( | ||
@RequestBody TeamRequestDTO teamRequestDTO) { | ||
TeamRequestDTO createdTeamRequest = teamRequestService.createTeamRequest(teamRequestDTO); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(createdTeamRequest); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<TeamRequestDTO> updateTeamRequest( | ||
@PathVariable Long id, @RequestBody TeamRequestDTO teamRequestDTO) { | ||
return ResponseEntity.ok(teamRequestService.updateTeamRequest(id, teamRequestDTO)); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteTeamRequest(@PathVariable Long id) { | ||
teamRequestService.deleteTeamRequest(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters