Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Its my first time using angular and java. So Im learning from tasks. I already made a call from frontend to backend to retrieve a count number (sends number from frontend, searches the database and return the output from the query). Now I have a similar task to send the same number to backend but now when searching the database I receive 4 string returns and have to send that to frontend to output it. The problem is I don't know how to send 2 gets on the same endpoint.

Java
ItemService

public PayloadResponse<long> getCount(EntityRequest<long> request);

ItemServiceImpl

@Override
    public PayloadResponse<long> getCount(EntityRequest<long> request) {
        Long itemId = request.getEntity();
        Long count = itemDAO.getCount(itemId);
        PayloadResponse<long> response = new PayloadResponse<>(request, ResponseCode.OK, count);
        
        return response;
    }

ItemRestService

@GetMapping("/{itemId}/overview")
    public PayloadResponse<long> getCount(@PathVariable Long itemId) {
        var request = new EntityRequest<>(itemId);
        return itemService.getCount(request);
    }

ItemDAO

public Long getCount(Long itemId) {
        String hql = "select count( distinct m.id) from ItemEntity i join MapTileResourceEntity mtr on mtr.resourceId = :itemId "
                + "and mtr.resourceType = :resourceType join MapTileEntity mt on mt.id = mtr.mapTile.id join MapEntity m on m.id = mt.map.id";
        TypedQuery<long> query = entityManager.createQuery(hql, Long.class).setParameter("itemId", itemId).setParameter("resourceType",
                ObjectType.ITEM.getValue());
        return query.getSingleResult();
    }


What I have tried:

I tried making 2 getters with the same endpoint in frontend but it doesnt work
Posted
Updated 5-Jun-23 9:28am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900