Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testingdipinti #26

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
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
148 changes: 144 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,43 @@
</dependencyManagement>

<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>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
Expand All @@ -60,6 +76,130 @@
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency>


<!-- Adding these two dependencies made it work!!!-->
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.25.0-GA</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.thetransactioncompany/cors-filter -->
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>2.8</version>
</dependency>
<!-- testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>2.2.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.11.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>

</dependencies>

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/tresmigos/fullstackvideo/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.Tag;
import com.tresmigos.fullstackvideo.filestore.FileStore;
import com.tresmigos.fullstackvideo.model.Account;
import com.tresmigos.fullstackvideo.service.AwsServiceClient;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.List;

public class Main {
Expand All @@ -20,6 +24,11 @@ public static void main(String[] args) {
// System.out.println(tag.getValue());
// }

// EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu");
// EntityManager em = emf.createEntityManager();
//
// Account account = em.find(Account.class, 1);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:3001")
@CrossOrigin(origins = "*")
@RequestMapping(value = "/account") // We don't need to state that it's a controller in the query because of redundancy.
public class AccountController {
private AccountRepository accountRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.tresmigos.fullstackvideo.controller;

import com.tresmigos.fullstackvideo.model.Comment;
import com.tresmigos.fullstackvideo.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping(value = "/comment")
public class CommentController {
@Autowired
CommentService service;

@PostMapping("/")
public ResponseEntity<Comment> createComment(@RequestBody Comment comment) {
return new ResponseEntity<>(service.create(comment), HttpStatus.CREATED);
}

@GetMapping("/{id}")
public ResponseEntity<Comment> readCommentById(@PathVariable Long id) {
return new ResponseEntity<>(service.read(id), HttpStatus.OK);
}

@GetMapping("/allComment")
public ResponseEntity<List<Comment>> readAllComments() {
return new ResponseEntity<>(service.readAll(), HttpStatus.OK);
}

@PutMapping("/update/{id}")
public ResponseEntity<Comment> updatePost(@PathVariable Long id, @RequestBody Comment comment) {
return new ResponseEntity<>(service.update(id, comment), HttpStatus.OK);
}

@DeleteMapping("/delete")
public ResponseEntity<Comment> deletePost(@RequestBody Comment comment) {
return new ResponseEntity<>(service.delete(comment), HttpStatus.OK);
}

@DeleteMapping("/delete/{id}")
public ResponseEntity<Comment> deletePostById(@PathVariable Long id) {
return new ResponseEntity<>(service.delete(id), HttpStatus.OK);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

@RestController
@RequestMapping(value = "/video")
@CrossOrigin(origins = "http://localhost:3001")
@CrossOrigin(origins = "*")
public class VideoController {

@Autowired
private VideoService service;
VideoService service;

@Autowired
private AwsServiceClient AWS_CLIENT;
Expand Down Expand Up @@ -47,10 +47,10 @@ public ResponseEntity<Video> read(@PathVariable Long id) {
return new ResponseEntity<>(service.read(id),HttpStatus.OK);
}

@PutMapping(value = "/update/{id}")
public ResponseEntity<Video> updateVideoById(@PathVariable Long id, @RequestBody Video newVideo){
return new ResponseEntity<>(service.update(id, newVideo), HttpStatus.OK);
}
// @PutMapping(value = "/update/{id}")
// public ResponseEntity<Video> updateVideoById(@PathVariable Long id, @RequestBody Video newVideo){
// return new ResponseEntity<>(service.update(id, newVideo), HttpStatus.OK);
// }

@DeleteMapping(value = "/delete/{id}")
public ResponseEntity<Video> deleteVideoById(@PathVariable Long id){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public void save(String filePath, String fileName, Optional<Map<String, String>>
} catch(AmazonServiceException e){
throw new IllegalStateException("Failed to store file to S3", e);
}



//hey
}


Expand Down
36 changes: 24 additions & 12 deletions src/main/java/com/tresmigos/fullstackvideo/model/Account.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
package com.tresmigos.fullstackvideo.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.util.Set;
import java.util.List;

@Entity
@Table(name = "accounts_inDB")
public class Account {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ACCOUNT_ID")
//@Column(name = "ACCOUNT_ID")
private Long id;
private String username;
private String password;

@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "ACCOUNT_ID")
@OrderBy
Set<Video> videos;
@OneToMany(mappedBy = "account")
@JsonIgnore
private List<Video> videos;

public Account() {
}

public Account(Long id, String username, String password, Set<Video> videos) {
public Account(Long id, String username, String password, List<Video> videos) {
this.id = id;
this.username = username;
this.password = password;
this.videos = videos;
}

public Long getId() {
public Long getAccountId() {
return id;
}

public void setId(Long id) {
this.id = id;
public void setAccountId(Long accountId) {
this.id = accountId;
}

public String getUsername() {
Expand All @@ -52,11 +54,21 @@ public void setPassword(String password) {
this.password = password;
}

public Set<Video> getVideos() {
public List<Video> getVideos() {
return videos;
}

public void setVideos(Set<Video> videos) {
public void setVideos(List<Video> videos) {
this.videos = videos;
}

@Override
public String toString() {
return "Account{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
", videos=" + videos +
'}';
}
}
Loading