Browse Source

updated commit

Joshua Chung 6 years ago
parent
commit
8c21eae1d4

+ 11
- 11
src/main/java/com/proximity/demo/eventbriteApi/Categories/Category.java View File

@@ -21,8 +21,8 @@ public class Category {
21 21
 
22 22
     public Category() { }
23 23
 
24
-    @OneToMany(mappedBy = "category_id", fetch = FetchType.EAGER)
25
-    private Set<Event> events = new HashSet<>();
24
+//    @OneToMany(mappedBy = "category_id", fetch = FetchType.EAGER)
25
+//    private Set<Event> events = new HashSet<>();
26 26
 
27 27
     @OneToMany(mappedBy = "parent_id", fetch = FetchType.EAGER)
28 28
     private Set<Subcategory> subcategories = new HashSet<>();
@@ -31,7 +31,7 @@ public class Category {
31 31
         this.id = id;
32 32
         this.name = name;
33 33
         this.short_name = short_name;
34
-        this.events = events;
34
+//        this.events = events;
35 35
         this.subcategories = subcategories;
36 36
     }
37 37
 
@@ -59,13 +59,13 @@ public class Category {
59 59
         this.short_name = short_name;
60 60
     }
61 61
 
62
-    public Set<Event> getEvents() {
63
-        return events;
64
-    }
65
-
66
-    public void setEvents(Set<Event> events) {
67
-        this.events = events;
68
-    }
62
+//    public Set<Event> getEvents() {
63
+//        return events;
64
+//    }
65
+//
66
+//    public void setEvents(Set<Event> events) {
67
+//        this.events = events;
68
+//    }
69 69
 
70 70
     public Set<Subcategory> getSubcategories() {
71 71
         return subcategories;
@@ -81,7 +81,7 @@ public class Category {
81 81
                 ", id=" + id +
82 82
                 ", name='" + name + '\'' +
83 83
                 ", short_name='" + short_name + '\'' +
84
-                ", events=" + events +
84
+//                ", events=" + events +
85 85
                 ", subcategories=" + subcategories +
86 86
                 '}';
87 87
     }

+ 23
- 36
src/main/java/com/proximity/demo/eventbriteApi/Events/Event.java View File

@@ -35,23 +35,18 @@ public class Event {
35 35
 //    private String logo;
36 36
 
37 37
 
38
-    @JsonBackReference
39 38
     @ManyToOne
40 39
     @JoinColumn(name = "category_id", insertable = false, updatable = false)
41
-    @Nullable
42 40
     private Category category;
43 41
 
44
-    @JsonBackReference
45 42
     @ManyToOne
46 43
     @JoinColumn(name = "subcategory_id", insertable = false, updatable = false)
47
-    @Nullable
48 44
     private Subcategory subcategory;
49 45
 
50
-    @JsonBackReference
51
-    @ManyToOne
52
-    @JoinColumn(name = "venue_id", insertable = false, updatable = false)
53
-    @Nullable
54
-    private Venue venue;
46
+//    @ManyToOne
47
+//    @JsonBackReference
48
+//    @JoinColumn(name = "venue_id", insertable = false, updatable = false)
49
+//    private Venue venue;
55 50
 
56 51
     public Event() { }
57 52
 
@@ -69,7 +64,7 @@ public class Event {
69 64
         this.created = created;
70 65
         this.resource_url = resource_url;
71 66
 //        this.logo = logo;
72
-        this.venue = venue;
67
+//        this.venue = venue;
73 68
     }
74 69
 
75 70
     @JsonProperty("name")
@@ -91,14 +86,12 @@ public class Event {
91 86
     private void unpackEnd(Map<String, Object> end) {
92 87
         this.endDate =  LocalDateTime.parse((String) end.get("local"));
93 88
     }
94
-
89
+//
95 90
 //    @JsonProperty("logo")
96 91
 //    private void unpackLogo(Map<String, Object> logo) {
97 92
 //        this.logo = (String) logo.get("url");
98 93
 //    }
99 94
 
100
-
101
-
102 95
     public long getId() { return id; }
103 96
 
104 97
     public void setId(long id) { this.id = id; }
@@ -111,13 +104,15 @@ public class Event {
111 104
 
112 105
     public void setEventDescription(String eventDescription) { this.eventDescription = eventDescription; }
113 106
 
114
-    public long getCategory_id() { return category_id; }
107
+    public Long getCategory_id() { return category_id; }
108
+
109
+    public void setCategory_id(Long category_id) { this.category_id = category_id; }
115 110
 
116
-    public void setCategory_id(long category_id) { this.category_id = category_id; }
111
+    public Long getSubcategory_id() { return subcategory_id; }
117 112
 
118
-    public long getSubcategory_id() { return subcategory_id; }
113
+    public void setSubcategory_id(Long subcategory_id) { this.subcategory_id = subcategory_id; }
119 114
 
120
-    public void setSubcategory_id(long subcategory_id) { this.subcategory_id = subcategory_id; }
115
+    public void setVenue_id(Long venue_id) { this.venue_id = venue_id; }
121 116
 
122 117
     public long getVenue_id() { return venue_id; }
123 118
 
@@ -143,29 +138,21 @@ public class Event {
143 138
 
144 139
     public void setResource_url(String resource_url) { this.resource_url = resource_url; }
145 140
 
146
-    public Category getCategory() {
147
-        return category;
148
-    }
141
+//    public String getLogo() { return logo; }
142
+//
143
+//    public void setLogo(String logo) { this.logo = logo; }
149 144
 
150
-    public void setCategory(Category category) {
151
-        this.category = category;
152
-    }
145
+    public Category getCategory() { return category; }
153 146
 
154
-    public Subcategory getSubcategory() {
155
-        return subcategory;
156
-    }
147
+    public void setCategory(Category category) { this.category = category; }
157 148
 
158
-    public void setSubcategory(Subcategory subcategory) {
159
-        this.subcategory = subcategory;
160
-    }
149
+    public Subcategory getSubcategory() { return subcategory; }
161 150
 
162
-    public Venue getVenue() {
163
-        return venue;
164
-    }
151
+    public void setSubcategory(Subcategory subcategory) { this.subcategory = subcategory; }
165 152
 
166
-    public void setVenue(Venue venue) {
167
-        this.venue = venue;
168
-    }
153
+//    public Venue getVenue() { return venue; }
154
+//
155
+//    public void setVenue(Venue venue) { this.venue = venue; }
169 156
 
170 157
     @Override
171 158
     public String toString() {
@@ -183,7 +170,7 @@ public class Event {
183 170
                 ", resource_url='" + resource_url + '\'' +
184 171
                 ", category=" + category +
185 172
                 ", subcategory=" + subcategory +
186
-                ", venue=" + venue +
173
+//                ", venue=" + venue +
187 174
                 '}';
188 175
     }
189 176
 }

+ 17
- 16
src/main/java/com/proximity/demo/eventbriteApi/Events/EventController.java View File

@@ -24,15 +24,6 @@ public class EventController {
24 24
     @Autowired
25 25
     private EventRepository repository;
26 26
 
27
-    @Autowired
28
-    private VenueRepository venueRepository;
29
-
30
-    @Autowired
31
-    private CategoryRepository categoryRepository;
32
-
33
-    @Autowired
34
-    private SubcategoryRepository subcategoryRepository;
35
-
36 27
     @GetMapping("/events")
37 28
     public Event getAll(){
38 29
         return eventService.getPhillyEvents();
@@ -43,15 +34,25 @@ public class EventController {
43 34
         return repository.findAll();
44 35
     }
45 36
 
46
-    @GetMapping("/events/{id}")
47
-    public Event getEvent(@PathVariable long id) {
48
-        Event event = repository.findById(id).get();
49
-        event.setVenue(venueRepository.findById(event.getVenue_id()).orElse(null));
50
-        event.setCategory(categoryRepository.findById(event.getCategory_id()).orElse(null));
51
-        event.setSubcategory(subcategoryRepository.findById(event.getSubcategory_id()).orElse(null));
52
-        return event;
37
+    @GetMapping("event/category/{categoryId}")
38
+    public List<Event> getEventByCategory(@PathVariable Long categoryId) {
39
+        return repository.findByCategory_Id(categoryId);
40
+    }
41
+
42
+    @GetMapping("event/subcategory/{subcategoryId}")
43
+    public List<Event> getEventBySubcategory(@PathVariable Long subcategoryId) {
44
+        return repository.findBySubcategory_Id(subcategoryId);
53 45
     }
54 46
 
47
+//    @GetMapping("/events/{id}")
48
+//    public Event getEvent(@PathVariable long id) {
49
+//        Event event = repository.findById(id).get();
50
+//        event.setVenue(venueRepository.findById(event.getVenue_id()).orElse(null));
51
+//        event.setCategory(categoryRepository.findById(event.getCategory_id()).orElse(null));
52
+//        event.setSubcategory(subcategoryRepository.findById(event.getSubcategory_id()).orElse(null));
53
+//        return event;
54
+//    }
55
+
55 56
     @GetMapping("/events/{categoryId}")
56 57
     public List<Event> getEventByCategory(@PathVariable long category_id) {
57 58
         return null;

+ 3
- 3
src/main/java/com/proximity/demo/eventbriteApi/Events/EventRepository.java View File

@@ -1,6 +1,8 @@
1 1
 package com.proximity.demo.eventbriteApi.Events;
2 2
 
3 3
 import org.springframework.data.jpa.repository.JpaRepository;
4
+import org.springframework.data.jpa.repository.Query;
5
+import org.springframework.data.repository.query.Param;
4 6
 import org.springframework.stereotype.Repository;
5 7
 
6 8
 import java.util.List;
@@ -8,9 +10,7 @@ import java.util.List;
8 10
 
9 11
 @Repository
10 12
 public interface EventRepository extends JpaRepository<Event, Long> {
11
-
12 13
     Event findByEventName(String name);
13
-
14 14
     List<Event> findByCategory_Id(Long categoryId);
15
-
15
+    List<Event> findBySubcategory_Id(Long subcategoryId);
16 16
 }

+ 17
- 11
src/main/java/com/proximity/demo/eventbriteApi/Subcategories/Subcategory.java View File

@@ -22,13 +22,17 @@ public class Subcategory {
22 22
     private String name;
23 23
     private int parent_id;
24 24
 
25
+//    @OneToMany(mappedBy = "subcategory_id")
26
+//    private Set<Event> event = new HashSet<>();
27
+
28
+
25 29
     public Subcategory() {}
26 30
 
27 31
     public Subcategory(long id, String name, int parent_id, Set<Event> event) {
28 32
         this.id = id;
29 33
         this.name = name;
30 34
         this.parent_id = parent_id;
31
-        this.event = event;
35
+//        this.event = event;
32 36
 //        this.category = category;
33 37
     }
34 38
 
@@ -37,8 +41,10 @@ public class Subcategory {
37 41
         this.parent_id = Integer.valueOf((String)parent_category.get("id"));
38 42
     }
39 43
 
40
-    @OneToMany(mappedBy = "subcategory_id")
41
-    private Set<Event> event = new HashSet<>();
44
+//    @ManyToOne(fetch = FetchType.EAGER)
45
+//    @JoinColumn(name = "parent_id")
46
+//    private Category category;
47
+
42 48
 
43 49
 
44 50
     public long getId() {
@@ -66,13 +72,13 @@ public class Subcategory {
66 72
     }
67 73
 
68 74
 
69
-    public Set<Event> getEvent() {
70
-        return event;
71
-    }
72
-
73
-    public void setEvent(Set<Event> event) {
74
-        this.event = event;
75
-    }
75
+//    public Set<Event> getEvent() {
76
+//        return event;
77
+//    }
78
+//
79
+//    public void setEvent(Set<Event> event) {
80
+//        this.event = event;
81
+//    }
76 82
 
77 83
     @Override
78 84
     public String toString() {
@@ -80,7 +86,7 @@ public class Subcategory {
80 86
                 ", id=" + id +
81 87
                 ", name='" + name + '\'' +
82 88
                 ", parent_id=" + parent_id +
83
-                ", event=" + event +
89
+//                ", event=" + event +
84 90
                 '}';
85 91
     }
86 92
 }

+ 1
- 1
src/main/java/com/proximity/demo/eventbriteApi/Subcategories/SubcategoryRepository.java View File

@@ -9,7 +9,7 @@ import java.util.List;
9 9
 @Repository
10 10
 public interface SubcategoryRepository extends JpaRepository<Subcategory, Long> {
11 11
 
12
-    Subcategory findSubcategoryByEvent(List<Event> event);
12
+//    Subcategory findSubcategoryByEvent(List<Event> event);
13 13
 
14 14
 //    String findSubcategory(long eventID);
15 15
 }

+ 7
- 4
src/main/java/com/proximity/demo/eventbriteApi/Subcategories/SubcategoryService.java View File

@@ -26,10 +26,13 @@ public class SubcategoryService {
26 26
     }
27 27
 
28 28
     public Subcategory getSubcategories() {
29
-        String url = "http://www.eventbriteapi.com/v3/subcategories?"
30
-                + "token=" + token;
31
-        SubcategoryWrapper wrapper = restTemplate.getForObject(url, SubcategoryWrapper.class);
32
-        subcategoryRepository.saveAll(wrapper.getSubcategories());
29
+        for(int i = 0; i <= 4; i++) {
30
+            String url = "http://www.eventbriteapi.com/v3/subcategories?"
31
+                    + "token=" + token
32
+                    + "&page=" + i;
33
+            SubcategoryWrapper wrapper = restTemplate.getForObject(url, SubcategoryWrapper.class);
34
+            subcategoryRepository.saveAll(wrapper.getSubcategories());
35
+        }
33 36
         return null;
34 37
     }
35 38
 

+ 3
- 3
src/main/java/com/proximity/demo/eventbriteApi/Venues/Venue.java View File

@@ -35,6 +35,9 @@ public class Venue implements Serializable {
35 35
     private int age_restriction;
36 36
     private int capacity;
37 37
 
38
+    @OneToMany(mappedBy = "venue_id", fetch = FetchType.EAGER)
39
+    private Set<Event> event = new HashSet<>();
40
+
38 41
     public Venue() {
39 42
 
40 43
     }
@@ -70,9 +73,6 @@ public class Venue implements Serializable {
70 73
         this.country = (String) address.get("country");
71 74
     }
72 75
 
73
-    @OneToMany(mappedBy = "venue_id", fetch = FetchType.EAGER)
74
-    private Set<Event> event = new HashSet<>();
75
-
76 76
     public Long getId() { return id; }
77 77
 
78 78
     public void setId(Long id) { this.id = id; }

+ 9
- 4
src/main/java/com/proximity/demo/eventbriteApi/Venues/VenueController.java View File

@@ -20,11 +20,16 @@ public class VenueController {
20 20
     @Autowired
21 21
     private VenueRepository venueRepository;
22 22
 
23
-    @Async
24
-    @GetMapping("/venues")
25
-    public Venue getAll() {
26
-        return venueService.getEventVenue();
23
+    @GetMapping("/v")
24
+    public Venue get() {
25
+        return venueService.getEventV();
27 26
     }
27
+//
28
+//    @Async
29
+//    @GetMapping("/venues")
30
+//    public Venue getAll() {
31
+//        return venueService.getVenue();
32
+//    }
28 33
 
29 34
     @GetMapping("/venue")
30 35
     public List<Venue> getVenue() {

+ 24
- 3
src/main/java/com/proximity/demo/eventbriteApi/Venues/VenueService.java View File

@@ -27,11 +27,19 @@ public class VenueService {
27 27
         this.venueRepository = venueRepository;
28 28
     }
29 29
 
30
+    public Venue getEventV() {
31
+        String url = "https://www.eventbriteapi.com/v3/venues/15846940"
32
+                + "?token=" + token;
33
+        Venue venue = restTemplate.getForObject(url, Venue.class);
34
+        venueRepository.save(venue);
35
+        return null;
36
+    }
37
+
30 38
     @Async
31 39
     public Venue getEventVenue(){
32
-        List<Event> events = new ArrayList<>(eventRepository.findAll());
33
-        for(int i = 0; i < events.size(); i++) {
34
-            Long venue_id = events.get(i).getVenue_id();
40
+        List<Event> events = eventRepository.findAll();
41
+        for(Event event : events) {
42
+            Long venue_id = event.getVenue_id();
35 43
             String url = "https://www.eventbriteapi.com/v3/venues/"
36 44
                     + venue_id
37 45
                     + "?token=" + token;
@@ -41,6 +49,19 @@ public class VenueService {
41 49
         return null;
42 50
     }
43 51
 
52
+//    public Venue getVenue(){
53
+//    List<Event> events = eventRepository.findAll();
54
+//    for(int i = 1475; i < events.size(); i++) {
55
+//        Long venue_id = events.get(i).getVenue_id();
56
+//        String url = "https://www.eventbriteapi.com/v3/venues/"
57
+//                + venue_id
58
+//                + "?token=" + token;
59
+//        Venue venue = restTemplate.getForObject(url, Venue.class);
60
+//        venueRepository.save(venue);
61
+//        }
62
+//        return null;
63
+//    }
64
+
44 65
     private Venue save(Venue venue) { return this.venueRepository.save(venue); }
45 66
 
46 67
     public Venue find(String name) { return this.venueRepository.findByName(venue.getName()); }

+ 1
- 0
src/main/resources/application.properties View File

@@ -4,4 +4,5 @@ spring.datasource.password=molonlabe27
4 4
 spring.jpa.show-sql=true
5 5
 jdbcCompliantTruncation=false&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8
6 6
 spring.jpa.hibernate.ddl-auto=update
7
+#logging.level.org.springframework.web=DEBUG
7 8