Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen committed Dec 2, 2024
1 parent 4cefab0 commit c09edd0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public TeamRequestFieldHandlerRegistry(

@Override
protected void initializeFieldHandlers() {
addFieldHandler("requestTitle", new EntityFieldHandler<TeamRequestDTO>("Title"));
addFieldHandler(
"requestDescription", new EntityFieldHandler<TeamRequestDTO>("Description"));
addFieldHandler("priority", new EntityFieldHandler<TeamRequestDTO>("Priority"));
addFieldHandler(
"channel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public TeamDTO createTeam(TeamDTO teamDTO) {
return teamMapper.toDto(teamRepository.save(team));
}

public Team updateTeam(TeamDTO updatedTeam) {
public TeamDTO updateTeam(TeamDTO updatedTeam) {
Team existingTeam =
teamRepository
.findById(updatedTeam.getId())
Expand All @@ -80,7 +80,7 @@ public Team updateTeam(TeamDTO updatedTeam) {
"Team not found with id: " + updatedTeam.getId()));
teamMapper.updateFromDto(updatedTeam, existingTeam);

return teamRepository.save(existingTeam);
return teamMapper.toDto(teamRepository.save(existingTeam));
}

public void deleteTeam(Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.flexwork.modules.fss.ResourceRemoveEvent;
import io.flexwork.modules.fss.service.StorageService;
import io.flexwork.modules.teams.domain.Team;
import io.flexwork.modules.teams.service.TeamService;
import io.flexwork.modules.teams.service.dto.TeamDTO;
import io.flexwork.modules.usermanagement.service.dto.UserDTO;
Expand Down Expand Up @@ -74,7 +73,7 @@ public ResponseEntity<TeamDTO> createTeam(
}

@PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Team> updateTeam(
public ResponseEntity<TeamDTO> updateTeam(
@RequestPart("teamDTO") TeamDTO team,
@RequestPart(value = "file", required = false) MultipartFile file)
throws Exception {
Expand All @@ -87,7 +86,7 @@ public ResponseEntity<Team> updateTeam(
"teams", UUID.randomUUID().toString(), file.getInputStream());
team.setLogoUrl(teamLogoPath);
}
Team updatedTeam = teamService.updateTeam(team);
TeamDTO updatedTeam = teamService.updateTeam(team);
// Remove the old logo
if (fileRemovedPath.isPresent()) {
eventPublisher.publishEvent(new ResourceRemoveEvent(this, fileRemovedPath.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.flexwork.modules.usermanagement.domain.User;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand Down Expand Up @@ -31,5 +32,6 @@ List<User> findUsersNotInAuthority(
Pageable pageable);

@Query("SELECT u FROM User u JOIN u.authorities a WHERE a.name = :authorityName")
List<User> findAllUsersByAuthority(@Param("authorityName") String authorityName);
Page<User> findUsersByAuthority(
@Param("authorityName") String authorityName, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.flexwork.modules.usermanagement.service.mapper.UserMapper;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -83,10 +82,10 @@ public Optional<AuthorityDTO> findAuthorityByName(String authorityName) {
}

@Transactional(readOnly = true)
public List<UserDTO> findAllUsersByAuthority(String authorityName) {
return authorityRepository.findAllUsersByAuthority(authorityName).stream()
.map(userMapper::toDto)
.collect(Collectors.toList());
public Page<UserDTO> findAllUsersByAuthority(String authorityName, Pageable pageable) {
return authorityRepository
.findUsersByAuthority(authorityName, pageable)
.map(userMapper::toDto);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,9 @@ public ResponseEntity<Void> deleteAuthority(@PathVariable("id") String id) {
}

@GetMapping("/{authorityName}/users")
public ResponseEntity<List<UserDTO>> getUsersByAuthority(@PathVariable String authorityName) {
List<UserDTO> users = authorityService.findAllUsersByAuthority(authorityName);

if (users.isEmpty()) {
return ResponseEntity.noContent().build();
}

public ResponseEntity<Page<UserDTO>> getUsersByAuthority(
@PathVariable String authorityName, Pageable pageable) {
Page<UserDTO> users = authorityService.findAllUsersByAuthority(authorityName, pageable);
return ResponseEntity.ok(users);
}

Expand Down

0 comments on commit c09edd0

Please sign in to comment.