Skip to content

Commit

Permalink
Added front end and friends feature
Browse files Browse the repository at this point in the history
  • Loading branch information
greenfish8090 committed Nov 28, 2020
1 parent 00b01cf commit f074eb6
Show file tree
Hide file tree
Showing 81 changed files with 57,020 additions and 441 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>

</dependencies>

<build>
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/raven/app/DasboardController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.raven.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.raven.app.filters.JwtRequestFilter;

@Controller
public class DasboardController
{
@Autowired
JwtRequestFilter jwtRequestFilter;

@RequestMapping("my/{page}")
public String getPage(@PathVariable String page)
{
Expand All @@ -21,9 +29,19 @@ public String getPage(@PathVariable String page)
case "diary":
System.out.println("in /my/diary");
return "diary.html";
case "friends":
System.out.println("in /my/friends");
return "friends.html";
default:
System.out.println("in default");
return "homepage.html";
}
}
@GetMapping("/get-username")
@ResponseBody
public String getUsername()
{
System.out.println(jwtRequestFilter.getJwtUsername());
return jwtRequestFilter.getJwtUsername();
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/raven/app/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public String home()
return "homepage.html";
}

@GetMapping("/just-once")
public String getJustOnce()
{
System.out.println("in /just-once");
return "justonce.html";
}

@GetMapping("/login")
public String getLogin()
{
Expand Down Expand Up @@ -77,6 +84,12 @@ public ResponseEntity<?> signUp(@RequestBody User user, @RequestParam Integer mo
return signUpService.signUp(user, mode);
}

@GetMapping("/confirm-otp")
public String getConfirmOtp()
{
return "otp.html";
}

@PostMapping("/confirm-otp")
@ResponseBody
public ResponseEntity<?> otp(@RequestBody SignUpRequest signUpRequest) throws Exception
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/raven/app/SecurityConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void configure(HttpSecurity http) throws Exception
.antMatchers("/oauth/facebook").permitAll()
.antMatchers("/just-once").permitAll()
.antMatchers("/img/*").permitAll()
.antMatchers("/styles/*").permitAll()
.antMatchers("/styles/**").permitAll()
.antMatchers("/scripts/*").permitAll()
.antMatchers("/favicon.ico").permitAll()
.antMatchers("/my/*").permitAll()
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/raven/app/SignUpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.concurrent.ThreadLocalRandom;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.raven.app.email.EmailService;
Expand Down Expand Up @@ -70,10 +69,7 @@ public ResponseEntity<?> confirmOtp(SignUpRequest signUpRequest) throws Exceptio
cl.add(Calendar.MINUTE, 5);
if (new Date().compareTo(cl.getTime()) > 0)
{
userRepo.delete(user);
return ResponseEntity
.status(HttpStatus.FORBIDDEN)
.body("Timeout");
return ResponseEntity.ok(0);
}

System.out.println(signUpRequest.getOtp());
Expand All @@ -87,9 +83,7 @@ public ResponseEntity<?> confirmOtp(SignUpRequest signUpRequest) throws Exceptio
return createToken.createAuthenticationTokenNormal(authenticationRequest, true);
}
System.out.println("invalid");
return ResponseEntity
.status(HttpStatus.FORBIDDEN)
.body("Wrong OTP");
return ResponseEntity.ok(1);
// if(createToken.validateOtp(signUpRequest.getUsername(), signUpRequest.getOtp()))
// {
// authenticationRequest.setUsername(signUpRequest.getUsername());
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/com/raven/app/common/Common.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.raven.app.common;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "common_items")
public class Common {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="itemid")
private int itemid;

@Column(name="Username1")
private String username1;

@Column(name="Username2")
private String username2;

@Column(name="Category")
private String category;

@Column(name="Name")
private String name;

@Column(name="Quantity")
private int quantity;

@Column(name="Price")
private double price;

public int getItemid() {
return itemid;
}
public void setItemid(int itemid) {
this.itemid = itemid;
}
public String getUsername1() {
return username1;
}
public void setUsername1(String username1) {
this.username1 = username1;
}
public String getUsername2() {
return username2;
}
public void setUsername2(String username2) {
this.username2 = username2;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "Common [itemid=" + itemid + ", username1=" + username1 + ", username2=" + username2 + ", category="
+ category + ", name=" + name + ", quantity=" + quantity + ", price=" + price + "]";
}
}
138 changes: 138 additions & 0 deletions src/main/java/com/raven/app/common/CommonController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.raven.app.common;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.raven.app.filters.JwtRequestFilter;
import com.raven.app.friend.Friends;
import com.raven.app.friend.FriendsRepo;

