-
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.
Merge pull request #32 from Grupo13-PES-Mascotas/release/v1.1.0
Release/v1.1.0
- Loading branch information
Showing
121 changed files
with
12,189 additions
and
301 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: chmod a+x .github/scripts/decrypt_key.sh && ./.github/scripts/decrypt_key.sh && java -jar -Dserver.port=$PORT build/libs/webservice-1.0.0.jar | ||
web: chmod a+x .github/scripts/decrypt_key.sh && ./.github/scripts/decrypt_key.sh && java -jar -Dserver.port=$PORT build/libs/webservice-2.0.0.jar |
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
143 changes: 143 additions & 0 deletions
143
.../java/org/pesmypetcare/webservice/controller/appmanager/GoogleCalendarRestController.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,143 @@ | ||
package org.pesmypetcare.webservice.controller.appmanager; | ||
import com.google.api.services.calendar.model.Event; | ||
import org.pesmypetcare.webservice.entity.EventEntity; | ||
import org.pesmypetcare.webservice.error.CalendarAccessException; | ||
import org.pesmypetcare.webservice.error.DatabaseAccessException; | ||
import org.pesmypetcare.webservice.service.GoogleCalendarService; | ||
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.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
/** | ||
* @author Marc Simó | ||
*/ | ||
@RestController | ||
@RequestMapping("/calendar") | ||
public class GoogleCalendarRestController { | ||
private static final String TOKEN = "token"; | ||
|
||
@Autowired | ||
private GoogleCalendarService googleCalendarService; | ||
|
||
/** | ||
* Creates a Secondary Google Calendar in the account specified by the accessToken. | ||
* @param accessToken oauth2 token needed to access the Google Calendar | ||
* @param owner Name of the owner of the pet | ||
* @param petName Name of the pet the calendar is created for | ||
* @throws CalendarAccessException If an error occurs when accessing the calendar | ||
*/ | ||
@PostMapping("/{owner}/{petName}") | ||
public void createSecondaryCalendar(@RequestHeader(TOKEN) String accessToken, @PathVariable String owner, | ||
@PathVariable String petName) throws CalendarAccessException { | ||
googleCalendarService.createSecondaryCalendar(accessToken, owner, petName); | ||
} | ||
|
||
/** | ||
* Deletes a Secondary Google Calendar in the account specified by the accessToken. | ||
* @param accessToken oauth2 token needed to access the Google Calendar | ||
* @param owner Name of the owner of the pet | ||
* @param petName Name of the pet the calendar belongs to | ||
* @throws CalendarAccessException If an error occurs when accessing the calendar | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
*/ | ||
@DeleteMapping("/{owner}/{petName}") | ||
public void deleteSecondaryCalendar(@RequestHeader(TOKEN) String accessToken, @PathVariable String owner, | ||
@PathVariable String petName) | ||
throws CalendarAccessException, DatabaseAccessException { | ||
googleCalendarService.deleteSecondaryCalendar(accessToken, owner, petName); | ||
} | ||
|
||
/** | ||
* Returns all Calendar Events from a specified Calendar. | ||
* @param accessToken oauth2 token needed to access the Google Calendar | ||
* @param owner Name of the owner of the pet | ||
* @param petName Name of the pet the calendar belongs to | ||
* @return List containing all the Events from the specified Calendar | ||
* @throws CalendarAccessException If an error occurs when accessing the calendar | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
*/ | ||
@GetMapping("/{owner}/{petName}") | ||
public List<EventEntity> getAllEventsFromCalendar(@RequestHeader(TOKEN) String accessToken, | ||
@PathVariable String owner, | ||
@PathVariable String petName) | ||
throws CalendarAccessException, DatabaseAccessException { | ||
return googleCalendarService.getAllEventsFromCalendar(accessToken, owner, petName); | ||
} | ||
|
||
/** | ||
* Creates an Event in a specified Google Calendar. | ||
* @param accessToken oauth2 token needed to access the Google Calendar | ||
* @param owner Name of the owner of the pet | ||
* @param petName Name of the pet the calendar belongs to | ||
* @param eventEntity Event to create | ||
* @throws CalendarAccessException If an error occurs when accessing the calendar | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
*/ | ||
@PostMapping("/event/{owner}/{petName}") | ||
public void createEvent(@RequestHeader(TOKEN) String accessToken, @PathVariable String owner, | ||
@PathVariable String petName, @RequestBody EventEntity eventEntity) | ||
throws CalendarAccessException, DatabaseAccessException { | ||
googleCalendarService.createEvent(accessToken, owner, petName, eventEntity); | ||
} | ||
|
||
/** | ||
* Retrieves an Event in a specified Google Calendar. | ||
* @param accessToken oauth2 token needed to access the Google Calendar | ||
* @param owner Name of the owner of the pet | ||
* @param petName Name of the pet the calendar belongs to | ||
* @param body Body of the request containing the id of the event to retrieve with key eventId assigned | ||
* @return Event retrieved | ||
* @throws CalendarAccessException If an error occurs when accessing the calendar | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
*/ | ||
@GetMapping("/event/{owner}/{petName}") | ||
public EventEntity retrieveEvent(@RequestHeader(TOKEN) String accessToken, @PathVariable String owner, | ||
@PathVariable String petName, @RequestBody Map<String, Object> body) | ||
throws CalendarAccessException, DatabaseAccessException { | ||
return googleCalendarService.retrieveEvent(accessToken, owner, petName, (String) body.get("eventId")); | ||
} | ||
|
||
/** | ||
* Updates an Event in a specified Google Calendar. | ||
* @param accessToken oauth2 token needed to access the Google Calendar | ||
* @param owner Name of the owner of the pet | ||
* @param petName Name of the pet the calendar belongs to | ||
* @param eventEntity New Event that overwrites the past event with the same id | ||
* @throws CalendarAccessException If an error occurs when accessing the calendar | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
*/ | ||
@PutMapping("/event/{owner}/{petName}") | ||
public void updateEvent(@RequestHeader(TOKEN) String accessToken, @PathVariable String owner, | ||
@PathVariable String petName, @RequestBody EventEntity eventEntity) | ||
throws CalendarAccessException, DatabaseAccessException { | ||
googleCalendarService.updateEvent(accessToken, owner, petName, eventEntity); | ||
} | ||
|
||
/** | ||
* Deletes an Event in a specified Google Calendar. | ||
* @param accessToken oauth2 token needed to access the Google Calendar | ||
* @param owner Name of the owner of the pet | ||
* @param petName Name of the pet the calendar belongs to | ||
* @param body Body of the request containing the id of the event to delete with key eventId assigned | ||
* @throws CalendarAccessException If an error occurs when accessing the calendar | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
*/ | ||
@DeleteMapping("/event/{owner}/{petName}") | ||
public void deleteEvent(@RequestHeader(TOKEN) String accessToken, @PathVariable String owner, | ||
@PathVariable String petName, @RequestBody Map<String, Object> body) | ||
throws CalendarAccessException, DatabaseAccessException { | ||
googleCalendarService.deleteEvent(accessToken, owner, petName, (String) body.get("eventId")); | ||
} | ||
|
||
} |
35 changes: 27 additions & 8 deletions
35
src/main/java/org/pesmypetcare/webservice/controller/appmanager/MyPetCareRestController.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 |
---|---|---|
@@ -1,30 +1,49 @@ | ||
package org.pesmypetcare.webservice.controller.appmanager; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.firebase.auth.FirebaseAuthException; | ||
import org.pesmypetcare.webservice.entity.UserEntity; | ||
import org.pesmypetcare.webservice.error.DatabaseAccessException; | ||
import org.pesmypetcare.webservice.service.UserService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@RestController | ||
public class MyPetCareRestController { | ||
@Autowired | ||
private UserService userService; | ||
|
||
/** | ||
* Given a username, an email and a password creates the user on the data base. | ||
* @param user The entity that contains the username and the email for the new account | ||
* @param password The password for the new account | ||
* @throws FirebaseAuthException If a user tries to create an account with an existing username or | ||
* email, or with an invalid email | ||
* @param user The request body that contains the username, password and email for the new account | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
* @throws FirebaseAuthException If an error occurs when retrieving the data | ||
*/ | ||
@PostMapping("/signup") | ||
public void signUp(@RequestBody UserEntity user, @RequestParam String password) | ||
throws FirebaseAuthException { | ||
//userService.createUserAuth(user, password); | ||
userService.createUser(user); | ||
public void signUp(@RequestBody Map<String, Object> user) throws DatabaseAccessException, FirebaseAuthException { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
UserEntity userEntity = mapper.convertValue(user.get("user"), UserEntity.class); | ||
userService.createUser((String) user.get("uid"), userEntity); | ||
} | ||
|
||
/** | ||
* Checks if a username is already in use. | ||
* @param username The username to check | ||
* @return True if the username is in use | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
*/ | ||
@GetMapping("/usernames") | ||
public Map<String, Boolean> usernameAlreadyInUse(@RequestParam String username) throws DatabaseAccessException { | ||
boolean exists = userService.existsUsername(username); | ||
Map<String, Boolean> response = new HashMap<>(); | ||
response.put("exists", exists); | ||
return response; | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
src/main/java/org/pesmypetcare/webservice/controller/appmanager/StorageRestController.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,108 @@ | ||
package org.pesmypetcare.webservice.controller.appmanager; | ||
|
||
import org.pesmypetcare.webservice.entity.ImageEntity; | ||
import org.pesmypetcare.webservice.error.DatabaseAccessException; | ||
import org.pesmypetcare.webservice.form.StorageForm; | ||
import org.pesmypetcare.webservice.service.StorageService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
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.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Map; | ||
|
||
@RestController | ||
@RequestMapping("/storage") | ||
public class StorageRestController { | ||
private final String TOKEN = "token"; | ||
@Autowired | ||
private StorageService storage; | ||
|
||
/** | ||
* Saves an image in user storage. | ||
* @param token The personal access token of the user | ||
* @param image The image entity containing the image, its path and name | ||
*/ | ||
@PutMapping("/image") | ||
public void saveImage(@RequestHeader(TOKEN) String token, @RequestBody ImageEntity image) { | ||
storage.saveImage(image); | ||
} | ||
|
||
/** | ||
* Saves a pet image in user storage. | ||
* @param token The personal access token of the user | ||
* @param user The user's username | ||
* @param image The image entity containing the image, its path and name | ||
*/ | ||
@PutMapping("/image/{user}/pets") | ||
public void savePetImage(@RequestHeader(TOKEN) String token, @PathVariable String user, | ||
@RequestBody ImageEntity image) { | ||
storage.savePetImage(user, image); | ||
} | ||
|
||
/** | ||
* Downloads an image from user storage. | ||
* @param token The personal access token of the user | ||
* @param user The user's username | ||
* @param name The image name | ||
* @return The image as a base64 encoded byte array | ||
*/ | ||
@GetMapping(value = "/image/{user}", | ||
produces = MediaType.IMAGE_PNG_VALUE) | ||
@ResponseBody | ||
public String downloadImage(@RequestHeader(TOKEN) String token, @PathVariable String user, | ||
@RequestParam String name) { | ||
StorageForm form = new StorageForm(user, name); | ||
return storage.getImage(form); | ||
} | ||
|
||
/** | ||
* Downloads a pet image from user storage. | ||
* @param token The personal access token of the user | ||
* @param user The user's username | ||
* @param name The image name | ||
* @return The image as a base64 encoded byte array | ||
*/ | ||
@GetMapping(value = "/image/{user}/pets/{name}", | ||
produces = MediaType.IMAGE_PNG_VALUE) | ||
@ResponseBody | ||
public String downloadPetImage(@RequestHeader(TOKEN) String token, @PathVariable String user, | ||
@PathVariable String name) { | ||
String path = user + "/pets"; | ||
StorageForm form = new StorageForm(path, name); | ||
return storage.getImage(form); | ||
} | ||
|
||
/** | ||
* Downloads all pet profile pictures from user storage. | ||
* @param token The personal access token of the user | ||
* @param user The user's username | ||
* @return A map with the pets names and the their profile pictures as a byte array | ||
* @throws DatabaseAccessException If an error occurs when accessing the database | ||
*/ | ||
@GetMapping(value = "/image/{user}/pets", | ||
produces = MediaType.APPLICATION_JSON_VALUE) | ||
@ResponseBody | ||
public Map<String, String> downloadAllPetsImages(@RequestHeader(TOKEN) String token, | ||
@PathVariable String user) throws DatabaseAccessException { | ||
return storage.getAllImages(user); | ||
} | ||
|
||
/** | ||
* Deletes an image from user storage. | ||
* @param token The personal access token of the user | ||
* @param storageForm A form with the image name and its path | ||
*/ | ||
@DeleteMapping("/image") | ||
public void deleteImage(@RequestHeader(TOKEN) String token, @RequestBody StorageForm storageForm) { | ||
storage.deleteImage(storageForm); | ||
} | ||
} |
Oops, something went wrong.