diff --git a/.gitignore b/.gitignore index 8d68e90..9022d84 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ target/ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# order infos +orders/ \ No newline at end of file diff --git a/README.md b/README.md index cb24060..911b5e1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,17 @@ # Codecool Online Shop -Java SE: Web Project skeleton +Java SE: Web Project in Codecool + +A simple demo webshop made with Java, Jetty, Thymeleaf, PostgreSQL and JUnit. # Install -Import this project to IntelliJ as a Maven project. -IntelliJ can auto-install the dependencies based on the pom.xml +Import this project as a Maven project. + +Create a PostgreSQL database naming codecoolshop listening on port: localhost:5432 + +Set environmental variables according to lines 12-13 of CodecoolShopDB.java + +Run server with command mvn jetty:run + +Run tests as JUnit5 tests (also add JUnit5 to classpath) diff --git a/config b/config new file mode 100644 index 0000000..79fe122 --- /dev/null +++ b/config @@ -0,0 +1 @@ +datasource=DB \ No newline at end of file diff --git a/pom.xml b/pom.xml index 415c26c..5acd56e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ war - UTF-8 - 9.4.12.v20180830 + UTF-8 + 9.4.12.v20180830 @@ -24,8 +24,8 @@ maven-compiler-plugin 3.7.0 - 1.8 - 1.8 + 11 + 11 @@ -65,5 +65,33 @@ thymeleaf 3.0.9.RELEASE + + com.fasterxml.jackson.core + jackson-databind + 2.3.1 + + + org.postgresql + postgresql + 42.1.4.jre7 + + + org.junit.jupiter + junit-jupiter-api + 5.3.2 + compile + + + org.junit.jupiter + junit-jupiter-params + 5.1.0 + test + + + org.junit.jupiter + junit-jupiter-params + 5.3.2 + compile + - + \ No newline at end of file diff --git a/src/data/csv/animals.csv b/src/data/csv/animals.csv new file mode 100644 index 0000000..36a2922 --- /dev/null +++ b/src/data/csv/animals.csv @@ -0,0 +1,48 @@ +Griffon Vulture|Bird|1990|USD|The griffon vulture is 93-122 cm (37-48 in) long with a 2.3-2.8 m (7.5-9.2 ft) wingspan. In the nominate race the males weigh 6.2 to 10.5 kg (14 to 23 lb) and females typically weigh 6.5 to 11.3 kg (14 to 25 lb), while in the Indian subspecies (G. f. fulvescens), the vultures average 7.1 kg (16 lb). Extreme adult weights have been reported from 4.5 to 15 kg (9.9 to 33.1 lb), the latter likely a weight attained in captivity. Hatched naked, it is a typical Old World vulture in appearance, with a very white head, very broad wings and short tail feathers. It has a white neck ruff and yellow bill. The buff body and wing coverts contrast with the dark flight feathers.|https://vignette.wikia.nocookie.net/animals/images/c/c9/Depositphotos_34843177-Eurasian-griffon.-vulture.jpg/revision/latest?cb=20160421023933 +Bald Eagle|Bird|3490|USD|The Bald eagle (Haliaeetus leucocephalus, from Greek hali "sea", aietos "eagle", leuco "white", cephalos "head") is a bird of prey found in North America. A sea eagle, it has two known subspecies and forms a species pair with the white-tailed eagle (Haliaeetus albicilla). Its range includes most of Canada and Alaska, all of the contiguous United States, and northern Mexico. It is found near large bodies of open water with an abundant food supply and old-growth trees for nesting. The bald eagle is an opportunistic feeder which subsists mainly on fish, which it swoops down and snatches from the water with its talons.|https://vignette.wikia.nocookie.net/animals/images/8/80/Bald_Eagle.jpg/revision/latest?cb=20181221184710 +Osprey|Bird|1249|USD|The osprey (Pandion haliaetus) - also called fish eagle, sea hawk, river hawk, and fish hawk - is a diurnal, fish-eating bird of prey with a cosmopolitan range. It is a large raptor, reaching more than 60 cm (24 in) in length and 180 cm (71 in) across the wings. It is brown on the upperparts and predominantly greyish on the head and underparts. The osprey tolerates a wide variety of habitats, nesting in any location near a body of water providing an adequate food supply. It is found on all continents except Antarctica, although in South America it occurs only as a non-breeding migrant.|https://vignette.wikia.nocookie.net/animals/images/7/75/Osprey.jpg/revision/latest?cb=20120527074703 +Southern Cassowary|Bird|8990|USD|The Southern Cassowary is a specie from the Casuarius genus. It lives in Northern Australia. It is a large, flightless bird. It is mainly black physique, a blue head and neck, a large casque on its head, two large red wattles, and sharp claws on its foot. They have a length of 4-5.5 ft. They have a height of up to 5 ft. They can weigh up to 63-128 lb.|https://vignette.wikia.nocookie.net/animals/images/2/28/Southern_Cassowary.jpg/revision/latest?cb=20120525034613 +Wilson's Bird-of-paradise|Bird|5499|USD|The Wilson's bird-of-paradise (Cicinnurus respublica), is a species of bird-of-paradise. An Indonesian endemic, the Wilson's bird-of-paradise is distributed to the hill and lowland rainforests of Waigeo and Batanta Islands off West Papua. Its diet consists mainly of fruits and small insects. Due to ongoing habitat loss, limited range and exploitation, the Wilson's bird-of-paradise is evaluated as Near Threatened on the IUCN Red List of Threatened Species. It is listed on Appendix II of the Convention on International Trade in Endangered Species of Wild Fauna and Flora (CITES).|https://vignette.wikia.nocookie.net/animals/images/7/70/Wilsons_Bird-of-paradise_Cicinnurus_respublica2_0.jpg/revision/latest?cb=20160307003933 +Henderson Fruit Dove|Bird|12990|USD|The Henderson fruit dove (Ptilinopus insularis), also known as scarlet-capped fruit dove, is a species of dove in the Columbidae family. It is endemic to Henderson Island in the Pitcairn Island group. Its natural habitat is tropical moist lowland scrub forest.|https://vignette.wikia.nocookie.net/animals/images/1/18/P_hendersoni.jpg/revision/latest?cb=20160808032012 +Seram Swiftlet|Bird|799|USD|The Seram swiftlet (Aerodramus ceramensis), is a species of swift in the Apodidae family. It is endemic to Buru and Seram Islands. It used to be considered a subspecies of the Moluccan swiftlet. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical moist montane forests.|https://vignette.wikia.nocookie.net/animals/images/d/d3/Moluccanswift2.jpg/revision/latest?cb=20160826191222 +Yap Monarch|Bird|499|USD|The Yap monarch (Monarcha godeffroyi), is a species of monarch flycatcher in the Monarchidae family. It is endemic to Micronesia. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical mangrove forests.|https://vignette.wikia.nocookie.net/animals/images/5/5a/20100206002034.jpg/revision/latest?cb=20151125225519 +Harpy Eagle|Bird|999|USD|It is sometimes known as the American harpy eagle to distinguish it from the Papuan eagle, which is sometimes known as the New Guinea harpy eagle or Papuan harpy eagle. It is the largest and most powerful raptor found in the Americas, and among the largest extant species of eagles in the world. It usually inhabits tropical lowland rainforests in the upper (emergent) canopy layer. Destruction of its natural habitat has caused it to vanish from many parts of its former range, and it is nearly extirpated in Central America. In Brazil, the harpy eagle is also known as royal-hawk.|https://vignette.wikia.nocookie.net/animals/images/f/fe/8e495ffbe5c95cfdc38c5501751ff25d.jpg/revision/latest?cb=20160411193709 +Speckled Piculet|Bird|1390|USD|The male and female birds look alike. They have olive-green backs, with two white stripes on the side of their heads. The male bird has orange and brown on the forecrown. They have a creamy-white coloring below, with black spots. There is a dark green band near the eyes.|https://vignette.wikia.nocookie.net/animals/images/8/8d/Speckled_piculet_copy1.jpg/revision/latest/?cb=20170109010813 +Congo Serpent Eagle|Bird|2990|USD|The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests' dark understories.|https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745 +Bearded Bellbird|Bird|6990|USD|This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations, breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).|https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300 +Western Gorilla|Mammal|7290|USD|The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.|https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304 +Snow Leopard|Mammal|15490|USD|The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.|https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225 +Humpback Whale|Mammal|39990|USD|The Humpback Whale is a species from the Megaptera genus. Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.|https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349 +Gray Wolf|Mammal|14990|USD|The Gray Wolf is a species of the Canis genus. It is native to Eurasia, North Africa and North America. It has a slender body with a powerful build. It has triangular ears and wide forehead, and has strong jaws. The front paws have five toes each while the back paws have four. Gray Wolves travel and hunts in packs. They're also highly territorial.|https://vignette.wikia.nocookie.net/animals/images/b/bc/Gray_Wolf.jpg/revision/latest?cb=20120824083608 +Moose|Mammal|27990|USD|The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males, other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.|https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550 +Brown Bear|Mammal|99990|USD|The Brown Bear is a species of a bear that is found in North America. It is also known as the Grizzly bear. The awe-inspiring brown bear lives in the forests and mountains of northern North America, Europe, and Asia. It is the most widely distributed bear in the world. Brown bears have very large and curved claws, those present on the forelimbs being longer than those on the hind limbs. They may reach 5 to 6 centimeters (2.0 to 2.4 in) and sometimes 7 to 10 centimeters (2.8 to 3.9 in) along the curve. They are generally dark with a light tip, with some forms having completely light claws. Brown bear claws are longer and straighter than those of American black bears. The claws are blunt, while those of a black bear are sharp. It can make you it's pet.|https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821 +Tiger|Mammal|49990|USD|The Tiger is a species from the of Panthera genus. Native to much of eastern and southern Asia. The tiger is an apex predator and an obligate carnivore. Reaching up to 3.3 metres (11 ft) in total length and weighing up to 300 kilograms (660 pounds), the larger tiger subspecies are comparable in size to the biggest extinct felids. Aside from their great bulk and power, their most recognizable feature is the pattern of dark vertical stripes that overlays near-white to reddish-orange fur, with lighter underparts. The most numerous tiger subspecies is the Bengal tiger while the largest subspecies is the Siberian tiger.|https://vignette.wikia.nocookie.net/animals/images/0/05/Tiger.jpg/revision/latest?cb=20181221165111 +Lion|Mammal|32790|USD|The lion (Panthera leo) is one of the big cats in the genus Panthera and a member of the family Felidae. The commonly used term African lion collectively denotes the several subspecies found in Africa. With some males exceeding 250 kg (550 lb) in weight, it is the second-largest living cat after the tiger. Wild lions currently exist in sub-Saharan Africa and in India (where an endangered remnant population resides in Gir Forest National Park). In ancient historic times, their range was in most of Africa, including North Africa, and across Eurasia from Greece and southeastern Europe to India.|https://vignette.wikia.nocookie.net/animals/images/d/d2/Lion.jpg/revision/latest?cb=20181222014314 +Leopard|Mammal|26790|USD|The leopard (Panthera pardus) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard's rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar's do. Both leopards and jaguars that are melanistic are known as black panthers.|https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105 +Aardvark|Mammal|799|USD|The Aardvark, (Orycteropus afer), is a medium-sized, burrowing, nocturnal mammal native to Africa. t is the only living species of the order Tubulidentata, although other prehistoric species and genera of Tubulidentata are known. The aardvark looks like a cross between a pig and an anteater. Its body is stout with an arched back and is sparsely covered with coarse hairs. The limbs are of moderate length. The front feet have lost the pollex (or 'thumb'), resulting in four toes, while the rear feet have all five toes.|https://vignette.wikia.nocookie.net/animals/images/5/5f/Aardvark.jpg/revision/latest?cb=20120606060128 +Bison|Mammal|37490|USD|The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American, Bison antiquus, B. latifrons, and B. occidentalis. The fourth, the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species, the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)|https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550 +Cheetah|Mammal|24990|USD|The cheetah (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.|https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800 +Inland Taipan|Reptile|1290|USD|The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.|https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446 +Green Sea Turtle|Reptile|499|USD|The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.|https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939 +Komodo Dragon|Reptile|7690|USD|The Komodo dragon, (Varanus komodoensis), also known as the komodo monitor, is a large species of lizard found in the Indonesian islands of Komodo, Rinca, Flores, Gili Motang, and Padar. A member of the monitor lizard family it is the largest living species of lizard, growing to a maximum length of 3 metres (10 ft) in rare cases and weighing up to approximately 70 kilograms (150 lb). Their unusually large size has been attributed to island gigantism, since no other carnivorous animals fill the niche on the islands where they live.|https://vignette.wikia.nocookie.net/animals/images/3/3e/Komodo-dragon_599_600x450.jpg/revision/latest?cb=20130804224809 +Egyptian Cobra|Reptile|2390|USD|The Egyptian cobra (Naja haje) is a species in the genus Naja, found in Africa and the Arabian Peninsula. It is one of the largest Naja species in Africa. The Egyptian cobra was first described by Swedish zoologist Carolus Linnaeus in 1758. The generic name naja is a Latinisation of the Sanskrit word naga meaning "cobra". The specific epithet haje is derived from the Arabic word hayya which literally means small "snake"-according to the Quran or "viper".|https://vignette.wikia.nocookie.net/animals/images/2/20/Egyptian-Cobra.jpg/revision/latest?cb=20130807221716 +Round Island Burrowing Boa|Reptile|1790|USD|The Round island burrowing boa (Bolyeria multocarinata), is a extinct species of snake in the Bolyeriidae family, in the monotypic genus Bolyeria, which was endemic to Mauritius/Mauritius. The species was last seen on Round Island in 1975. No subspecies are currently recognized. It reached about 1 m (3 ft 3 in) in length, but preserved specimens have reported total lengths of 54-140 cm. Its colour was described as light brown with blackish spots dorsally and pink marbled with blackish ventrally. It had a pointed snout with a cylindrical body and head. Its general body form suggests that the Round Island Burrowing Boa had fossorial tendencies.|https://vignette.wikia.nocookie.net/animals/images/3/31/Bolyeria-multocarinata.jpg/revision/latest?cb=20140807031644 +Nile Crocodile|Reptile|14990|USD|The Nile crocodile (Crocodylus niloticus) is an African crocodile and may be considered the second largest extant reptile in the world, after the saltwater crocodile (Crocodylus porosus). The Nile crocodile is quite widespread throughout Sub-Saharan Africa, occurring mostly in the central, eastern, and southern regions of the continent and lives in different types of aquatic environments such as lakes, rivers and marshlands. Although capable of living in saline environments, this species is rarely found in saltwater, but occasionally inhabits deltas and brackish lakes. The range of this species once stretched northward throughout the Nile, as far north as the Nile delta.|https://vignette.wikia.nocookie.net/animals/images/a/a9/Nile_Crocodile.jpg/revision/latest?cb=20181231201310 +American Alligator|Reptile|17890|USD|The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.|https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010 +Black Mamba|Reptile|2290|USD|The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent, mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.|https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636 +Saltwater Crocodile|Reptile|31990|USD|The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz). This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates. Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.|https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609 +Panther chameleon|Reptile|1199|USD|The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal's feet. The specific name pardalisrefers to the animals' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleo, a borrowing of the Ancient Greek (khamailéon), a compound of (khamaí) "on the ground" and (léon) "lion".|https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041 +King Cobra|Reptile|1990|USD|The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world's longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.|https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332 +Cape Melville Leaf-tailed Gecko|Reptile|99|USD|The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard's distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.|https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111 +Axolotl|Amphibian|99|USD|The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.|https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251 +Cream-backed Poison Frog|Amphibian|49|USD|The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males, this is the most notable difference between the sexes.|https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857 +Tiger Salamander|Amphibian|79|USD|The Tiger Salamander is a specie from the Ambystoma genus. The species originates from numerous lakes, such as Lake Xochimilco underlying Mexico City. Thick-bodied amphibians with short snouts, sturdy legs, and long tails, tigers are the largest land-dwelling salamander on Earth. They can grow to 14 inches in length, but the average size is more like 6 to 8 inches. Highly voracious predators, they emerge from their burrows at night to feed on worms, insects, frogs, and even other salamanders. Their population is healthy throughout their range, but deforestation, pollution, and rising acidity levels in their breeding pools is affecting their distribution.|https://vignette.wikia.nocookie.net/animals/images/c/c8/Salamandra_Tigre.png/revision/latest?cb=20120530094118 +Adelphobates galactonotus|Amphibian|129|USD|Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.|https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest?cb=20150626050901 +Bale Mountains Tree Frog|Amphibian|169|USD|The Bale Mountains tree frog (Balebreviceps hillmani), is a species of frog in the Brevicipitidae family. It is monotypic within the genus Balebreviceps. It is endemic to the Bale Mountains of Ethiopia. Its natural habitats are tree heath (Erica arborea) woodlands near the timberline as well as partly cleared mixed forests further down. Despite its entire range being within the Bale Mountains National Park, it is threatened by habitat loss and deterioration (deforestation) caused by cattle grazing, firewood collection, fencing, and settlement development.|https://vignette.wikia.nocookie.net/animals/images/0/03/Male-Ethiopian-short-headed-frog.jpg/revision/latest?cb=20150622043022 +Cape Rain Frog|Amphibian|99|USD|The Cape rain frog or giant rain frog (Breviceps gibbosus), is a species of frog in the Brevicipitidae family. Krefft's Warty Frog. It is endemic to South Africa, where it occurs in the far south-western Cape, in Cape Town and northwards as far as Citrusdal. In this area it inhabits Mediterranean-type shrubby vegetation, known as fynbos, renosterveld, pastureland on farms, rural gardens, and even urban areas. It seems to adapt well to suburban gardens, but like most frog species it is vulnerable to herbicide poisons and domestic pets.|https://vignette.wikia.nocookie.net/animals/images/1/1a/20110913durbanville-caperainfrog.jpg/revision/latest?cb=20150617222413 +Desert Rain Frog|Amphibian|179|USD|The Desert rain frog (Breviceps macrops), is a species of frog in the Brevicipitidae family. It is found in Namibia and South Africa. Its natural habitats are subtropical or tropical dry shrubland and sandy shores. It is threatened by habitat loss. The desert rain frog is a small, plump species with bulging eyes, a short snout, short limbs, spade-like feet and webbed toes. On the underside it has a transparent area of skin through which its internal organs can be seen. Its colour is yellowish-brown and it often has sand adhering to its skin.|https://vignette.wikia.nocookie.net/animals/images/4/47/Desert-rain-frog-walking.jpg/revision/latest?cb=20150618040240 +Excidobates captivus|Amphibian|239|USD|Excidobates captivus, also known as the Santiago poison frog or Rio Santiago poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Peru and southern Ecuador. Its natural habitat is tropical moist lowland forests. This frog is black with rows of orange-red spots on its back and yellow spots underneath. With an adult snout-to-vent length of 15 to 17 mm (0.6 to 0.7 in), Excidobates captivus is a very small species of poison frog. It is black with orange-red splotches arranged in a row down either side of the back. It also has small yellow spots above the armpit and groin and further pale yellow spots beneath the chin and scattered on the chest and belly and under the thighs.|https://vignette.wikia.nocookie.net/animals/images/9/90/Captivus5.jpg/revision/latest?cb=20150627075858 +Forest Rain Frog|Amphibian|29|USD|The Forest rain frog (Breviceps sylvestris), is a species of frog in the Brevicipitidae family. It is endemic to Limpopo, South Africa. Two allopatric subspecies are recognized: the nominate one, Breviceps sylvestris sylvestris, and Breviceps sylvestris taeniatus from near Soutpansberg. Its natural habitats are temperate forests, temperate grassland, and rural gardens. It is threatened by habitat loss. Forest rain frogs can range in colour from red, orange, yellow, green, and purple. They can also vary in size from a mere 2cm and grow to be about 10cm in body length. The frogs are known to contain a defense mechanism consisting of a toxic chemical on their slimy exterior. If contact is made with this toxin the temporary effect of paralysis can occur.|https://vignette.wikia.nocookie.net/animals/images/3/33/Forest-rain-frog.jpg/revision/latest?cb=20150619050517 +Golden Poison Frog|Amphibian|399|USD|The golden frog is found only in isolated regions of Panama. It's bright colour warns predators that it is toxic. Scientists believe that a major cause of its decline is climate change. During drought years, the frogs are forced into overcrowded wet areas, which lead to fatal diseases. The Golden poison frog (Phyllobates terribilis), also known as the golden frog, golden poison arrow frog, or golden dart frog, is a species of frog in the Dendrobatidae family. It is endemic to the Pacific coast of Colombia.|https://vignette.wikia.nocookie.net/animals/images/2/28/Golden-poison-frog-sitting-on-leaf.jpg/revision/latest?cb=20150701043049 +Kihansi Spray Toad|Amphibian|149|USD|The Kihansi spray toad (Nectophrynoides asperginis), is a species of toad in the Bufonidae family. Females reaching up to 2.9 cm (1.1 in) long and males up to 1.9 cm (0.75 in). This ovoviviparous species was scientifically described in 1999. It was found only in the spray zone around the Kihansi waterfalls in the southern Udzungwa Mountains in Tanzania. At about 20,000 m2 (220,000 sq ft), this was one of the smallest natural distribution known for any vertebrate species, Following the construction of the Kihansi Dam, it became extinct in the wild.|https://vignette.wikia.nocookie.net/animals/images/d/d0/2145.jpeg/revision/latest?cb=20150508024143 +Yellow-bellied Poison Frog|Amphibian|239|USD|The Yellow-bellied poison frog (Andinobates fulguritus), also known as the yellow-bellied poison-arrow frog or yellowbelly poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Colombia and east-central Panama. Its natural habitats are tropical moist lowland forests. It is a locally common, terrestrial frog. The eggs are deposited in leaf-litter, both parents carry the tadpoles to leaf axils, usually bromeliads, where they complete their development. It is threatened by habitat loss and pollution. This species seems not to be collected for pet trade.|https://vignette.wikia.nocookie.net/animals/images/f/f9/6819263362_b66923d65a_b.jpg/revision/latest?cb=20150702233228 \ No newline at end of file diff --git a/src/data/csv/species.csv b/src/data/csv/species.csv new file mode 100644 index 0000000..6c4faf1 --- /dev/null +++ b/src/data/csv/species.csv @@ -0,0 +1,4 @@ +Bird|Vertebrate|Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton. +Mammal|Vertebrate|Mammals (class Mammalia /məˈmeɪli.ə/ from Latin mamma "breast") are a clade of endothermic amniotes distinguished from reptiles and birds by the possession of a neocortex (a region of the brain), hair, three middle ear bones and mammary glands. +Reptile|Vertebrate|Reptiles are a group (Reptilia) of tetrapod animals comprising today's turtles, crocodilians, snakes, amphisbaenians, lizards, tuatara, and their extinct relatives. +Amphibian|Vertebrate|The amphibians are tetrapods, a class of vertebrate animals with four limbs. They are non-amniotes, which means that their eggs are not surrounded by the several membranes, some impervious, which enable mammals, reptiles and birds to reproduce on land. \ No newline at end of file diff --git a/src/data/csv/zoos.csv b/src/data/csv/zoos.csv new file mode 100644 index 0000000..9336a1f --- /dev/null +++ b/src/data/csv/zoos.csv @@ -0,0 +1,12 @@ +Montgomery Zoo|Alabama|Montgomery|Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species. +Alaska Zoo|Alaska|Anchorage|The Alaska Zoo is a zoo in Anchorage, Alaska, located on 25 acres (10 ha) of the Anchorage Hillside. It is a popular attraction in Alaska, with nearly 200,000 visitors per year. The zoo is currently home to more than 100 birds and mammals representing some 50 species. +Phoenix Zoo|Arizona|Phoenix|The Phoenix Zoo opened in 1962 and is the largest privately owned, non-profit zoo in the United States. Located in Phoenix, Arizona, the zoo was founded by Robert Maytag, a member of the Maytag family, and operates on 125 acres (51 ha) of land in the Papago Park area of Phoenix. It has been designated as a Phoenix Point of Pride. +Los Angeles Zoo|California|Los Angeles|The Los Angeles Zoo and Botanical Gardens is a 133-acre (54 ha) zoo founded in 1966 and located in Los Angeles, California. The city of Los Angeles owns the entire zoo, its land and facilities, and the animals. Animal care, grounds maintenance, construction, education, public information, and administrative staff are city employees. +San Diego Zoo|California|San Diego|The San Diego Zoo is a zoo in Balboa Park, San Diego, California, housing more than 3,500 animals of more than 650 species and subspecies. Its parent organization, San Diego Zoo Global, is one of the largest[better source need zoological membership associations in the world, with more than 250,000 member households and 130,000 child memberships, representing more than a half million people. +San Francisco Zoo|California|San Francisco|The San Francisco Zoo is a 100-acre (40 ha) zoo located in the southwestern corner of San Francisco, California, between Lake Merced and the Pacific Ocean along the Great Highway. As of 2016, the zoo housed more than one thousand individual animals, representing more than 250 species. It is noted as the birthplace of Koko the gorilla, and, since 1974, the home of Elly, the oldest black rhinoceros in North America. +Disney's Animal Kingdom|Florida|Bay Lake|Disney's Animal Kingdom is a zoological theme park at the Walt Disney World Resort in Bay Lake, Florida, near Orlando. Owned and operated by The Walt Disney Company through its Parks, Experiences and Consumer Products division, it is the largest theme park in the world, covering 580 acres (230 ha). The park opened on Earth Day, April 22, 1998, and was the fourth theme park built at the resort. +Lion Country Safari|Florida|Loxahatchee|Lion Country Safari is a drive-through safari park and walk-through amusement park located on over 600 acres in Loxahatchee (near West Palm Beach), in Palm Beach County, Florida. Founded in 1967, it claims to be the first 'cageless zoo' in the United States. +Monkey Jungle|Florida|Miami|Monkey Jungle is a 30-acre (12 ha) wildlife park established in 1933 for the exhibition and study of endangered monkeys in semi-natural habitats. Many projects have been conducted at the park, which is a tourist attraction in the Miami, Florida area. The park is in Redland, Florida at Southwest 216th Street/Hainlin Mill Road near Southwest 147th Avenue. +Reptile World Serpentarium|Florida|St. Cloud|Reptile World Serpentarium is a reptile zoo in St. Cloud, Osceola County, Florida. It features more than 75 species of snakes, as well as lizards, crocodiles, alligators, and turtles. It is operated by the herpetologist George Van Horn. In addition to having animals on display, it has venom milking shows. +World Center for Birds of Prey|Idaho|Boise|Built 35 years ago in 1984, the World Center for Birds of Prey is located on 580 acres (2.3 km2) on a hilltop overlooking Boise, south of the airport and east of Kuna. The campus consists of the business offices of The Peregrine Fund, breeding facilities for endangered raptors, the Velma Morrison Interpretive Center, and the Herrick Collections Building, which houses a large research library and the Archives of Falconry. +Yellowstone Bear World|Idaho|Rexburg|Yellowstone Bear World is a privately owned drive-thru wildlife park. It is located in Rexburg, Idaho, near Yellowstone National Park. It was established in 1998. The park holds over 8 species of wildlife indigenous to the Greater Yellowstone Ecosystem. Other attractions in the park include a small amusement park and a petting zoo. Yellowstone Bear World is the only wildlife park in the United States where guests can bottle feed bear cubs. \ No newline at end of file diff --git a/src/data/database/animal.sql b/src/data/database/animal.sql new file mode 100644 index 0000000..b54fbdd --- /dev/null +++ b/src/data/database/animal.sql @@ -0,0 +1,61 @@ +drop table if exists animals; + +CREATE TABLE "animals" ( + "id" SERIAL NOT NULL UNIQUE PRIMARY KEY, + "name" TEXT, + "species" TEXT constraint animals_species references species, + "price" INT, + "currency" TEXT, + "description" TEXT, + "img_url" TEXT +); + +INSERT INTO "animals" VALUES + (DEFAULT,'Griffon Vulture','Bird',1990,'USD','The griffon vulture is 93-122 cm (37-48 in) long with a 2.3-2.8 m (7.5-9.2 ft) wingspan. In the nominate race the males weigh 6.2 to 10.5 kg (14 to 23 lb) and females typically weigh 6.5 to 11.3 kg (14 to 25 lb), while in the Indian subspecies (G. f. fulvescens), the vultures average 7.1 kg (16 lb). Extreme adult weights have been reported from 4.5 to 15 kg (9.9 to 33.1 lb), the latter likely a weight attained in captivity. Hatched naked, it is a typical Old World vulture in appearance, with a very white head, very broad wings and short tail feathers. It has a white neck ruff and yellow bill. The buff body and wing coverts contrast with the dark flight feathers.','https://vignette.wikia.nocookie.net/animals/images/c/c9/Depositphotos_34843177-Eurasian-griffon.-vulture.jpg/revision/latest?cb=20160421023933'), + (DEFAULT,'Bald Eagle','Bird',3490,'USD','The Bald eagle (Haliaeetus leucocephalus, from Greek hali "sea", aietos "eagle", leuco "white", cephalos "head") is a bird of prey found in North America. A sea eagle, it has two known subspecies and forms a species pair with the white-tailed eagle (Haliaeetus albicilla). Its range includes most of Canada and Alaska, all of the contiguous United States, and northern Mexico. It is found near large bodies of open water with an abundant food supply and old-growth trees for nesting. The bald eagle is an opportunistic feeder which subsists mainly on fish, which it swoops down and snatches from the water with its talons.','https://vignette.wikia.nocookie.net/animals/images/8/80/Bald_Eagle.jpg/revision/latest?cb=20181221184710'), + (DEFAULT,'Osprey','Bird',1249,'USD','The osprey (Pandion haliaetus) - also called fish eagle, sea hawk, river hawk, and fish hawk - is a diurnal, fish-eating bird of prey with a cosmopolitan range. It is a large raptor, reaching more than 60 cm (24 in) in length and 180 cm (71 in) across the wings. It is brown on the upperparts and predominantly greyish on the head and underparts. The osprey tolerates a wide variety of habitats, nesting in any location near a body of water providing an adequate food supply. It is found on all continents except Antarctica, although in South America it occurs only as a non-breeding migrant.','https://vignette.wikia.nocookie.net/animals/images/7/75/Osprey.jpg/revision/latest?cb=20120527074703'), + (DEFAULT,'Southern Cassowary','Bird',8990,'USD','The Southern Cassowary is a specie from the Casuarius genus. It lives in Northern Australia. It is a large, flightless bird. It is mainly black physique, a blue head and neck, a large casque on its head, two large red wattles, and sharp claws on its foot. They have a length of 4-5.5 ft. They have a height of up to 5 ft. They can weigh up to 63-128 lb.','https://vignette.wikia.nocookie.net/animals/images/2/28/Southern_Cassowary.jpg/revision/latest?cb=20120525034613'), + (DEFAULT,'Wilson''s Bird-of-paradise','Bird',5499,'USD','The Wilson''s bird-of-paradise (Cicinnurus respublica), is a species of bird-of-paradise. An Indonesian endemic, the Wilson''s bird-of-paradise is distributed to the hill and lowland rainforests of Waigeo and Batanta Islands off West Papua. Its diet consists mainly of fruits and small insects. Due to ongoing habitat loss, limited range and exploitation, the Wilson''s bird-of-paradise is evaluated as Near Threatened on the IUCN Red List of Threatened Species. It is listed on Appendix II of the Convention on International Trade in Endangered Species of Wild Fauna and Flora (CITES).','https://vignette.wikia.nocookie.net/animals/images/7/70/Wilsons_Bird-of-paradise_Cicinnurus_respublica2_0.jpg/revision/latest?cb=20160307003933'), + (DEFAULT,'Henderson Fruit Dove','Bird',12990,'USD','The Henderson fruit dove (Ptilinopus insularis), also known as scarlet-capped fruit dove, is a species of dove in the Columbidae family. It is endemic to Henderson Island in the Pitcairn Island group. Its natural habitat is tropical moist lowland scrub forest.','https://vignette.wikia.nocookie.net/animals/images/1/18/P_hendersoni.jpg/revision/latest?cb=20160808032012'), + (DEFAULT,'Seram Swiftlet','Bird',799,'USD','The Seram swiftlet (Aerodramus ceramensis), is a species of swift in the Apodidae family. It is endemic to Buru and Seram Islands. It used to be considered a subspecies of the Moluccan swiftlet. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical moist montane forests.','https://vignette.wikia.nocookie.net/animals/images/d/d3/Moluccanswift2.jpg/revision/latest?cb=20160826191222'), + (DEFAULT,'Yap Monarch','Bird',499,'USD','The Yap monarch (Monarcha godeffroyi), is a species of monarch flycatcher in the Monarchidae family. It is endemic to Micronesia. Its natural habitats are subtropical or tropical moist lowland forests and subtropical or tropical mangrove forests.','https://vignette.wikia.nocookie.net/animals/images/5/5a/20100206002034.jpg/revision/latest?cb=20151125225519'), + (DEFAULT,'Harpy Eagle','Bird',999,'USD','It is sometimes known as the American harpy eagle to distinguish it from the Papuan eagle, which is sometimes known as the New Guinea harpy eagle or Papuan harpy eagle. It is the largest and most powerful raptor found in the Americas, and among the largest extant species of eagles in the world. It usually inhabits tropical lowland rainforests in the upper (emergent) canopy layer. Destruction of its natural habitat has caused it to vanish from many parts of its former range, and it is nearly extirpated in Central America. In Brazil, the harpy eagle is also known as royal-hawk.','https://vignette.wikia.nocookie.net/animals/images/f/fe/8e495ffbe5c95cfdc38c5501751ff25d.jpg/revision/latest?cb=20160411193709'), + (DEFAULT,'Speckled Piculet','Bird',1390,'USD','The male and female birds look alike. They have olive-green backs, with two white stripes on the side of their heads. The male bird has orange and brown on the forecrown. They have a creamy-white coloring below, with black spots. There is a dark green band near the eyes.','https://vignette.wikia.nocookie.net/animals/images/8/8d/Speckled_piculet_copy1.jpg/revision/latest/?cb=20170109010813'), + (DEFAULT,'Congo Serpent Eagle','Bird',2990,'USD','The Congo serpent eagle (Dryotriorchis spectabilis), is a species of bird of prey in the Accipitridae family. It is placed in the monotypic genus Dryotriorchis. This species is found in western and central Africa, with its range stretching from Sierra Leone south to Angola and west to the Democratic Republic of the Congo. It occurs in upper and lower Guinean forests, which are dense rainforests. This serpent eagle specializes in hunting in these forests'' dark understories.','https://vignette.wikia.nocookie.net/animals/images/2/21/Dryotriorchis_spectabilis.jpg/revision/latest?cb=20160405022745'), + (DEFAULT,'Bearded Bellbird','Bird',6990,'USD','This cotinga occurs in humid forests and woodland. It is mainly resident, but some populations take part in altitudinal migrations; breeding at altitudes of up to 1900 m (6250 ft) and spending the non-breeding season in the lowlands. It is a localised and uncommon bird in Venezuela, but is fairly common in Trinidad. The nominate Brazilian race is relatively rare due to extensive habitat destruction in its range and heavy trapping for the cagebird trade, and as such is considered "vulnerable" by Brazilian environmental authority (IBAMA).','https://vignette.wikia.nocookie.net/animals/images/6/61/BeardedBellbird_100301_6211.jpg/revision/latest?cb=20141225234300'), + (DEFAULT,'Western Gorilla','Mammal',7290,'USD','The Western gorilla (Gorilla gorilla) is a great ape and the most populous species of the genus Gorilla. Nearly all of the individuals of this taxon belong to the western lowland gorilla subspecies (G. g. gorilla) whose population is approximately 95,000 individuals. Only 250 to 300 of the only other western gorilla subspecies, the cross river gorilla (G. g. diehli) are thought to remain.','https://vignette.wikia.nocookie.net/animals/images/1/15/Gorilla.jpg/revision/latest?cb=20120527170304'), + (DEFAULT,'Snow Leopard','Mammal',15490,'USD','The Snow Leopard is a species from the Panthera genus. It is found in the snowy woodlands of Central Asia. Snow leopards have long thick fur, and their base colour varies from smoky gray to yellowish tan, with whitish underparts. They have dark gray to black open rosettes on their body with small spots of the same color on their heads and larger spots on their legs and tail. Unusually among cats, their eyes are pale green or gray in color.','https://vignette.wikia.nocookie.net/animals/images/1/19/Snow_Leopard.jpg/revision/latest?cb=20181221200225'), + (DEFAULT,'Humpback Whale','Mammal',39990,'USD','The Humpback Whale is a species from the Megaptera genus. Found in oceans and seas around the world, humpback whales typically migrate up to 25,000 kilometres (16,000 mi) each year. A Humpback whale can easily be identified by its stocky body with an obvious hump and black dorsal coloring. The head and lower jaw are covered with knobs called tubercles, which are actually hair follicles, and are characteristic of the species. The fluked tail, which it lifts above the surface in some dive sequences, has wavy trailing edges. The long black and white tail fin, which can be up to a third of body length, and the pectoral fins have unique patterns, which make individual whales identifiable.','https://vignette.wikia.nocookie.net/animals/images/4/41/Humpback_Whale.jpg/revision/latest?cb=20181221184349'), + (DEFAULT,'Gray Wolf','Mammal',14990,'USD','The Gray Wolf is a species of the Canis genus. It is native to Eurasia, North Africa and North America. It has a slender body with a powerful build. It has triangular ears and wide forehead, and has strong jaws. The front paws have five toes each while the back paws have four. Gray Wolves travel and hunts in packs. They''re also highly territorial.','https://vignette.wikia.nocookie.net/animals/images/b/bc/Gray_Wolf.jpg/revision/latest?cb=20120824083608'), + (DEFAULT,'Moose','Mammal',27990,'USD','The moose (North America) or elk (Eurasia), Alces alces, is the largest extant species in the deer family. Moose are distinguished by the palmate antlers of the males; other members of the family have antlers with a dendritic ("twig-like") configuration. Moose typically inhabit boreal and mixed deciduous forests of the Northern Hemisphere in temperate to subarctic climates. Moose used to have a much wider range but hunting and other human activities have greatly reduced it. Moose have been reintroduced to some of their former habitats. Currently, most moose are found in Canada, Alaska, New England, Scandinavia, Latvia, Estonia and Russia. Their diet consists of both terrestrial and aquatic vegetation. The most common moose predators are wolves, bears and humans.','https://vignette.wikia.nocookie.net/animals/images/a/a3/Moose.jpg/revision/latest?cb=20181221184550'), + (DEFAULT,'Brown Bear','Mammal',99990,'USD','The Brown Bear is a species of a bear that is found in North America. It is also known as the Grizzly bear. The awe-inspiring brown bear lives in the forests and mountains of northern North America, Europe, and Asia. It is the most widely distributed bear in the world. Brown bears have very large and curved claws, those present on the forelimbs being longer than those on the hind limbs. They may reach 5 to 6 centimeters (2.0 to 2.4 in) and sometimes 7 to 10 centimeters (2.8 to 3.9 in) along the curve. They are generally dark with a light tip, with some forms having completely light claws. Brown bear claws are longer and straighter than those of American black bears. The claws are blunt, while those of a black bear are sharp. It can make you it''s pet.','https://vignette.wikia.nocookie.net/animals/images/9/95/Kodiak_Bear.jpg/revision/latest?cb=20120515121821'), + (DEFAULT,'Tiger','Mammal',49990,'USD','The Tiger is a species from the of Panthera genus. Native to much of eastern and southern Asia. The tiger is an apex predator and an obligate carnivore. Reaching up to 3.3 metres (11 ft) in total length and weighing up to 300 kilograms (660 pounds), the larger tiger subspecies are comparable in size to the biggest extinct felids. Aside from their great bulk and power, their most recognizable feature is the pattern of dark vertical stripes that overlays near-white to reddish-orange fur, with lighter underparts. The most numerous tiger subspecies is the Bengal tiger while the largest subspecies is the Siberian tiger.','https://vignette.wikia.nocookie.net/animals/images/0/05/Tiger.jpg/revision/latest?cb=20181221165111'), + (DEFAULT,'Lion','Mammal',32790,'USD','The lion (Panthera leo) is one of the big cats in the genus Panthera and a member of the family Felidae. The commonly used term African lion collectively denotes the several subspecies found in Africa. With some males exceeding 250 kg (550 lb) in weight, it is the second-largest living cat after the tiger. Wild lions currently exist in sub-Saharan Africa and in India (where an endangered remnant population resides in Gir Forest National Park). In ancient historic times, their range was in most of Africa, including North Africa, and across Eurasia from Greece and southeastern Europe to India.','https://vignette.wikia.nocookie.net/animals/images/d/d2/Lion.jpg/revision/latest?cb=20181222014314'), + (DEFAULT,'Leopard','Mammal',26790,'USD','The leopard (Panthera pardus) is one of the five "big cats" in the genus Panthera. It is a member of the familyFelidae with a wide range in sub-Saharan Africa and parts of Asia. Fossil records found in Italy suggest that in the Pleistocene it ranged as far as Europe and Japan. Compared to other members of Felidae, the leopard has relatively short legs and a long body with a large skull. It is similar in appearance to the jaguar, but is smaller and more lightly built. Its fur is marked with rosettessimilar to those of the jaguar, but the leopard''s rosettes are smaller and more densely packed, and do not usually have central spots as the jaguar''s do. Both leopards and jaguars that are melanistic are known as black panthers.','https://vignette.wikia.nocookie.net/animals/images/a/ae/Leopard.jpg/revision/latest?cb=20181221204105'), + (DEFAULT,'Aardvark','Mammal',799,'USD','The Aardvark, (Orycteropus afer), is a medium-sized, burrowing, nocturnal mammal native to Africa. t is the only living species of the order Tubulidentata, although other prehistoric species and genera of Tubulidentata are known. The aardvark looks like a cross between a pig and an anteater. Its body is stout with an arched back and is sparsely covered with coarse hairs. The limbs are of moderate length. The front feet have lost the pollex (or ''thumb''), resulting in four toes, while the rear feet have all five toes.','https://vignette.wikia.nocookie.net/animals/images/5/5f/Aardvark.jpg/revision/latest?cb=20120606060128'), + (DEFAULT,'Bison','Mammal',37490,'USD','The Bison is a genus from the Bovidae family. There are two extant and four extinct species recognized. Of the four extinct species, three were North American; Bison antiquus, B. latifrons, and B. occidentalis. The fourth; the Bison priscus ranged across steppe environments from Western Europe, through Central Asia, and onto North America. There are two surviving species; the American bison, Bison bison, also known as the American buffalo, found only in North America, is the most numerous. (It is only distantly related to the true buffalo.)','https://vignette.wikia.nocookie.net/animals/images/3/3e/American_Bison.jpg/revision/latest?cb=20120601045550'), + (DEFAULT,'Cheetah','Mammal',24990,'USD','The cheetah (Acinonyx jubatus), also known as the hunting leopard, is a big cat that occurs mainly in eastern and southern Africa and a few parts of Iran. The only extant member of the genus Acinonyx, the cheetah was first described by Johann Christian Daniel von Schreber in 1775. The cheetah is characterised by a slender body, deep chest, spotted coat, a small rounded head, black tear-like streaks on the face, long thin legs and a long spotted tail. Its lightly built, thin form is in sharp contrast with the robust build of the other big cats.','https://vignette.wikia.nocookie.net/animals/images/8/8e/Cheetah.jpg/revision/latest?cb=20181221181800'), + (DEFAULT,'Inland Taipan','Reptile',1290,'USD','The Inland Taipan is a specie from the Oxyranus that in native to Australia. The Inland Tapian has a dark tan, ranging from a rich, dark hue to a brownish olive-green, depending on season. Its back, sides and tail may be different shades of brown and grey, with many scales having a wide blackish edge. The lowermost lateral scales often have an anterior yellow edge. The eye is of average size with a blackish brown iris and without a noticeable coloured rim around the pupil.','https://vignette.wikia.nocookie.net/animals/images/5/5e/Inland_Taipan.jpg/revision/latest?cb=20120526014446'), + (DEFAULT,'Green Sea Turtle','Reptile',499,'USD','The Green Sea Turtle is a specie from the Cholonia genus. Its range extends throughout tropical and subtropical seas and oceans around the world, with two distinct populations in the Atlantic and Pacific Oceans. It has a teardrop-shaped carapace with a flattened body. It has a pair of paddle-like flippers and a beaked head at the end of its short neck.','https://vignette.wikia.nocookie.net/animals/images/3/33/Green_Sea_Turtle.jpg/revision/latest?cb=20181221182939'), + (DEFAULT,'Komodo Dragon','Reptile',7690,'USD','The Komodo dragon, (Varanus komodoensis), also known as the komodo monitor, is a large species of lizard found in the Indonesian islands of Komodo, Rinca, Flores, Gili Motang, and Padar. A member of the monitor lizard family it is the largest living species of lizard, growing to a maximum length of 3 metres (10 ft) in rare cases and weighing up to approximately 70 kilograms (150 lb). Their unusually large size has been attributed to island gigantism, since no other carnivorous animals fill the niche on the islands where they live.','https://vignette.wikia.nocookie.net/animals/images/3/3e/Komodo-dragon_599_600x450.jpg/revision/latest?cb=20130804224809'), + (DEFAULT,'Egyptian Cobra','Reptile',2390,'USD','The Egyptian cobra (Naja haje) is a species in the genus Naja, found in Africa and the Arabian Peninsula. It is one of the largest Naja species in Africa. The Egyptian cobra was first described by Swedish zoologist Carolus Linnaeus in 1758. The generic name naja is a Latinisation of the Sanskrit word naga meaning "cobra". The specific epithet haje is derived from the Arabic word hayya which literally means small "snake"-according to the Quran or "viper".','https://vignette.wikia.nocookie.net/animals/images/2/20/Egyptian-Cobra.jpg/revision/latest?cb=20130807221716'), + (DEFAULT,'Round Island Burrowing Boa','Reptile',1790,'USD','The Round island burrowing boa (Bolyeria multocarinata), is a extinct species of snake in the Bolyeriidae family, in the monotypic genus Bolyeria, which was endemic to Mauritius/Mauritius. The species was last seen on Round Island in 1975. No subspecies are currently recognized. It reached about 1 m (3 ft 3 in) in length, but preserved specimens have reported total lengths of 54-140 cm. Its colour was described as light brown with blackish spots dorsally and pink marbled with blackish ventrally. It had a pointed snout with a cylindrical body and head. Its general body form suggests that the Round Island Burrowing Boa had fossorial tendencies.','https://vignette.wikia.nocookie.net/animals/images/3/31/Bolyeria-multocarinata.jpg/revision/latest?cb=20140807031644'), + (DEFAULT,'Nile Crocodile','Reptile',14990,'USD','The Nile crocodile (Crocodylus niloticus) is an African crocodile and may be considered the second largest extant reptile in the world, after the saltwater crocodile (Crocodylus porosus). The Nile crocodile is quite widespread throughout Sub-Saharan Africa, occurring mostly in the central, eastern, and southern regions of the continent and lives in different types of aquatic environments such as lakes, rivers and marshlands. Although capable of living in saline environments, this species is rarely found in saltwater, but occasionally inhabits deltas and brackish lakes. The range of this species once stretched northward throughout the Nile, as far north as the Nile delta.','https://vignette.wikia.nocookie.net/animals/images/a/a9/Nile_Crocodile.jpg/revision/latest?cb=20181231201310'), + (DEFAULT,'American Alligator','Reptile',17890,'USD','The American Alligator is a large reptile that lives in the Southeast parts of the United States. The American alligator has a large, slightly rounded body, with thick limbs, a broad head, and a very powerful tail. Adult alligators generally have dark grey or nearly black color. They may at times appear to be lighter based on detritus or algae in the water covering their skin. Alligators eat fish, turtles, snakes, mammals, and amphibians. Hatchlings diet on invertebrates, insects, larvae, snails, spiders, worms, and other small prey. Young alligator regularly eat small fish at any opportunity.','https://vignette.wikia.nocookie.net/animals/images/0/03/American_Alligator.jpg/revision/latest?cb=20190101172010'), + (DEFAULT,'Black Mamba','Reptile',2290,'USD','The black mamba (Dendroaspis polylepis) is a venomous snake endemicto parts of sub-Saharan Africa. Specimens vary in colour from grey to dark brown, but not black. Juvenile black mambas tend to be lighter in colour than adults and darken with age. It is the longest species of venomous snake indigenous to the African continent; mature specimens generally exceed 2 meters (6.6 ft) and commonly attain 3 meters (9.8 ft). Specimens of 4.3 to 4.5 meters (14.1 to 14.8 ft) have been reported.','https://vignette.wikia.nocookie.net/animals/images/c/cf/Black_Mamba.jpg/revision/latest?cb=20190101165636'), + (DEFAULT,'Saltwater Crocodile','Reptile',31990,'USD','The Saltwater Crocodile is a specie from the Crocodylus genus. It is found in suitable habitats from Northern Australia through Southeast Asia to the eastern coast of India. Saltwater crocodiles are the largest extant riparian predators in the world. However, they start life fairly small. Newly hatched saltwater crocodiles measure about 28 cm (11 in) long and weigh an average of 71 g (2.5 oz). This distinct contrast in size between hatchlings and adult males is one of the greatest in terrestrial vertebrates. Males reach sexual maturity around 3.3 m (10 ft 10 in) at around 16 years of age, while females reach sexual maturity at 2.1 m (6 ft 11 in) and 12-14 years of age.','https://vignette.wikia.nocookie.net/animals/images/c/c1/Saltwater_Crocodile.jpg/revision/latest?cb=20180202031609'), + (DEFAULT,'Panther chameleon','Reptile',1199,'USD','The panther chameleon (Furcifer pardalis) is a species of chameleon found in the eastern and northern parts of Madagascar in a tropical forest biome. Additionally, it has been introduced to Reunion and Mauritius. The panther chameleon was first described by French naturalist Georges Cuvier in 1829. Its generic name (Furcifer) is derived from the Latin root furci meaning "forked" and refers to the shape of the animal''s feet. The specific name pardalisrefers to the animals'' markings, as it is Latin for "leopard" or "spotted like a panther". The English word chameleon (also chamaeleon) derives from Latin chamaeleo, a borrowing of the Ancient Greek (khamailéon), a compound of (khamaí) "on the ground" and (léon) "lion".','https://vignette.wikia.nocookie.net/animals/images/c/c1/Image-1459175441.jpeg/revision/latest?cb=20160328143041'), + (DEFAULT,'King Cobra','Reptile',1990,'USD','The king cobra (Ophiophagus hannah) is an elapid found predominantly in forests from India through Southeast Asia. This species is the world''s longest venomous snake, with a length up to 18.5 to 18.8 ft (5.6 to 5.7 m). Despite the word "cobra" in its common name, this snake is not a member of the Naja genus ("true cobras"), which contains most cobra species, but the sole member of its own genus. It preys chiefly on other snakes and occasionally on some other vertebrates, such as lizards and rodents. The king cobra is a dangerous snake that has a fearsome reputation in its range, although it typically avoids confrontation with humans when possible.','https://vignette.wikia.nocookie.net/animals/images/9/9c/King_Cobra_Close.jpg/revision/latest?cb=20120525094332'), + (DEFAULT,'Cape Melville Leaf-tailed Gecko','Reptile',99,'USD','The Cape Melville leaf-tailed gecko, (Saltuarius eximius), is a species of gecko that is endemic to the Melville Range on Cape Melville in Northern Australia. The species was described in 2013 by Australian zoologists Conrad Hoskin (of James Cook University) and Patrick Couper (curator of herpetology at Queensland Museum). The lizards are about 20 cm long and are believed to be a relic species from the time period rainforests were more abundant in Australia. The name derives from the Latin word for "extraordinary" or "exquisite", and refers to the lizard''s distinctive, camoflauged appearance. It hides among rocky boulders in the day and emerges at night to hunt on rocks and trees.','https://vignette.wikia.nocookie.net/animals/images/0/06/The_Cape_Melville_Leaf-tailed_Gecko_%28Saltuarius_eximius%29._Photo_by_Conrad_Hoskin.jpg/revision/latest?cb=20140423213111'), + (DEFAULT,'Axolotl','Amphibian',99,'USD','The Axolotl is a specie from the Ambystoma genus. The species originates from Lake Xochimilco underlying Mexico City. Axolotls have feather-like external gills, and lidless eyes. They are closely related to Tiger salamanders, and many mistaken axolotls for Tiger Salamander larva Color Variations Axolotls of various colours occur in captivity, including grey, shades of brown, leucistic (white with black eyes), golden albino, white albino, as well as other varieties, such as the melanoid (a near-black animal). The normally coloured axolotl, the "wild type", can be near-black, or even creamy in colour, and anywhere in between.','https://vignette.wikia.nocookie.net/animals/images/3/39/Mexican_Axolotl.jpg/revision/latest?cb=20120530090251'), + (DEFAULT,'Cream-backed Poison Frog','Amphibian',49,'USD','The Cream-backed Poison Frog is a specie from the Hyloxalus genus. It is endemic to Ecuador. The cream-backed poison frog is named for its back, which is cream-coloured in the males; this is the most notable difference between the sexes.','https://vignette.wikia.nocookie.net/animals/images/0/07/Hyloxalus.png/revision/latest?cb=20100731123857'), + (DEFAULT,'Tiger Salamander','Amphibian',79,'USD','The Tiger Salamander is a specie from the Ambystoma genus. The species originates from numerous lakes, such as Lake Xochimilco underlying Mexico City. Thick-bodied amphibians with short snouts, sturdy legs, and long tails, tigers are the largest land-dwelling salamander on Earth. They can grow to 14 inches in length, but the average size is more like 6 to 8 inches. Highly voracious predators, they emerge from their burrows at night to feed on worms, insects, frogs, and even other salamanders. Their population is healthy throughout their range, but deforestation, pollution, and rising acidity levels in their breeding pools is affecting their distribution.','https://vignette.wikia.nocookie.net/animals/images/c/c8/Salamandra_Tigre.png/revision/latest?cb=20120530094118'), + (DEFAULT,'Adelphobates galactonotus','Amphibian',129,'USD','Adelphobates galactonotus, also known as the splash-backed poison frog or splashback poison frog, is a species of frog in the Dendrobatidae family. It is endemic to the rainforest of the southern Amazon Basin in Brazil. Its natural habitats are tropical moist lowland forests and intermittent freshwater marshes. Though a common species, it is threatened by habitat loss.','https://vignette.wikia.nocookie.net/animals/images/b/b2/Adelphobates-galactonotus.jpg/revision/latest?cb=20150626050901'), + (DEFAULT,'Bale Mountains Tree Frog','Amphibian',169,'USD','The Bale Mountains tree frog (Balebreviceps hillmani), is a species of frog in the Brevicipitidae family. It is monotypic within the genus Balebreviceps. It is endemic to the Bale Mountains of Ethiopia. Its natural habitats are tree heath (Erica arborea) woodlands near the timberline as well as partly cleared mixed forests further down. Despite its entire range being within the Bale Mountains National Park, it is threatened by habitat loss and deterioration (deforestation) caused by cattle grazing, firewood collection, fencing, and settlement development.','https://vignette.wikia.nocookie.net/animals/images/0/03/Male-Ethiopian-short-headed-frog.jpg/revision/latest?cb=20150622043022'), + (DEFAULT,'Cape Rain Frog','Amphibian',99,'USD','The Cape rain frog or giant rain frog (Breviceps gibbosus), is a species of frog in the Brevicipitidae family. Krefft''s Warty Frog. It is endemic to South Africa, where it occurs in the far south-western Cape, in Cape Town and northwards as far as Citrusdal. In this area it inhabits Mediterranean-type shrubby vegetation, known as fynbos, renosterveld, pastureland on farms, rural gardens, and even urban areas. It seems to adapt well to suburban gardens, but like most frog species it is vulnerable to herbicide poisons and domestic pets.','https://vignette.wikia.nocookie.net/animals/images/1/1a/20110913durbanville-caperainfrog.jpg/revision/latest?cb=20150617222413'), + (DEFAULT,'Desert Rain Frog','Amphibian',179,'USD','The Desert rain frog (Breviceps macrops), is a species of frog in the Brevicipitidae family. It is found in Namibia and South Africa. Its natural habitats are subtropical or tropical dry shrubland and sandy shores. It is threatened by habitat loss. The desert rain frog is a small, plump species with bulging eyes, a short snout, short limbs, spade-like feet and webbed toes. On the underside it has a transparent area of skin through which its internal organs can be seen. Its colour is yellowish-brown and it often has sand adhering to its skin.','https://vignette.wikia.nocookie.net/animals/images/4/47/Desert-rain-frog-walking.jpg/revision/latest?cb=20150618040240'), + (DEFAULT,'Excidobates captivus','Amphibian',239,'USD','Excidobates captivus, also known as the Santiago poison frog or Rio Santiago poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Peru and southern Ecuador. Its natural habitat is tropical moist lowland forests. This frog is black with rows of orange-red spots on its back and yellow spots underneath. With an adult snout-to-vent length of 15 to 17 mm (0.6 to 0.7 in), Excidobates captivus is a very small species of poison frog. It is black with orange-red splotches arranged in a row down either side of the back. It also has small yellow spots above the armpit and groin and further pale yellow spots beneath the chin and scattered on the chest and belly and under the thighs.','https://vignette.wikia.nocookie.net/animals/images/9/90/Captivus5.jpg/revision/latest?cb=20150627075858'), + (DEFAULT,'Forest Rain Frog','Amphibian',29,'USD','The Forest rain frog (Breviceps sylvestris), is a species of frog in the Brevicipitidae family. It is endemic to Limpopo, South Africa. Two allopatric subspecies are recognized: the nominate one, Breviceps sylvestris sylvestris, and Breviceps sylvestris taeniatus from near Soutpansberg. Its natural habitats are temperate forests, temperate grassland, and rural gardens. It is threatened by habitat loss. Forest rain frogs can range in colour from red, orange, yellow, green, and purple. They can also vary in size from a mere 2cm and grow to be about 10cm in body length. The frogs are known to contain a defense mechanism consisting of a toxic chemical on their slimy exterior. If contact is made with this toxin the temporary effect of paralysis can occur.','https://vignette.wikia.nocookie.net/animals/images/3/33/Forest-rain-frog.jpg/revision/latest?cb=20150619050517'), + (DEFAULT,'Golden Poison Frog','Amphibian',399,'USD','The golden frog is found only in isolated regions of Panama. It''s bright colour warns predators that it is toxic. Scientists believe that a major cause of its decline is climate change. During drought years, the frogs are forced into overcrowded wet areas, which lead to fatal diseases. The Golden poison frog (Phyllobates terribilis), also known as the golden frog, golden poison arrow frog, or golden dart frog, is a species of frog in the Dendrobatidae family. It is endemic to the Pacific coast of Colombia.','https://vignette.wikia.nocookie.net/animals/images/2/28/Golden-poison-frog-sitting-on-leaf.jpg/revision/latest?cb=20150701043049'), + (DEFAULT,'Kihansi Spray Toad','Amphibian',149,'USD','The Kihansi spray toad (Nectophrynoides asperginis), is a species of toad in the Bufonidae family. Females reaching up to 2.9 cm (1.1 in) long and males up to 1.9 cm (0.75 in). This ovoviviparous species was scientifically described in 1999. It was found only in the spray zone around the Kihansi waterfalls in the southern Udzungwa Mountains in Tanzania. At about 20,000 m2 (220,000 sq ft), this was one of the smallest natural distribution known for any vertebrate species, Following the construction of the Kihansi Dam, it became extinct in the wild.','https://vignette.wikia.nocookie.net/animals/images/d/d0/2145.jpeg/revision/latest?cb=20150508024143'), + (DEFAULT,'Yellow-bellied Poison Frog','Amphibian',239,'USD','The Yellow-bellied poison frog (Andinobates fulguritus), also known as the yellow-bellied poison-arrow frog or yellowbelly poison frog, is a species of frog in the Dendrobatidae family. It is endemic to northwestern Colombia and east-central Panama. Its natural habitats are tropical moist lowland forests. It is a locally common, terrestrial frog. The eggs are deposited in leaf-litter; both parents carry the tadpoles to leaf axils, usually bromeliads, where they complete their development. It is threatened by habitat loss and pollution. This species seems not to be collected for pet trade.','https://vignette.wikia.nocookie.net/animals/images/f/f9/6819263362_b66923d65a_b.jpg/revision/latest?cb=20150702233228'); diff --git a/src/data/database/species.sql b/src/data/database/species.sql new file mode 100644 index 0000000..0aa0dc6 --- /dev/null +++ b/src/data/database/species.sql @@ -0,0 +1,13 @@ +drop table if exists species cascade; + +CREATE TABLE "species" ( + "id" SERIAL NOT NULL UNIQUE, + "name" TEXT primary key, + "family" TEXT, + "description" TEXT +); +INSERT INTO "species" VALUES + (DEFAULT,'Bird','Vertebrate','Birds (Aves) are a group of endothermic vertebrates, characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton.'), + (DEFAULT,'Mammal','Vertebrate','Mammals (class Mammalia /məˈmeɪli.ə/ from Latin mamma "breast") are a clade of endothermic amniotes distinguished from reptiles and birds by the possession of a neocortex (a region of the brain), hair, three middle ear bones and mammary glands.'), + (DEFAULT,'Reptile','Vertebrate','Reptiles are a group (Reptilia) of tetrapod animals comprising today''s turtles, crocodilians, snakes, amphisbaenians, lizards, tuatara, and their extinct relatives.'), + (DEFAULT,'Amphibian','Vertebrate','The amphibians are tetrapods, a class of vertebrate animals with four limbs. They are non-amniotes, which means that their eggs are not surrounded by the several membranes, some impervious, which enable mammals, reptiles and birds to reproduce on land.'); diff --git a/src/data/database/users.sql b/src/data/database/users.sql new file mode 100644 index 0000000..c1e930e --- /dev/null +++ b/src/data/database/users.sql @@ -0,0 +1,8 @@ +drop table if exists users; + +CREATE TABLE "users" ( + "id" SERIAL NOT NULL UNIQUE PRIMARY KEY, + "name" VARCHAR(255), + "email" VARCHAR(255), + "password" VARCHAR(255) +); \ No newline at end of file diff --git a/src/data/database/zoo.sql b/src/data/database/zoo.sql new file mode 100644 index 0000000..f977a40 --- /dev/null +++ b/src/data/database/zoo.sql @@ -0,0 +1,22 @@ +drop table if exists zoos; + +CREATE TABLE "zoos" ( + "id" SERIAL NOT NULL UNIQUE PRIMARY KEY, + "name" TEXT, + "state" TEXT, + "city" TEXT, + "description" TEXT +); +INSERT INTO "zoos" VALUES + (DEFAULT,'Montgomery Zoo','Alabama','Montgomery','Montgomery Zoo is a 40-acre (16 ha) zoo located on the north side of Montgomery, Alabama. The zoo is an independent city family, and is aided by The Montgomery Area Zoolocal Society. It is home to approximately 750 animals representing 140 species.'), + (DEFAULT,'Alaska Zoo','Alaska','Anchorage','The Alaska Zoo is a zoo in Anchorage, Alaska, located on 25 acres (10 ha) of the Anchorage Hillside. It is a popular attraction in Alaska, with nearly 200,000 visitors per year. The zoo is currently home to more than 100 birds and mammals representing some 50 species.'), + (DEFAULT,'Phoenix Zoo','Arizona','Phoenix','The Phoenix Zoo opened in 1962 and is the largest privately owned, non-profit zoo in the United States. Located in Phoenix, Arizona, the zoo was founded by Robert Maytag, a member of the Maytag family, and operates on 125 acres (51 ha) of land in the Papago Park area of Phoenix. It has been designated as a Phoenix Point of Pride.'), + (DEFAULT,'Los Angeles Zoo','California','Los Angeles','The Los Angeles Zoo and Botanical Gardens is a 133-acre (54 ha) zoo founded in 1966 and located in Los Angeles, California. The city of Los Angeles owns the entire zoo, its land and facilities, and the animals. Animal care, grounds maintenance, construction, education, public information, and administrative staff are city employees.'), + (DEFAULT,'San Diego Zoo','California','San Diego','The San Diego Zoo is a zoo in Balboa Park, San Diego, California, housing more than 3,500 animals of more than 650 species and subspecies. Its parent organization, San Diego Zoo Global, is one of the largest[better source need zoological membership associations in the world, with more than 250,000 member households and 130,000 child memberships, representing more than a half million people.'), + (DEFAULT,'San Francisco Zoo','California','San Francisco','The San Francisco Zoo is a 100-acre (40 ha) zoo located in the southwestern corner of San Francisco, California, between Lake Merced and the Pacific Ocean along the Great Highway. As of 2016, the zoo housed more than one thousand individual animals, representing more than 250 species. It is noted as the birthplace of Koko the gorilla, and, since 1974, the home of Elly, the oldest black rhinoceros in North America.'), + (DEFAULT,'Disney''s Animal Kingdom','Florida','Bay Lake','Disney''s Animal Kingdom is a zoological theme park at the Walt Disney World Resort in Bay Lake, Florida, near Orlando. Owned and operated by The Walt Disney Company through its Parks, Experiences and Consumer Products division, it is the largest theme park in the world, covering 580 acres (230 ha). The park opened on Earth Day, April 22, 1998, and was the fourth theme park built at the resort.'), + (DEFAULT,'Lion Country Safari','Florida','Loxahatchee','Lion Country Safari is a drive-through safari park and walk-through amusement park located on over 600 acres in Loxahatchee (near West Palm Beach), in Palm Beach County, Florida. Founded in 1967, it claims to be the first ''cageless zoo'' in the United States.'), + (DEFAULT,'Monkey Jungle','Florida','Miami','Monkey Jungle is a 30-acre (12 ha) wildlife park established in 1933 for the exhibition and study of endangered monkeys in semi-natural habitats. Many projects have been conducted at the park, which is a tourist attraction in the Miami, Florida area. The park is in Redland, Florida at Southwest 216th Street/Hainlin Mill Road near Southwest 147th Avenue.'), + (DEFAULT,'Reptile World Serpentarium','Florida','St. Cloud','Reptile World Serpentarium is a reptile zoo in St. Cloud, Osceola County, Florida. It features more than 75 species of snakes, as well as lizards, crocodiles, alligators, and turtles. It is operated by the herpetologist George Van Horn. In addition to having animals on display, it has venom milking shows.'), + (DEFAULT,'World Center for Birds of Prey','Idaho','Boise','Built 35 years ago in 1984, the World Center for Birds of Prey is located on 580 acres (2.3 km2) on a hilltop overlooking Boise, south of the airport and east of Kuna. The campus consists of the business offices of The Peregrine Fund, breeding facilities for endangered raptors, the Velma Morrison Interpretive Center, and the Herrick Collections Building, which houses a large research library and the Archives of Falconry.'), + (DEFAULT,'Yellowstone Bear World','Idaho','Rexburg','Yellowstone Bear World is a privately owned drive-thru wildlife park. It is located in Rexburg, Idaho, near Yellowstone National Park. It was established in 1998. The park holds over 8 species of wildlife indigenous to the Greater Yellowstone Ecosystem. Other attractions in the park include a small amusement park and a petting zoo. Yellowstone Bear World is the only wildlife park in the United States where guests can bottle feed bear cubs.'); diff --git a/src/main/java/com/codecool/shop/config/Initializer.java b/src/main/java/com/codecool/shop/config/Initializer.java index 68bc9ff..6db55ad 100644 --- a/src/main/java/com/codecool/shop/config/Initializer.java +++ b/src/main/java/com/codecool/shop/config/Initializer.java @@ -1,15 +1,5 @@ package com.codecool.shop.config; -import com.codecool.shop.dao.ProductCategoryDao; -import com.codecool.shop.dao.ProductDao; -import com.codecool.shop.dao.SupplierDao; -import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; -import com.codecool.shop.dao.implementation.ProductDaoMem; -import com.codecool.shop.dao.implementation.SupplierDaoMem; -import com.codecool.shop.model.Product; -import com.codecool.shop.model.ProductCategory; -import com.codecool.shop.model.Supplier; - import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; @@ -19,23 +9,6 @@ public class Initializer implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { - ProductDao productDataStore = ProductDaoMem.getInstance(); - ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); - SupplierDao supplierDataStore = SupplierDaoMem.getInstance(); - - //setting up a new supplier - Supplier amazon = new Supplier("Amazon", "Digital content and services"); - supplierDataStore.add(amazon); - Supplier lenovo = new Supplier("Lenovo", "Computers"); - supplierDataStore.add(lenovo); - - //setting up a new product category - ProductCategory tablet = new ProductCategory("Tablet", "Hardware", "A tablet computer, commonly shortened to tablet, is a thin, flat mobile computer with a touchscreen display."); - productCategoryDataStore.add(tablet); - //setting up products and printing it - productDataStore.add(new Product("Amazon Fire", 49.9f, "USD", "Fantastic price. Large content ecosystem. Good parental controls. Helpful technical support.", tablet, amazon)); - productDataStore.add(new Product("Lenovo IdeaPad Miix 700", 479, "USD", "Keyboard cover is included. Fanless Core m5 processor. Full-size USB ports. Adjustable kickstand.", tablet, lenovo)); - productDataStore.add(new Product("Amazon Fire HD 8", 89, "USD", "Amazon's latest Fire HD 8 tablet is a great value for media consumption.", tablet, amazon)); } } diff --git a/src/main/java/com/codecool/shop/controller/CheckoutController.java b/src/main/java/com/codecool/shop/controller/CheckoutController.java new file mode 100644 index 0000000..86a6915 --- /dev/null +++ b/src/main/java/com/codecool/shop/controller/CheckoutController.java @@ -0,0 +1,37 @@ +package com.codecool.shop.controller; + +import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.model.Order; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(urlPatterns = {"/checkout"}) +public class CheckoutController extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); + WebContext context = new WebContext(req, resp, req.getServletContext()); + context.setVariable("order", Order.getInstance()); + engine.process("checkout/checkout.html", context, resp.getWriter()); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + Order.getInstance().setCustomerName(request.getParameter("ShippingName")); + Order.getInstance().setCustomerEmail(request.getParameter("ShippingEmail")); + Order.getInstance().setCustomerPhone(request.getParameter("ShippingPhone")); + Order.getInstance().setCountry(request.getParameter("ShippingCountry")); + Order.getInstance().setCity(request.getParameter("ShippingCity")); + Order.getInstance().setZip(request.getParameter("ShippingZip")); + Order.getInstance().setAddress(request.getParameter("ShippingAddress")); + response.sendRedirect("/payment"); + } +} diff --git a/src/main/java/com/codecool/shop/controller/PaymentController.java b/src/main/java/com/codecool/shop/controller/PaymentController.java new file mode 100644 index 0000000..0c385f0 --- /dev/null +++ b/src/main/java/com/codecool/shop/controller/PaymentController.java @@ -0,0 +1,32 @@ +package com.codecool.shop.controller; + +import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.model.Order; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(urlPatterns = {"/payment"}) +public class PaymentController extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); + WebContext context = new WebContext(req, resp, req.getServletContext()); + context.setVariable("order", Order.getInstance()); + engine.process("payment/payment.html", context, resp.getWriter()); + + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + Order.getInstance().complete(); + resp.sendRedirect("/"); + } +} diff --git a/src/main/java/com/codecool/shop/controller/ProductController.java b/src/main/java/com/codecool/shop/controller/ProductController.java index 53c7df0..75a8a97 100644 --- a/src/main/java/com/codecool/shop/controller/ProductController.java +++ b/src/main/java/com/codecool/shop/controller/ProductController.java @@ -1,10 +1,12 @@ package com.codecool.shop.controller; -import com.codecool.shop.dao.ProductCategoryDao; -import com.codecool.shop.dao.ProductDao; -import com.codecool.shop.dao.implementation.ProductCategoryDaoMem; -import com.codecool.shop.dao.implementation.ProductDaoMem; import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.dao.implementation.Main.MainDao; +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.Order; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.WebContext; @@ -14,26 +16,44 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; +import java.util.List; +import java.util.stream.Collectors; @WebServlet(urlPatterns = {"/"}) public class ProductController extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - ProductDao productDataStore = ProductDaoMem.getInstance(); - ProductCategoryDao productCategoryDataStore = ProductCategoryDaoMem.getInstance(); + AnimalDao animalDataStore = MainDao.getAnimalDaoInstance(); + SpeciesDao speciesDataStore = MainDao.getSpeciesDaoInstance(); + ZooDao zooDataStore = MainDao.getZooDaoInstance(); -// Map params = new HashMap<>(); -// params.put("category", productCategoryDataStore.find(1)); -// params.put("products", productDataStore.getBy(productCategoryDataStore.find(1))); + if (req.getParameter("id") != null){ + int animalId = Integer.valueOf(req.getParameter("id")); + Order.getInstance().add(animalId); + } TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); WebContext context = new WebContext(req, resp, req.getServletContext()); - context.setVariable("category", productCategoryDataStore.find(1)); - context.setVariable("products", productDataStore.getBy(productCategoryDataStore.find(1))); + + String filter_species = req.getParameter("species"); + String filter_zoo = req.getParameter("zoo"); + + context.setVariable("species", speciesDataStore.getAll()); + context.setVariable("zoos", zooDataStore.getAll()); + context.setVariable("cart", Order.getInstance()); + context.setVariable("animals", filterAnimals(filter_species, filter_zoo, animalDataStore)); engine.process("product/index.html", context, resp.getWriter()); } + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + doGet(req, resp); + } + + private List filterAnimals(String species, String zoo, AnimalDao animalDataStore) { + return animalDataStore.getAll().stream() + .filter(animal -> species == null || species.equals("") || animal.getSpecies().getId() == Integer.valueOf(species)) + .filter(animal -> zoo == null || zoo.equals("") || animal.getZoo().getId() == Integer.valueOf(zoo)) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/com/codecool/shop/controller/RegistrationController.java b/src/main/java/com/codecool/shop/controller/RegistrationController.java new file mode 100644 index 0000000..201277a --- /dev/null +++ b/src/main/java/com/codecool/shop/controller/RegistrationController.java @@ -0,0 +1,42 @@ +package com.codecool.shop.controller; + +import com.codecool.shop.config.TemplateEngineUtil; +import com.codecool.shop.dao.UserDao; +import com.codecool.shop.dao.implementation.DB.UserDaoDB; +import com.codecool.shop.model.User; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(urlPatterns = "/registration") +public class RegistrationController extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); + WebContext context = new WebContext(req, resp, req.getServletContext()); + engine.process("registration/registration.html", context, resp.getWriter()); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String registrationName = req.getParameter("RegistrationName"); + String registrationEmail = req.getParameter("RegistrationEmail"); + String registrationPassword = req.getParameter("RegistrationPassword"); + + User user = new User(registrationName, registrationEmail, registrationPassword); + + UserDao userDao = UserDaoDB.getInstance(); + userDao.add(user); + + resp.sendRedirect("/"); + + } + +} diff --git a/src/main/java/com/codecool/shop/controller/ShoppingCartController.java b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java new file mode 100644 index 0000000..cc83f8b --- /dev/null +++ b/src/main/java/com/codecool/shop/controller/ShoppingCartController.java @@ -0,0 +1,46 @@ +package com.codecool.shop.controller; + +import com.codecool.shop.config.TemplateEngineUtil; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.WebContext; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import com.codecool.shop.model.Order; + + +@WebServlet(urlPatterns = {"/shopping-cart"}) +public class ShoppingCartController extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + TemplateEngine engine = TemplateEngineUtil.getTemplateEngine(req.getServletContext()); + WebContext context = new WebContext(req, resp, req.getServletContext()); + context.setVariable("cart", Order.getInstance()); + engine.process("cart/cart.html", context, resp.getWriter()); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + if (req.getParameter("id") != null) { + int animalId = Integer.valueOf(req.getParameter("id")); + Order.getInstance().add(animalId); + + resp.sendRedirect("/"); + } else if (req.getParameter("add-item-by-id") != null){ + int animalId = Integer.valueOf(req.getParameter("add-item-by-id")); + Order.getInstance().add(animalId); + doGet(req, resp); + } else if (req.getParameter("reduce-item-by-id") != null){ + int animalId = Integer.valueOf(req.getParameter("reduce-item-by-id")); + Order.getInstance().reduce(animalId); + doGet(req, resp); + } + + } +} diff --git a/src/main/java/com/codecool/shop/dao/AnimalDao.java b/src/main/java/com/codecool/shop/dao/AnimalDao.java new file mode 100644 index 0000000..6f5aa90 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/AnimalDao.java @@ -0,0 +1,15 @@ +package com.codecool.shop.dao; + +import com.codecool.shop.model.Animal; + +import java.util.List; + +public interface AnimalDao { + + void add(Animal animal); + Animal find(int id); + void remove(int id); + + List getAll(); + +} diff --git a/src/main/java/com/codecool/shop/dao/ProductCategoryDao.java b/src/main/java/com/codecool/shop/dao/ProductCategoryDao.java deleted file mode 100644 index 7ab03c5..0000000 --- a/src/main/java/com/codecool/shop/dao/ProductCategoryDao.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.codecool.shop.dao; - -import com.codecool.shop.model.ProductCategory; - -import java.util.List; - -public interface ProductCategoryDao { - - void add(ProductCategory category); - ProductCategory find(int id); - void remove(int id); - - List getAll(); - -} diff --git a/src/main/java/com/codecool/shop/dao/ProductDao.java b/src/main/java/com/codecool/shop/dao/ProductDao.java deleted file mode 100644 index 82074b5..0000000 --- a/src/main/java/com/codecool/shop/dao/ProductDao.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.codecool.shop.dao; - -import com.codecool.shop.model.Supplier; -import com.codecool.shop.model.Product; -import com.codecool.shop.model.ProductCategory; - -import java.util.List; - -public interface ProductDao { - - void add(Product product); - Product find(int id); - void remove(int id); - - List getAll(); - List getBy(Supplier supplier); - List getBy(ProductCategory productCategory); - -} diff --git a/src/main/java/com/codecool/shop/dao/SpeciesDao.java b/src/main/java/com/codecool/shop/dao/SpeciesDao.java new file mode 100644 index 0000000..51c8f00 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/SpeciesDao.java @@ -0,0 +1,17 @@ +package com.codecool.shop.dao; + +import com.codecool.shop.model.Species; + +import java.util.List; + +public interface SpeciesDao { + + void add(Species species); + Species find(int id); + Species find(String name); + + void remove(int id); + + List getAll(); + +} diff --git a/src/main/java/com/codecool/shop/dao/SupplierDao.java b/src/main/java/com/codecool/shop/dao/SupplierDao.java deleted file mode 100644 index 3246e2f..0000000 --- a/src/main/java/com/codecool/shop/dao/SupplierDao.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.codecool.shop.dao; - -import com.codecool.shop.model.Supplier; - -import java.util.List; - -public interface SupplierDao { - - void add(Supplier supplier); - Supplier find(int id); - void remove(int id); - - List getAll(); -} diff --git a/src/main/java/com/codecool/shop/dao/UserDao.java b/src/main/java/com/codecool/shop/dao/UserDao.java new file mode 100644 index 0000000..2f40a39 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/UserDao.java @@ -0,0 +1,11 @@ +package com.codecool.shop.dao; + +import com.codecool.shop.model.User; + +public interface UserDao { + + void add(User user); + public User find(int id); + void remove(int id); + +} diff --git a/src/main/java/com/codecool/shop/dao/ZooDao.java b/src/main/java/com/codecool/shop/dao/ZooDao.java new file mode 100644 index 0000000..30bb9ee --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/ZooDao.java @@ -0,0 +1,15 @@ +package com.codecool.shop.dao; + +import com.codecool.shop.model.Zoo; + +import java.util.List; + +public interface ZooDao { + + void add(Zoo zoo); + Zoo find(int id); + Zoo find(String name); + void remove(int id); + + List getAll(); +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java new file mode 100644 index 0000000..1c44cfd --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/AnimalDaoDB.java @@ -0,0 +1,100 @@ +package com.codecool.shop.dao.implementation.DB; + +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.databaseHandler.CodecoolShopDB; +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.Species; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class AnimalDaoDB implements AnimalDao { + + private static AnimalDaoDB instance; + private CodecoolShopDB cdb; + + private AnimalDaoDB() { + cdb = CodecoolShopDB.getInstance(); + } + + public static AnimalDaoDB getInstance() { + if (instance == null) instance = new AnimalDaoDB(); + return instance; + } + + @Override + public void add(Animal animal) { + try { + cdb.executeUpdate(String.format("INSERT INTO animals VALUES(default, '%1$s', '%2$s', %3$f, '%4$s', '%5$s', '%6$s')", + animal.getName(), + animal.getSpecies(), + animal.getDefaultPrice(), + animal.getDefaultCurrency(), + animal.getDescription(), + animal.getImgLink())); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void add(String name, String speciesString, Double price, String currency, String description, String imgUrl) { + Species species = SpeciesDaoDB.getInstance().find(speciesString); + Animal animal = new Animal(name, species, price, currency, description, imgUrl); + add(animal); + } + + @Override + public Animal find(int id) { + ResultSet result; + try { + result = cdb.executeQuery(String.format( + "SELECT * FROM animals WHERE id = %1$d", id) + ); + if (result.next()) { + return getAnimalFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void remove(int id) { + try { + cdb.executeUpdate(String.format("DELETE FROM animals WHERE id = %1$d", id)); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public List getAll() { + List animals = new ArrayList<>(); + ResultSet result; + try { + result = cdb.executeQuery("SELECT * FROM animals"); + while(result.next()) { + animals.add(getAnimalFromResultSet(result)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return animals; + } + + private Animal getAnimalFromResultSet(ResultSet result) throws SQLException { + Species species = SpeciesDaoDB.getInstance().find(result.getString("species")); + return new Animal( + result.getInt("id"), + result.getString("name"), + species, + result.getDouble("price"), + result.getString("currency"), + result.getString("description"), + result.getString("img_url")); + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/SpeciesDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/SpeciesDaoDB.java new file mode 100644 index 0000000..40149da --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/SpeciesDaoDB.java @@ -0,0 +1,96 @@ +package com.codecool.shop.dao.implementation.DB; + +import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.databaseHandler.CodecoolShopDB; +import com.codecool.shop.model.Species; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class SpeciesDaoDB implements SpeciesDao { + private static SpeciesDaoDB instance; + private CodecoolShopDB cdb; + + private SpeciesDaoDB() { + cdb = CodecoolShopDB.getInstance(); + } + + public static SpeciesDaoDB getInstance() { + if (instance == null) instance = new SpeciesDaoDB(); + return instance; + } + + @Override + public void add(Species species) { + try { + cdb.executeUpdate(String.format("INSERT INTO species VALUES(default, '%1$s', '%2$s', '%3$s')", + species.getName(), + species.getFamily(), + species.getDescription())); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public Species find(int id) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM species WHERE id = %1$d", id)); + if (result.next()) { + return getSpeciesFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public Species find(String name) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM species WHERE name = '%1$s'", name)); + if (result.next()) { + return getSpeciesFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void remove(int id) { + try { + cdb.executeUpdate(String.format("DELETE FROM species WHERE id = %1$d", id)); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public List getAll() { + List species = new ArrayList<>(); + ResultSet result; + try { + result = cdb.executeQuery("SELECT * FROM species"); + while(result.next()) { + species.add(getSpeciesFromResultSet(result)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return species; + } + + private Species getSpeciesFromResultSet(ResultSet result) throws SQLException { + return new Species( + result.getInt("id"), + result.getString("name"), + result.getString("family"), + result.getString("description")); + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/UserDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/UserDaoDB.java new file mode 100644 index 0000000..0bbce07 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/UserDaoDB.java @@ -0,0 +1,78 @@ +package com.codecool.shop.dao.implementation.DB; + +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.UserDao; +import com.codecool.shop.databaseHandler.CodecoolShopDB; +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.Species; +import com.codecool.shop.model.User; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + + +public class UserDaoDB implements UserDao { + + private static UserDaoDB instance; + private CodecoolShopDB cdb; + + private UserDaoDB() { + cdb = CodecoolShopDB.getInstance(); + } + + public static UserDaoDB getInstance() { + if (instance == null) instance = new UserDaoDB(); + return instance; + } + + + @Override + public void add(User user) { + try { + cdb.executeUpdate(String.format("INSERT INTO users VALUES(default, '%1$s', '%2$s', '%3$s')", + user.getName(), + user.getEmail(), + user.getPassword())); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void add(String name, String email, String password) { + User user = new User(name, email, password); + add(user); + } + + @Override + public User find(int id) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM users WHERE id = %1$d", id)); + if (result.next()) { + return getUserFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void remove(int id) { + try { + cdb.executeUpdate(String.format("DELETE FROM users WHERE id = %1$d", id)); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private User getUserFromResultSet(ResultSet result) throws SQLException { + return new User( + result.getString("name"), + result.getString("email"), + result.getString("password")); + } + +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java b/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java new file mode 100644 index 0000000..2586a10 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/DB/ZooDaoDB.java @@ -0,0 +1,125 @@ +package com.codecool.shop.dao.implementation.DB; + +import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.databaseHandler.CodecoolShopDB; +import com.codecool.shop.model.Zoo; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class ZooDaoDB implements ZooDao { + private static ZooDaoDB instance = null; + private CodecoolShopDB cdb; + private int current; + private int numOfZoos; + + private ZooDaoDB() { + cdb = CodecoolShopDB.getInstance(); + try { + ResultSet result = cdb.executeQuery("SELECT COUNT(*) FROM zoos"); + if (result.next()) { + numOfZoos = result.getInt(1); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static ZooDaoDB getInstance() { + if (instance == null) instance = new ZooDaoDB(); + return instance; + } + + @Override + public void add(Zoo zoo) { + try { + cdb.executeUpdate(String.format("INSERT INTO zoos VALUES(default, '%1$s', '%2$s', '%3$s', '%4$s')", + zoo.getName(), + zoo.getState(), + zoo.getCity(), + zoo.getDescription())); + numOfZoos++; + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public Zoo find(int id) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM zoos WHERE id = %1$d", id)); + if (result.next()) { + return getZooFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public Zoo find(String name) { + ResultSet result; + try { + result = cdb.executeQuery(String.format("SELECT * FROM zoos WHERE name = '%1$s'", name)); + if (result.next()) { + return getZooFromResultSet(result); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public void remove(int id) { + try { + cdb.executeUpdate(String.format("DELETE FROM zoos WHERE id = %1$d", id)); + numOfZoos--; + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + public List getAll() { + List zoos = new ArrayList<>(); + ResultSet result; + try { + result = cdb.executeQuery("SELECT * FROM zoos"); + while(result.next()) { + zoos.add(getZooFromResultSet(result)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return zoos; + } + + private Zoo getZooFromResultSet(ResultSet result) throws SQLException { + return new Zoo( + result.getInt("id"), + result.getString("name"), + result.getString("state"), + result.getString("city"), + result.getString("description")); + } + + public Zoo next() { + current = (current % numOfZoos) + 1; + ResultSet result; + try { + result = cdb.executeQuery("SELECT * FROM zoos"); + for (int i = 0; i < current; i++) { + result.next(); + } + return getZooFromResultSet(result); + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/Main/MainDao.java b/src/main/java/com/codecool/shop/dao/implementation/Main/MainDao.java new file mode 100644 index 0000000..6479f04 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/Main/MainDao.java @@ -0,0 +1,81 @@ +package com.codecool.shop.dao.implementation.Main; + +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; +import com.codecool.shop.dao.implementation.DB.SpeciesDaoDB; +import com.codecool.shop.dao.implementation.DB.ZooDaoDB; +import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; +import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; + +public class MainDao { + private static final Path PATH_TO_CONFIG = Paths.get( + System.getProperty("user.dir"), "/config"); + + private static AnimalDao animalDaoInstance; + private static SpeciesDao speciesDaoInstance; + private static ZooDao zooDaoInstance; + + private static String dataSource = getDataSource(); + + public static AnimalDao getAnimalDaoInstance() { + if (animalDaoInstance == null) { + if (dataSource.equals("DB")) { + animalDaoInstance = AnimalDaoDB.getInstance(); + System.out.println("Using DataBase"); + } else { + animalDaoInstance = AnimalDaoMem.getInstance(); + System.out.println("Using Memory"); + } + } + return animalDaoInstance; + } + + public static SpeciesDao getSpeciesDaoInstance() { + if (speciesDaoInstance == null) { + if (dataSource.equals("DB")) { + speciesDaoInstance = SpeciesDaoDB.getInstance(); + System.out.println("Using DataBase"); + } else { + speciesDaoInstance = SpeciesDaoMem.getInstance(); + System.out.println("Using Memory"); + } + } + return speciesDaoInstance; + } + + public static ZooDao getZooDaoInstance() { + if (zooDaoInstance == null) { + if (dataSource.equals("DB")) { + zooDaoInstance = ZooDaoDB.getInstance(); + System.out.println("Using DataBase"); + } else { + zooDaoInstance = ZooDaoMem.getInstance(); + System.out.println("Using Memory"); + } + } + return zooDaoInstance; + } + + private static Properties getProperties() { + Properties properties = new Properties(); + try { + properties.load(Files.newBufferedReader(PATH_TO_CONFIG)); + } catch (IOException e) { + e.printStackTrace(); + } + return properties; + } + + private static String getDataSource() { + return getProperties().getProperty("datasource"); + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java new file mode 100644 index 0000000..c1da088 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/AnimalDaoMem.java @@ -0,0 +1,58 @@ +package com.codecool.shop.dao.implementation.Mem; + + +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.model.Animal; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +public class AnimalDaoMem implements AnimalDao { + private static final Path PATH = Paths.get(System.getProperty("user.dir"),"/src/data/csv/animals.csv"); + + private List data = new ArrayList<>(); + private static AnimalDaoMem instance = null; + + /* A private Constructor prevents any other class from instantiating. + */ + private AnimalDaoMem() { + try { + Files.lines(PATH).forEach(line -> add(new Animal(line.strip().split("\\|")))); + } catch (IOException e) { + System.out.println("No such file or something is wrong with the file... go figure"); + e.printStackTrace(); + } + } + + public static AnimalDaoMem getInstance() { + if (instance == null) { + instance = new AnimalDaoMem(); + } + return instance; + } + + @Override + public void add(Animal animal) { + animal.setId(data.size() + 1); + data.add(animal); + } + + @Override + public Animal find(int id) { + return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); + } + + @Override + public void remove(int id) { + data.remove(find(id)); + } + + @Override + public List getAll() { + return data; + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/Mem/SpeciesDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/SpeciesDaoMem.java new file mode 100644 index 0000000..e48103a --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/SpeciesDaoMem.java @@ -0,0 +1,66 @@ +package com.codecool.shop.dao.implementation.Mem; + + +import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.model.Species; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +public class SpeciesDaoMem implements SpeciesDao { + private static final Path PATH = Paths.get(System.getProperty("user.dir"),"/src/data/csv/species.csv"); + + + private List data = new ArrayList<>(); + private static SpeciesDaoMem instance = null; + + /* A private Constructor prevents any other class from instantiating. + */ + private SpeciesDaoMem() { + try { + Files.lines(PATH).forEach(line -> { + add(new Species(line.strip().split("\\|"))); + }); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("No such file or something is wrong with the file... go figure"); + } + } + + public static SpeciesDaoMem getInstance() { + if (instance == null) { + instance = new SpeciesDaoMem(); + } + return instance; + } + + @Override + public void add(Species species) { + species.setId(data.size() + 1); + data.add(species); + } + + @Override + public Species find(int id) { + return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); + } + + @Override + public Species find(String name) { + return data.stream().filter(species -> species.getName().equals(name)).findFirst().orElse(null); + } + + @Override + public void remove(int id) { + data.remove(find(id)); + } + + @Override + public List getAll() { + return data; + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/Mem/UserDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/UserDaoMem.java new file mode 100644 index 0000000..b03988e --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/UserDaoMem.java @@ -0,0 +1,38 @@ +package com.codecool.shop.dao.implementation.Mem; + +import com.codecool.shop.dao.UserDao; +import com.codecool.shop.model.User; + +import java.util.ArrayList; +import java.util.List; + +public class UserDaoMem implements UserDao { + + private List data = new ArrayList<>(); + private static UserDaoMem instance = null; + + /* A private Constructor prevents any other class from instantiating. + */ + private UserDaoMem() { + } + + public static UserDaoMem getInstance() { + if (instance == null) { + instance = new UserDaoMem(); + } + return instance; + } + + public void add(User user) { + data.add(user); + } + + public User find(int id) { + return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); + } + + public void remove(int id) { + data.remove(find(id)); + } + +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/Mem/ZooDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/Mem/ZooDaoMem.java new file mode 100644 index 0000000..45487c4 --- /dev/null +++ b/src/main/java/com/codecool/shop/dao/implementation/Mem/ZooDaoMem.java @@ -0,0 +1,75 @@ +package com.codecool.shop.dao.implementation.Mem; + +import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.model.Zoo; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class ZooDaoMem implements ZooDao { + + private static final Path PATH = Paths.get(System.getProperty("user.dir"),"/src/data/csv/zoos.csv"); + + private int current; + private List data = new ArrayList<>(); + private static ZooDaoMem instance = null; + + /* A private Constructor prevents any other class from instantiating. + */ + private ZooDaoMem() { + try { + Files.lines(PATH).forEach(line -> { + add(new Zoo(line.strip().split("\\|"))); + }); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("No such file or something is wrong with the file... go figure"); + } + } + + public static ZooDaoMem getInstance() { + if (instance == null) { + instance = new ZooDaoMem(); + } + return instance; + } + + @Override + public void add(Zoo supplier) { + supplier.setId(data.size() + 1); + data.add(supplier); + } + + @Override + public Zoo find(int id) { + return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); + } + + @Override + public Zoo find(String name) { + return data.stream().filter(zoo -> zoo.getName().equals(name)).findFirst().orElse(null); + } + + @Override + public void remove(int id) { + data.remove(find(id)); + } + + @Override + public List getAll() { + return data; + } + + public Zoo next() { + return data.get((++current) % data.size()); + } + + public Zoo getRandom() { + return data.get(new Random().nextInt(data.size())); + } +} diff --git a/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java deleted file mode 100644 index a8cd7be..0000000 --- a/src/main/java/com/codecool/shop/dao/implementation/ProductCategoryDaoMem.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.codecool.shop.dao.implementation; - - -import com.codecool.shop.dao.ProductCategoryDao; -import com.codecool.shop.model.ProductCategory; - -import java.util.ArrayList; -import java.util.List; - -public class ProductCategoryDaoMem implements ProductCategoryDao { - - private List data = new ArrayList<>(); - private static ProductCategoryDaoMem instance = null; - - /* A private Constructor prevents any other class from instantiating. - */ - private ProductCategoryDaoMem() { - } - - public static ProductCategoryDaoMem getInstance() { - if (instance == null) { - instance = new ProductCategoryDaoMem(); - } - return instance; - } - - @Override - public void add(ProductCategory category) { - category.setId(data.size() + 1); - data.add(category); - } - - @Override - public ProductCategory find(int id) { - return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); - } - - @Override - public void remove(int id) { - data.remove(find(id)); - } - - @Override - public List getAll() { - return data; - } -} diff --git a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java deleted file mode 100644 index df65171..0000000 --- a/src/main/java/com/codecool/shop/dao/implementation/ProductDaoMem.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.codecool.shop.dao.implementation; - - -import com.codecool.shop.dao.ProductDao; -import com.codecool.shop.model.Product; -import com.codecool.shop.model.ProductCategory; -import com.codecool.shop.model.Supplier; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class ProductDaoMem implements ProductDao { - - private List data = new ArrayList<>(); - private static ProductDaoMem instance = null; - - /* A private Constructor prevents any other class from instantiating. - */ - private ProductDaoMem() { - } - - public static ProductDaoMem getInstance() { - if (instance == null) { - instance = new ProductDaoMem(); - } - return instance; - } - - @Override - public void add(Product product) { - product.setId(data.size() + 1); - data.add(product); - } - - @Override - public Product find(int id) { - return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); - } - - @Override - public void remove(int id) { - data.remove(find(id)); - } - - @Override - public List getAll() { - return data; - } - - @Override - public List getBy(Supplier supplier) { - return data.stream().filter(t -> t.getSupplier().equals(supplier)).collect(Collectors.toList()); - } - - @Override - public List getBy(ProductCategory productCategory) { - return data.stream().filter(t -> t.getProductCategory().equals(productCategory)).collect(Collectors.toList()); - } -} diff --git a/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java b/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java deleted file mode 100644 index f177f0d..0000000 --- a/src/main/java/com/codecool/shop/dao/implementation/SupplierDaoMem.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.codecool.shop.dao.implementation; - -import com.codecool.shop.dao.SupplierDao; -import com.codecool.shop.model.Supplier; - -import java.util.ArrayList; -import java.util.List; - -public class SupplierDaoMem implements SupplierDao { - - private List data = new ArrayList<>(); - private static SupplierDaoMem instance = null; - - /* A private Constructor prevents any other class from instantiating. - */ - private SupplierDaoMem() { - } - - public static SupplierDaoMem getInstance() { - if (instance == null) { - instance = new SupplierDaoMem(); - } - return instance; - } - - @Override - public void add(Supplier supplier) { - supplier.setId(data.size() + 1); - data.add(supplier); - } - - @Override - public Supplier find(int id) { - return data.stream().filter(t -> t.getId() == id).findFirst().orElse(null); - } - - @Override - public void remove(int id) { - data.remove(find(id)); - } - - @Override - public List getAll() { - return data; - } -} diff --git a/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java new file mode 100644 index 0000000..9bf8d4a --- /dev/null +++ b/src/main/java/com/codecool/shop/databaseHandler/CodecoolShopDB.java @@ -0,0 +1,73 @@ +package com.codecool.shop.databaseHandler; + + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.sql.*; + +public class CodecoolShopDB { + private static final String DEFAULT_PATH = System.getProperty("user.dir") + "/src/data"; + private static final String DATABASE = "jdbc:postgresql://localhost:5432/codecoolshop"; + private static final String DB_USER = System.getenv("POSTGRES_DB_USER"); + private static final String DB_PASSWORD = System.getenv("POSTGRES_DB_PASSWORD"); + + private static CodecoolShopDB instance; + + private CodecoolShopDB() { + executeUpdateFromFile("/database/species.sql"); + executeUpdateFromFile("/database/zoo.sql"); + executeUpdateFromFile("/database/animal.sql"); + executeUpdateFromFile("/database/users.sql"); + } + + public static CodecoolShopDB getInstance() { + if (instance == null) instance = new CodecoolShopDB(); + return instance; + } + + public Connection getConnection() { + try { + return DriverManager.getConnection(DATABASE, DB_USER, DB_PASSWORD); + } catch (SQLException e) { + System.err.println("ERROR: Connection error."); + e.printStackTrace(); + } + return null; + } + + public void executeUpdate(String query) throws SQLException { + try (Connection connection = getConnection()) { + + PreparedStatement statement = connection.prepareStatement(query); + statement.executeUpdate(); + + } catch (SQLTimeoutException e) { + System.err.println("ERROR: SQL Timeout"); + } + } + + public void executeUpdateFromFile(String filePath) { + try { + String query = Files.readString(Paths.get(DEFAULT_PATH, filePath)); + executeUpdate(query); + } catch (IOException fileError) { + System.err.println("Bad filepath"); + } catch (SQLException sqlError) { + System.err.println("Sql problem"); + sqlError.printStackTrace(); + } + } + + public ResultSet executeQuery(String query) throws SQLException { + try (Connection connection = getConnection()) { + + PreparedStatement statement = connection.prepareStatement(query); + return statement.executeQuery(); + + } catch (SQLTimeoutException e) { + System.err.println("ERROR: SQL Timeout"); + } + return null; + } +} diff --git a/src/main/java/com/codecool/shop/model/Animal.java b/src/main/java/com/codecool/shop/model/Animal.java new file mode 100644 index 0000000..0acf501 --- /dev/null +++ b/src/main/java/com/codecool/shop/model/Animal.java @@ -0,0 +1,110 @@ +package com.codecool.shop.model; + +import com.codecool.shop.dao.implementation.DB.ZooDaoDB; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; + +import java.util.Currency; + +public class Animal extends BaseModel { + + private double defaultPrice; + private Currency defaultCurrency; + private Species species; + private Zoo zoo; + private String imgLink; + + + public Animal(String name, Species species, double defaultPrice, String currencyString, String description, String imgLink) { + super(name, description); + this.species = species; + this.defaultPrice = defaultPrice; + this.defaultCurrency = Currency.getInstance(currencyString); + this.imgLink = imgLink; +// zoo = ZooDaoMem.getInstance().next(); + zoo = ZooDaoDB.getInstance().next(); + } + + public Animal(int id, String name, Species species, double defaultPrice, String currencyString, String description, String imgLink) { + super(id, name, description); + this.species = species; + this.defaultPrice = defaultPrice; + this.defaultCurrency = Currency.getInstance(currencyString); + this.imgLink = imgLink; +// zoo = ZooDaoMem.getInstance().next(); + zoo = ZooDaoDB.getInstance().next(); + } + + public Animal(String[] data) { + super(data[0], data[4]); + species = SpeciesDaoMem.getInstance().find(data[1]); + defaultPrice = Integer.valueOf(data[2]); + defaultCurrency = Currency.getInstance(data[3]); + imgLink = data[5]; +// zoo = ZooDaoMem.getInstance().next(); + zoo = ZooDaoDB.getInstance().next(); + } + + public double getDefaultPrice() { + return defaultPrice; + } + + public void setDefaultPrice(float defaultPrice) { + this.defaultPrice = defaultPrice; + } + + public Currency getDefaultCurrency() { + return defaultCurrency; + } + + public void setDefaultCurrency(Currency defaultCurrency) { + this.defaultCurrency = defaultCurrency; + } + + public String getPrice() { + return String.valueOf(this.defaultPrice) + " " + this.defaultCurrency.toString(); + } + + public void setPrice(float price, String currency) { + this.defaultPrice = price; + this.defaultCurrency = Currency.getInstance(currency); + } + + public Species getSpecies() { + return species; + } + + public void setSpecies(Species species) { + this.species = species; + this.species.addProduct(this); + } + + public Zoo getZoo() { + return zoo; + } + + public void setZoo(Zoo zoo) { + this.zoo = zoo; + this.zoo.addProduct(this); + } + + + @Override + public String toString() { + return String.format("id: %1$d, " + + "name: %2$s, " + + "defaultPrice: %3$f, " + + "defaultCurrency: %4$s, " + + "species: %5$s, " + + "zoo: %6$s", + this.id, + this.name, + this.defaultPrice, + this.defaultCurrency.toString(), + this.species.getName(), + this.zoo.getName()); + } + + public String getImgLink() { + return imgLink; + } +} \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/model/BaseModel.java b/src/main/java/com/codecool/shop/model/BaseModel.java index d6e4fc1..ad0f5d0 100644 --- a/src/main/java/com/codecool/shop/model/BaseModel.java +++ b/src/main/java/com/codecool/shop/model/BaseModel.java @@ -3,7 +3,7 @@ import java.lang.reflect.Field; -public class BaseModel { +public abstract class BaseModel { protected int id; protected String name; @@ -18,6 +18,12 @@ public BaseModel(String name, String description) { this.description = description; } + public BaseModel(int id, String name, String description) { + this.id = id; + this.name = name; + this.description = description; + } + public int getId() { return id; diff --git a/src/main/java/com/codecool/shop/model/Order.java b/src/main/java/com/codecool/shop/model/Order.java new file mode 100644 index 0000000..debb192 --- /dev/null +++ b/src/main/java/com/codecool/shop/model/Order.java @@ -0,0 +1,181 @@ +package com.codecool.shop.model; + +import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + + +public class Order { + + private static int instanceCounter; + private static Order instance = null; + + private static final String FOLDER_PATH = System.getProperty("user.dir") + "/orders/"; + + private String customerName; + private String customerEmail; + private String customerPhone; + private String country; + private String city; + private String address; + private String zip; + + private int id; + private double priceSum; + private int sumOfProducts; + private boolean confirmed; + private boolean paid; + private Map animals; + + private Order(){ + this.id = ++instanceCounter; + animals = new HashMap<>(); + } + + public static Order getInstance() { + if (instance == null) { + instance = new Order(); + } + return instance; + } + + public void add(int animalId){ + Animal existingAnimal = animals.keySet().stream().filter(anim -> anim.getId() == animalId) + .findFirst().orElse(null); + if (existingAnimal == null) animals.put(AnimalDaoDB.getInstance().find(animalId), 1); + else animals.merge(existingAnimal, 1, Integer::sum); + } + + public void reduce(int animalId){ + Animal existingAnimal = animals.keySet().stream().filter(anim -> anim.getId() == animalId) + .findFirst().orElse(null); + + if (animals.get(existingAnimal) != null) { + if(animals.get(existingAnimal) == 1){ + animals.remove(existingAnimal); + }else{ + animals.put(existingAnimal, animals.get(existingAnimal) - 1); + } + } + } + + public int getId() { + return id; + } + + public double getPriceSum(){ + priceSum = 0; + for (Map.Entry animal : animals.entrySet()){ + priceSum += animal.getKey().getDefaultPrice() * animal.getValue(); + } + return priceSum; + } + + public int getNumberOfProducts(){ + sumOfProducts = 0; + for(int value : animals.values()){ + sumOfProducts += value; + } + return sumOfProducts; + } + + public boolean isConfirmed() { + return confirmed; + } + + public boolean isPaid() { + return paid; + } + + public Map getProductsOfOrder(){ + return animals; + } + + public double getSumOfPriceBy(Animal animal) { + if (animals.get(animal) != null) { + return animals.get(animal) * animal.getDefaultPrice(); + } + return 0.0; + } + + public void complete() { + confirmed = true; + paid = true; + saveOrderToFile(); + instance = new Order(); + } + + private void saveOrderToFile() { + ObjectMapper mapper = new ObjectMapper(); + DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); + + try { + mapper.writeValue(new File(FOLDER_PATH + id + "_" + dateFormat.format(new Date()) + ".json"), instance); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getCustomerEmail() { + return customerEmail; + } + + public void setCustomerEmail(String customerEmail) { + this.customerEmail = customerEmail; + } + + public String getCustomerPhone() { + return customerPhone; + } + + public void setCustomerPhone(String customerPhone) { + this.customerPhone = customerPhone; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getZip() { + return zip; + } + + public void setZip(String zip) { + this.zip = zip; + } +} diff --git a/src/main/java/com/codecool/shop/model/Product.java b/src/main/java/com/codecool/shop/model/Product.java deleted file mode 100644 index eaf07a6..0000000 --- a/src/main/java/com/codecool/shop/model/Product.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.codecool.shop.model; - -import java.util.Currency; - -public class Product extends BaseModel { - - private float defaultPrice; - private Currency defaultCurrency; - private ProductCategory productCategory; - private Supplier supplier; - - - public Product(String name, float defaultPrice, String currencyString, String description, ProductCategory productCategory, Supplier supplier) { - super(name, description); - this.setPrice(defaultPrice, currencyString); - this.setSupplier(supplier); - this.setProductCategory(productCategory); - } - - public float getDefaultPrice() { - return defaultPrice; - } - - public void setDefaultPrice(float defaultPrice) { - this.defaultPrice = defaultPrice; - } - - public Currency getDefaultCurrency() { - return defaultCurrency; - } - - public void setDefaultCurrency(Currency defaultCurrency) { - this.defaultCurrency = defaultCurrency; - } - - public String getPrice() { - return String.valueOf(this.defaultPrice) + " " + this.defaultCurrency.toString(); - } - - public void setPrice(float price, String currency) { - this.defaultPrice = price; - this.defaultCurrency = Currency.getInstance(currency); - } - - public ProductCategory getProductCategory() { - return productCategory; - } - - public void setProductCategory(ProductCategory productCategory) { - this.productCategory = productCategory; - this.productCategory.addProduct(this); - } - - public Supplier getSupplier() { - return supplier; - } - - public void setSupplier(Supplier supplier) { - this.supplier = supplier; - this.supplier.addProduct(this); - } - - @Override - public String toString() { - return String.format("id: %1$d, " + - "name: %2$s, " + - "defaultPrice: %3$f, " + - "defaultCurrency: %4$s, " + - "productCategory: %5$s, " + - "supplier: %6$s", - this.id, - this.name, - this.defaultPrice, - this.defaultCurrency.toString(), - this.productCategory.getName(), - this.supplier.getName()); - } -} diff --git a/src/main/java/com/codecool/shop/model/ProductCategory.java b/src/main/java/com/codecool/shop/model/ProductCategory.java deleted file mode 100644 index 704dd9d..0000000 --- a/src/main/java/com/codecool/shop/model/ProductCategory.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.codecool.shop.model; - -import java.util.ArrayList; -import java.util.List; - -public class ProductCategory extends BaseModel { - private String department; - private List products; - - public ProductCategory(String name, String department, String description) { - super(name); - this.department = department; - this.products = new ArrayList<>(); - } - - public String getDepartment() { - return department; - } - - public void setDepartment(String department) { - this.department = department; - } - - public void setProducts(ArrayList products) { - this.products = products; - } - - public List getProducts() { - return this.products; - } - - public void addProduct(Product product) { - this.products.add(product); - } - - public String toString() { - return String.format( - "id: %1$d," + - "name: %2$s, " + - "department: %3$s, " + - "description: %4$s", - this.id, - this.name, - this.department, - this.description); - } -} \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/model/Species.java b/src/main/java/com/codecool/shop/model/Species.java new file mode 100644 index 0000000..798cbf7 --- /dev/null +++ b/src/main/java/com/codecool/shop/model/Species.java @@ -0,0 +1,59 @@ +package com.codecool.shop.model; + +import java.util.ArrayList; +import java.util.List; + +public class Species extends BaseModel { + private String family; + private List animals; + + public Species(String name, String family, String description) { + super(name); + this.family = family; + this.animals = new ArrayList<>(); + this.description = description; + } + + public Species(int id, String name, String family, String description) { + super(id, name, description); + this.family = family; + this.animals = new ArrayList<>(); + } + + public Species(String[] data) { + super(data[0], data[2]); + family = data[1]; + } + + public String getFamily() { + return family; + } + + public void setFamily(String family) { + this.family = family; + } + + public void setAnimals(ArrayList animals) { + this.animals = animals; + } + + public List getAnimals() { + return this.animals; + } + + public void addProduct(Animal product) { + this.animals.add(product); + } + + public String toString() { + return String.format( + "id: %1$d," + + "name: %2$s, " + + "family: %3$s, " + + "description: %4$s", + this.id, + this.name, + this.family, + this.description); + } +} \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/model/Supplier.java b/src/main/java/com/codecool/shop/model/Supplier.java deleted file mode 100644 index 72620aa..0000000 --- a/src/main/java/com/codecool/shop/model/Supplier.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.codecool.shop.model; - -import java.util.ArrayList; -import java.util.List; - -public class Supplier extends BaseModel { - private List products; - - public Supplier(String name, String description) { - super(name); - this.products = new ArrayList<>(); - } - - public void setProducts(ArrayList products) { - this.products = products; - } - - public List getProducts() { - return this.products; - } - - public void addProduct(Product product) { - this.products.add(product); - } - - public String toString() { - return String.format("id: %1$d, " + - "name: %2$s, " + - "description: %3$s", - this.id, - this.name, - this.description - ); - } -} \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/model/User.java b/src/main/java/com/codecool/shop/model/User.java new file mode 100644 index 0000000..65d4272 --- /dev/null +++ b/src/main/java/com/codecool/shop/model/User.java @@ -0,0 +1,45 @@ +package com.codecool.shop.model; + +public class User { + + String name; + String email; + String password; + int id; + private static int idCounter; + + public User(String name, String email, String phone) { + this.name = name; + this.email = email; + this.password = phone; + this.id = idCounter++; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/src/main/java/com/codecool/shop/model/Zoo.java b/src/main/java/com/codecool/shop/model/Zoo.java new file mode 100644 index 0000000..520dcd2 --- /dev/null +++ b/src/main/java/com/codecool/shop/model/Zoo.java @@ -0,0 +1,61 @@ +package com.codecool.shop.model; + +import java.util.ArrayList; +import java.util.List; + +public class Zoo extends BaseModel { + private String state; + private String city; + private List animals; + + public Zoo(String name, String state, String city, String description) { + super(name, description); + this.state = state; + this.city = city; + this.animals = new ArrayList<>(); + } + + public Zoo(int id, String name, String state, String city, String description) { + super(id, name, description); + this.state = state; + this.city = city; + this.animals = new ArrayList<>(); + } + + public Zoo(String[] data) { + super(data[0], data[3]); + state = data[1]; + city = data[2]; + this.animals = new ArrayList<>(); + } + + public void setAnimals(ArrayList animals) { + this.animals = animals; + } + + public List getAnimals() { + return this.animals; + } + + public void addProduct(Animal product) { + this.animals.add(product); + } + + public String toString() { + return String.format("id: %1$d, " + + "name: %2$s, " + + "description: %3$s", + this.id, + this.name, + this.description + ); + } + + public String getState() { + return state; + } + + public String getCity() { + return city; + } +} \ No newline at end of file diff --git a/src/main/java/com/codecool/shop/tests/TestAnimalDao.java b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java new file mode 100644 index 0000000..1bfc64d --- /dev/null +++ b/src/main/java/com/codecool/shop/tests/TestAnimalDao.java @@ -0,0 +1,58 @@ +package com.codecool.shop.tests; + +import com.codecool.shop.dao.AnimalDao; +import com.codecool.shop.dao.implementation.DB.AnimalDaoDB; +import com.codecool.shop.dao.implementation.Mem.AnimalDaoMem; + +import com.codecool.shop.model.Animal; +import com.codecool.shop.model.Species; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestAnimalDao { + + private static Stream getDAOs() { + return Stream.of( + AnimalDaoMem.getInstance(), + AnimalDaoDB.getInstance() + ); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testAdd(AnimalDao dao) { + Animal newAnimal = new Animal( + "Sample", + new Species("", "", ""), + 0f, + "USD", + "", + "" + ); + dao.add(newAnimal); + assertEquals(49, dao.getAll().size()); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testFind(AnimalDao dao) { + String expected = + "id: 1, " + + "name: Griffon Vulture, " + + "defaultPrice: 1990,000000, " + + "defaultCurrency: USD, " + + "species: Bird, " + + "zoo: Montgomery Zoo"; + assertEquals(expected, dao.find(1).toString()); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testGetAll(AnimalDao dao) { + assertEquals(48, dao.getAll().size()); + } +} diff --git a/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java new file mode 100644 index 0000000..0efaa23 --- /dev/null +++ b/src/main/java/com/codecool/shop/tests/TestSpeciesDao.java @@ -0,0 +1,63 @@ +package com.codecool.shop.tests; + +import com.codecool.shop.dao.SpeciesDao; +import com.codecool.shop.dao.implementation.DB.SpeciesDaoDB; +import com.codecool.shop.dao.implementation.Mem.SpeciesDaoMem; +import com.codecool.shop.model.Species; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.stream.Stream; + +public class TestSpeciesDao { + + private static Stream getDAOs() { + return Stream.of( + SpeciesDaoMem.getInstance(), + SpeciesDaoDB.getInstance() + ); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testAdd(SpeciesDao dao) { + Species newSpecies = new Species("Sample", "Sample", "Sample"); + dao.add(newSpecies); + assertEquals(5, dao.getAll().size()); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testFindById(SpeciesDao dao) { + String expected = + "id: 1," + + "name: Bird, " + + "family: Vertebrate, " + + "description: Birds (Aves) are a group of endothermic vertebrates, " + + "characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, " + + "a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; + assertEquals(expected, dao.find(1).toString()); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testFindByName(SpeciesDao dao) { + String expected = + "id: 1," + + "name: Bird, " + + "family: Vertebrate, " + + "description: Birds (Aves) are a group of endothermic vertebrates, " + + "characterised by feathers, toothless beaked jaws, the laying of hard-shelled eggs, " + + "a high metabolic rate, a four-chambered heart, and a lightweight but strong skeleton."; + assertEquals(expected, dao.find("Bird").toString()); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testGetAll(SpeciesDao dao) { + assertEquals(5, dao.getAll().size()); + } +} diff --git a/src/main/java/com/codecool/shop/tests/TestZooDao.java b/src/main/java/com/codecool/shop/tests/TestZooDao.java new file mode 100644 index 0000000..24f247a --- /dev/null +++ b/src/main/java/com/codecool/shop/tests/TestZooDao.java @@ -0,0 +1,64 @@ +package com.codecool.shop.tests; + +import com.codecool.shop.dao.ZooDao; +import com.codecool.shop.dao.implementation.DB.ZooDaoDB; +import com.codecool.shop.dao.implementation.Mem.ZooDaoMem; +import com.codecool.shop.model.Zoo; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestZooDao { + + private static Stream getDAOs() { + return Stream.of( + ZooDaoMem.getInstance(), + ZooDaoDB.getInstance() + ); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testAdd(ZooDao dao) { + int expected = dao.getAll().size() + 1; + Zoo newZoo = new Zoo("Sample", "Sample", "Sample", "Sample"); + dao.add(newZoo); + assertEquals(expected, dao.getAll().size()); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testFindById(ZooDao dao) { + String expected = + "id: 1, " + + "name: Montgomery Zoo, " + + "description: Montgomery Zoo is a 40-acre (16 ha) zoo " + + "located on the north side of Montgomery, Alabama. The zoo is an independent city family, " + + "and is aided by The Montgomery Area Zoolocal Society. " + + "It is home to approximately 750 animals representing 140 species."; + assertEquals(expected, dao.find(1).toString()); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testFindByName(ZooDao dao) { + String expected = + "id: 1, " + + "name: Montgomery Zoo, " + + "description: Montgomery Zoo is a 40-acre (16 ha) zoo " + + "located on the north side of Montgomery, Alabama. The zoo is an independent city family, " + + "and is aided by The Montgomery Area Zoolocal Society. " + + "It is home to approximately 750 animals representing 140 species."; + assertEquals(expected, dao.find("Montgomery Zoo").toString()); + } + + @ParameterizedTest + @MethodSource("getDAOs") + void testGetAll(ZooDao dao) { + assertEquals(13, dao.getAll().size()); + } +} diff --git a/src/main/webapp/static/css/custom.css b/src/main/webapp/static/css/custom.css index 4e4f29b..d4dbc5a 100644 --- a/src/main/webapp/static/css/custom.css +++ b/src/main/webapp/static/css/custom.css @@ -60,3 +60,70 @@ { margin: 0 0 11px; } +h1 { + margin-top: 5%; +} +.crop { + overflow: auto; + text-align: center; +} +.crop::-webkit-scrollbar { + width: 0px; /* Remove scrollbar space */ + background: transparent; /* Optional: just make scrollbar invisible */ +} +.crop img { + alignment: center; + height: 250px; + /*margin: -75px 0 0 -100px;*/ +} +.animal-description { + height: 200px; + overflow-y: auto; +} +.animal-description::-webkit-scrollbar { + width: 0px; /* Remove scrollbar space */ + background: transparent; /* Optional: just make scrollbar invisible */ +} +.animal-name { + overflow: hidden; + height: 2.5em; + overflow-y: auto; +} +.animal-name::-webkit-scrollbar { + width: 0px; /* Remove scrollbar space */ + background: transparent; /* Optional: just make scrollbar invisible */ +} + + +.fa-stack[data-count]:after{ + position:absolute; + right:0%; + top:0%; + content: attr(data-count); + font-size:40%; + padding:.6em; + border-radius:999px; + line-height:.75em; + color: white; + color:#17a2b8; + text-align:center; + min-width:2em; + font-weight:bold; + background: white; + border-style:solid; +} +.fa-circle { + color:#17a2b8; +} + +.red-cart { + color: #17a2b8; background:white; +} + +#paypal-img{ + width: 70%; +} + +#nav-tab-paypal{ + display: inline-block; +} diff --git a/src/main/webapp/static/js/paypal.js b/src/main/webapp/static/js/paypal.js new file mode 100644 index 0000000..5b66372 --- /dev/null +++ b/src/main/webapp/static/js/paypal.js @@ -0,0 +1,24 @@ + + paypal.Buttons({ + + // Set up the transaction + createOrder: function(data, actions) { + return actions.order.create({ + purchase_units: [{ + amount: { + value: '0.01' + } + }] + }); + }, + + // Finalize the transaction + onApprove: function(data, actions) { + return actions.order.capture().then(function(details) { + // Show a success message to the buyer + alert('Transaction completed by ' + details.payer.name.given_name + '!'); + }); + } + + + }).render('#paypal-button-container'); diff --git a/src/main/webapp/templates/cart/cart.html b/src/main/webapp/templates/cart/cart.html new file mode 100644 index 0000000..cde6d59 --- /dev/null +++ b/src/main/webapp/templates/cart/cart.html @@ -0,0 +1,90 @@ + + + + + + + + Shopping Cart + + + + + + + + + + + + + + + + + + + + +
+

