Skip to content

Commit

Permalink
Add mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronmacaron committed Oct 29, 2023
1 parent cff930b commit 31c0efe
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 14 deletions.
2 changes: 1 addition & 1 deletion api-docs.json
@@ -1 +1 @@
{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost:8080","description":"Generated server url"}],"paths":{"/users/":{"put":{"tags":["user-controller"],"operationId":"registerUser","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RegisterUserRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterUserResponse"}}}}}},"post":{"tags":["user-controller"],"operationId":"requestAutoUser","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RequestAutoUserRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/RequestAutoUserResponse"}}}}}}},"/events/{id}":{"put":{"tags":["event-controller"],"operationId":"updateEvent","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int32"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateEventRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/GenericEventResponse"}}}}}}},"/media-items/":{"post":{"tags":["media-item-controller"],"operationId":"uploadNewMediaItem","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateRequest"}}},"required":true},"responses":{"204":{"description":"No Content"}}}},"/events/{id}/participations":{"post":{"tags":["event-controller"],"operationId":"participateEvent","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int32"}}],"responses":{"200":{"description":"OK"}}}},"/events/{event_id}/medias/{media_id}/comments/":{"get":{"tags":["comment-controller"],"operationId":"receiveCommentsForMediaItem","parameters":[{"name":"media_id","in":"path","required":true,"schema":{"type":"integer","format":"int32"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Comment"}}}}}}},"post":{"tags":["comment-controller"],"operationId":"createNewComment","parameters":[{"name":"media_id","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateCommentRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/Comment"}}}}}}},"/events/":{"get":{"tags":["event-controller"],"operationId":"getEvents","responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/GenericEventResponse"}}}}}}},"post":{"tags":["event-controller"],"operationId":"createEvent","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateEventRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/GenericEventResponse"}}}}}}},"/events/{id}/medias":{"get":{"tags":["event-controller"],"operationId":"getAllMedias","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int32"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ReLivePostItem"}}}}}}}}},"components":{"schemas":{"RegisterUserRequest":{"type":"object","properties":{"email":{"type":"string"},"password":{"maxLength":2147483647,"minLength":10,"type":"string"}}},"RegisterUserResponse":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"name":{"type":"string"},"email":{"type":"string"},"registrationState":{"type":"string"}}},"CreateEventRequest":{"type":"object","properties":{"displayName":{"type":"string"},"description":{"type":"string"},"startDateTime":{"type":"string","format":"date-time"},"duration":{"type":"integer","format":"int32"}}},"GenericEventResponse":{"type":"object","properties":{"displayName":{"type":"string"},"description":{"type":"string"},"startDateTime":{"type":"string","format":"date-time"},"duration":{"type":"integer","format":"int32"},"state":{"type":"string","enum":["PLANNED","ONGOING","PAST"]}}},"RequestAutoUserRequest":{"type":"object","properties":{"name":{"maxLength":100,"minLength":2,"type":"string"}}},"RequestAutoUserResponse":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"name":{"type":"string"},"registrationState":{"type":"string"}}},"CreateRequest":{"type":"object","properties":{"dateTime":{"type":"string","format":"date-time"},"imgDataBase64":{"type":"string"},"eventId":{"type":"integer","format":"int32"},"creatorId":{"type":"integer","format":"int32"}}},"CreateCommentRequest":{"type":"object","properties":{"content":{"type":"string"},"mediaId":{"type":"integer","format":"int32"},"userId":{"type":"integer","format":"int32"}}},"Comment":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"mediaItem":{"$ref":"#/components/schemas/MediaItem"},"owner":{"$ref":"#/components/schemas/User"},"content":{"type":"string"},"dateTime":{"type":"string","format":"date-time"}}},"Event":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"owner":{"$ref":"#/components/schemas/User"},"medias":{"type":"array","items":{"$ref":"#/components/schemas/MediaItem"}},"displayName":{"type":"string"},"description":{"type":"string"},"startDateTime":{"type":"string","format":"date-time"},"duration":{"type":"integer","format":"int32"}}},"MediaItem":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"time":{"type":"string","format":"date-time"},"hash":{"type":"string"},"event":{"$ref":"#/components/schemas/Event"},"creator":{"$ref":"#/components/schemas/User"},"comments":{"type":"array","items":{"$ref":"#/components/schemas/Comment"}}}},"User":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"email":{"type":"string"},"pwHash":{"type":"string"},"name":{"type":"string"},"registrationState":{"type":"string","enum":["AUTO_CREATED","REGISTERED"]}}},"ReLivePostItem":{"type":"object","properties":{"mediaItemId":{"type":"integer","format":"int32"},"imageHash":{"type":"string"},"creatorName":{"type":"string"},"comments":{"type":"array","items":{"$ref":"#/components/schemas/Comment"}}}}}}}
{"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers":[{"url":"http://localhost:8080","description":"Generated server url"}],"paths":{"/users/":{"put":{"tags":["user-controller"],"operationId":"registerUser","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RegisterUserRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterUserResponse"}}}}}},"post":{"tags":["user-controller"],"operationId":"requestAutoUser","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RequestAutoUserRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/RequestAutoUserResponse"}}}}}}},"/events/{id}":{"put":{"tags":["event-controller"],"operationId":"updateEvent","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int32"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateEventRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/Event"}}}}}}},"/media-items/":{"post":{"tags":["media-item-controller"],"operationId":"uploadNewMediaItem","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateRequest"}}},"required":true},"responses":{"204":{"description":"No Content"}}}},"/events/{id}/participations":{"post":{"tags":["event-controller"],"operationId":"participateEvent","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int32"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/Participation"}}}}}}},"/events/{event_id}/medias/{media_id}/comments/":{"get":{"tags":["comment-controller"],"operationId":"receiveCommentsForMediaItem","parameters":[{"name":"media_id","in":"path","required":true,"schema":{"type":"integer","format":"int32"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Comment"}}}}}}},"post":{"tags":["comment-controller"],"operationId":"createNewComment","parameters":[{"name":"media_id","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateCommentRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/Comment"}}}}}}},"/events/":{"get":{"tags":["event-controller"],"operationId":"getEvents","responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Event"}}}}}}},"post":{"tags":["event-controller"],"operationId":"createEvent","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateEventRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"$ref":"#/components/schemas/Event"}}}}}}},"/events/{id}/medias":{"get":{"tags":["event-controller"],"operationId":"getAllMedias","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer","format":"int32"}}],"responses":{"200":{"description":"OK","content":{"*/*":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ReLivePostItem"}}}}}}}}},"components":{"schemas":{"RegisterUserRequest":{"type":"object","properties":{"email":{"type":"string"},"password":{"maxLength":2147483647,"minLength":10,"type":"string"}}},"RegisterUserResponse":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"name":{"type":"string"},"email":{"type":"string"},"registrationState":{"type":"string"}}},"CreateEventRequest":{"type":"object","properties":{"displayName":{"type":"string"},"description":{"type":"string"},"startDateTime":{"type":"string","format":"date-time"},"duration":{"type":"integer","format":"int32"}}},"Comment":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"mediaItem":{"$ref":"#/components/schemas/MediaItem"},"owner":{"$ref":"#/components/schemas/User"},"content":{"type":"string"},"dateTime":{"type":"string","format":"date-time"}}},"Event":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"owner":{"$ref":"#/components/schemas/User"},"medias":{"type":"array","items":{"$ref":"#/components/schemas/MediaItem"}},"displayName":{"type":"string"},"description":{"type":"string"},"startDateTime":{"type":"string","format":"date-time"},"duration":{"type":"integer","format":"int32"},"state":{"type":"string","enum":["PLANNED","ONGOING","PAST"]}}},"MediaItem":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"time":{"type":"string","format":"date-time"},"hash":{"type":"string"},"event":{"$ref":"#/components/schemas/Event"},"creator":{"$ref":"#/components/schemas/User"},"comments":{"type":"array","items":{"$ref":"#/components/schemas/Comment"}}}},"User":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"email":{"type":"string"},"pwHash":{"type":"string"},"name":{"type":"string"},"registrationState":{"type":"string","enum":["AUTO_CREATED","REGISTERED"]}}},"RequestAutoUserRequest":{"type":"object","properties":{"name":{"maxLength":100,"minLength":2,"type":"string"}}},"RequestAutoUserResponse":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"name":{"type":"string"},"registrationState":{"type":"string"}}},"CreateRequest":{"type":"object","properties":{"dateTime":{"type":"string","format":"date-time"},"imgDataBase64":{"type":"string"},"eventId":{"type":"integer","format":"int32"},"creatorId":{"type":"integer","format":"int32"}}},"Participation":{"type":"object","properties":{"id":{"type":"integer","format":"int32"},"user":{"$ref":"#/components/schemas/User"},"event":{"$ref":"#/components/schemas/Event"}}},"CreateCommentRequest":{"type":"object","properties":{"content":{"type":"string"},"mediaId":{"type":"integer","format":"int32"},"userId":{"type":"integer","format":"int32"}}},"ReLivePostItem":{"type":"object","properties":{"mediaItemId":{"type":"integer","format":"int32"},"imageHash":{"type":"string"},"creatorName":{"type":"string"},"comments":{"type":"array","items":{"$ref":"#/components/schemas/Comment"}}}}}}}
Expand Up @@ -14,7 +14,7 @@
@RequiredArgsConstructor
public class CommentController {

private CommentService commentService;
private final CommentService commentService;

@GetMapping("/")
public List<Comment> receiveCommentsForMediaItem(
Expand All @@ -23,11 +23,12 @@ public List<Comment> receiveCommentsForMediaItem(
}

@PostMapping("/")
public Comment createNewComment(
public CommentControllerDto.CreateCommentResponse createNewComment(
@RequestBody CommentControllerDto.CreateCommentRequest commentRequest,
@PathVariable String media_id,
@PathVariable int media_id,
Principal principal) {
commentRequest.setUserId(Integer.valueOf(principal.getName()));
commentRequest.setMediaId(media_id);
return commentService.createComment(commentRequest);
}
}
@@ -1,6 +1,7 @@
package ch.relievers.relive.controllers;

import ch.relievers.relive.dtos.EventControllerDtos;
import ch.relievers.relive.dtos.EventControllerDtos.ReLivePostItem;
import ch.relievers.relive.entities.Event;
import ch.relievers.relive.entities.Participation;
import ch.relievers.relive.services.EventService;
Expand Down Expand Up @@ -42,4 +43,9 @@ public Event updateEvent(
public Participation participateEvent(@PathVariable Integer id, Principal principal) {
return eventService.participateEvent(id, Integer.valueOf(principal.getName()));
}

@GetMapping("/{id}/medias")
public List<EventControllerDtos.ReLivePostItem> getAllMedias(@PathVariable int id){
return eventService.getAllPosts(id);
}
}
Expand Up @@ -4,6 +4,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

public class CommentControllerDto {

@Data
Expand All @@ -15,4 +17,14 @@ public static class CreateCommentRequest {
private Integer userId;
}

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class CreateCommentResponse {
private int commentId;
private String content;
private String authorName;
private LocalDateTime dateTime;
}

}
Expand Up @@ -5,6 +5,7 @@
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

public class EventControllerDtos {

Expand All @@ -17,4 +18,28 @@ public static class CreateEventRequest {
private LocalDateTime startDateTime;
private Integer duration;
}


@Data
@AllArgsConstructor
@NoArgsConstructor
public static class ReLivePostItem {

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Comment {
private int commentId;
private int authorId;
private String authorName;
private LocalDateTime dateTime;
private String content;
}

private int mediaItemId;
private LocalDateTime dateTime;
private String imageHash;
private String creatorName;
private List<Comment> comments;
}
}
2 changes: 2 additions & 0 deletions backend/src/main/java/ch/relievers/relive/entities/Event.java
@@ -1,5 +1,6 @@
package ch.relievers.relive.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -32,6 +33,7 @@ public Event(String displayName, String description, LocalDateTime startDateTime
private User owner;

@OneToMany(mappedBy = "event")
@JsonIgnore
private List<MediaItem> medias;

private String displayName;
Expand Down
Expand Up @@ -6,6 +6,7 @@
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.List;

@Entity(name = "`media`")
@NoArgsConstructor
Expand Down Expand Up @@ -36,5 +37,7 @@ public MediaItem(LocalDateTime time, String hash, Event event, User creator) {
@JoinColumn(name = "creator_id")
private User creator;

@OneToMany(mappedBy = "mediaItem")
private List<Comment> comments;

}
@@ -1,7 +1,12 @@
package ch.relievers.relive.repositories;

import ch.relievers.relive.entities.Event;
import ch.relievers.relive.entities.MediaItem;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface MediaItemRepository extends CrudRepository<MediaItem, Integer> {

List<MediaItem> getAllByEvent(Event event);
}
Expand Up @@ -8,20 +8,22 @@
import ch.relievers.relive.repositories.MediaItemRepository;
import ch.relievers.relive.repositories.UserRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class CommentService {

private UserRepository userRepository;
private MediaItemRepository mediaItemRepository;
private CommentRepository commentRepository;
private final UserRepository userRepository;
private final MediaItemRepository mediaItemRepository;
private final CommentRepository commentRepository;

@Transactional
public Comment createComment(CommentControllerDto.CreateCommentRequest commentRequest) {
public CommentControllerDto.CreateCommentResponse createComment(CommentControllerDto.CreateCommentRequest commentRequest) {
User owner = userRepository.findById(commentRequest.getUserId()).orElseThrow();
MediaItem mediaItem = mediaItemRepository
.findById(commentRequest.getMediaId()).orElseThrow();
Expand All @@ -31,7 +33,8 @@ public Comment createComment(CommentControllerDto.CreateCommentRequest commentRe
commentRequest.getContent(),
LocalDateTime.now()
);
return commentRepository.save(comment);
var newComment = commentRepository.save(comment);
return new CommentControllerDto.CreateCommentResponse(newComment.getId(), newComment.getContent(), newComment.getOwner().getName(), newComment.getDateTime());
}

public List<Comment> getCommentsForMediaItem(Integer mediaId) {
Expand Down

0 comments on commit 31c0efe

Please sign in to comment.