@RestController
public class CommonController
{
@Autowired
JwtRequestFilter jwtRequestFilter;

@Autowired
CommonRepo commonRepo;

@Autowired
FriendsRepo friendsRepo;

@GetMapping("/commons")
public List<Common> getTasks()
{
return(commonRepo.findAllByUsername1OrUsername2(jwtRequestFilter.getJwtUsername(),jwtRequestFilter.getJwtUsername()));
}

@PostMapping("/common")
public void addProduct(@RequestBody CommonRequest commonRequest)
{
List<Friends> friendShipList1 = friendsRepo.findByUsername1AndStatus(jwtRequestFilter.getJwtUsername(), 2);
friendShipList1.forEach(friend -> {
if(commonRequest.getUsername2().equals(friend.getUsername2()))
{
Common common = new Common();
common.setUsername1(jwtRequestFilter.getJwtUsername());
common.setUsername2(commonRequest.getUsername2());
common.setCategory(commonRequest.getCategory());
common.setName(commonRequest.getName());
common.setPrice(commonRequest.getPrice());
common.setQuantity(commonRequest.getQuantity());
commonRepo.save(common);
}
});
List<Friends> friendShipList2 = friendsRepo.findByUsername2AndStatus(jwtRequestFilter.getJwtUsername(), 2);
friendShipList2.forEach(friend -> {
if(commonRequest.getUsername2().equals(friend.getUsername1()))
{
Common common = new Common();
common.setUsername1(jwtRequestFilter.getJwtUsername());
common.setUsername2(commonRequest.getUsername2());
common.setCategory(commonRequest.getCategory());
common.setName(commonRequest.getName());
common.setPrice(commonRequest.getPrice());
common.setQuantity(commonRequest.getQuantity());
commonRepo.save(common);
}
});
}

@PutMapping("/commons/{itemid}")
public void updateProduct(@PathVariable int itemid, @RequestBody CommonRequest commonRequest) {
commonRepo.findById(itemid).ifPresentOrElse(
existingCommon ->
{
if(existingCommon.getUsername1().equals(jwtRequestFilter.getJwtUsername())||existingCommon.getUsername2().equals(jwtRequestFilter.getJwtUsername()))
{
existingCommon.setCategory(commonRequest.getCategory());
existingCommon.setName(commonRequest.getName());
existingCommon.setQuantity(commonRequest.getQuantity());
existingCommon.setPrice(commonRequest.getPrice());
commonRepo.save(existingCommon);
}
else
System.out.println("No item found to update");
},
() -> System.out.println("No item found to update"));

}

@DeleteMapping("/commons/{itemid}")
public void deleteItem(@PathVariable int itemid)
{
commonRepo.findById(itemid).ifPresentOrElse(
common ->
{
if(common.getUsername1().equals(jwtRequestFilter.getJwtUsername())||common.getUsername2().equals(jwtRequestFilter.getJwtUsername()))
{
commonRepo.delete(common);
}
else
System.out.println("No item found to delete");
},
() -> System.out.println("No item found to delete"));
}

@PutMapping("/commons/{itemid}/add")
public void addQuantity(@PathVariable int itemid)
{
commonRepo.findById(itemid).ifPresentOrElse(
common ->
{
if(common.getUsername1().equals(jwtRequestFilter.getJwtUsername())||common.getUsername2().equals(jwtRequestFilter.getJwtUsername()))
{
common.setQuantity(common.getQuantity() + 1);
commonRepo.save(common);
}
else
System.out.println("No item found to add to");
},
() -> System.out.println("No item found to add to"));
}

@PutMapping("/commons/{itemid}/subtract")
public void subtractQuantity(@PathVariable int itemid)
{
commonRepo.findById(itemid).ifPresentOrElse(
common ->
{
if(common.getUsername1().equals(jwtRequestFilter.getJwtUsername())||common.getUsername2().equals(jwtRequestFilter.getJwtUsername()))
{
common.setQuantity(common.getQuantity() - 1);
commonRepo.save(common);
}
else
System.out.println("No item found to subtract from");
},
() -> System.out.println("No item found to subtract from"));
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/raven/app/common/CommonRepo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.raven.app.common;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

public interface CommonRepo extends JpaRepository<Common,Integer>
{
List<Common> findAllByUsername1OrUsername2(String username1, String username2);
}
41 changes: 41 additions & 0 deletions src/main/java/com/raven/app/common/CommonRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.raven.app.common;

public class CommonRequest
{
private String username2;
private String category;
private String name;
private int quantity;
private double price;

public String getUsername2() {
return username2;
}
public void setUsername2(String username2) {
this.username2 = username2;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
Loading

0 comments on commit f074eb6

Please sign in to comment.