Changeset View
Changeset View
Standalone View
Standalone View
src/main/java/net/wildfyre/users/LoggedUser.java
/* | /* | ||||
Lint: Lint: net.wildfyre.http.RequestTest > testMultipart [01;31m[KFAILED[m[K | |||||
Lint: Lint net.wildfyre.http.RequestTest > testPatchMethod [01;31m[KFAILED[m[K Lint: Lint: net.wildfyre.http.RequestTest > testPatchMethod [01;31m[KFAILED[m[K | |||||
Lint: Lint :test [01;31m[KFAILED[m[K Lint: Lint: :test [01;31m[KFAILED[m[K | |||||
* Copyright 2018 Wildfyre.net | * Copyright 2018 Wildfyre.net | ||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
* You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
* | * | ||||
* http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
Show All 27 Lines | |||||
*/ | */ | ||||
public class LoggedUser extends User { | public class LoggedUser extends User { | ||||
LoggedUser(int id) { | LoggedUser(int id) { | ||||
super(id); | super(id); | ||||
} | } | ||||
@Override | @Override | ||||
public boolean canEdit(){ | public boolean isEditable(){ | ||||
return true; | return true; | ||||
} | } | ||||
//region UniqueSetters | //region UniqueSetters | ||||
/** | /** | ||||
* Sets this user's bio. | * Sets this user's bio. | ||||
* | * | ||||
* <p>This method is a wrapper around {@link #set(String, String, String)}, see its documentation for more | * <p>This method is a wrapper around {@link #set(String, String, String)}, see its documentation for more | ||||
* information.</p> | * information.</p> | ||||
* | * | ||||
* @param bio the new bio | * @param bio the new bio | ||||
*/ | */ | ||||
@Override | |||||
public void setBio(String bio){ | public void setBio(String bio){ | ||||
set(null, bio, null); | set(null, bio, null); | ||||
} | } | ||||
/** | /** | ||||
* Sets this user's name. | * Sets this user's name. | ||||
* | * | ||||
* <p>This method is a wrapper around {@link #set(String, String, String)}, see its documentation for more | * <p>This method is a wrapper around {@link #set(String, String, String)}, see its documentation for more | ||||
* information.</p> | * information.</p> | ||||
* | * | ||||
* @param username the new user's name | * @param username the new user's name | ||||
*/ | */ | ||||
public void setUsername(String username){ | public void setUsername(String username){ | ||||
set(username, null, null); | set(username, null, null); | ||||
} | } | ||||
/** | /** | ||||
* Sets this user's avatar. | * Sets this user's avatar. | ||||
* | * | ||||
* <p>This method is a wrapper around {@link #set(String, String, String)}, see its documentation for more | * <p>This method is a wrapper around {@link #set(String, String, String)}, see its documentation for more | ||||
* information.</p> | * information.</p> | ||||
* | * | ||||
* @param avatar the new user's avatar | * @param avatar the new user's avatar | ||||
*/ | */ | ||||
@Override | |||||
public void setAvatar(String avatar){ | public void setAvatar(String avatar){ | ||||
set(null, null, avatar); | set(null, null, avatar); | ||||
} | } | ||||
//endregion | //endregion | ||||
//region Setter | //region Setter | ||||
/** | /** | ||||
Show All 11 Lines | public class LoggedUser extends User { | ||||
* @see #setAvatar(String) Set only the avatar | * @see #setAvatar(String) Set only the avatar | ||||
* @see #setBio(String) Set only the bio | * @see #setBio(String) Set only the bio | ||||
* @see #setUsername(String) Set only the username | * @see #setUsername(String) Set only the username | ||||
*/ | */ | ||||
public void set(String username, String bio, String avatar){ | public void set(String username, String bio, String avatar){ | ||||
JsonObject json = new JsonObject(); | JsonObject json = new JsonObject(); | ||||
if(username != null){ | if(username != null){ | ||||
super.name = username; | super.setName(username); | ||||
json.add("name", username); | json.add("name", username); | ||||
} | } | ||||
if(bio != null){ | if(bio != null){ | ||||
super.bio = bio; | super.setBio(bio); | ||||
json.add("bio", bio); | json.add("bio", bio); | ||||
} | } | ||||
if(avatar != null){ | if(avatar != null){ | ||||
super.avatar = avatar; | super.setAvatar(avatar); | ||||
json.add("avatar", avatar); | json.add("avatar", avatar); | ||||
} | } | ||||
if(json.isEmpty()) | if(json.isEmpty()) | ||||
throw new NullPointerException("Every provided parameter was null, at least one should not be!"); | return; | ||||
Internal.submit(() -> { // Send query to server | Internal.submit(() -> { // Send query to server | ||||
try { | try { | ||||
new Request(PATCH, "/users/") | new Request(PATCH, "/users/") | ||||
.addToken(Internal.token()) | .addToken(Internal.token()) | ||||
.addJson(json) | .addJson(json) | ||||
.getJson(); | .getJson(); | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
net.wildfyre.http.RequestTest > testMultipart [01;31m[KFAILED[m[K