Commit 88a8f938 authored by Martins Berzins's avatar Martins Berzins
Browse files

Updated database

parent 0f2f4df6
......@@ -58,10 +58,33 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.24.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version> 5.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
......
......@@ -6,20 +6,22 @@ import java.sql.Date;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.example.calendar.models.Event;
import com.example.calendar.models.EventType;
@SpringBootApplication
@EnableJpaRepositories
public class CalendarApplication {
public static void main(String[] args) {
SpringApplication.run(CalendarApplication.class, args);
ApplicationContext context =
new ClassPathXmlApplicationContext(
"/META-INF/spring/app-context.xml");
System.out.println("Event test");
Date startingDate = new Date(2019, 05, 11);
Date endingDate = new Date(2019, 05, 12);
}
......
package com.example.calendar.controller;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDate;
import java.time.LocalTime;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import com.example.calendar.models.Calendar;
......@@ -17,7 +23,6 @@ import com.example.calendar.repo.UserRepo;
@Controller
public class DBController {
@Autowired
UserRepo userRepo;
......@@ -27,18 +32,36 @@ public class DBController {
@Autowired
CalendarRepo calendarRepo;
@Autowired
private DataSource dataSource;
@GetMapping(value="/ok")
public String test()
{
try {
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
statement.executeUpdate(
"INSERT INTO UserTable " +
"(Username, Password) " +
"VALUES " + "('DONALD', 'TRUMP')"
);
statement.close();
connection.close();
}
catch (SQLException e) {
e.printStackTrace();
}
User u1 = new User("Janis", "parole123");
userRepo.save(u1);
Event e1 = new Event("Test Event", LocalDate.now().plusDays(1), LocalTime.now().plusHours(1), false);
eventRepo.save(e1);
Calendar c1 = new Calendar();
c1.addNewEvent(e1);
//c1.addNewEvent(e1);
calendarRepo.save(c1);
//
......@@ -48,4 +71,11 @@ public class DBController {
return "ok";
}
@GetMapping(value="/getallevents")
public String getAllEvents(Model model){
//model.addAttribute("list", eventRepo.findAll());
System.out.println("---------------------");
System.out.println(eventRepo.findAll());
return "ok";
}
}
......@@ -41,6 +41,7 @@ public class Calendar {
//TODO verification
public boolean addNewEvent(Event newEvent)
{
event.add(newEvent);
return true;
}
......
......@@ -158,6 +158,10 @@ public class Event {
+ "]";
}
public Event() {
super();
}
}
package com.example.calendar.repo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.example.calendar.models.Calendar;
@Repository
public interface CalendarRepo extends CrudRepository<Calendar, Integer>{
}
package com.example.calendar.repo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.example.calendar.models.Event;
@Repository
public interface EventRepo extends CrudRepository<Event, Integer> {
}
package com.example.calendar.repo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.example.calendar.models.User;
@Repository
public interface UserRepo extends CrudRepository<User, Integer>{
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment