diff --git a/Rakendus.java b/Rakendus.java new file mode 100644 index 0000000..ea9f186 --- /dev/null +++ b/Rakendus.java @@ -0,0 +1,53 @@ +package karolin; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@SpringBootApplication +public class Rakendus { + private final ToidunimekiriDao toidunimekiriDao; + + @Autowired + public Rakendus(ToidunimekiriDao toidunimekiriDao) { + this.toidunimekiriDao = toidunimekiriDao; + } + + @RequestMapping("/listall") + String listall(String food) { + StringBuffer sb = new StringBuffer(); + for (Toidunimekiri item : toidunimekiriDao.findAll()) { + sb.append(item); + } + String thead = "IdFoodAmount"; + return thead + sb.toString(); + } + + @RequestMapping("/lisa") + String lisa(String food, Integer amount) { + Toidunimekiri toidunimekiri = new Toidunimekiri(); + toidunimekiri.food = food; + toidunimekiri.amount = amount; + toidunimekiriDao.save(toidunimekiri); + return "Lisatud " + food + amount; + } + + @RequestMapping("/kustuta") + String kustuta(Integer id) { + Toidunimekiri toidunimekiri = toidunimekiriDao.findOne(id); + toidunimekiriDao.delete(toidunimekiri); + return toidunimekiri.food + " " + toidunimekiri.amount + " on kustutatud"; + } + + public static void main(String[] args) { + System.getProperties().put("server.port", 5555); + SpringApplication.run(Rakendus.class, args); + } +} + +//scl enable rh-maven33 bash +//mvn package +//java -jar target/rakendus-1.jar \ No newline at end of file diff --git a/Toidunimekiri.java b/Toidunimekiri.java new file mode 100644 index 0000000..db9901a --- /dev/null +++ b/Toidunimekiri.java @@ -0,0 +1,22 @@ +package karolin; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Entity +@Table(name = "toidunimekiri") +public class Toidunimekiri { + @Id + @GeneratedValue + Integer id; + String food; + Integer amount; + + @Override + public String toString() { + return "" + id + "" + food + "" + amount + ""; + } +} \ No newline at end of file diff --git a/ToidunimekiriDao.java b/ToidunimekiriDao.java new file mode 100644 index 0000000..7ad2f75 --- /dev/null +++ b/ToidunimekiriDao.java @@ -0,0 +1,10 @@ +package karolin; + +import org.springframework.data.repository.CrudRepository; + +import javax.transaction.Transactional; + +@Transactional +public interface ToidunimekiriDao extends CrudRepository { + +} \ No newline at end of file diff --git a/application.properties b/application.properties new file mode 100644 index 0000000..e512a8c --- /dev/null +++ b/application.properties @@ -0,0 +1,4 @@ +spring.datasource.url = jdbc:mysql://localhost/if16_karojyrg_2 + +spring.datasource.username = if16 +spring.datasource.password = ifikad16 diff --git a/index.html b/index.html new file mode 100644 index 0000000..7a281e1 --- /dev/null +++ b/index.html @@ -0,0 +1,66 @@ + + + + Toidunimekiri + + + + + + +

Loetelu

+
+
+
+ +

Lisa

+
+
+
+
+ + + +

Kustuta

+
+ + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c5a27df --- /dev/null +++ b/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + karolin + rakendus + jar + 1 + + org.springframework.boot + spring-boot-starter-parent + 1.5.2.RELEASE + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/rakendus.iml b/rakendus.iml new file mode 100644 index 0000000..24639e6 --- /dev/null +++ b/rakendus.iml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/t05veebirakendus.iml b/t05veebirakendus.iml new file mode 100644 index 0000000..75aae28 --- /dev/null +++ b/t05veebirakendus.iml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tabel.txt b/tabel.txt new file mode 100644 index 0000000..229abf5 --- /dev/null +++ b/tabel.txt @@ -0,0 +1,10 @@ +CREATE TABLE `toidunimekiri` ( + `food` VARCHAR(255) NOT NULL , + `amount` INT NOT NULL , + ENGINE = InnoDB; + +INSERT INTO `toidunimekiri` (`food`, `amount`) VALUES + ('Piim', '2'), + +ALTER TABLE `toidunimekiri` ADD `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD UNIQUE (`id`); +ALTER TABLE `toidunimekiri` DROP PRIMARY KEY, ADD PRIMARY KEY(`id`);