diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/controller/EventController.java b/resq/backend/resq/src/main/java/com/groupa1/resq/controller/EventController.java new file mode 100644 index 00000000..3262bf84 --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/controller/EventController.java @@ -0,0 +1,38 @@ +package com.groupa1.resq.controller; + + +import com.groupa1.resq.request.CreateEventRequest; +import com.groupa1.resq.service.EventService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import com.groupa1.resq.response.EventResponse; +import java.util.List; + +@RestController +@RequestMapping("/event") +public class EventController { + + @Autowired + private EventService eventService; + + @PreAuthorize("hasRole('RESPONDER') or hasRole('COORDINATOR') or hasRole('FACILITATOR') or hasRole('VICTIM')") + @PostMapping("/createEvent") + public ResponseEntity createEvent(@RequestBody CreateEventRequest createEventRequest){ + return eventService.createEvent(createEventRequest); + } + + @PreAuthorize("hasRole('RESPONDER') or hasRole('COORDINATOR') or hasRole('FACILITATOR') or hasRole('VICTIM')") + @GetMapping("/viewEvents") + public ResponseEntity> viewEvents(@RequestParam Long reporterId) { + return eventService.viewEvents( reporterId); + } + + +} diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/converter/NeedConverter.java b/resq/backend/resq/src/main/java/com/groupa1/resq/converter/NeedConverter.java index a977071a..8f9b4ddd 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/converter/NeedConverter.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/converter/NeedConverter.java @@ -31,6 +31,7 @@ public NeedDto convertToDto(Need need) { needDto.setLatitude(need.getLatitude()); needDto.setLongitude(need.getLongitude()); needDto.setCreatedDate(need.getCreatedAt()); + needDto.setSize(need.getSize()); Request request = need.getRequest(); if (request != null) { needDto.setRequestId(request.getId()); @@ -51,6 +52,7 @@ public Need convertToEntity(NeedDto needDto) { need.setLongitude(needDto.getLongitude()); need.setStatus(needDto.getStatus()); need.setCreatedAt(needDto.getCreatedDate()); + need.setSize(needDto.getSize()); Request request = requestRepository.findById(needDto.getRequestId()).orElse(null); need.setRequest(request); return need; diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/converter/ResourceConverter.java b/resq/backend/resq/src/main/java/com/groupa1/resq/converter/ResourceConverter.java index 8ae5d0a6..966cb069 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/converter/ResourceConverter.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/converter/ResourceConverter.java @@ -2,6 +2,7 @@ import com.groupa1.resq.dto.ResourceDto; import com.groupa1.resq.entity.Resource; +import com.groupa1.resq.entity.enums.ESize; import com.groupa1.resq.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -26,6 +27,7 @@ public ResourceDto convertToDto(Resource resource){ resourceDto.setLatitude(resource.getLatitude()); resourceDto.setLongitude(resource.getLongitude()); resourceDto.setCreatedDate(resource.getCreatedAt()); + resourceDto.setSize(resource.getSize().toString()); return resourceDto; } @@ -47,6 +49,7 @@ public Resource convertToEntity(ResourceDto resourceDto){ resource.setLatitude(resourceDto.getLatitude()); resource.setLongitude(resourceDto.getLongitude()); resource.setCreatedAt(resourceDto.getCreatedDate()); + resource.setSize(ESize.valueOf(resourceDto.getSize())); return resource; } } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/dto/EventDto.java b/resq/backend/resq/src/main/java/com/groupa1/resq/dto/EventDto.java new file mode 100644 index 00000000..242e975d --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/dto/EventDto.java @@ -0,0 +1,25 @@ +package com.groupa1.resq.dto; + + +import com.groupa1.resq.entity.User; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +public class EventDto { + + private Long reporterId; + + private String description; + + private LocalDateTime reportDate; + + private boolean isVerified; + + private BigDecimal eventLatitude; + private BigDecimal eventLongitude; + + +} diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/dto/NeedDto.java b/resq/backend/resq/src/main/java/com/groupa1/resq/dto/NeedDto.java index 42d0ebbd..a148d7c1 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/dto/NeedDto.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/dto/NeedDto.java @@ -1,6 +1,7 @@ package com.groupa1.resq.dto; import com.groupa1.resq.entity.enums.ENeedStatus; +import com.groupa1.resq.entity.enums.ESize; import lombok.Data; import java.math.BigDecimal; @@ -18,4 +19,5 @@ public class NeedDto { private Long requestId; private ENeedStatus status; private LocalDateTime createdDate; + private ESize size; } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/dto/ResourceDto.java b/resq/backend/resq/src/main/java/com/groupa1/resq/dto/ResourceDto.java index 6b8733d1..19da9b50 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/dto/ResourceDto.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/dto/ResourceDto.java @@ -17,4 +17,5 @@ public class ResourceDto { private BigDecimal latitude; private BigDecimal longitude; private LocalDateTime createdDate; + private String size; } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Action.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Action.java index cdc478ec..6db223a8 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Action.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Action.java @@ -24,8 +24,7 @@ public class Action extends BaseEntity { @JoinColumn(name = "verifier_id") private User verifier; - @Lob - @Column(length = 3000) + @Column(length = 2048) private String description; private LocalDateTime dueDate; diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Event.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Event.java new file mode 100644 index 00000000..a16db4a9 --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Event.java @@ -0,0 +1,38 @@ +package com.groupa1.resq.entity; + +import jakarta.persistence.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@NoArgsConstructor +@Entity +@Table( name = "EVENT") +@Data +@EqualsAndHashCode(callSuper = true, exclude = {"reporter"}) +@ToString(callSuper = true, exclude = {"reporter"}) +public class Event extends BaseEntity { + + //@Enumerated(EnumType.STRING) + //private EEventType eventType; + + @ManyToOne + @JoinColumn(name = "reporter_id") + private User reporter; + + @Column(length = 2048) + private String description; + + private LocalDateTime reportDate; + + private boolean isVerified; + + private BigDecimal eventLatitude; + private BigDecimal eventLongitude; + +} + diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Feedback.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Feedback.java index 292616e5..e8a59c8b 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Feedback.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Feedback.java @@ -24,7 +24,6 @@ public class Feedback extends BaseEntity { @JoinColumn(name = "creator_id") private User creator; - @Lob - @Column(length = 3000) + @Column(length = 2048) private String message; } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Info.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Info.java index 87e0f417..c1eeaede 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Info.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Info.java @@ -21,8 +21,7 @@ public class Info extends BaseEntity{ @JoinColumn(name = "user_id") private User user; - @Lob - @Column(length = 3000) + @Column(length = 2048) private String description; private BigDecimal latitude; diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Need.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Need.java index f4f95d3b..acfe4f25 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Need.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Need.java @@ -1,6 +1,8 @@ package com.groupa1.resq.entity; +import com.groupa1.resq.entity.enums.EGender; import com.groupa1.resq.entity.enums.ENeedStatus; +import com.groupa1.resq.entity.enums.ESize; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -34,6 +36,13 @@ public class Need extends BaseEntity{ private BigDecimal latitude; private BigDecimal longitude; + @Enumerated(EnumType.STRING) + private EGender gender; + + // These field only for clothing + @Enumerated(EnumType.STRING) + private ESize size; + @ManyToOne @JoinColumn(name = "request_id") private Request request; diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Notification.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Notification.java index d31ded24..741df185 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Notification.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Notification.java @@ -21,8 +21,7 @@ public class Notification extends BaseEntity{ private String title; - @Lob - @Column(length = 1000) + @Column(length = 2048) private String body; private boolean isRead; diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Resource.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Resource.java index 8c288c72..d9ef1a32 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Resource.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Resource.java @@ -1,10 +1,8 @@ package com.groupa1.resq.entity; import com.groupa1.resq.entity.enums.EGender; -import jakarta.persistence.Entity; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import com.groupa1.resq.entity.enums.ESize; +import jakarta.persistence.*; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @@ -32,6 +30,10 @@ public class Resource extends BaseEntity { private EGender gender; + // These field only for clothing + @Enumerated(EnumType.STRING) + private ESize size; + private Integer quantity; private BigDecimal latitude; diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Task.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Task.java index b5f7cf3f..3c762b35 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Task.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/Task.java @@ -5,7 +5,6 @@ import jakarta.persistence.*; import lombok.Data; import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; import lombok.ToString; import java.util.HashSet; @@ -41,8 +40,7 @@ public class Task extends BaseEntity { @Enumerated(EnumType.STRING) private EStatus status; - @Lob - @Column(length = 3000) + @Column(length = 2048) private String description; public Task() { diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/User.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/User.java index fd5f2929..5899c8b6 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/User.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/User.java @@ -18,8 +18,8 @@ @UniqueConstraint(columnNames = "email") }) @Data -@EqualsAndHashCode(callSuper = true, exclude = {"userProfile", "requests", "needs", "resourcesReceived","resourcesSent", "tasksAssigned", "tasksAssignedTo", "feedbacks", "actions", "infos", "notifications"}) -@ToString(callSuper = true, exclude = {"userProfile", "requests", "needs", "resourcesReceived","resourcesSent", "tasksAssigned", "tasksAssignedTo", "feedbacks", "actions", "infos", "notifications"}) +@EqualsAndHashCode(callSuper = true, exclude = {"userProfile", "requests", "needs", "resourcesReceived","resourcesSent", "tasksAssigned", "tasksAssignedTo", "feedbacks", "actions", "infos", "notifications", "reportedEvents"}) +@ToString(callSuper = true, exclude = {"userProfile", "requests", "needs", "resourcesReceived","resourcesSent", "tasksAssigned", "tasksAssignedTo", "feedbacks", "actions", "infos", "notifications", "reportedEvents"}) public class User extends BaseEntity { @NotBlank @@ -44,7 +44,8 @@ public class User extends BaseEntity { @Enumerated(EnumType.STRING) private Set roles = new HashSet<>(); - @OneToOne(mappedBy = "user") + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "user_profile_id", referencedColumnName = "id") private UserProfile userProfile; @OneToMany(fetch = FetchType.LAZY, mappedBy="requester") @@ -68,6 +69,9 @@ public class User extends BaseEntity { @OneToMany(fetch = FetchType.LAZY, mappedBy = "assignee") private Set tasksAssignedTo; + @OneToMany(fetch = FetchType.LAZY, mappedBy = "reporter") + private Set reportedEvents; + @OneToMany(fetch = FetchType.LAZY, mappedBy = "creator") private Set feedbacks; @@ -99,5 +103,6 @@ public User() { this.actions = new HashSet<>(); this.infos = new HashSet<>(); this.notifications = new HashSet<>(); + this.reportedEvents = new HashSet<>(); } } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/UserProfile.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/UserProfile.java index f80b3717..84c75040 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/UserProfile.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/UserProfile.java @@ -3,7 +3,9 @@ import com.groupa1.resq.entity.enums.EGender; import jakarta.persistence.*; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.ToString; import java.time.LocalDate; @@ -12,6 +14,8 @@ @Entity @Table( name = "USER_PROFILE") @Data +@EqualsAndHashCode(callSuper = true, exclude = {"user"}) +@ToString(exclude = {"user"}) public class UserProfile extends BaseEntity{ private String name; @@ -22,8 +26,7 @@ public class UserProfile extends BaseEntity{ @Enumerated(EnumType.STRING) private EGender gender; - @OneToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "user_id") + @OneToOne(mappedBy = "userProfile") private User user; private boolean isEmailConfirmed; diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EEventType.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EEventType.java new file mode 100644 index 00000000..26650bf3 --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EEventType.java @@ -0,0 +1,9 @@ +package com.groupa1.resq.entity.enums; + +public enum EEventType { + FIRE, + EARTHQUAKE, + FLOOD, + TSUNAMI, + OTHER +} diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EGender.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EGender.java index 9907de81..8e41e575 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EGender.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EGender.java @@ -1,6 +1,8 @@ package com.groupa1.resq.entity.enums; public enum EGender { - MALE, - FEMALE + MAN, + WOMAN, + CHILDREN_BOY, CHILDREN_GIRL, + BABY } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/ESize.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/ESize.java new file mode 100644 index 00000000..cf3ddea3 --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/ESize.java @@ -0,0 +1,7 @@ +package com.groupa1.resq.entity.enums; + +public enum ESize { + XL, L, M, S, XS, // For Gender: MAN, WOMAN + AGE_0_2, AGE_2_4, // For Gender: BABY + AGE_4_8, AGE_8_12, AGE_12_18, // For Gender: CHILDREN_BOY, CHILDREN_GIRL +} diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/repository/EventRepository.java b/resq/backend/resq/src/main/java/com/groupa1/resq/repository/EventRepository.java new file mode 100644 index 00000000..dca54991 --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/repository/EventRepository.java @@ -0,0 +1,15 @@ +package com.groupa1.resq.repository; + + +import com.groupa1.resq.entity.Event; +import com.groupa1.resq.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface EventRepository extends JpaRepository { + List findByReporter(User reporter); + +} diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateEventRequest.java b/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateEventRequest.java new file mode 100644 index 00000000..b8f3a8a8 --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateEventRequest.java @@ -0,0 +1,23 @@ +package com.groupa1.resq.request; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class CreateEventRequest { + private Long reporterId; + private String description; + + private BigDecimal eventLatitude; + private BigDecimal eventLongitude; + + //private LocalDateTime reportDate; + + + +} diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateNeedRequest.java b/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateNeedRequest.java index 2a957ac7..e388f353 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateNeedRequest.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateNeedRequest.java @@ -11,4 +11,5 @@ public class CreateNeedRequest { private BigDecimal longitude; private String categoryTreeId; private Integer quantity; + private String size; } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateResourceRequest.java b/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateResourceRequest.java index 0393f8e9..87d1c672 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateResourceRequest.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/request/CreateResourceRequest.java @@ -15,5 +15,5 @@ public class CreateResourceRequest { private BigDecimal latitude; private BigDecimal longitude; private EGender gender; - + private String size; } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/request/UpdateNeedRequest.java b/resq/backend/resq/src/main/java/com/groupa1/resq/request/UpdateNeedRequest.java index e4a1e165..a4b30e93 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/request/UpdateNeedRequest.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/request/UpdateNeedRequest.java @@ -11,4 +11,5 @@ public class UpdateNeedRequest { private BigDecimal longitude; private String categoryTreeId; private Integer quantity; + private String size; } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/response/EventResponse.java b/resq/backend/resq/src/main/java/com/groupa1/resq/response/EventResponse.java new file mode 100644 index 00000000..2045d1ca --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/response/EventResponse.java @@ -0,0 +1,22 @@ +package com.groupa1.resq.response; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +@Accessors(chain = true) +public class EventResponse { + private long id; + private long reporterId; + private String description; + private boolean isCompleted; + private BigDecimal eventLatitude; + private BigDecimal eventLongitude; + private LocalDateTime reportDate; + + + +} diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/service/EventService.java b/resq/backend/resq/src/main/java/com/groupa1/resq/service/EventService.java new file mode 100644 index 00000000..396993aa --- /dev/null +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/service/EventService.java @@ -0,0 +1,94 @@ +package com.groupa1.resq.service; + +import com.fasterxml.jackson.databind.deser.std.NumberDeserializers; +import com.groupa1.resq.dto.EventDto; +import com.groupa1.resq.dto.NeedDto; +import com.groupa1.resq.entity.Event; +import com.groupa1.resq.entity.Event; +import com.groupa1.resq.entity.Task; +import com.groupa1.resq.entity.User; +import com.groupa1.resq.exception.EntityNotFoundException; +import com.groupa1.resq.repository.EventRepository; +import com.groupa1.resq.repository.UserRepository; +import com.groupa1.resq.request.CreateEventRequest; +import com.groupa1.resq.request.CreateEventRequest; +import com.groupa1.resq.response.EventResponse; +import com.groupa1.resq.response.EventResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestBody; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +@Service +@Slf4j +public class EventService { + + @Autowired + private EventRepository eventRepository; + + @Autowired + private UserRepository userRepository; + + + public ResponseEntity createEvent(CreateEventRequest createEventRequest) { + + // creating event for a user + Event eventEntity = new Event(); + User reporter = userRepository.findById(createEventRequest.getReporterId()).orElseThrow(()-> new EntityNotFoundException("No user found")); + String description = createEventRequest.getDescription(); + BigDecimal startLatitude = createEventRequest.getEventLatitude(); + BigDecimal startLongitude =createEventRequest.getEventLongitude(); + eventEntity.setReporter(reporter); + eventEntity.setVerified(false); // default + eventEntity.setDescription(description); + eventEntity.setEventLatitude(startLatitude); + eventEntity.setEventLongitude(startLongitude); + eventEntity.setCreatedAt(LocalDateTime.now()); + eventEntity.setModifiedAt(LocalDateTime.now()); + eventEntity.setReportDate(LocalDateTime.now()); + + + eventRepository.save(eventEntity); + return ResponseEntity.ok("Event saved successfully!"); + + } + + public ResponseEntity> viewEvents(Long reporterId){ + User reporter = userRepository.findById(reporterId).orElseThrow(()-> new EntityNotFoundException("No user found")); + + List events = eventRepository.findByReporter(reporter); + + List eventResponses = new ArrayList<>(); +// Set events = reporter.getReportedEvents(); + + + System.out.println(reporter); + System.out.println(reporter.getReportedEvents()); + events.forEach(event -> { + EventResponse eventResponse = new EventResponse(); + eventResponse.setId(event.getId()) + .setReporterId(event.getReporter().getId()) + .setDescription(event.getDescription()) + .setCompleted(event.isVerified()) + .setEventLatitude(event.getEventLatitude()) + .setEventLongitude(event.getEventLongitude()) + .setReportDate(LocalDateTime.now()); + eventResponses.add(eventResponse); + }); + System.out.println(eventResponses.get(0)); + return ResponseEntity.ok(eventResponses); + } + + + + +} diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/service/NeedService.java b/resq/backend/resq/src/main/java/com/groupa1/resq/service/NeedService.java index ae8ff626..03c4899b 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/service/NeedService.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/service/NeedService.java @@ -5,6 +5,7 @@ import com.groupa1.resq.entity.Need; import com.groupa1.resq.entity.User; import com.groupa1.resq.entity.enums.ENeedStatus; +import com.groupa1.resq.entity.enums.ESize; import com.groupa1.resq.exception.EntityNotFoundException; import com.groupa1.resq.exception.NotOwnerException; import com.groupa1.resq.repository.NeedRepository; @@ -55,6 +56,7 @@ public Long save(Long userId, CreateNeedRequest createNeedRequest) { need.setLatitude(createNeedRequest.getLatitude()); need.setQuantity(createNeedRequest.getQuantity()); need.setCategoryTreeId(createNeedRequest.getCategoryTreeId()); + need.setSize(ESize.valueOf(createNeedRequest.getSize())); need.setStatus(ENeedStatus.NOT_INVOLVED); return needRepository.save(need).getId(); @@ -102,6 +104,7 @@ public ResponseEntity update (UpdateNeedRequest updateNeedRequest, Long need.setLatitude(updateNeedRequest.getLatitude()); need.setQuantity(updateNeedRequest.getQuantity()); need.setCategoryTreeId(updateNeedRequest.getCategoryTreeId()); + need.setSize(ESize.valueOf(updateNeedRequest.getSize())); needRepository.save(need); return ResponseEntity.ok("Need updated successfully"); } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/service/ResourceService.java b/resq/backend/resq/src/main/java/com/groupa1/resq/service/ResourceService.java index ce6eebc6..b1dce64d 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/service/ResourceService.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/service/ResourceService.java @@ -4,6 +4,7 @@ import com.groupa1.resq.dto.ResourceDto; import com.groupa1.resq.entity.Resource; import com.groupa1.resq.entity.User; +import com.groupa1.resq.entity.enums.ESize; import com.groupa1.resq.exception.EntityNotFoundException; import com.groupa1.resq.repository.ResourceRepository; import com.groupa1.resq.request.CreateResourceRequest; @@ -54,6 +55,7 @@ public ResponseEntity createResource(CreateResourceRequest createResourc resource.setLatitude(createResourceRequest.getLatitude()); resource.setQuantity(createResourceRequest.getQuantity()); resource.setCategoryTreeId(createResourceRequest.getCategoryTreeId()); + resource.setSize(ESize.valueOf(createResourceRequest.getSize())); Long resourceId = resourceRepository.save(resource).getId(); return ResponseEntity.ok(resourceId); } @@ -64,6 +66,7 @@ public ResponseEntity updateResource(CreateResourceRequest createResourc resource.setLatitude(createResourceRequest.getLatitude()); resource.setLongitude(createResourceRequest.getLongitude()); resource.setCategoryTreeId(createResourceRequest.getCategoryTreeId()); + resource.setSize(ESize.valueOf(createResourceRequest.getSize())); resourceRepository.save(resource); return ResponseEntity.ok("Resource updated successfully"); }