Cart

+
+ +
+
+
+
+ Sign up +
+
+ + + + + + + + +
+
+ + + + + + + + + + +
NameQuantitySum PriceUnit Price
Product name +
+ +
+
Quantity + +
+ +
+
SumPrice of ItemUnit price
+
+
+
+
+

Sum Of Price

+ Checkout +
+ +
+ +
+ + + \ No newline at end of file diff --git a/src/main/webapp/templates/checkout/checkout.html b/src/main/webapp/templates/checkout/checkout.html new file mode 100644 index 0000000..3c2506e --- /dev/null +++ b/src/main/webapp/templates/checkout/checkout.html @@ -0,0 +1,140 @@ + + + + + + + + Codecool Shop + + + + + + + + + + + + + + + + + + + + +
+

Checkout details

+
+
+
+
+
+

Shipping details

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+

Billing address

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ +
+ + + \ No newline at end of file diff --git a/src/main/webapp/templates/footer.html b/src/main/webapp/templates/footer.html index 35adb99..734e574 100644 --- a/src/main/webapp/templates/footer.html +++ b/src/main/webapp/templates/footer.html @@ -5,7 +5,7 @@
- © 2016 Codecool Budapest + © 2019 Codecool Budapest
diff --git a/src/main/webapp/templates/payment/payment.html b/src/main/webapp/templates/payment/payment.html new file mode 100644 index 0000000..962981a --- /dev/null +++ b/src/main/webapp/templates/payment/payment.html @@ -0,0 +1,153 @@ + + + + + + + + Codecool Shop + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+

Pay Invoice

+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/src/main/webapp/templates/product/index.html b/src/main/webapp/templates/product/index.html index f9fc8b1..172426d 100644 --- a/src/main/webapp/templates/product/index.html +++ b/src/main/webapp/templates/product/index.html @@ -23,42 +23,77 @@ - + + - +
+
+

Codecool Shop

+
-
-

Codecool Shop

-
+
+
+
+ + + + +
+
+ + + + +
+
+
-
-
- Category Title +
+ Sign up +
+
+
-
-
-
- +
+
+
+
+
+ +
+
-

Product name

-

Product description...

+

Product name

+

Product description...

-

100 USD

+

100 USD

- Add to cart +
+ +
- +
diff --git a/src/main/webapp/templates/registration/registration.html b/src/main/webapp/templates/registration/registration.html new file mode 100644 index 0000000..5132aac --- /dev/null +++ b/src/main/webapp/templates/registration/registration.html @@ -0,0 +1,60 @@ + + + + + + + + Codecool Shop + + + + + + + + + + + + + + + + + + + + +
+

Registration

+
+
+ +
+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ + + \ No newline at end of file