Skip to content

Commit

Permalink
getAll operation is implemented for userType
Browse files Browse the repository at this point in the history
  • Loading branch information
ituitis20-karadagd20 committed Jan 1, 2024
1 parent 25ee886 commit 7f092e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/usertypes")
public class UserTypeController {
Expand All @@ -27,6 +29,17 @@ public ResponseEntity<UserTypeDTO> getUserTypeById(@PathVariable Integer id) {
}
}

@GetMapping("/all")
public ResponseEntity<List<UserTypeDTO>> getAllUserTypes() {
List<UserTypeDTO> response = userTypeService.getAllUserTypes();

if (!response.isEmpty()) {
return new ResponseEntity<>(response, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

//no other crud operation is necessary

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.production.ehayvanbackendapi.Mappers.UserTypeMapper;
import com.production.ehayvanbackendapi.Repositories.UserTypeRepository;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,6 +27,17 @@ public UserTypeDTO getUserTypeById(Integer id) {
return userType != null ? userTypeMapper.convertToDto(userType) : null;
}

public List<UserTypeDTO> getAllUserTypes() {
List<UserType> userTypeList = userTypeRepository.findAll();
List<UserTypeDTO> userTypeDtoList = new ArrayList<>();

for (UserType userType : userTypeList) {
userTypeDtoList.add(userTypeMapper.convertToDto(userType));
}

return userTypeDtoList;
}


// Other service methods for updating, deleting user types, etc.
}
Expand Down

0 comments on commit 7f092e6

Please sign in to comment.