Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #757 from SE-TINF22B6/event-refactoring
Browse files Browse the repository at this point in the history
Backend: Added and Adjusted Event Endpoints
  • Loading branch information
FurKay00 authored May 29, 2024
2 parents 303a8ea + 5b22b50 commit fb73c9e
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public EventCommentThreadViewProposal getCommentThreadView(@PathVariable Long id
return service.getEventCommentThreadView(id);
}

@GetMapping("/calendar-events")
public List<CalendarEventProposal> getCalendarEvents() {
return service.getCalendarEvents();
}

@PostMapping("/create-event")
public EventThreadViewProposal create(@RequestBody CreateEventPostProposal proposal) {
return service.create(proposal);
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/de/tinf22b6/dhbwhub/mapper/EventMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,21 @@ public static EventThreadViewProposal mapToPostThreadViewProposal(EventPost post
new LocationProposal(post.getLocation(), post.getLatitude(), post.getLongitude()),
post.getLikes(),
0,
post.getTimestamp(),
post.getStartdate(),
post.getEnddate(),
post.getPicture() != null ? post.getPicture().getImageData() : null,
post.getUser() != null ? post.getUser().getAccount().getId() : null,
post.getUser() != null ? post.getUser().getAccount().getUsername(): null,
post.getUser().getAccount().getPicture() != null ? post.getUser().getAccount().getPicture().getImageData() : null,
null
);
}

public static CalendarEventProposal mapToCalendarEventProposal(EventPost post) {
return new CalendarEventProposal(
post.getId(),
post.getTitle(),
post.getStartdate(),
post.getEnddate()
);
}

public static EventCommentThreadViewProposal mapToThreadView(EventComment comment) {
return new EventCommentThreadViewProposal(
comment.getEventPost() != null? comment.getEventPost().getId() : null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

package de.tinf22b6.dhbwhub.proposal.simplified_models;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class CalendarEventProposal {
private Long eventId;

private String title;

private Date startDate;

private Date endDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,9 @@ public class EventThreadViewProposal {

private int commentAmount;

private Date timestamp;
private Date startDate;

private Date startdate;

private Date enddate;

private byte[] postImage;

private Long accountId;

private String username;

private byte[] userImage;
private Date endDate;

private List<EventCommentThreadViewProposal> comments;
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ public int adjustCommentLikes(LikeEventCommentProposal likeEventCommentProposal,
return repository.save(updatedComment).getLikes();
}

@Override
public List<CalendarEventProposal> getCalendarEvents() {
return this.repository.findAllEventPosts().stream().map(EventMapper::mapToCalendarEventProposal).toList();
}

@Override
public List<EventCommentThreadViewProposal> getEventComments(Long id) {
return repository.getEventComments(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public interface EventService {
EventCommentThreadViewProposal getEventCommentThreadView(Long id);
int adjustPostLikes(LikeEventPostProposal likeEventPostProposal, int i);
int adjustCommentLikes(LikeEventCommentProposal likeEventCommentProposal, int i);
List<CalendarEventProposal> getCalendarEvents();
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ protected UpdateEventPostProposal createDefaultUpdateEventPostProposal() {
}

protected EventThreadViewProposal createDefaultEventThreadViewProposal() {
return new EventThreadViewProposal(1L, "Titel 1", "Beschreibung 1", List.of("Tag 1", "Tag 2"), createDefaultLocationProposal(), 0, 0, new Date(1478979207L), new Date(1478979208L), new Date(1478979209L), createDefaultPicture().getImageData(), 1L, "Maxi", createDefaultPicture2().getImageData(), List.of(createDefaultEventCommentThreadViewProposal(),createDefaultEventCommentThreadViewProposal()));
return new EventThreadViewProposal(1L, "Titel 1", "Beschreibung 1", List.of("Tag 1", "Tag 2"), createDefaultLocationProposal(), 0, 0, new Date(1478979208L), new Date(1478979209L), List.of(createDefaultEventCommentThreadViewProposal(),createDefaultEventCommentThreadViewProposal()));
}

protected CalendarEventProposal createDefaultCalendarEventProposal() {
return new CalendarEventProposal(1L, "Titel 1", new Date(1478979208L), new Date(1478979209L));
}

protected HomepageEventPreviewProposal createDefaultEventPostPreviewProposal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ void GetEventPreviewsHomepage_StatusIsOk() throws Exception {
.andExpect(jsonPath("$", hasSize(2)));
}

@Test
void GetCalendarEvents_StatusIsOk() throws Exception {
CalendarEventProposal calendarEventProposal = createDefaultCalendarEventProposal();
when(eventService.getCalendarEvents()).thenReturn(List.of(calendarEventProposal, calendarEventProposal));

ResultActions response = mockMvc.perform(get("/event/calendar-events")
.contentType(MediaType.APPLICATION_JSON));

response.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(2)));
}

@Test
void GetEventThreadView_StatusIsOk() throws Exception {
EventThreadViewProposal eventThreadView = createDefaultEventThreadViewProposal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ void GetHomepageEvents_HasSize_Two() {
assertThat(eventService.getHomepageEvents()).hasSize(2);
}

@Test
void GetCalendarEvents_IsEmpty() {
assertThat(eventService.getCalendarEvents()).isEmpty();
}

@Test
void GetCalendarEvents_HasSize_Two() {
EventPost post1 = createDefaultEventPost();
EventPost post2 = createDefaultEventPost();
when(eventRepository.findAllEventPosts()).thenReturn(List.of(post1, post2));

assertThat(eventService.getCalendarEvents()).hasSize(2);
}

@Test
void GetEventThreadView_IsNotNull() {
EventPost post = createDefaultEventPost();
Expand Down

0 comments on commit fb73c9e

Please sign in to comment.