Skip to content

Commit

Permalink
adding JAP and hibernate ORM lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamSupekar committed May 28, 2024
1 parent 166caf9 commit fdfc196
Show file tree
Hide file tree
Showing 17 changed files with 243 additions and 135 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/com/example/treaders/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EnableJpaRepositories
public class Application {

public static void main(String[] args) {
Expand Down

This file was deleted.

36 changes: 25 additions & 11 deletions src/main/java/com/example/treaders/controller/AllController.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
package com.example.treaders.controller;

import com.example.treaders.DataBaseConnection.JdbcClientRepository;
import com.example.treaders.models.VideoFormat;
import com.example.treaders.models.UserFormat;
import com.example.treaders.services.VideoRepository;
import com.example.treaders.user.InputForm;
import com.example.treaders.LLM.LlamaService;
import com.example.treaders.videoFormat.VideoFormat;
import com.example.treaders.videoFormat.VideoService;
import com.example.treaders.services.VideoService;
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 org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.example.treaders.services.UserRepository;

import java.io.IOException;
import java.util.List;


@Controller
public class AllController {
private final JdbcClientRepository jdbcClientRepository;

@Autowired
private UserRepository UserRepo;

@Autowired
private VideoRepository VideoRepo;

@Autowired
private LlamaService llamaService;

private boolean UserLoggedIn = false;

private String UserName;

@Autowired
private VideoService videoService;

public AllController(JdbcClientRepository jdbcClientRepository) {
this.jdbcClientRepository = jdbcClientRepository;
}

@GetMapping("/")
public String Login(){
Expand All @@ -39,7 +47,7 @@ public String Login(){
@GetMapping("/home")
public String home(Model model){
if(UserLoggedIn){
List<VideoFormat> videos = jdbcClientRepository.getAllVideoPath();
List<VideoFormat> videos = VideoRepo.findAll();
model.addAttribute("videos", videos);
model.addAttribute("username", UserName);
return "welcome";
Expand All @@ -49,8 +57,9 @@ public String home(Model model){

@PostMapping("/home")
public String authenticate(@RequestParam String username, @RequestParam String password, Model model){
if(jdbcClientRepository.authenticate(username, password)){
List<VideoFormat> videos = jdbcClientRepository.getAllVideoPath();
UserFormat user = UserRepo.findByUsername(username);
if(user!=null && user.getPassword().equals(password)){
List<VideoFormat> videos = VideoRepo.findAll();
model.addAttribute("videos", videos);
model.addAttribute("username", username);
UserName=username;
Expand All @@ -68,9 +77,14 @@ public String Signup(){

@PostMapping("/newuser")
public String addNewUser(@RequestParam String username, @RequestParam String password){
jdbcClientRepository.addUser(username, password);
UserFormat user=new UserFormat();
user.setUsername(username);
user.setPassword(password);
UserRepo.save(user);
return "redirect:/";
}


@PostMapping("/logout")
public String logout(){
UserLoggedIn = false;
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/example/treaders/models/UserFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.treaders.models;

import jakarta.persistence.*;

@Entity
@Table(name = "user")
public class UserFormat {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@Column(unique = true, nullable = false, length = 250)
private String username;

@Column(nullable = false, length = 250)
private String password;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
78 changes: 78 additions & 0 deletions src/main/java/com/example/treaders/models/VideoFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.example.treaders.models;

import jakarta.persistence.*;

import java.time.LocalDateTime;

@Entity
@Table(name = "videos")
public class VideoFormat {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@Column(length = 255)
private String title;

@Column(columnDefinition = "TEXT")
private String description;

@Column(length = 255)
private String filepath;

@ManyToOne
@JoinColumn(name = "uploaded_by", nullable = false)
private UserFormat uploadedBy;

@Column(name = "uploaded_at", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
private LocalDateTime uploadedAt=LocalDateTime.now();

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getFilepath() {
return filepath;
}

public void setFilepath(String filepath) {
this.filepath = filepath;
}

public UserFormat getUploadedBy() {
return uploadedBy;
}

public void setUploadedBy(UserFormat uploadedBy) {
this.uploadedBy = uploadedBy;
}

public LocalDateTime getUploadedAt() {
return uploadedAt;
}

public void setUploadedAt(LocalDateTime uploadedAt) {
this.uploadedAt = uploadedAt;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/example/treaders/services/UserRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.treaders.services;

import com.example.treaders.models.UserFormat;
import org.springframework.data.jpa.repository.JpaRepository;



public interface UserRepository extends JpaRepository<UserFormat, Integer> {
UserFormat findByUsername(String username);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.treaders.services;

import com.example.treaders.models.VideoFormat;
import org.springframework.data.jpa.repository.JpaRepository;

public interface VideoRepository extends JpaRepository<VideoFormat,Integer> {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.treaders.videoFormat;
package com.example.treaders.services;

import com.example.treaders.DataBaseConnection.JdbcClientRepository;
import com.example.treaders.models.VideoFormat;
import com.example.treaders.models.UserFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -9,23 +10,42 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;

@Service
public class VideoService {

private final JdbcClientRepository jdbcClientRepository;
@Autowired
private VideoRepository videoRepository;

@Autowired
public VideoService(JdbcClientRepository jdbcClientRepository) {
this.jdbcClientRepository = jdbcClientRepository;
}
private UserRepository UserRepo;

private UserFormat userFormat;
// private final JdbcClientRepository jdbcClientRepository;
//
// @Autowired
// public VideoService(JdbcClientRepository jdbcClientRepository) {
// this.jdbcClientRepository = jdbcClientRepository;
// }

public void saveVideo(MultipartFile file, String title, String description, String uploadedBy) throws IOException {
public void saveVideo(MultipartFile file, String title, String description, String UserName) throws IOException {
// Save the uploaded video file to a directory
String filePath = saveVideoFile(file);

UserFormat user = UserRepo.findByUsername(UserName);

if(user==null){
throw new IllegalArgumentException("User not found "+UserName);
}

// Save video details to the database
jdbcClientRepository.saveVideoIntoDatabase(title, description, filePath, uploadedBy);
VideoFormat videoFormat = new VideoFormat();
videoFormat.setTitle(title);
videoFormat.setDescription(description);
videoFormat.setFilepath(filePath);
videoFormat.setUploadedBy(user);
videoFormat.setUploadedAt(LocalDateTime.now());
videoRepository.save(videoFormat);
}

private String saveVideoFile(MultipartFile file) throws IOException {
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/example/treaders/videoFormat/VideoFormat.java

This file was deleted.

Loading

0 comments on commit fdfc196

Please sign in to comment.