joyofpw / chileanbirds-api

🐦 A Small ProcessWire API with a Sample React Frontend. Filled with Birds from Chile 🇨🇱.
https://aves.ninjas.cl
MIT License
11 stars 0 forks source link

[feature] Create ProcessWire Backend #3

Closed clsource closed 4 years ago

clsource commented 4 years ago

This is a simple backend that will support the Chilean Bird API. https://github.com/NinjasCL/chileanbirds-dataset

GET /birds

{
  "data": [
    {
    "id": 1,
    "uid": "1-nothoprocta-perdicaria",
    "map": {
        "svg": "http://www.buscaves.cl/images/svg.php?ave=1"
    },
    "image": {
        "url": "http://www.buscaves.cl/img/18082018074355perdiz_chilena_pedro_valencia_web.jpg",
        "uri": "http://www.buscaves.cl/img/",
        "filename": "18082018074355perdiz_chilena_pedro_valencia_web.jpg",
        "name": "18082018074355perdiz_chilena_pedro_valencia_web",
        "ext": "jpg"
    },
    "gallery": [{
        "url": "http://www.buscaves.cl/img/18082018074355perdiz_chilena_pedro_valencia_web.jpg",
        "uri": "http://www.buscaves.cl/img/",
        "filename": "18082018074355perdiz_chilena_pedro_valencia_web.jpg",
        "name": "18082018074355perdiz_chilena_pedro_valencia_web",
        "ext": "jpg"
    }],
    "names": {
        "spanish": "Perdiz chilena",
        "latin": "Nothoprocta perdicaria",
        "english": "Chilean Tinamou"
    },
    "audio": {
        "author": "Guillermo Egli",
        "src": "http://www.buscaves.cl/img/09092018084011",
        "type": "audio/wav",
        "ext": "wav",
        "name": "09092018084011",
        "filename": "09092018084011.wav"
    },
    "info": {
        "name": {
            "name": "Nombre en Inglés",
            "key": "name",
            "value": "Chilean Tinamou"
        },
        "dimorfism": {
            "name": "Dimorfismo",
            "key": "dimorfism",
            "value": "No"
        },
        "migration": {
            "name": "Migratoria",
            "key": "migration",
            "value": "No"
        },
        "size": {
            "name": "Longitud",
            "key": "size",
            "value": "29 - 32 cm."
        },
        "geo": {
            "name": "Ubicación geográfica",
            "key": "geo",
            "value": "Entre la Región de Atacama y la Región de Los Lagos"
        },
        "order": {
            "name": "Orden",
            "key": "order",
            "value": "Tinamiformes"
        },
        "species": {
            "name": "Especie",
            "key": "species",
            "value": "Nativa"
        },
        "iucn": {
            "name": "Conservación según IUCN",
            "key": "iucn",
            "value": "Menor riesgo (LC)"
        }
    },
    "description": "Es un ave muy compacta de tamaño mediano que alcanza los 450 gramos de peso. Estas aves no poseen dimorfismo sexual.El plumaje es café palido con moteado negro y café oscuro. Pecho gris claro, abdomen café amarillento. Tienen corona semierictil café negruzca. Pico curvo grisáceo y patas amarillas.Se alimentan de semillas, vegetales e insectos, los cuales capturan buscando en terrenos abiertos mientras escarban en el suelo.La Perdiz es un ave esquiva pero territorial. Emite un silbido característico frente alguna amenaza. Le gusta desplazarse en solitario o en parejas y ocultarse entre la vegetación. Es la única Perdiz con esta distribución por lo que confundirla con otra es díficil. Sus parientes en Chile son especies pertenecientes a la familia Tinamidae, como la Perdiz Copetona, la Perdiz Cordillerana, la Perdiz de la Puna, entre otras.",
    "habitat": "Estas aves se mimetizan excelente en el ambiente y se pueden observar solitarias o en parejas desde la Región de Atacama hasta la Región de Los Lagos, incluyendo Rapa nui, donde es una especie introducida. Es especie endémica, es decir, sólo se encuentra en nuestro país. Suelen frecuentar zonas de pastizales, matorrales, arbustos bajos, cultivos, laderas, areas semi áridas aunque también se pueden observar en zonas más urbanas como caminos y carreteras. Estas aves nidifican en el suelo, en donde más de una hembra puede poner el nido. Colocan entre 5 a 9 huevos de color chocolate brillante.",
    "iucn": "Según la lista roja de los vertebrados del mundo de la Unión Internacional para la Conservación de la Naturaleza (UICN), la Perdiz Chilena está catalogada como especie de preocupación menor (LC), sin embargo, su población podría verse afectada por la destrucción y contaminación de su hábitat, la caza, recolección de huevos y por el ataque de perros, gatos u otros animales exóticos invasivos.",
    "didyouknow": "Es la Perdiz más común en nuestro país. Es un ave muy esquiva, que corre para ocultarse entre la vegetación y se logra camuflar perfectamente."
}
  ]
}
clsource commented 4 years ago

Sketch of Relationships

"""
@once: Only one copy of this page can be created.
@strong: Can be deleted only when all the children are deleted.
@many: Can have any number of children.
(!!): Repeats the last signature used.
# : Comment
"""

@document
/++ "Home" (template:home, options:{@once, @strong}) @many -> 
    ++ "Birds" (template:birds, options:{@strong}) @many ->
        ++ "Bird 1" (template:birds-item, fields: {

            body: textarea()
                    .description("Stores the description of the bird"),

            habitat: textarea()
                    .description("Stores the habitat property"),

            didyouknow: textarea()
                    .description("Stores the did you know property)

        }) 
        # ++ "Bird 2" (!!)
        # ++ "Bird 3" (!!)
    ... #/birds
... #/home
@end
clsource commented 4 years ago

Let's keep improving the Bird template.


@document {

    /**
    @once: Only one copy of this page can be created. Alias of {once:true}.
    @strong: Can be deleted only when all the children are deleted. Alias of {strong:true}.
    @root: Is the root of the page tree. Alias of {root:true}.
    @childless: Can not have children. Alias of {children:false}.
    @i18n: Can be multi lang enabled. Alias of {i18n:true}.
    @global: This input will be present in every page instance. Alias of {global:true}.
    @many: Can have any number of children. Alias of {many:true}.
    (!!): Repeats the last signature used.
    77 : Comment
    */

    @wire {
        @templates {
            home: template().options({@once, @strong, @root}),
            notfound: template().options({@once, @childless}).description("Used in 404 errors"),
            birds: template().options({@strong}).family({
                    parents: ["home"],
                    children: ["birds-item"]
            }),
            birds-item: template().options({@childless}).family({
                parents: ["birds"]
            })
        },

        @fields {

            title: text().options({@i18n, @global}),

            body: textarea().options({@i18n}),

            uid: text(),

            href: url(),

            file: files().max(1),

            migration: checkbox(),

            dimorfism: checkbox(),

            size: text(),

            order: text(),

            species: text(),

            image: images().max(1).mediatypes([@jpg, @png, @svg]),

            images: images().mediatypes([@jpg, @png, @svg]),

            value: text().options({@i18n}),

            habitat: textarea()
                    .description("Stores the habitat property")
                    .options({@i18n}),

            didyouknow: textarea()
                    .description("Stores the did you know property")
                    .options({@i18n}),

            iucn: pagetable()
                    .max(1)
                    .fields({
                        body: body().description("Stores the iucn description"),
                        value: value().description("Stores the iucn value")
                    }),

            audio: pagetable()
                    .max(1)
                    .fields({
                        file,
                        title
                    }),

            map: pagetable()
                .max(1)
                .fields({
                    image,
                    value
                }),

        },

        @pages {
            ++ "Home" (template:home) @many -> {
                ++ "Birds" (template:birds) @many -> {
                    ++ "Bird 1" (template:birds-item, fields: {
                        title: title().label("Names"),
                        body: body().label("Description").description("Stores the bird description"),
                        images,
                        habitat,
                        didyouknow,
                        iucn,
                        audio,
                        map,
                        species,
                        migration,
                        dimorfism
                    })
                    } // /birds
                } // /home
        } // /pages
    } // /wire
} // /document
clsource commented 4 years ago

Firefox_Screenshot_2020-08-24T22-29-48 541Z