Skip to content

Commit

Permalink
Add is groupchat consultant to response (Onlineberatung#659)
Browse files Browse the repository at this point in the history
* Add isGroupchatConsultant to /users/consultants/search response

* Add isGroupchatConsultant to /users/consultants/search response
  • Loading branch information
dodalovicgran authored and CarlosSoares committed Jun 20, 2023
1 parent 64fded1 commit d991584
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions api/useradminservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1224,8 +1224,11 @@ components:
type: integer
example: "1"
isGroupchatConsultant:
type: boolean
example: true
$ref: '#/components/schemas/IsGroupchatConsultant'

IsGroupchatConsultant:
type: boolean
example: true

UpdateAdminConsultantDTO:
type: object
Expand Down Expand Up @@ -1277,9 +1280,7 @@ components:
example: true
description: Flag that indicates does the user accepted new data privacy text
isGroupchatConsultant:
type: boolean
example: true

$ref: '#/components/schemas/IsGroupchatConsultant'

ConsultantDTO:
type: object
Expand Down Expand Up @@ -1323,6 +1324,8 @@ components:
type: array
items:
$ref: './../services/agencyadminservice.yaml#/components/schemas/AgencyAdminResponseDTO'
isGroupchatConsultant:
$ref: '#/components/schemas/IsGroupchatConsultant'

CreateAdminDTO:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
import de.caritas.cob.userservice.api.adapters.web.dto.PaginationLinks;
import de.caritas.cob.userservice.api.adapters.web.dto.UpdateAdminConsultantDTO;
import de.caritas.cob.userservice.api.adapters.web.dto.UpdateConsultantDTO;
import de.caritas.cob.userservice.api.config.auth.UserRole;
import de.caritas.cob.userservice.api.model.Consultant;
import de.caritas.cob.userservice.api.port.out.IdentityClient;
import de.caritas.cob.userservice.generated.api.adapters.web.controller.UseradminApi;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Service;

@Service
public class ConsultantDtoMapper implements DtoMapperUtils {
@Autowired private IdentityClient identityClient;

public UpdateAdminConsultantDTO updateAdminConsultantOf(
UpdateConsultantDTO updateConsultantDTO, Consultant consultant) {
Expand Down Expand Up @@ -110,6 +115,9 @@ public ConsultantDTO consultantDtoOf(Map<String, Object> consultantMap) {
consultant.setCreateDate((String) consultantMap.get("createdAt"));
consultant.setUpdateDate((String) consultantMap.get("updatedAt"));
consultant.setDeleteDate((String) consultantMap.get("deletedAt"));
val isGroupChatConsultant =
identityClient.userHasRole(consultant.getId(), UserRole.GROUP_CHAT_CONSULTANT.getValue());
consultant.setIsGroupchatConsultant(isGroupChatConsultant);

var agencies = new ArrayList<AgencyAdminResponseDTO>();
var agencyMaps = (ArrayList<Map<String, Object>>) consultantMap.get("agencies");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ void searchConsultantsShouldRespondOkAndFilterConsultantsByRestrictedAdminAgenci
.andExpect(jsonPath("_embedded[0]._embedded.lastname", containsString(infix)))
.andExpect(jsonPath("_embedded[*]._embedded.username", not(contains(nullValue()))))
.andExpect(jsonPath("_embedded[*]._embedded.email", not(contains(nullValue()))))
.andExpect(jsonPath("_embedded[0]._embedded.isGroupchatConsultant", is(true)))
.andExpect(jsonPath("_embedded[1]._embedded.isGroupchatConsultant", is(true)))
.andExpect(jsonPath("_embedded[0]._embedded.agencies", hasSize(1)))
.andExpect(
jsonPath("_embedded[0]._embedded.agencies[0].id", not(contains(nullValue()))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public void deleteUser(String userId) {}

@Override
public void deactivateUser(String userId) {}

@Override
public boolean userHasRole(String userId, String userRole) {
return true;
}
};
}
}

0 comments on commit d991584

Please sign in to comment.