мой API продолжает возвращать ноль из столбца mongoDB, где существуют данные - PullRequest
0 голосов
/ 05 октября 2019

API загрузки My Spring для извлечения списка всех учетных записей портала по appCode из моего mongoDB возвращает null (где данные существуют в БД) для некоторых полей, как мне получить данные null?

Это часть моей коллекции БД

{"_id":"5d927f14c61810332425ee7f","portalAccount":{"_id":"5d927f13c61810332425ee7d","name":"Codelab2","dateCreated":"2019-09-30T22:17:55.929Z","code":"CL-ACCT-   2","status":"ACTIVE","accountType":"CODELAB"},"portalUser":{"_id":"5d927f14c61810332425ee7e","username":"iyke","password":"$2a$10$29j8SONBRdqGtYUtonJ9bulmdiPhUiyB5kj9sZHK.zICnXkh3YlA6","lastName":"Ezugworie","firstName":"Ikechukwu","email":"i.ezugworie@gmail.com","resetPassword":true,"failedLoginAttemptsSinceLastSuccessful":"0","locked":false,"dateCreated":"2019-09-30T22:17:55.933Z"},"status":"ACTIVE","role":{"_id":"5d8f7a58c6181021c820afc9","name":"ADMIN","status":"ACTIVE","permissions":[{"name":"CREATE_APP","status":"ACTIVE"}]},"app":{"_id":"5d8f7a57c6181021c820afc8","name":"Codelab Account","code":"CL-001","description":"Account App for Codelab","status":"ACTIVE","apiKeys":[{"key":"2FCUSKSHFU===sfsh13Xa","status":"ACTIVE"}]},"_class":"com.codelab.accounts.domain.entity.account.Membership"}

{"_id":"5d927f3bc61810332425ee82","portalAccount":{"_id":"5d927f3ac61810332425ee80","name":"Codelab2","dateCreated":"2019-09-30T22:18:34.895Z","code":"CL-ACCT-   3","status":"ACTIVE","accountType":"CODELAB"},"portalUser":{"_id":"5d927f3bc61810332425ee81","username":"bille","password":"$2a$10$.ERPBlkPF6rPHs1aAV9rpeNodqb83T2M1eI/mweW4zrD9xYDF3NpC","lastName":"Bille","firstName":"Ibinabo","email":"ibille@gmail.com","resetPassword":true,"failedLoginAttemptsSinceLastSuccessful":"0","locked":false,"dateCreated":"2019-09-30T22:18:34.915Z"},"status":"ACTIVE","role":{"_id":"5d8f7a58c6181021c820afc9","name":"ADMIN","status":"ACTIVE","permissions":[{"name":"CREATE_APP","status":"ACTIVE"}]},"app":{"_id":"5d8f7a57c6181021c820afc8","name":"Codelab Account","code":"CL-001","description":"Account App for Codelab","status":"ACTIVE","apiKeys":[{"key":"2FCUSKSHFU===sfsh13Xa","status":"ACTIVE"}]},"_class":"com.codelab.accounts.domain.entity.account.Membership"}

Вот мой контроллер

    public ResponseEntity<?> accounts(@RequestHeader("X-APP-CODE") String appCode,
                                      @RequestParam("limit") int limit,
                                      @RequestParam("offset") int offset) {
       List<PortalAccountDto> portalAccount = accountService.getAllPortalAccount(appCode, limit, offset);
       if ( portalAccount.isEmpty()){
         throw  new NotFoundException("Portal Account with app code "+appCode+ " not found" );
       }
        return ResponseEntity.ok(portalAccount);
    }

Вот мой сервис

 List<PortalAccountDto>
    getAllPortalAccount(String appCode, int limit, int offset);

И мой сервисРеализация

 @Override
    public List<PortalAccountDto> getAllPortalAccount(String appCode, 
                                                      int limit,
                                                      int offset) {
        QPortalAccount qPortalAccount = new QPortalAccount(QPortalAccount.portalAccount);
        QMembership qMembership = new QMembership(QMembership.membership);
        Predicate predicate =  qMembership.app.code.endsWithIgnoreCase(appCode.trim());
        logger.debug("Get all Portal Accounts with limit {} and offset {}", limit, offset);
        Pageable pageable = new OffsetBasedPageRequest(limit, offset);
        return membershipRepository.findByAppCode(appCode, pageable);
    }

И Репозиторий

public interface MembershipRepository extends MongoRepository<Membership, String>, QuerydslPredicateExecutor<Membership>{

    List<PortalAccountDto> findByAppCode(String appCode, Pageable pageable);

}

Ожидаемый результат

[
 {
        "id": "5d927f13c61810332425ee7d",
        "name": "Codelab2",
        "dateCreated": "2019-09-30T22:17:55.929Z",
        "code": "CL-ACCT-   2",
        "status": "ACTIVE",
        "accountType": "CODELAB"
    },
    {
        "id": "5d927f3ac61810332425ee80",
        "name": Codelab2,
        "dateCreated": "2019-09-30T22:18:34.895Z",
        "code": "CL-ACCT-   3",
        "status": "ACTIVE",
        "accountType": "CODELAB"
    }
]

Но фактический результат

[
 {
        "id": "5d927fe0c61810332425ef03",
        "name": null,
        "dateCreated": null,
        "code": null,
        "status": "ACTIVE",
        "accountType": null
    },
    {
        "id": "5d927fe0c61810332425ef00",
        "name": null,
        "dateCreated": null,
        "code": null,
        "status": "ACTIVE",
        "accountType": null
    }
]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...