-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contacts list and searching.
- Loading branch information
Showing
11 changed files
with
436 additions
and
9 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
app/src/main/java/io/xeres/app/api/controller/contact/ContactController.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,56 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.app.api.controller.contact; | ||
|
||
import io.swagger.v3.oas.annotations.ExternalDocumentation; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import io.xeres.app.service.ContactService; | ||
import io.xeres.common.rest.contact.Contact; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
import static io.xeres.common.rest.PathConfig.CONTACT_PATH; | ||
|
||
@Tag(name = "Contact", description = "Contact service", externalDocs = @ExternalDocumentation(url = "https://xeres.io/docs/api/contact", description = "Contact documentation")) | ||
@RestController | ||
@RequestMapping(value = CONTACT_PATH, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public class ContactController | ||
{ | ||
private final ContactService contactService; | ||
|
||
public ContactController(ContactService contactService) | ||
{ | ||
this.contactService = contactService; | ||
} | ||
|
||
@GetMapping("") | ||
@Operation(summary = "Get all the contacts") | ||
@ApiResponse(responseCode = "200", description = "Request successful") | ||
public List<Contact> getContacts() | ||
{ | ||
return contactService.getContacts(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/io/xeres/app/service/ContactService.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,56 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.app.service; | ||
|
||
import io.xeres.app.xrs.service.identity.IdentityRsService; | ||
import io.xeres.common.rest.contact.Contact; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
public class ContactService | ||
{ | ||
private final ProfileService profileService; | ||
private final LocationService locationService; | ||
private final IdentityRsService identityRsService; | ||
|
||
public ContactService(ProfileService profileService, LocationService locationService, IdentityRsService identityRsService) | ||
{ | ||
this.profileService = profileService; | ||
this.locationService = locationService; | ||
this.identityRsService = identityRsService; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<Contact> getContacts() | ||
{ | ||
var profiles = profileService.getAllProfiles(); | ||
var identities = identityRsService.getAll(); | ||
|
||
// XXX: for now return all of them, in the future it would be possible to merge the identity to the profile (if the name is the same) | ||
List<Contact> contacts = new ArrayList<>(profiles.size() + identities.size()); | ||
profiles.forEach(profile -> contacts.add(new Contact(profile.getName(), profile.getId(), 0L))); | ||
identities.forEach(identity -> contacts.add(new Contact(identity.getName(), 0L, identity.getId()))); // XXX: put the profile too | ||
return contacts; | ||
} | ||
} |
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
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
24 changes: 24 additions & 0 deletions
24
common/src/main/java/io/xeres/common/rest/contact/Contact.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,24 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.common.rest.contact; | ||
|
||
public record Contact(String name, long profileId, long identityId) | ||
{ | ||
} |
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,59 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.ui.client; | ||
|
||
import io.xeres.common.events.StartupEvent; | ||
import io.xeres.common.rest.contact.Contact; | ||
import io.xeres.common.util.RemoteUtils; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Flux; | ||
|
||
import static io.xeres.common.rest.PathConfig.CONTACT_PATH; | ||
|
||
@Component | ||
public class ContactClient | ||
{ | ||
private final WebClient.Builder webClientBuilder; | ||
|
||
private WebClient webClient; | ||
|
||
public ContactClient(WebClient.Builder webClientBuilder) | ||
{ | ||
this.webClientBuilder = webClientBuilder; | ||
} | ||
|
||
@EventListener | ||
public void init(@SuppressWarnings("unused") StartupEvent event) | ||
{ | ||
webClient = webClientBuilder | ||
.baseUrl(RemoteUtils.getControlUrl() + CONTACT_PATH) | ||
.build(); | ||
} | ||
|
||
public Flux<Contact> getContacts() | ||
{ | ||
return webClient.get() | ||
.uri("") | ||
.retrieve() | ||
.bodyToFlux(Contact.class); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
ui/src/main/java/io/xeres/ui/controller/contact/ContactCell.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,59 @@ | ||
/* | ||
* Copyright (c) 2024 by David Gerber - https://zapek.com | ||
* | ||
* This file is part of Xeres. | ||
* | ||
* Xeres is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Xeres is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Xeres. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.xeres.ui.controller.contact; | ||
|
||
import io.xeres.common.rest.contact.Contact; | ||
import io.xeres.ui.client.GeneralClient; | ||
import io.xeres.ui.custom.AsyncImageView; | ||
import javafx.scene.control.TableCell; | ||
import javafx.scene.image.ImageView; | ||
|
||
import static io.xeres.common.rest.PathConfig.IDENTITIES_PATH; | ||
|
||
public class ContactCell extends TableCell<Contact, Contact> | ||
{ | ||
private final GeneralClient generalClient; | ||
|
||
public ContactCell(GeneralClient generalClient) | ||
{ | ||
super(); | ||
this.generalClient = generalClient; | ||
} | ||
|
||
@Override | ||
protected void updateItem(Contact item, boolean empty) | ||
{ | ||
super.updateItem(item, empty); | ||
setText(empty ? null : item.name()); | ||
setGraphic(empty ? null : updateContactImage((AsyncImageView) getGraphic(), item)); | ||
} | ||
|
||
private ImageView updateContactImage(AsyncImageView imageView, Contact contact) | ||
{ | ||
if (imageView == null) | ||
{ | ||
imageView = new AsyncImageView(); | ||
imageView.setFitWidth(32); | ||
imageView.setFitHeight(32); | ||
} | ||
imageView.setUrl(contact.identityId() != 0 ? (IDENTITIES_PATH + "/" + contact.identityId() + "/image") : null, url -> generalClient.getImage(url).block()); | ||
return imageView; | ||
} | ||
} |
Oops, something went wrong.