Search in sources :

Example 1 with Pet

use of org.springdoc.demo.app2.model.Pet in project springdoc-openapi-demos by springdoc.

the class PetApiDelegateImpl method createPet.

private static Pet createPet(long id, Category category, String name, String[] urls, String[] tags, Pet.StatusEnum status) {
    Pet pet = new Pet().id(id).category(category).name(name).status(status);
    if (null != urls) {
        pet.setPhotoUrls(Arrays.asList(urls));
    }
    final AtomicLong i = new AtomicLong(0);
    if (null != tags && tags.length > 0) {
        Arrays.stream(tags).map(tag -> new Tag().name(tag).id(i.incrementAndGet())).forEach(pet::addTagsItem);
    }
    return pet;
}
Also used : Arrays(java.util.Arrays) ResponseStatusException(org.springframework.web.server.ResponseStatusException) FileOutputStream(java.io.FileOutputStream) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Category(org.springdoc.demo.app2.model.Category) File(java.io.File) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) Tag(org.springdoc.demo.app2.model.Tag) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) IOUtils(org.apache.tomcat.util.http.fileupload.IOUtils) PetRepository(org.springdoc.demo.app2.repository.PetRepository) Service(org.springframework.stereotype.Service) ModelApiResponse(org.springdoc.demo.app2.model.ModelApiResponse) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) MultipartFile(org.springframework.web.multipart.MultipartFile) Pageable(org.springframework.data.domain.Pageable) ResponseEntity(org.springframework.http.ResponseEntity) Pet(org.springdoc.demo.app2.model.Pet) StringUtils(org.springframework.util.StringUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) Tag(org.springdoc.demo.app2.model.Tag) Pet(org.springdoc.demo.app2.model.Pet)

Example 2 with Pet

use of org.springdoc.demo.app2.model.Pet in project aws-serverless-java-container by awslabs.

the class PetsController method createPet.

@RequestMapping(path = "/pets", method = RequestMethod.POST)
public Pet createPet(@RequestBody Pet newPet) {
    if (newPet.getName() == null || newPet.getBreed() == null) {
        return null;
    }
    Pet dbPet = newPet;
    dbPet.setId(UUID.randomUUID().toString());
    return dbPet;
}
Also used : Pet(com.amazonaws.serverless.sample.springboot2.model.Pet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Pet

use of org.springdoc.demo.app2.model.Pet in project aws-serverless-java-container by awslabs.

the class PetsController method listPets.

@RequestMapping(path = "/pets", method = RequestMethod.GET)
public Pet[] listPets(@RequestParam("limit") Optional<Integer> limit, Principal principal) {
    int queryLimit = 10;
    if (limit.isPresent()) {
        queryLimit = limit.get();
    }
    Pet[] outputPets = new Pet[queryLimit];
    for (int i = 0; i < queryLimit; i++) {
        Pet newPet = new Pet();
        newPet.setId(UUID.randomUUID().toString());
        newPet.setName(PetData.getRandomName());
        newPet.setBreed(PetData.getRandomBreed());
        newPet.setDateOfBirth(PetData.getRandomDoB());
        outputPets[i] = newPet;
    }
    return outputPets;
}
Also used : Pet(com.amazonaws.serverless.sample.springboot2.model.Pet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Pet

use of org.springdoc.demo.app2.model.Pet in project aws-serverless-java-container by awslabs.

the class PetsController method listPets.

@RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET)
public Pet listPets() {
    Pet newPet = new Pet();
    newPet.setId(UUID.randomUUID().toString());
    newPet.setBreed(PetData.getRandomBreed());
    newPet.setDateOfBirth(PetData.getRandomDoB());
    newPet.setName(PetData.getRandomName());
    return newPet;
}
Also used : Pet(com.amazonaws.serverless.sample.springboot2.model.Pet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Pet (com.amazonaws.serverless.sample.springboot2.model.Pet)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1 NotNull (javax.validation.constraints.NotNull)1 IOUtils (org.apache.tomcat.util.http.fileupload.IOUtils)1 Category (org.springdoc.demo.app2.model.Category)1 ModelApiResponse (org.springdoc.demo.app2.model.ModelApiResponse)1 Pet (org.springdoc.demo.app2.model.Pet)1 Tag (org.springdoc.demo.app2.model.Tag)1 PetRepository (org.springdoc.demo.app2.repository.PetRepository)1 Pageable (org.springframework.data.domain.Pageable)1 HttpStatus (org.springframework.http.HttpStatus)1 ResponseEntity (org.springframework.http.ResponseEntity)1