-
Notifications
You must be signed in to change notification settings - Fork 7
#8 Adds Event Endpoint, Auditing entity #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1d6ee5f
c5afdda
fd28788
790abb8
1e4e32a
1d5c440
e5484b1
5eb1342
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.lbcc.bms.bms_monolith.common.config; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.data.domain.AuditorAware; | ||
| import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @EnableJpaAuditing | ||
| public class JpaConfig { | ||
|
|
||
| @Bean | ||
| public AuditorAware<String> auditorProvider() { | ||
| return () -> Optional.of("system"); // TODO: Replace with code to fetch username when spring-security is implemented. | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.lbcc.bms.bms_monolith.common.constants; | ||
|
|
||
| public final class BMSConstants { | ||
|
|
||
| private BMSConstants() { | ||
| } | ||
|
|
||
| public static final String STATUS_200 = "200"; | ||
| public static final String MESSAGE_200 = "Request processed successfully"; | ||
| public static final String EVENT_SUCCESS_MESSAGE = "Events fetched successfully"; | ||
| public static final String UNEXPECTED_ERROR_MESSAGE = "An unexpected error occurred"; | ||
| public static final String UNEXPECTED_ERROR_CODE = "UNEXPECTED_ERROR"; | ||
| public static final String EVENT_SERVICE_ERROR = "EVENT_SERVICE_ERROR"; | ||
| public static final String INVALID_PAGINATION_PARAMETER = "INVALID_PAGINATION_PARAMETER"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,21 @@ | ||
| package org.lbcc.bms.bms_monolith.common.entity; | ||
|
|
||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.MappedSuperclass; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.EntityListeners; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import lombok.experimental.SuperBuilder; | ||
| import org.springframework.data.annotation.CreatedBy; | ||
| import org.springframework.data.annotation.CreatedDate; | ||
| import org.springframework.data.annotation.LastModifiedBy; | ||
| import org.springframework.data.annotation.LastModifiedDate; | ||
| import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.UUID; | ||
|
|
@@ -17,14 +26,27 @@ | |
| @NoArgsConstructor | ||
| @Setter | ||
| @SuperBuilder | ||
| @EntityListeners(AuditingEntityListener.class) | ||
damini1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public abstract class BaseAuditingEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| @Column(columnDefinition = "CHAR(36)") | ||
| private UUID id; | ||
|
|
||
| @CreatedDate | ||
| @Column(updatable = false) | ||
| private Instant createdDate; | ||
|
|
||
| @LastModifiedDate | ||
| @Column(insertable = false) | ||
| private Instant lastModifiedDate; | ||
|
|
||
| @CreatedBy | ||
| @Column(updatable = false) | ||
| private String createdBy; | ||
|
|
||
| @LastModifiedBy | ||
| @Column(insertable = false) | ||
| private String lastModifiedBy; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add method @AssertTrue(message = "LastModifiedDate should be after createdDate") |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package org.lbcc.bms.bms_monolith.controller; | ||
|
|
||
| import org.lbcc.bms.bms_monolith.common.constants.BMSConstants; | ||
| import org.lbcc.bms.bms_monolith.common.response.ApiListResponse; | ||
| import org.lbcc.bms.bms_monolith.entity.Event; | ||
| import org.lbcc.bms.bms_monolith.service.IEventService; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.data.web.PageableDefault; | ||
| import org.springframework.data.web.SortDefault; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequestMapping(path="/events") | ||
| public class EventController { | ||
|
|
||
| private final IEventService iEventService; | ||
|
|
||
| public EventController(IEventService iEventService) { | ||
| this.iEventService = iEventService; | ||
| } | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<ApiListResponse<Event>> getAllEvents( | ||
| @PageableDefault(page = 0, size = 10) | ||
| @SortDefault(sort = "startDate", direction = Sort.Direction.DESC) Pageable pageable) { | ||
|
|
||
| Page<Event> eventsPage = iEventService.getAllEvents(pageable); | ||
|
|
||
| ApiListResponse<Event> response = ApiListResponse.<Event>builder() | ||
| .success(true) | ||
| .message(BMSConstants.EVENT_SUCCESS_MESSAGE) | ||
| .setPage(eventsPage) | ||
| .build(); | ||
|
|
||
| return ResponseEntity.ok(response); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package org.lbcc.bms.bms_monolith.entity; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.OneToMany; | ||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import org.lbcc.bms.bms_monolith.common.entity.BaseAuditingEntity; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter @Setter | ||
| @AllArgsConstructor @NoArgsConstructor | ||
| public class Event extends BaseAuditingEntity { | ||
|
|
||
damini1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Size(min=10, max=50, message = "Title must be between 10 and 50 characters.") | ||
| @Column(nullable = false, length = 50) | ||
| private String title; | ||
damini1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Column(length = 1000) | ||
| private String description; | ||
|
|
||
| @ManyToOne(fetch = FetchType.EAGER) | ||
| @JoinColumn(name = "vendor_id") | ||
| private Vendor vendor; | ||
|
|
||
| @ManyToOne(fetch = FetchType.EAGER) | ||
| @JoinColumn(name = "venue_id") | ||
| private Venue venue; | ||
|
|
||
| @OneToMany(mappedBy = "event", cascade = CascadeType.ALL) | ||
| private List<EventShow> show; | ||
|
|
||
| @ManyToOne(fetch = FetchType.EAGER) | ||
| @JoinColumn(name = "event_type_id") | ||
| private EventType eventType; | ||
|
|
||
damini1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Column(nullable = false) | ||
| private Instant startDate; | ||
|
|
||
damini1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Column(length = 255) | ||
| private String thumbnailUrl; | ||
|
|
||
| @Column(nullable = false) | ||
| private Instant endDate; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package org.lbcc.bms.bms_monolith.entity; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.ElementCollection; | ||
| import jakarta.persistence.CollectionTable; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.OneToMany; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.EnumType; | ||
| import jakarta.persistence.CascadeType; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Builder; | ||
|
|
||
| import lombok.experimental.SuperBuilder; | ||
| import org.lbcc.bms.bms_monolith.common.entity.BaseAuditingEntity; | ||
| import org.lbcc.bms.bms_monolith.entity.enums.Genre; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @SuperBuilder | ||
| public class EventShow extends BaseAuditingEntity { | ||
damini1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @ElementCollection(targetClass = Genre.class) | ||
| @CollectionTable(name = "show_genre", joinColumns = @JoinColumn(name = "show_id")) | ||
| @Column(name = "genre") | ||
| @Enumerated(EnumType.STRING) | ||
| private List<Genre> genres; | ||
|
|
||
| @NotNull | ||
| private Instant startDate; | ||
|
|
||
| @NotNull | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NotNull will enforce a not null check from the application side, but it will not create a NOT NULL constraint on the database end. Bothe has to be added. What is missing here is the Request, Response, and DTO layers. Entity should have @column(nullable = false) |
||
| private Instant endDate; | ||
damini1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "event_id", nullable = false) | ||
| private Event event; | ||
|
|
||
| @OneToMany(mappedBy = "show", cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
| private List<SeatInShow> seatInShows; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Builder.Default |
||
|
|
||
| @OneToMany(mappedBy = "show", cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
| private List<SeatTypeInShow> seatTypeInShows; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Builder.Default |
||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add these methods to the class public void addSeatInShow(SeatInShow seatInShow) { public void removeSeatInShow(SeatInShow seatInShow) { public void addSeatTypeInShow(SeatTypeInShow seatTypeInShow) { public void removeSeatTypeInShow(SeatTypeInShow seatTypeInShow) { |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.lbcc.bms.bms_monolith.entity; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import org.lbcc.bms.bms_monolith.common.entity.BaseAuditingEntity; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above for annotations |
||
| public class EventType extends BaseAuditingEntity { | ||
|
|
||
| private String label; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package org.lbcc.bms.bms_monolith.entity; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.EnumType; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import org.lbcc.bms.bms_monolith.common.entity.BaseAuditingEntity; | ||
| import org.lbcc.bms.bms_monolith.entity.enums.OperationalStatus; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above for annotations |
||
| public class Seat extends BaseAuditingEntity { | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "seat_type_id") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nullable = false |
||
| private SeatType seatType; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "venue_id") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nullable = false |
||
| private Venue venue; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Enumerated(EnumType.STRING) |
||
| private OperationalStatus operationalStatus; | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| private String label; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package org.lbcc.bms.bms_monolith.entity; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.EnumType; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import org.lbcc.bms.bms_monolith.common.entity.BaseAuditingEntity; | ||
| import org.lbcc.bms.bms_monolith.entity.enums.BookingStatus; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above for annotations |
||
| public class SeatInShow extends BaseAuditingEntity { | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "seat_type_in_show_id") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nullable=false |
||
| private SeatTypeInShow seatTypeInShow; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "show_id") | ||
| private EventShow show; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Enumerated(EnumType.STRING) |
||
| private BookingStatus bookingStatus; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.lbcc.bms.bms_monolith.entity; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import org.lbcc.bms.bms_monolith.common.entity.BaseAuditingEntity; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class SeatType extends BaseAuditingEntity { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above for annotations |
||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| private String label; | ||
|
|
||
| @Column(precision = 10, scale = 2) | ||
| private BigDecimal price; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove price; Price will be part of SeatTypeInShow |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.lbcc.bms.bms_monolith.entity; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.Column; | ||
| import lombok.experimental.SuperBuilder; | ||
| import org.lbcc.bms.bms_monolith.common.entity.BaseAuditingEntity; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| @Entity | ||
| @SuperBuilder | ||
| public class SeatTypeInShow extends BaseAuditingEntity { | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "seat_type_id") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nullable=false |
||
| private SeatType seatType; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "show_id") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nullable = false |
||
| private EventShow show; | ||
|
|
||
damini1994 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Column(precision = 10, scale = 2) | ||
| private BigDecimal price; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could use interface for constants , I am not sure creating constant in class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nareshthecoder No, interface can be inherited and usually Interface in Java is used to define API not constants.