-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3358861
commit f77fb84
Showing
46 changed files
with
1,387 additions
and
35 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
src/main/java/de/tum/cit/aet/artemis/iris/domain/session/IrisLectureChatSession.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,44 @@ | ||
package de.tum.cit.aet.artemis.iris.domain.session; | ||
|
||
import java.util.Optional; | ||
|
||
import jakarta.persistence.DiscriminatorValue; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.ManyToOne; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import de.tum.cit.aet.artemis.core.domain.User; | ||
import de.tum.cit.aet.artemis.lecture.domain.Lecture; | ||
|
||
@Entity | ||
@DiscriminatorValue("LECTURE_CHAT") | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class IrisLectureChatSession extends IrisChatSession { | ||
|
||
@ManyToOne | ||
@JsonIgnore | ||
private Lecture lecture; | ||
|
||
public IrisLectureChatSession() { | ||
} | ||
|
||
public IrisLectureChatSession(Lecture lecture, User user) { | ||
super(user); | ||
this.lecture = lecture; | ||
} | ||
|
||
public Lecture getLecture() { | ||
return lecture; | ||
} | ||
|
||
public void setLecture(Lecture lecture) { | ||
this.lecture = lecture; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "IrisLectureChatSession{" + "user=" + Optional.ofNullable(getUser()).map(User::getLogin).orElse("null") + ", lecture=" + lecture + '}'; | ||
} | ||
} |
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
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
72 changes: 72 additions & 0 deletions
72
src/main/java/de/tum/cit/aet/artemis/iris/domain/settings/IrisLectureChatSubSettings.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,72 @@ | ||
package de.tum.cit.aet.artemis.iris.domain.settings; | ||
|
||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
||
import jakarta.annotation.Nullable; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Convert; | ||
import jakarta.persistence.DiscriminatorValue; | ||
import jakarta.persistence.Entity; | ||
import jakarta.validation.constraints.Min; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
/** | ||
* An {@link IrisSubSettings} implementation for the settings for the chat in a text exercise. | ||
*/ | ||
@Entity | ||
@DiscriminatorValue("LECTURE_CHAT") | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public class IrisLectureChatSubSettings extends IrisSubSettings { | ||
|
||
/** | ||
* Maximum number of messages allowed within the specified timeframe. | ||
* Must be a positive integer or null to disable rate limiting. | ||
*/ | ||
@Nullable | ||
@Min(1) | ||
@Column(name = "rate_limit") | ||
private Integer rateLimit; | ||
|
||
/** | ||
* Timeframe in hours for the rate limit. | ||
* Must be a positive integer when rate limit is set. | ||
*/ | ||
@Nullable | ||
@Min(1) | ||
@Column(name = "rate_limit_timeframe_hours") | ||
private Integer rateLimitTimeframeHours; | ||
|
||
@Nullable | ||
@Column(name = "enabled_for_categories") | ||
@Convert(converter = IrisListConverter.class) | ||
private SortedSet<String> enabledForCategories = new TreeSet<>(); | ||
|
||
@Nullable | ||
public Integer getRateLimit() { | ||
return rateLimit; | ||
} | ||
|
||
public void setRateLimit(@Nullable Integer rateLimit) { | ||
this.rateLimit = rateLimit; | ||
} | ||
|
||
@Nullable | ||
public Integer getRateLimitTimeframeHours() { | ||
return rateLimitTimeframeHours; | ||
} | ||
|
||
public void setRateLimitTimeframeHours(@Nullable Integer rateLimitTimeframeHours) { | ||
this.rateLimitTimeframeHours = rateLimitTimeframeHours; | ||
} | ||
|
||
@Nullable | ||
public SortedSet<String> getEnabledForCategories() { | ||
return enabledForCategories; | ||
} | ||
|
||
public void setEnabledForCategories(@Nullable SortedSet<String> enabledForCategories) { | ||
this.enabledForCategories = enabledForCategories; | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/java/de/tum/cit/aet/artemis/iris/dto/IrisCombinedLectureChatSubSettingsDTO.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,8 @@ | ||
package de.tum.cit.aet.artemis.iris.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
public record IrisCombinedLectureChatSubSettingsDTO(boolean enabled, Integer rateLimit, Integer rateLimitTimeframeHours) { | ||
|
||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/de/tum/cit/aet/artemis/iris/repository/IrisLectureChatSessionRepository.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,47 @@ | ||
package de.tum.cit.aet.artemis.iris.repository; | ||
|
||
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_IRIS; | ||
import static org.springframework.data.jpa.repository.EntityGraph.EntityGraphType.LOAD; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import de.tum.cit.aet.artemis.core.domain.DomainObject; | ||
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository; | ||
import de.tum.cit.aet.artemis.iris.domain.session.IrisLectureChatSession; | ||
|
||
@Repository | ||
@Profile(PROFILE_IRIS) | ||
public interface IrisLectureChatSessionRepository extends ArtemisJpaRepository<IrisLectureChatSession, Long> { | ||
|
||
List<IrisLectureChatSession> findByLectureIdAndUserIdOrderByCreationDateDesc(Long lectureId, Long userId); | ||
|
||
List<IrisLectureChatSession> findByLectureIdAndUserIdOrderByCreationDateDesc(Long lectureId, Long userId, Pageable pageable); | ||
|
||
@EntityGraph(type = LOAD, attributePaths = "messages") | ||
List<IrisLectureChatSession> findSessionsWithMessagesByIdIn(List<Long> ids); | ||
|
||
/** | ||
* Finds the latest chat sessions by lecture ID and user ID, including their messages, with pagination support. | ||
* This method avoids in-memory paging by retrieving the session IDs directly from the database. | ||
* | ||
* @param lectureId the ID of the lecture to find the chat sessions for | ||
* @param userId the ID of the user to find the chat sessions for | ||
* @param pageable the pagination information | ||
* @return a list of {@code IrisLectureChatSession} with messages, or an empty list if no sessions are found | ||
*/ | ||
default List<IrisLectureChatSession> findLatestSessionsByLectureIdAndUserIdWithMessages(Long lectureId, Long userId, Pageable pageable) { | ||
List<Long> ids = findByLectureIdAndUserIdOrderByCreationDateDesc(lectureId, userId, pageable).stream().map(DomainObject::getId).toList(); | ||
|
||
if (ids.isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return findSessionsWithMessagesByIdIn(ids); | ||
} | ||
} |
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
Oops, something went wrong.