Klasse ContactService
java.lang.Object
com.spaghetticodegang.trylater.contact.ContactService
Service layer for handling business logic related to user contacts.
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungcreateContact
(User me, ContactRequestDto request) Creates a new contact request between the authenticated user and the target user.createContactResponseDto
(User me, Contact contact) Creates a response DTO from aContact
entity.void
deleteContact
(User me, Long contactId) Deletes aContact
entity.boolean
existsByUserIds
(Long userId1, Long userId2) Checks whether a contact relationship exists between two users, regardless of which user was the requester or receiver.findContactById
(Long contactId) Finds a contact by their unique ID.getAllContactsByStatusAndRole
(User me, ContactStatus contactStatus, ContactRole contactRole) Searches the contact repository for all contact of the user.getContact
(User me, Long contactId) Searches the contact repository for a given id.updateContactStatus
(User me, Long contactId, ContactStatusRequestDto contactStatusRequestDto) Performs validation and updates the contact's status, including setting the acceptance date if applicable.
-
Konstruktordetails
-
ContactService
public ContactService()
-
-
Methodendetails
-
existsByUserIds
Checks whether a contact relationship exists between two users, regardless of which user was the requester or receiver.- Parameter:
userId1
- the ID of the first useruserId2
- the ID of the second user- Gibt zurück:
- true if a contact already exists between the two users, false otherwise
-
findContactById
Finds a contact by their unique ID.- Parameter:
contactId
- the ID of the contact- Gibt zurück:
- the contact entity
- Löst aus:
ContactNotFoundException
- if the contact is not found
-
createContactResponseDto
Creates a response DTO from aContact
entity. Determines which user is the contact partner (not the authenticated user).- Parameter:
me
- the authenticated usercontact
- the contact entity- Gibt zurück:
- a response DTO representing the contact
-
getContact
Searches the contact repository for a given id.- Parameter:
me
- the authenticated usercontactId
- the contact id- Gibt zurück:
- a response DTO representing the contact
- Löst aus:
ValidationException
- if the user is neither the requester nor receiver of the contact
-
getAllContactsByStatusAndRole
public List<ContactResponseDto> getAllContactsByStatusAndRole(User me, ContactStatus contactStatus, ContactRole contactRole) Searches the contact repository for all contact of the user.- Parameter:
me
- the authenticated user- Gibt zurück:
- a list of response DTO representing the contacts optional filters
-
createContact
Creates a new contact request between the authenticated user and the target user. Performs validation to prevent duplicate or self-referential contacts.- Parameter:
me
- the authenticated user initiating the requestrequest
- the contact request containing the target user's ID- Gibt zurück:
- a response DTO representing the newly created contact
- Löst aus:
ValidationException
- if the target is the same as the requester or if a contact already exists between the users
-
updateContactStatus
public ContactResponseDto updateContactStatus(User me, Long contactId, ContactStatusRequestDto contactStatusRequestDto) Performs validation and updates the contact's status, including setting the acceptance date if applicable.- Parameter:
me
- the currently authenticated usercontactId
- the ID of the contact whose status is to be updatedcontactStatusRequestDto
- the DTO containing the new contact status- Gibt zurück:
- a response DTO representing the updated contact
- Löst aus:
ValidationException
- if the status change is invalid
-
deleteContact
-