Search in sources :

Example 6 with AddUserRequest

use of com.cmput301w18t05.taskzilla.request.command.AddUserRequest in project Taskzilla by CMPUT301W18T05.

the class SignUpActivity method addUserToDB.

/**
 * This method takes the user object created and adds it to the elastic search
 * database.
 * <p>
 * This method returns false if the username the user is trying to use is already in the databse.
 *
 * @return  boolean value to determine if user was successfully added or not
 * @see     AddUserRequest
 * @see     RequestManager
 */
public boolean addUserToDB() {
    RequestManager requestManager = RequestManager.getInstance();
    AddUserRequest addUserRequest = new AddUserRequest(newUser);
    requestManager.invokeRequest(addUserRequest);
    return addUserRequest.getResult();
}
Also used : RequestManager(com.cmput301w18t05.taskzilla.request.RequestManager) AddUserRequest(com.cmput301w18t05.taskzilla.request.command.AddUserRequest)

Example 7 with AddUserRequest

use of com.cmput301w18t05.taskzilla.request.command.AddUserRequest in project Taskzilla by CMPUT301W18T05.

the class BidTest method testCompareTo.

/**
 * Test for comparing a bid to another bid
 * <p>
 * greater than returns 1
 * equality returns 0
 * less than returns -1
 */
public void testCompareTo() {
    User user1 = new User();
    AddUserRequest addUserRequest = new AddUserRequest(user1);
    RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest);
    Task task = new Task("Task name", user1, "Task description");
    AddTaskRequest addTaskRequest = new AddTaskRequest(task);
    RequestManager.getInstance().invokeRequest(getActivity(), addTaskRequest);
    float bidAmount1 = 10.00f;
    Bid bid1 = new Bid(user1.getId(), task.getId(), bidAmount1);
    User user2 = new User();
    AddUserRequest addUserRequest2 = new AddUserRequest(user2);
    RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest2);
    float bidAmount2 = 1.00f;
    Bid bid2 = new Bid(user2.getId(), task.getId(), bidAmount2);
    assertEquals(bid1.compareTo(bid2), 1);
    User user3 = new User();
    AddUserRequest addUserRequest3 = new AddUserRequest(user3);
    RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest3);
    float bidAmount3 = 10.00f;
    Bid bid3 = new Bid(user3.getId(), task.getId(), bidAmount3);
    assertEquals(bid1.compareTo(bid3), 0);
    User user4 = new User();
    AddUserRequest addUserRequest4 = new AddUserRequest(user4);
    RequestManager.getInstance().invokeRequest(getActivity(), addUserRequest4);
    float bidAmount4 = 20.00f;
    Bid bid4 = new Bid(user4.getId(), task.getId(), bidAmount4);
    assertEquals(bid1.compareTo(bid4), -1);
}
Also used : AddTaskRequest(com.cmput301w18t05.taskzilla.request.command.AddTaskRequest) AddUserRequest(com.cmput301w18t05.taskzilla.request.command.AddUserRequest)

Example 8 with AddUserRequest

use of com.cmput301w18t05.taskzilla.request.command.AddUserRequest in project Taskzilla by CMPUT301W18T05.

the class NewReviewActivity method reviewSaveButton.

/**
 * when save button clicked, save the review and the rating to the
 * elastic search
 * @param view
 */
public void reviewSaveButton(android.view.View view) {
    String reviewTitle = TitleText.getText().toString();
    String reviewDescription = DescriptionText.getText().toString();
    Float reviewRating = RatingBar.getRating();
    if (reviewTitle.equals("") || reviewRating == 0.0f) {
        Toast.makeText(this, "Please fill out the required fields", Toast.LENGTH_SHORT).show();
        return;
    }
    Review review = new Review(reviewTitle, reviewRating, reviewDescription, targetUserId, currentUserId, revieweeType);
    Float newRating;
    if (revieweeType.equals("r")) {
        newRating = ((float) (targetUser.getNumReviewsAsRequester()) * targetUser.getRequesterRating() + reviewRating) / (targetUser.getNumReviewsAsRequester() + 1);
        targetUser.setRequesterRating(newRating);
        targetUser.addNumRequesterReviews();
    } else {
        newRating = ((float) targetUser.getNumReviewsAsProvider() * targetUser.getProviderRating() + reviewRating) / (targetUser.getNumReviewsAsProvider() + 1);
        targetUser.setProviderRating(newRating);
        targetUser.addNumProviderReviews();
    }
    AddUserRequest request = new AddUserRequest(targetUser);
    RequestManager.getInstance().invokeRequest(this, request);
    // send to ES
    review.updateThis();
    Toast.makeText(this, "Review created for " + targetUserName, Toast.LENGTH_SHORT).show();
    finish();
}
Also used : Review(com.cmput301w18t05.taskzilla.Review) AddUserRequest(com.cmput301w18t05.taskzilla.request.command.AddUserRequest)

Example 9 with AddUserRequest

use of com.cmput301w18t05.taskzilla.request.command.AddUserRequest in project Taskzilla by CMPUT301W18T05.

the class ProfileFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i("does this work", String.valueOf(requestCode));
    if (requestCode == 1) {
        // code to add to ESC
        if (resultCode == RESULT_OK) {
            String newName = data.getStringExtra("Name");
            String newEmail = data.getStringExtra("Email");
            String newPhone = data.getStringExtra("Phone");
            String newPhoto = data.getStringExtra("Photo");
            user.setName(newName);
            user.setEmail(new EmailAddress(newEmail));
            user.setPhone(new PhoneNumber(newPhone));
            user.setPhoto(new Photo(newPhoto));
            AddUserRequest request = new AddUserRequest(user);
            RequestManager.getInstance().invokeRequest(getContext(), request);
            nameField.setText(newName);
            emailField.setText(newEmail);
            phoneField.setText(newPhone);
            profilePicture.setImageBitmap(user.getPhoto().StringToBitmap());
        }
    }
}
Also used : PhoneNumber(com.cmput301w18t05.taskzilla.PhoneNumber) Photo(com.cmput301w18t05.taskzilla.Photo) EmailAddress(com.cmput301w18t05.taskzilla.EmailAddress) AddUserRequest(com.cmput301w18t05.taskzilla.request.command.AddUserRequest)

Aggregations

AddUserRequest (com.cmput301w18t05.taskzilla.request.command.AddUserRequest)9 AddTaskRequest (com.cmput301w18t05.taskzilla.request.command.AddTaskRequest)3 EmailAddress (com.cmput301w18t05.taskzilla.EmailAddress)1 PhoneNumber (com.cmput301w18t05.taskzilla.PhoneNumber)1 Photo (com.cmput301w18t05.taskzilla.Photo)1 Review (com.cmput301w18t05.taskzilla.Review)1 RequestManager (com.cmput301w18t05.taskzilla.request.RequestManager)1 ArrayList (java.util.ArrayList)1