From b29783a780dd2763802a6ff58923ac5545bf619a Mon Sep 17 00:00:00 2001 From: Aaron Schmid <56757286+Aaron2000119@users.noreply.github.com> Date: Sun, 19 Oct 2025 20:38:42 +0200 Subject: [PATCH 1/2] add documentation for forum --- .../media_service/service/ForumService.java | 109 +++++++++++++++++- .../service/SubmissionService.java | 6 +- 2 files changed, 110 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/ForumService.java b/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/ForumService.java index 05e6679..128e100 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/ForumService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/ForumService.java @@ -48,6 +48,12 @@ public class ForumService { private final InfoThreadMapper infoThreadMapper; private final QuestionThreadRepository questionThreadRepository; + /** + * Add user to Forum + * @param forumId id of the forum + * @param userId id of the user + * @return forum the user was added to + */ public Forum addUserToForum(UUID forumId, UUID userId) { ForumEntity forum = forumRepository.findById(forumId).orElseThrow(() -> new EntityNotFoundException("Forum with id: " + forumId + " not found!")); @@ -56,6 +62,12 @@ public Forum addUserToForum(UUID forumId, UUID userId) { return forumMapper.forumEntityToForum(forum); } + /** + * Add user to Forum + * @param courseId id of the course of the forum + * @param userId id of the user + * @return forum the user was added to + */ public Forum addUserToForumCourseId(UUID courseId, UUID userId) { ForumEntity forum = forumRepository.findByCourseId(courseId).orElseThrow(() -> new EntityNotFoundException("Forum for the course with the id: " + courseId + " not found!")); @@ -79,11 +91,23 @@ public ThreadEntity getThreadById(UUID id) { new EntityNotFoundException("Thread with the id " + id + " not found")); } + /** + * Returns the thread by the given contentReferences + * @param threadContentReferenceEntities references between the content and the thread + * @return threads for the given contentReferences + */ public List getThreadsByThreadContentReferences(List threadContentReferenceEntities) { return threadContentReferenceEntities.stream().map(ThreadContentReferenceEntity::getThread) .map(threadMapper::mapThread).toList(); } + /** + * Adds a post to the thread + * @param post Post that gets added + * @param thread Thread the post gets added to + * @param userId Id of the user that writes the post + * @return Post that was added to the thread + */ public Post addPostToThread(InputPost post, ThreadEntity thread, UUID userId) { String censored_content = profanityFilter.censor(post.getContent()); log.info("Censored post content: {}", censored_content); @@ -109,6 +133,12 @@ public Post addPostToThread(InputPost post, ThreadEntity thread, UUID userId) { return postMapper.mapToPostWithThread(postEntity, thread); } + /** + * Upvotes a post and deletes the downvote if the user downvoted the post before + * @param postEntity post that the user upvotes + * @param userId id of the user + * @return upvoted post + */ public Post upvotePost(PostEntity postEntity, UUID userId) { postEntity.getDownvotedByUsers().removeIf(id -> id.equals(userId)); if (!postEntity.getUpvotedByUsers().contains(userId)) { @@ -119,6 +149,12 @@ public Post upvotePost(PostEntity postEntity, UUID userId) { return postMapper.mapToPost(postRepository.save(postEntity)); } + /** + * Downvotes a post and deletes the upvote if the user downvoted the post before + * @param postEntity post that the user downvotes + * @param userId id of the user + * @return downvoted post + */ public Post downvotePost(PostEntity postEntity, UUID userId) { postEntity.getUpvotedByUsers().removeIf(id -> id.equals(userId)); if (!postEntity.getDownvotedByUsers().contains(userId)) { @@ -129,6 +165,13 @@ public Post downvotePost(PostEntity postEntity, UUID userId) { return postMapper.mapToPost(postRepository.save(postEntity)); } + /** + * Creates a question Thread + * @param thread thread that gets created + * @param forum forum the thread gets created in + * @param userId user that creates the thread + * @return created thread + */ public QuestionThread createQuestionThread(InputQuestionThread thread, ForumEntity forum ,UUID userId) { String question_censored = profanityFilter.censor(thread.getQuestion().getContent()); String title_censored = profanityFilter.censor(thread.getTitle()); @@ -154,6 +197,13 @@ public QuestionThread createQuestionThread(InputQuestionThread thread, ForumEnti return questionThreadMapper.mapQuestionThread(threadEntity); } + /** + * Creates a info Thread + * @param thread thread that gets created + * @param forum forum the thread gets created in + * @param userId user that creates the thread + * @return created thread + */ public InfoThread createInfoThread(InputInfoThread thread, ForumEntity forum, UUID userId) { String info_censored = profanityFilter.censor(thread.getInfo().getContent()); String title_censored = profanityFilter.censor(thread.getTitle()); @@ -193,6 +243,14 @@ private void addThreatToContentOnThreadCreation(ThreadEntity thread, UUID conten thread.setThreadContentReference(new ThreadContentReferenceEntity(thread, contentId, timeStampSeconds, pageNumber)); } + /** + * Updates the given post + * @param post updates to the post + * @param postEntity the post that gets updated + * @param userId user that updates the post + * @return updated post + * @throws AuthenticationException if another user tries to change the post + */ public Post updatePost(InputPost post, PostEntity postEntity, UUID userId) throws AuthenticationException { if (!postEntity.getAuthorId().equals(userId)) { throw new AuthenticationException("User is not authorized to update this post"); @@ -203,6 +261,13 @@ public Post updatePost(InputPost post, PostEntity postEntity, UUID userId) throw return postMapper.mapToPost(postRepository.save(postEntity)); } + /** + * Deletes the given post + * @param post post that gets deleted + * @param user user that deletes the ost + * @return deleted post + * @throws AuthenticationException if the user is different of the user that created the post and not superuser or course creator + */ public Post deletePost(PostEntity post, LoggedInUser user) throws AuthenticationException { if (!post.getAuthorId().equals(user.getId()) && !(user.getRealmRoles().contains(LoggedInUser.RealmRole.COURSE_CREATOR) @@ -219,6 +284,13 @@ public Post deletePost(PostEntity post, LoggedInUser user) throws Authentication return realPost; } + /** + * Deletes the given thread + * @param thread thread that gets deleted + * @param user user that deletes the thread + * @return deleted thread + * @throws AuthenticationException if the user is different of the user that created the thread and not superuser or course creator + */ public Thread deleteThread(ThreadEntity thread, LoggedInUser user) throws AuthenticationException { if (!thread.getCreatorId().equals(user.getId()) && !(user.getRealmRoles().contains(LoggedInUser.RealmRole.COURSE_CREATOR) @@ -233,6 +305,14 @@ public Thread deleteThread(ThreadEntity thread, LoggedInUser user) throws Authen return realThread; } + /** + * Adds thread to a contentId + * @param thread thread that gets added to the content + * @param contentId id of the content + * @param timeStamp timestamp of the video where the thread is created + * @param pageNumber pageNumber of the slides where the thread is created + * @return reference between the thread and the content + */ public ThreadContentReference addThreadToContent(ThreadEntity thread, UUID contentId, Integer timeStamp, Integer pageNumber) { ThreadContentReferenceEntity threadContentReferenceEntity = new ThreadContentReferenceEntity(thread, contentId, timeStamp, pageNumber); threadContentReferenceRepository.save(threadContentReferenceEntity); @@ -241,6 +321,11 @@ public ThreadContentReference addThreadToContent(ThreadEntity thread, UUID conte return modelMapper.map(threadContentReferenceEntity, ThreadContentReference.class); } + /** + * Selects the answer for a question thread + * @param postId post that is the answer + * @return QuestionThread where the post was selected + */ public QuestionThread addAnswerToQuestionThread(UUID postId) { PostEntity answer = postRepository.findById(postId).orElseThrow( () -> new EntityNotFoundException("Post with the id " + postId + NOT_FOUND) @@ -271,6 +356,11 @@ private ForumEntity createForum(UUID courseId) { return forum; } + /** + * Last 4 activities of the forum + * @param forum forum with the activities + * @return up to 4 activities + */ public List forumActivity(Forum forum) { List activities = new ArrayList<>(); @@ -293,6 +383,12 @@ public List forumActivity(Forum forum) { } + /** + * Returns the forum activities of the other user + * @param userId user that requests the activities + * @param otherUserId user the activities have been requested + * @return list of forum activities + */ public List otherUserForumActivityByUserId(UUID userId, UUID otherUserId) { List forumEntitiesUser = forumRepository.findAllByUserIdsContaining(userId); List forumEntitiesOtherUser = forumRepository.findAllByUserIdsContaining(otherUserId); @@ -316,6 +412,11 @@ public List otherUserForumActivityByUserId(UUID userId, UUID return activities; } + /** + * Returns the forum activities of a user + * @param userId user that did the forum activities + * @return list of forum activities + */ public List forumActivityByUserId(UUID userId) { List forumEntities = forumRepository.findAllByUserIdsContaining(userId); @@ -329,7 +430,7 @@ public List forumActivityByUserId(UUID userId) { return activities; } - public List extractForumActivitiesForUser( + private List extractForumActivitiesForUser( List forumEntities, UUID userId, ForumMapper forumMapper @@ -366,7 +467,11 @@ public List extractForumActivitiesForUser( return activities; } - + /** + * Returns the open questions for a forum + * @param forum forum the questions are open in + * @return list of threads with open questions + */ public List openQuestions(Forum forum) { double alpha = 0.6; double beta = 0.4; diff --git a/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/SubmissionService.java b/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/SubmissionService.java index 55b50e3..f710387 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/SubmissionService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/SubmissionService.java @@ -174,7 +174,7 @@ public Result updateResult(InputResult result) { responses.add(response); }); - double correctness = (double)requiredScore.get() / (double)achievedScore.get(); + double correctness = (double)achievedScore.get() / (double) requiredScore.get(); final ContentProgressedEvent userProgressLogEvent = ContentProgressedEvent.builder() .userId(resultEntity.getUserId()) @@ -499,7 +499,7 @@ private void createUploadUrl(FileEntity fileEntity) { .method(Method.PUT) .bucket(BUCKET_ID) .object(fileEntity.getId().toString()) - .expiry(UPLOAD_URL_EXPIRY.toMinutesPart(), TimeUnit.MINUTES) + .expiry((int) UPLOAD_URL_EXPIRY.toMinutes(), TimeUnit.MINUTES) .build()); fileEntity.setUploadUrl(uploadUrl); fileRepository.save(fileEntity); @@ -512,7 +512,7 @@ private void createDownloadUrl(FileEntity fileEntity) { .method(Method.GET) .bucket(BUCKET_ID) .object(fileEntity.getId().toString()) - .expiry(DOWNLOAD_URL_EXPIRY.toHoursPart(), TimeUnit.HOURS) + .expiry((int) DOWNLOAD_URL_EXPIRY.toHours(), TimeUnit.HOURS) .build()); fileEntity.setDownloadUrl(downloadUrl); fileRepository.save(fileEntity); From 439d7a8c5ae16b0ce874eb862c086baae5dfaf08 Mon Sep 17 00:00:00 2001 From: Aaron Schmid <56757286+Aaron2000119@users.noreply.github.com> Date: Sun, 19 Oct 2025 22:24:37 +0200 Subject: [PATCH 2/2] add comments --- .../iste/meitrex/media_service/service/ForumService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/ForumService.java b/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/ForumService.java index 128e100..b8da26b 100644 --- a/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/ForumService.java +++ b/src/main/java/de/unistuttgart/iste/meitrex/media_service/service/ForumService.java @@ -81,6 +81,11 @@ public Forum getForumById(UUID id) { new EntityNotFoundException("Forum with the id " + id + " not found"))); } + /** + * Returns the forum by the courseId and creates a forum if it does not exists. + * @param id of the course + * @return forum of the course + */ public Forum getForumByCourseId(UUID id) { ForumEntity forum = forumRepository.findByCourseId(id).orElseGet(() -> createForum(id)); return forumMapper.forumEntityToForum(forum);