Search in sources :

Example 1 with UserNeed

use of won.owner.model.UserNeed in project webofneeds by researchstudio-sat.

the class WonWebSocketHandler method saveNeedUriWithUser.

private void saveNeedUriWithUser(final WonMessage wonMessage, final WebSocketSession session) {
    User user = getUserForSession(session);
    URI needURI = wonMessage.getReceiverNeedURI();
    UserNeed userNeed = new UserNeed(needURI);
    // reload the user so we can save it
    // (the user object we get from getUserForSession is detached)
    user = userRepository.findOne(user.getId());
    userNeedRepository.save(userNeed);
    user.addNeedUri(userNeed);
    userRepository.save(user);
}
Also used : User(won.owner.model.User) UserNeed(won.owner.model.UserNeed) URI(java.net.URI)

Example 2 with UserNeed

use of won.owner.model.UserNeed in project webofneeds by researchstudio-sat.

the class RestNeedController method getAllNeedsOfUser.

/**
 * returns a List containing needs belonging to the user
 * @return JSON List of need objects
 */
@ResponseBody
@RequestMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
public List<URI> getAllNeedsOfUser() {
    logger.info("Getting all needs of user: ");
    User user = getCurrentUser();
    List<UserNeed> userNeeds = user.getUserNeeds();
    List<URI> needUris = new ArrayList(userNeeds.size());
    for (UserNeed userNeed : userNeeds) {
        needUris.add(userNeed.getUri());
    }
    return needUris;
}
Also used : User(won.owner.model.User) UserNeed(won.owner.model.UserNeed) ArrayList(java.util.ArrayList) URI(java.net.URI) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

URI (java.net.URI)2 User (won.owner.model.User)2 UserNeed (won.owner.model.UserNeed)2 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1