Search in sources :

Example 1 with OrganizationDTO

use of org.c4sg.dto.OrganizationDTO in project c4sg-services by Code4SocialGood.

the class OrganizationController method updateOrganization.

@CrossOrigin
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
@ApiOperation(value = "Update an existing organization")
public Map<String, Object> updateOrganization(@ApiParam(value = "Updated organization object", required = true) @PathVariable("id") int id, @RequestBody @Valid OrganizationDTO organizationDTO) {
    System.out.println("**************Update : id=" + organizationDTO.getId() + "**************");
    Map<String, Object> responseData = null;
    try {
        OrganizationDTO updatedOrganization = organizationService.updateOrganization(id, organizationDTO);
        responseData = Collections.synchronizedMap(new HashMap<>());
        responseData.put("organization", updatedOrganization);
    } catch (Exception e) {
        System.err.println(e);
    }
    return responseData;
}
Also used : HashMap(java.util.HashMap) CreateOrganizationDTO(org.c4sg.dto.CreateOrganizationDTO) OrganizationDTO(org.c4sg.dto.OrganizationDTO) NotFoundException(org.c4sg.exception.NotFoundException) UserProjectException(org.c4sg.exception.UserProjectException) UserOrganizationException(org.c4sg.exception.UserOrganizationException) IOException(java.io.IOException) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with OrganizationDTO

use of org.c4sg.dto.OrganizationDTO in project c4sg-services by Code4SocialGood.

the class OrganizationController method createOrganization.

// TODO Define error codes: required input missing, etc
@CrossOrigin
@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "Create organization", notes = "Creates an organization, and returns the organization created.", response = OrganizationDTO.class)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Internal server error") })
public Map<String, Object> createOrganization(@ApiParam(value = "Organization to create", required = true) @RequestBody @Valid CreateOrganizationDTO createOrganizationDTO) {
    System.out.println("**************Create Organization: Begin**************");
    System.out.println("Organization Name = " + createOrganizationDTO.getName());
    Map<String, Object> responseData = null;
    // organizationDTO.setLogo(organizationService.getLogoUploadPath(organizationDTO.getId()));
    try {
        OrganizationDTO createdOrganization = organizationService.createOrganization(createOrganizationDTO);
        responseData = Collections.synchronizedMap(new HashMap<>());
        responseData.put("organization", createdOrganization);
    } catch (Exception e) {
        System.err.println(e);
    }
    System.out.println("**************Create Organization: End**************");
    return responseData;
}
Also used : HashMap(java.util.HashMap) CreateOrganizationDTO(org.c4sg.dto.CreateOrganizationDTO) OrganizationDTO(org.c4sg.dto.OrganizationDTO) NotFoundException(org.c4sg.exception.NotFoundException) UserProjectException(org.c4sg.exception.UserProjectException) UserOrganizationException(org.c4sg.exception.UserOrganizationException) IOException(java.io.IOException) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with OrganizationDTO

use of org.c4sg.dto.OrganizationDTO in project c4sg-services by Code4SocialGood.

the class OrganizationServiceImpl method findByUser.

@Override
public List<OrganizationDTO> findByUser(Integer userId) {
    User user = userDAO.findById(userId);
    requireNonNull(user, "Invalid User Id");
    List<UserOrganization> userOrganizations = userOrganizationDAO.findByUserId(userId);
    List<OrganizationDTO> organizationDtos = new ArrayList<OrganizationDTO>();
    for (UserOrganization userOrganization : userOrganizations) {
        organizationDtos.add(organizationMapper.getOrganizationDtoFromEntity(userOrganization));
    }
    return organizationDtos;
}
Also used : User(org.c4sg.entity.User) UserOrganization(org.c4sg.entity.UserOrganization) ArrayList(java.util.ArrayList) CreateOrganizationDTO(org.c4sg.dto.CreateOrganizationDTO) OrganizationDTO(org.c4sg.dto.OrganizationDTO)

Example 4 with OrganizationDTO

use of org.c4sg.dto.OrganizationDTO in project c4sg-services by Code4SocialGood.

the class UserServiceImpl method deleteUser.

public void deleteUser(Integer id) {
    User user = userDAO.findById(id);
    user.setStatus(Constants.USER_STATUS_DELETED);
    user.setEmail(user.getEmail() + "-deleted");
    user.setAvatarUrl(null);
    userDAO.save(user);
    userDAO.deleteUserProjects(id);
    userDAO.deleteUserSkills(id);
    List<OrganizationDTO> organizations = organizationService.findByUser(id);
    for (OrganizationDTO org : organizations) {
        organizationService.deleteOrganization(org.getId());
    }
}
Also used : User(org.c4sg.entity.User) OrganizationDTO(org.c4sg.dto.OrganizationDTO)

Aggregations

OrganizationDTO (org.c4sg.dto.OrganizationDTO)4 CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)3 ApiOperation (io.swagger.annotations.ApiOperation)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 User (org.c4sg.entity.User)2 NotFoundException (org.c4sg.exception.NotFoundException)2 UserOrganizationException (org.c4sg.exception.UserOrganizationException)2 UserProjectException (org.c4sg.exception.UserProjectException)2 CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 UserOrganization (org.c4sg.entity.UserOrganization)1