Skip to content

Commit

Permalink
Merge pull request #32 from Grupo13-PES-Mascotas/release/v1.1.0
Browse files Browse the repository at this point in the history
Release/v1.1.0
  • Loading branch information
marclll authored Apr 27, 2020
2 parents 5ba417e + 6be9511 commit 364e9eb
Show file tree
Hide file tree
Showing 121 changed files with 12,189 additions and 301 deletions.
2 changes: 1 addition & 1 deletion Procfile
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
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'org.asciidoctor.jvm.convert' version '3.1.0'
id 'org.asciidoctor.jvm.convert' version '3.2.0'
id 'java'
id 'jacoco'
}

group = 'org.pesmypetcare'
version = '1.0.0'
version = '2.0.0'
sourceCompatibility = '1.8'

configurations {
Expand All @@ -25,6 +25,7 @@ ext {
}

dependencies {
compile 'com.google.apis:google-api-services-calendar:v3-rev20200315-1.30.9'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.google.firebase:firebase-admin:6.12.2'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.10.3'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
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"));
}

}
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;
}
}
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);
}
}
Loading

0 comments on commit 364e9eb

Please sign in to comment.