Browse Source

WORKING SEARCH QUERY

Joshua Chung 6 years ago
parent
commit
a9de2bdb37

+ 19
- 34
src/main/java/com/proximity/demo/eventbriteApi/Events/Event.java View File

@@ -1,19 +1,15 @@
1 1
 package com.proximity.demo.eventbriteApi.Events;
2 2
 
3
-import com.fasterxml.jackson.annotation.JsonBackReference;
4 3
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5 4
 import com.fasterxml.jackson.annotation.JsonProperty;
6 5
 import com.proximity.demo.eventbriteApi.Categories.Category;
7 6
 import com.proximity.demo.eventbriteApi.Subcategories.Subcategory;
8
-import com.proximity.demo.eventbriteApi.Venues.Venue;
9
-import io.micrometer.core.lang.Nullable;
10 7
 
11 8
 import javax.persistence.*;
9
+import java.time.LocalDate;
12 10
 import java.time.LocalDateTime;
13 11
 import java.util.Date;
14
-import java.util.HashSet;
15 12
 import java.util.Map;
16
-import java.util.Set;
17 13
 
18 14
 @Entity
19 15
 @JsonIgnoreProperties(ignoreUnknown = true)
@@ -27,8 +23,8 @@ public class Event {
27 23
     private Long category_id;
28 24
     private Long subcategory_id;
29 25
     private Long venue_id;
30
-    private LocalDateTime startDate;
31
-    private LocalDateTime endDate;
26
+    private LocalDate start_date;
27
+    private LocalDate endDate;
32 28
     private String status;
33 29
     private Date created;
34 30
     private String resource_url;
@@ -51,14 +47,14 @@ public class Event {
51 47
     public Event() { }
52 48
 
53 49
     public Event(String eventName, String eventDescription, long category_id, long subcategory_id, long venue_id,
54
-                 LocalDateTime startDate, LocalDateTime endDate, String status, Date created, String resource_url,
50
+                 LocalDate start_date, LocalDate endDate, String status, Date created, String resource_url,
55 51
                  String logo) {
56 52
         this.eventName = eventName;
57 53
         this.eventDescription = eventDescription;
58 54
         this.category_id = category_id;
59 55
         this.subcategory_id = subcategory_id;
60 56
         this.venue_id = venue_id;
61
-        this.startDate = startDate;
57
+        this.start_date = start_date;
62 58
         this.endDate = endDate;
63 59
         this.status = status;
64 60
         this.created = created;
@@ -79,12 +75,12 @@ public class Event {
79 75
 
80 76
     @JsonProperty("start")
81 77
     private void unpackStart(Map<String, Object> start) {
82
-        this.startDate = LocalDateTime.parse((String) start.get("local"));
78
+        this.start_date = LocalDate.from(LocalDateTime.parse((String) start.get("local")));
83 79
     }
84 80
 
85 81
     @JsonProperty("end")
86 82
     private void unpackEnd(Map<String, Object> end) {
87
-        this.endDate =  LocalDateTime.parse((String) end.get("local"));
83
+        this.endDate = LocalDate.from(LocalDateTime.parse((String) end.get("local")));
88 84
     }
89 85
 //
90 86
 //    @JsonProperty("logo")
@@ -118,13 +114,21 @@ public class Event {
118 114
 
119 115
     public void setVenue_id(long venue_id) { this.venue_id = venue_id; }
120 116
 
121
-    public LocalDateTime getStartDate() { return startDate; }
117
+    public LocalDate getStart_date() {
118
+        return start_date;
119
+    }
122 120
 
123
-    public void setStartDate(LocalDateTime startDate) { this.startDate = startDate; }
121
+    public void setStart_date(LocalDate start_date) {
122
+        this.start_date = start_date;
123
+    }
124 124
 
125
-    public LocalDateTime getEndDate() { return endDate; }
125
+    public LocalDate getEndDate() {
126
+        return endDate;
127
+    }
126 128
 
127
-    public void setEndDate(LocalDateTime endDate) { this.endDate = endDate; }
129
+    public void setEndDate(LocalDate endDate) {
130
+        this.endDate = endDate;
131
+    }
128 132
 
129 133
     public String getStatus() { return status; }
130 134
 
@@ -154,23 +158,4 @@ public class Event {
154 158
 //
155 159
 //    public void setVenue(Venue venue) { this.venue = venue; }
156 160
 
157
-    @Override
158
-    public String toString() {
159
-        return "Event{" +
160
-                "id=" + id +
161
-                ", eventName='" + eventName + '\'' +
162
-                ", eventDescription='" + eventDescription + '\'' +
163
-                ", category_id=" + category_id +
164
-                ", subcategory_id=" + subcategory_id +
165
-                ", venue_id=" + venue_id +
166
-                ", startDate=" + startDate +
167
-                ", endDate=" + endDate +
168
-                ", status='" + status + '\'' +
169
-                ", created=" + created +
170
-                ", resource_url='" + resource_url + '\'' +
171
-                ", category=" + category +
172
-                ", subcategory=" + subcategory +
173
-//                ", venue=" + venue +
174
-                '}';
175
-    }
176 161
 }

+ 1
- 7
src/main/java/com/proximity/demo/eventbriteApi/Events/EventController.java View File

@@ -1,17 +1,11 @@
1 1
 package com.proximity.demo.eventbriteApi.Events;
2 2
 
3
-
4
-import com.proximity.demo.eventbriteApi.Categories.CategoryRepository;
5
-import com.proximity.demo.eventbriteApi.Subcategories.SubcategoryRepository;
6
-import com.proximity.demo.eventbriteApi.Venues.VenueRepository;
7 3
 import org.springframework.beans.factory.annotation.Autowired;
8 4
 import org.springframework.web.bind.annotation.CrossOrigin;
9 5
 import org.springframework.web.bind.annotation.GetMapping;
10 6
 import org.springframework.web.bind.annotation.PathVariable;
11 7
 import org.springframework.web.bind.annotation.RestController;
12 8
 
13
-import java.util.ArrayList;
14
-import java.util.Collections;
15 9
 import java.util.List;
16 10
 
17 11
 @RestController
@@ -51,7 +45,7 @@ public class EventController {
51 45
 //        event.setCategory(categoryRepository.findById(event.getCategory_id()).orElse(null));
52 46
 //        event.setSubcategory(subcategoryRepository.findById(event.getSubcategory_id()).orElse(null));
53 47
 //        return event;
54
-//    }
48
+//    }x`
55 49
 
56 50
     @GetMapping("/events/{categoryId}")
57 51
     public List<Event> getEventByCategory(@PathVariable long category_id) {

+ 27
- 0
src/main/java/com/proximity/demo/eventbriteApi/Venues/VenueController.java View File

@@ -1,13 +1,18 @@
1 1
 package com.proximity.demo.eventbriteApi.Venues;
2 2
 
3 3
 import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.format.annotation.DateTimeFormat;
4 5
 import org.springframework.scheduling.annotation.Async;
5 6
 import org.springframework.web.bind.annotation.CrossOrigin;
6 7
 import org.springframework.web.bind.annotation.GetMapping;
7 8
 import org.springframework.web.bind.annotation.PathVariable;
8 9
 import org.springframework.web.bind.annotation.RestController;
9 10
 
11
+import java.time.LocalDate;
12
+import java.time.LocalDateTime;
13
+import java.time.format.DateTimeFormatter;
10 14
 import java.util.List;
15
+import java.util.Locale;
11 16
 import java.util.Optional;
12 17
 
13 18
 @RestController
@@ -31,6 +36,28 @@ public class VenueController {
31 36
 //        return venueService.getVenue();
32 37
 //    }
33 38
 
39
+//    @GetMapping("/venue/category/{category_id}/{start_date}")
40
+//    public List<Venue> getVenues(
41
+//            @PathVariable(value="category_id") long category_id,
42
+//            @PathVariable(value="start_date") String start_date) {
43
+//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.US);
44
+//        LocalDate dateTime = LocalDate.parse(start_date, formatter);
45
+//
46
+//        return venueRepository.findByCategory(category_id, dateTime);
47
+//    }
48
+    @GetMapping("/venue/category/{category_id}/{input_start_date}")
49
+    public List<Venue> getVenues(
50
+        @PathVariable(value="category_id") long category_id,
51
+        @PathVariable(value="input_start_date") String input_start_date) {
52
+    return venueRepository.findByCategory(category_id, input_start_date);
53
+}
54
+
55
+    @GetMapping("/venue/category/{category_id}")
56
+    public List<Venue> getVenues2(
57
+            @PathVariable(value="category_id") long category_id) {
58
+        return venueRepository.findByCategoryId(category_id);
59
+    }
60
+
34 61
     @GetMapping("/venue")
35 62
     public List<Venue> getVenue() {
36 63
         return venueRepository.findAll();

+ 12
- 25
src/main/java/com/proximity/demo/eventbriteApi/Venues/VenueRepository.java View File

@@ -2,39 +2,26 @@ package com.proximity.demo.eventbriteApi.Venues;
2 2
 
3 3
 import com.proximity.demo.eventbriteApi.Events.Event;
4 4
 import org.springframework.data.jpa.repository.JpaRepository;
5
+import org.springframework.data.jpa.repository.Query;
5 6
 import org.springframework.stereotype.Repository;
6 7
 
8
+import java.time.LocalDate;
9
+import java.time.LocalDateTime;
7 10
 import java.util.List;
8 11
 
9 12
 @Repository
10 13
 public interface VenueRepository extends JpaRepository<Venue, Long> {
11 14
 
15
+    Venue findByName(String name);
12 16
 
13
-//    Venue findVenueByEvent(List<Event> Event);
17
+//    @Query("select v from Venue v join v.event as e where e.category_id = ?1 AND CAST(start_date as date) = DATE_FORMAT('%Y-%m-%d')")
18
+//    List<Venue> findByCategory(long category_id, LocalDate start_Date);
14 19
 
15
-    Venue findByName(String name);
20
+//    @Query("select v from Venue v join v.event as e where e.category_id = ?1 AND input_start_date = DATE_FORMAT(e.start_date, '%Y-%m-%d')")
21
+    @Query("select v from Venue v join v.event as e where e.category_id = ?1 AND DATE_FORMAT(e.start_date, '%Y-%m-%d') = ?2")
22
+    List<Venue> findByCategory(long category_id, String input_start_date);
23
+
24
+    @Query("select v from Venue v join v.event as e where e.category_id =?1")
25
+    List<Venue> findByCategoryId(long category_id);
16 26
 
17
-//    List<Venue> findVenuesByEvent(List<Event> event);
18
-//
19
-//    String findByName(long id);
20
-//
21
-//    String findByAddress1(long id);
22
-//
23
-//    String findByAddress2(long id);
24
-//
25
-//    String findVenueCity(long id);
26
-//
27
-//    String findVenuePostalCode(long id);
28
-//
29
-//    String findVenueLat(long id);
30
-//
31
-//    String findVenuelng(long id);
32
-//
33
-//    String findVenueLocalized(long id);
34
-//
35
-//    String findVenueURL(long id);
36
-//
37
-//    int findVenueAgeRestriction(long id);
38
-//
39
-//    int findVenueCapacity(long id);
40 27
 }