Skip to content

Commit bcf3f91

Browse files
authored
Merge pull request #33 from CSC207-2022F-UofT/Final-Merge
Final merge
2 parents c701443 + b7ab887 commit bcf3f91

File tree

97 files changed

+10325
-1323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+10325
-1323
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ fabric.properties
8181
**/build/
8282
!src/**/build/
8383

84-
## Mongo-Related
85-
src/main/resources/application.properties
8684

8785
# Ignore Gradle GUI config
8886
gradle-app.setting

src/main/java/com/backend/controller/AccountController.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
package com.backend.controller;
22

33
import com.backend.entities.IDs.SessionID;
4-
import com.backend.usecases.AccountManager;
4+
import com.backend.usecases.facades.AccountSystemFacade;
5+
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.http.ResponseEntity;
67
import org.springframework.web.bind.annotation.*;
78

89
@RestController
910
public class AccountController {
11+
private final AccountSystemFacade accountSystemFacade;
12+
13+
/**
14+
* Spring Boot Dependency Injection of the accountSystemFacade
15+
* @param accountSystemFacade the dependency to be injected
16+
*/
17+
@Autowired
18+
public AccountController(AccountSystemFacade accountSystemFacade) {
19+
this.accountSystemFacade = accountSystemFacade;
20+
}
21+
1022
/**
1123
* Post request to log in with the given credentials
1224
* @param username of type String, username to reference associated account
@@ -16,7 +28,7 @@ public class AccountController {
1628
@PostMapping("/login" )
1729
public ResponseEntity<Object> loginAccount(@RequestParam String username, String password){
1830
// Run AccountManager service
19-
return AccountManager.loginAccount(username, password);
31+
return this.accountSystemFacade.loginAccount(username, password);
2032
}
2133

2234
/**
@@ -27,7 +39,7 @@ public ResponseEntity<Object> loginAccount(@RequestParam String username, String
2739
@PostMapping("/logout" )
2840
public ResponseEntity<Object> logoutAccount(@RequestParam String sessionID){
2941
// Run AccountManager service
30-
return AccountManager.logoutAccount(new SessionID(sessionID));
42+
return this.accountSystemFacade.logoutAccount(new SessionID(sessionID));
3143
}
3244

3345
/**
@@ -39,7 +51,7 @@ public ResponseEntity<Object> logoutAccount(@RequestParam String sessionID){
3951
@PostMapping("/register" )
4052
public ResponseEntity<Object> registerAccount(@RequestParam String username, String password){
4153
// Run AccountManager service
42-
return AccountManager.registerAccount(username, password);
54+
return this.accountSystemFacade.registerAccount(username, password);
4355
}
4456

4557
/**
@@ -50,7 +62,31 @@ public ResponseEntity<Object> registerAccount(@RequestParam String username, Str
5062
@DeleteMapping("/delete" )
5163
public ResponseEntity<Object> deleteAccount(@RequestParam String sessionID){
5264
// Run AccountManager service
53-
return AccountManager.deleteAccount(new SessionID(sessionID));
65+
return this.accountSystemFacade.deleteAccount(new SessionID(sessionID));
66+
}
67+
68+
/**
69+
* Patch request to update the account associated with the given parameter
70+
* @param sessionID of type String, sessionID to reference the account to be deleted
71+
* @param newUsername of type String, newUsername to change the account credential to
72+
* @return a response entity detailing successful completion or any associated error
73+
*/
74+
@PatchMapping("/updateUsername" )
75+
public ResponseEntity<Object> updateAccountUsername(@RequestParam String sessionID, String newUsername){
76+
// Run AccountManager service
77+
return this.accountSystemFacade.updateUsername(new SessionID(sessionID), newUsername);
78+
}
79+
80+
/**
81+
* Patch request to update the account associated with the given parameter
82+
* @param sessionID of type String, sessionID to reference the account to be deleted
83+
* @param newPassword of type String, newPassword to change the account credential to
84+
* @return a response entity detailing successful completion or any associated error
85+
*/
86+
@PatchMapping("/updatePassword" )
87+
public ResponseEntity<Object> updateAccountPassword(@RequestParam String sessionID, String newPassword){
88+
// Run AccountManager service
89+
return this.accountSystemFacade.updatePassword(new SessionID(sessionID), newPassword);
5490
}
5591

5692
/**
@@ -61,6 +97,6 @@ public ResponseEntity<Object> deleteAccount(@RequestParam String sessionID){
6197
@GetMapping("/account" )
6298
public ResponseEntity<Object> getAccount(@RequestParam String sessionID) {
6399
// Run AccountManager service
64-
return AccountManager.getAccountInfo(new SessionID(sessionID));
100+
return this.accountSystemFacade.getAccountInfo(new SessionID(sessionID));
65101
}
66102
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.backend.controller;
2+
3+
import com.backend.usecases.facades.FeedSystemFacade;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestParam;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController
11+
public class FeedController {
12+
private final FeedSystemFacade feedSystemFacade;
13+
14+
/**
15+
* Spring Boot Dependency Injection of the accountSystemFacade
16+
* @param feedSystemFacade the dependency to be injected
17+
*/
18+
@Autowired
19+
public FeedController(FeedSystemFacade feedSystemFacade) {
20+
this.feedSystemFacade = feedSystemFacade;
21+
}
22+
23+
/**
24+
* Get a list of feed data representing information regarding recent posts made by friends
25+
* @param sessionID of type String, password to reference associated account
26+
* @return a response entity detailing successful completion (with a newly generated SessionID) or any associated error
27+
*/
28+
@GetMapping("/feed" )
29+
public ResponseEntity<Object> getFeed(@RequestParam String sessionID){
30+
// Run AccountManager service
31+
return this.feedSystemFacade.getFeed(sessionID);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.backend.controller;
2+
3+
4+
import com.backend.usecases.facades.FriendSystemFacade;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.web.bind.annotation.*;
8+
9+
@RestController
10+
public class FriendController {
11+
12+
private final FriendSystemFacade friendSystemFacade;
13+
14+
@Autowired
15+
public FriendController(FriendSystemFacade friendSystemFacade) {
16+
this.friendSystemFacade = friendSystemFacade;
17+
}
18+
19+
@GetMapping("/friends/getFriends")
20+
public ResponseEntity<Object> getFriends(@RequestParam String sessionID) {
21+
return this.friendSystemFacade.getUserFriends(sessionID);
22+
}
23+
24+
@DeleteMapping("/friends/deleteFriend")
25+
public ResponseEntity<Object> deleteFriend(@RequestParam String friendUserName, @RequestParam String sessionID) {
26+
return this.friendSystemFacade.deleteFriend(friendUserName, sessionID);
27+
}
28+
29+
@DeleteMapping("/friends/deleteAllCorrelatedFriends")
30+
public ResponseEntity<Object> deleteAllCorrelatedFriends(@RequestParam String sessionID) {
31+
return this.friendSystemFacade.deleteAllCorrelatedFriends(sessionID);
32+
}
33+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.backend.controller;
2+
3+
import com.backend.usecases.facades.FriendSystemFacade;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
@RestController
9+
public class InvitationController {
10+
11+
private final FriendSystemFacade friendSystemFacade;
12+
13+
@Autowired
14+
public InvitationController(FriendSystemFacade friendSystemFacade) {
15+
this.friendSystemFacade = friendSystemFacade;
16+
}
17+
18+
// create a get request to get invitations for a specific user
19+
@GetMapping("/friends/getInviteAsReceiver")
20+
public ResponseEntity<Object> getInvitationsAsReceiver(@RequestParam String sessionID) {
21+
// get sessionID from request
22+
// call getInvitations method from InvitationsManager
23+
// return response
24+
return this.friendSystemFacade.getInvitations(sessionID, true);
25+
}
26+
27+
@GetMapping("/friends/getInviteAsSender")
28+
public ResponseEntity<Object> getInvitationsAsSender(@RequestParam String sessionID) {
29+
// get sessionID from request
30+
// call getInvitations method from InvitationsManager
31+
// return response
32+
return this.friendSystemFacade.getInvitations(sessionID, false);
33+
}
34+
35+
// create a post request to send an invitation
36+
@PostMapping("/friends/sendInvite")
37+
public ResponseEntity<Object> sendInvitation(@RequestParam String receiverUsername, String sessionID) {
38+
// create invitation
39+
// save invitation to the database
40+
return this.friendSystemFacade.sendInvitation(receiverUsername, sessionID);
41+
}
42+
43+
@DeleteMapping("/friends/withdrawInvite")
44+
public ResponseEntity<Object> withdrawInvitation(@RequestParam String receiverUsername, String sessionID) {
45+
return this.friendSystemFacade.withdrawInvitation(receiverUsername, sessionID);
46+
}
47+
48+
// create a post request to accept an invitation
49+
@PostMapping("/friends/acceptInvite")
50+
public ResponseEntity<Object> acceptInvitation(@RequestParam String receiverUsername, String sessionID) {
51+
return this.friendSystemFacade.handleInvitation(receiverUsername, sessionID, true);
52+
}
53+
54+
55+
// create a post request to decline an invitation
56+
@DeleteMapping("/friends/declineInvite")
57+
public ResponseEntity<Object> declineInvitation(@RequestParam String receiverUsername, @RequestParam String sessionID) {
58+
// check if invitation exists
59+
// delete invitation from the database
60+
return this.friendSystemFacade.handleInvitation(receiverUsername, sessionID, false);
61+
}
62+
63+
@DeleteMapping("/friends/deleteAllCorrelatedInvitations")
64+
public ResponseEntity<Object> deleteAllCorrelatedInvitations(@RequestParam String sessionID) {
65+
66+
return this.friendSystemFacade.deleteAllCorrelatedInvitations(sessionID);
67+
}
68+
}

src/main/java/com/backend/controller/PetController.java

Lines changed: 16 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,42 @@
11
package com.backend.controller;
22

3-
import com.backend.entities.Pet;
4-
import com.backend.entities.ShopItem;
5-
import com.backend.error.handlers.LogHandler;
6-
import com.backend.repositories.PetRepo;
7-
import com.backend.usecases.ShopManager;
8-
import org.springframework.http.HttpStatus;
3+
import com.backend.entities.IDs.SessionID;
4+
import com.backend.usecases.facades.PetSystemFacade;
5+
import org.springframework.beans.factory.annotation.Autowired;
96
import org.springframework.http.ResponseEntity;
107
import org.springframework.web.bind.annotation.GetMapping;
118
import org.springframework.web.bind.annotation.PostMapping;
129
import org.springframework.web.bind.annotation.RequestParam;
1310
import org.springframework.web.bind.annotation.RestController;
1411

15-
import java.util.ArrayList;
16-
import java.util.Optional;
1712

1813
@RestController
1914
public class PetController {
20-
/**
21-
* Get request to getPet with the sessionID from the database
22-
* @param sessionID string that represents the current session and verifies the action
23-
*/
24-
@GetMapping("/pet")
25-
public ResponseEntity<Object> pets(@RequestParam String sessionID){
26-
Optional<Pet> pet = ShopManager.getPet(sessionID);
2715

28-
if (pet.isPresent()){
29-
return new ResponseEntity<>(pet, HttpStatus.OK);
30-
}
31-
return LogHandler.logError(new Exception("curAccount is null"), HttpStatus.BAD_REQUEST);
32-
}
33-
34-
/**
35-
* Post request to addPet with the petID from the database
36-
* @param id string that represents the current session and verifies the action
37-
*/
38-
@PostMapping("/addPet")
39-
public ResponseEntity<Object> addPet(@RequestParam String id){
40-
Pet pet = ShopManager.addPet(id);
16+
private final PetSystemFacade petSystemFacade;
4117

42-
return new ResponseEntity<>(pet, HttpStatus.OK);
18+
@Autowired
19+
public PetController(PetSystemFacade petSystemFacade){
20+
this.petSystemFacade = petSystemFacade;
4321
}
4422

4523
/**
46-
* Post request to replace the current pet with the same pet with an updated outfit from the database
47-
* @param sessionID string that represents the current session and verifies the action
48-
* @param newOutfit ArrayList of ShopItems that will be for the updated outfit
49-
*/
50-
@PostMapping("/updatePetOutfit")
51-
public ResponseEntity<Object> updatePetOutfit(@RequestParam String sessionID, ArrayList<ShopItem> newOutfit){
52-
boolean successful = ShopManager.updateCurrentOutfit(sessionID, newOutfit);
53-
54-
if (successful){
55-
return new ResponseEntity<>("Pet outfit successfully updated", HttpStatus.OK);
56-
}
57-
58-
return LogHandler.logError(new Exception("outfit failed to update"), HttpStatus.BAD_REQUEST);
59-
}
60-
61-
/**
62-
* Get request to get Pet Balance with the sessionID from the database
63-
* @param sessionID string that represents the current session and verifies the action
64-
*/
65-
@GetMapping("/petBalance")
66-
public ResponseEntity<Object> getBalance(@RequestParam String sessionID){
67-
Optional<Double> balance = ShopManager.getBalance(sessionID);
68-
69-
if (balance.isPresent()){
70-
return new ResponseEntity<>(balance, HttpStatus.OK);
71-
}
72-
73-
return LogHandler.logError(new Exception("Get balance failed"), HttpStatus.BAD_REQUEST);
74-
}
75-
76-
/**
77-
* Post request to add balance to a pet with the sessionID in the database
24+
* Get request to getPet with the sessionID from the database
7825
* @param sessionID string that represents the current session and verifies the action
79-
* @param balance double that represent amount that will be added
8026
*/
81-
@PostMapping("/addPetBalance")
82-
public ResponseEntity<Object> addPetBalance(@RequestParam String sessionID, Double balance){
83-
boolean successful = ShopManager.addBalance(sessionID, balance);
84-
if (successful){
85-
return new ResponseEntity<>("Balance added", HttpStatus.OK);
86-
}
87-
88-
return LogHandler.logError(new Exception("Add balance failed"), HttpStatus.BAD_REQUEST);
27+
@GetMapping("/pet")
28+
public ResponseEntity<Object> getPet(@RequestParam SessionID sessionID){
29+
return this.petSystemFacade.getPet(sessionID);
8930
}
9031

9132
/**
92-
* Post request to have the pet own the item and reduce the balance accordingly to the cost of the item from the database
33+
* Post request to replace the current pet with the same pet with an updated outfit from the database
9334
* @param sessionID string that represents the current session and verifies the action
94-
* @param itemId string that represents the item to be purchased
35+
* @param itemID ItemID that corrosponds with the shop item
9536
*/
96-
@PostMapping("/purchaseItems")
97-
public ResponseEntity<Object> purchaseItem(@RequestParam String sessionID, String itemId){
98-
boolean successful = ShopManager.purchaseItem(itemId, sessionID);
99-
100-
if (successful){
101-
return new ResponseEntity<>("Item purchased", HttpStatus.OK);
102-
}
103-
104-
return LogHandler.logError(new Exception("Purchase item failed"), HttpStatus.BAD_REQUEST);
105-
37+
@PostMapping("/updatePetOutfit")
38+
public ResponseEntity<Object> updatePetOutfit(@RequestParam SessionID sessionID, String itemID){
39+
return this.petSystemFacade.updateCurrentOutfit(sessionID, itemID);
10640
}
10741

10842

0 commit comments

Comments
 (0)