forked from Raven-46/task-tracker-new
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00b01cf
commit f074eb6
Showing
81 changed files
with
57,020 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
138
src/main/java/com/raven/app/common/CommonController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.