Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tanel</groupId>
<artifactId>tanel</artifactId>
<packaging>jar</packaging>
<version>1</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
50 changes: 50 additions & 0 deletions src/main/java/tanel/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package tanel;

import java.util.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController

//funktsiooni nimed ja muutujad on väikese algustähega
//klassinimed camelcase

public class Application{

@Autowired
private ManageTable manager;

@RequestMapping("/create")
String create(String kauplus, String tooteNimi, Integer hind){
manager.save(new Tooted(kauplus, tooteNimi, hind));
return "Toode "+ tooteNimi +" lisatud";
}

@RequestMapping("/search")
String Search(String tooteNimi){
if(tooteNimi.isEmpty()){return "no info";}
List<Tooted> tooted=manager.findBytooteNimi(tooteNimi);
if(tooted.isEmpty()){return tooteNimi+" not found";}
StringBuffer sb = new StringBuffer();
for(Tooted toode: tooted){
sb.append("<p>");
sb.append("Toode " + tooteNimi + " on kaupluses nimega " + toode.kauplus + " ja see maksab: "+ toode.hind.toString());
sb.append("</p>");
}
return sb.toString();

}

public static void main(String[] args){
SpringApplication.run(Application.class, args);
}


}



10 changes: 10 additions & 0 deletions src/main/java/tanel/ManageTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tanel;

import java.util.*;
import javax.transaction.Transactional;
import org.springframework.data.repository.CrudRepository;

@Transactional
public interface ManageTable extends CrudRepository<Tooted, Long> {
List<Tooted> findBytooteNimi(String tooteNimi);
}
26 changes: 26 additions & 0 deletions src/main/java/tanel/Tooted.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tanel;

import javax.persistence.*;

@Table(name="tooted")
@Entity
public class Tooted{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public Long id;
public String kauplus;
public String tooteNimi;
public Integer hind;


public Tooted(){

}

public Tooted(String kauplus, String tooteNimi, Integer hind){
this.kauplus = kauplus;
this.tooteNimi = tooteNimi;
this.hind = hind;
}

}
7 changes: 7 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url = jdbc:mysql://localhost/if16_Tanelmaas_1
spring.datasource.username = if16
spring.datasource.password = ifikad16
server.port = 8548
Binary file added src/main/resources/public/background.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/main/resources/public/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<title>Tooted</title>
<script>
var connection=new XMLHttpRequest();
connection.onreadystatechange=receivedData;
function create(){
var kauplus=document.getElementById("kauplus").value;
var tooteNimi=document.getElementById("tooteNimi").value;
var hind=document.getElementById("hind").value;
connection.open("GET", "/create?kauplus="+kauplus+"&tooteNimi="+tooteNimi+"&hind="+hind, true);
connection.send();
}
function search(){
var tooteNimi = document.getElementById("search").value;
connection.open("GET", "/search?tooteNimi="+tooteNimi, true);
connection.send();
}
function receivedData(){
document.getElementById("response").innerHTML=connection.responseText;
}
</script>
</head>
<body>
<div id="response"></div>
<h1>Lisa toode</h1>
<div>
<label for="tooteNimi">Kauplus:</label>
<input type="text" id="kauplus" />
</div>
<div>
<label for="tooteNimi">Toote nimi:</label>
<input type="text" id="tooteNimi" />
</div>
<div>
<label for="hind">Hind:</label>
<input type="number" id="hind" />
</div>
<br>
<div>
<input type="button" value="Lisa" onclick="create()"/>
</div>
<br>
<div>
<label for="search">Otsi</label>
<input type="text" id="search" />
<input type="button" value="Otsi" onclick="search()" />
</div>
</html>
7 changes: 7 additions & 0 deletions target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url = jdbc:mysql://localhost/if16_Tanelmaas_1
spring.datasource.username = if16
spring.datasource.password = ifikad16
server.port = 8548
Binary file added target/classes/public/background.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions target/classes/public/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html>
<style>
.laikast {
width: 50%;
height:70%;
background-color: #DCDCDC;
border: 2px solid #ccc;
text-align: center;
position: absolute;
right: 25%;
> h2 {
padding: 1rem;
margin: 0 0 0.5rem 0;
}
> p {
padding: 0 1rem;
}
}
.kitsaskast {
width: 80%;
background-color: white;
border: 2px solid #ccc;
text-align: center;
position: absolute;
right: 10%;
> h2 {
padding: 1rem;
margin: 0 0 0.5rem 0;
}
> p {
padding: 0 1rem;
}
}
.stripe-2 {
color: black;
background: repeating-linear-gradient(
45deg,
transparent,
transparent 10px,
#ccc 10px,
#ccc 20px
),
linear-gradient(
to bottom,
#eee,
#999
)
}
</style>
<head>
<title>Tooted</title>
<script>
var connection=new XMLHttpRequest();
connection.onreadystatechange=receivedData;
function create(){
var kauplus=document.getElementById("kauplus").value;
var tooteNimi=document.getElementById("tooteNimi").value;
var hind=document.getElementById("hind").value;
connection.open("GET", "/create?kauplus="+kauplus+"&tooteNimi="+tooteNimi+"&hind="+hind, true);
connection.send();
}
function search(){
var tooteNimi = document.getElementById("search").value;
connection.open("GET", "/search?tooteNimi="+tooteNimi, true);
connection.send();
}
function receivedData(){
document.getElementById("response").innerHTML=connection.responseText;
}
</script>
</head>
<body background="background.gif">
<div class="laikast">
<div class="kitsaskast">
<h2 class="stripe-2">Lisa toode</h2>
<div id="response"></div>
<div>
<label for="tooteNimi">Kauplus:</label>
<input type="text" id="kauplus" />
</div>
<br>
<div>
<label for="tooteNimi">Toote nimi:</label>
<input type="text" id="tooteNimi" />
</div>
<br>
<div>
<label for="hind">Hind:</label>
<input type="number" id="hind" />
</div>
<br>
<div>
<input type="button" value="Lisa" onclick="create()"/>
</div>
<br><br>
<div>
<label for="search">Otsi</label>
<input type="text" id="search" />
<input type="button" value="Otsi" onclick="search()" />
</div>
</html>
Binary file added target/classes/tanel/Application.class
Binary file not shown.
Binary file added target/classes/tanel/ManageTable.class
Binary file not shown.
Binary file added target/classes/tanel/Tooted.class
Binary file not shown.
5 changes: 5 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Generated by Maven
#Fri Apr 07 14:28:07 EEST 2017
version=1
groupId=tanel
artifactId=tanel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tanel/Application.class
tanel/ManageTable.class
tanel/Tooted.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/home/tanelmaas/public_html/t05veebirakendus/src/main/java/tanel/ManageTable.java
/home/tanelmaas/public_html/t05veebirakendus/src/main/java/tanel/Application.java
/home/tanelmaas/public_html/t05veebirakendus/src/main/java/tanel/Tooted.java
Binary file added target/tanel-1.jar.original
Binary file not shown.
Binary file added target/tanel-1.original
Binary file not shown.