Selaa lähdekoodia

updated commit

Joshua Chung 6 vuotta sitten
vanhempi
commit
8c21eae1d4

+ 11
- 11
src/main/java/com/proximity/demo/eventbriteApi/Categories/Category.java Näytä tiedosto

21
 
21
 
22
     public Category() { }
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
     @OneToMany(mappedBy = "parent_id", fetch = FetchType.EAGER)
27
     @OneToMany(mappedBy = "parent_id", fetch = FetchType.EAGER)
28
     private Set<Subcategory> subcategories = new HashSet<>();
28
     private Set<Subcategory> subcategories = new HashSet<>();
31
         this.id = id;
31
         this.id = id;
32
         this.name = name;
32
         this.name = name;
33
         this.short_name = short_name;
33
         this.short_name = short_name;
34
-        this.events = events;
34
+//        this.events = events;
35
         this.subcategories = subcategories;
35
         this.subcategories = subcategories;
36
     }
36
     }
37
 
37
 
59
         this.short_name = short_name;
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
     public Set<Subcategory> getSubcategories() {
70
     public Set<Subcategory> getSubcategories() {
71
         return subcategories;
71
         return subcategories;
81
                 ", id=" + id +
81
                 ", id=" + id +
82
                 ", name='" + name + '\'' +
82
                 ", name='" + name + '\'' +
83
                 ", short_name='" + short_name + '\'' +
83
                 ", short_name='" + short_name + '\'' +
84
-                ", events=" + events +
84
+//                ", events=" + events +
85
                 ", subcategories=" + subcategories +
85
                 ", subcategories=" + subcategories +
86
                 '}';
86
                 '}';
87
     }
87
     }

+ 23
- 36
src/main/java/com/proximity/demo/eventbriteApi/Events/Event.java Näytä tiedosto

35
 //    private String logo;
35
 //    private String logo;
36
 
36
 
37
 
37
 
38
-    @JsonBackReference
39
     @ManyToOne
38
     @ManyToOne
40
     @JoinColumn(name = "category_id", insertable = false, updatable = false)
39
     @JoinColumn(name = "category_id", insertable = false, updatable = false)
41
-    @Nullable
42
     private Category category;
40
     private Category category;
43
 
41
 
44
-    @JsonBackReference
45
     @ManyToOne
42
     @ManyToOne
46
     @JoinColumn(name = "subcategory_id", insertable = false, updatable = false)
43
     @JoinColumn(name = "subcategory_id", insertable = false, updatable = false)
47
-    @Nullable
48
     private Subcategory subcategory;
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
     public Event() { }
51
     public Event() { }
57
 
52
 
69
         this.created = created;
64
         this.created = created;
70
         this.resource_url = resource_url;
65
         this.resource_url = resource_url;
71
 //        this.logo = logo;
66
 //        this.logo = logo;
72
-        this.venue = venue;
67
+//        this.venue = venue;
73
     }
68
     }
74
 
69
 
75
     @JsonProperty("name")
70
     @JsonProperty("name")
91
     private void unpackEnd(Map<String, Object> end) {
86
     private void unpackEnd(Map<String, Object> end) {
92
         this.endDate =  LocalDateTime.parse((String) end.get("local"));
87
         this.endDate =  LocalDateTime.parse((String) end.get("local"));
93
     }
88
     }
94
-
89
+//
95
 //    @JsonProperty("logo")
90
 //    @JsonProperty("logo")
96
 //    private void unpackLogo(Map<String, Object> logo) {
91
 //    private void unpackLogo(Map<String, Object> logo) {
97
 //        this.logo = (String) logo.get("url");
92
 //        this.logo = (String) logo.get("url");
98
 //    }
93
 //    }
99
 
94
 
100
-
101
-
102
     public long getId() { return id; }
95
     public long getId() { return id; }
103
 
96
 
104
     public void setId(long id) { this.id = id; }
97
     public void setId(long id) { this.id = id; }
111
 
104
 
112
     public void setEventDescription(String eventDescription) { this.eventDescription = eventDescription; }
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
     public long getVenue_id() { return venue_id; }
117
     public long getVenue_id() { return venue_id; }
123
 
118
 
143
 
138
 
144
     public void setResource_url(String resource_url) { this.resource_url = resource_url; }
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
     @Override
157
     @Override
171
     public String toString() {
158
     public String toString() {
183
                 ", resource_url='" + resource_url + '\'' +
170
                 ", resource_url='" + resource_url + '\'' +
184
                 ", category=" + category +
171
                 ", category=" + category +
185
                 ", subcategory=" + subcategory +
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 Näytä tiedosto

24
     @Autowired
24
     @Autowired
25
     private EventRepository repository;
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
     @GetMapping("/events")
27
     @GetMapping("/events")
37
     public Event getAll(){
28
     public Event getAll(){
38
         return eventService.getPhillyEvents();
29
         return eventService.getPhillyEvents();
43
         return repository.findAll();
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
     @GetMapping("/events/{categoryId}")
56
     @GetMapping("/events/{categoryId}")
56
     public List<Event> getEventByCategory(@PathVariable long category_id) {
57
     public List<Event> getEventByCategory(@PathVariable long category_id) {
57
         return null;
58
         return null;

+ 3
- 3
src/main/java/com/proximity/demo/eventbriteApi/Events/EventRepository.java Näytä tiedosto

1
 package com.proximity.demo.eventbriteApi.Events;
1
 package com.proximity.demo.eventbriteApi.Events;
2
 
2
 
3
 import org.springframework.data.jpa.repository.JpaRepository;
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
 import org.springframework.stereotype.Repository;
6
 import org.springframework.stereotype.Repository;
5
 
7
 
6
 import java.util.List;
8
 import java.util.List;
8
 
10
 
9
 @Repository
11
 @Repository
10
 public interface EventRepository extends JpaRepository<Event, Long> {
12
 public interface EventRepository extends JpaRepository<Event, Long> {
11
-
12
     Event findByEventName(String name);
13
     Event findByEventName(String name);
13
-
14
     List<Event> findByCategory_Id(Long categoryId);
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 Näytä tiedosto

22
     private String name;
22
     private String name;
23
     private int parent_id;
23
     private int parent_id;
24
 
24
 
25
+//    @OneToMany(mappedBy = "subcategory_id")
26
+//    private Set<Event> event = new HashSet<>();
27
+
28
+
25
     public Subcategory() {}
29
     public Subcategory() {}
26
 
30
 
27
     public Subcategory(long id, String name, int parent_id, Set<Event> event) {
31
     public Subcategory(long id, String name, int parent_id, Set<Event> event) {
28
         this.id = id;
32
         this.id = id;
29
         this.name = name;
33
         this.name = name;
30
         this.parent_id = parent_id;
34
         this.parent_id = parent_id;
31
-        this.event = event;
35
+//        this.event = event;
32
 //        this.category = category;
36
 //        this.category = category;
33
     }
37
     }
34
 
38
 
37
         this.parent_id = Integer.valueOf((String)parent_category.get("id"));
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
     public long getId() {
50
     public long getId() {
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
     @Override
83
     @Override
78
     public String toString() {
84
     public String toString() {
80
                 ", id=" + id +
86
                 ", id=" + id +
81
                 ", name='" + name + '\'' +
87
                 ", name='" + name + '\'' +
82
                 ", parent_id=" + parent_id +
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 Näytä tiedosto

9
 @Repository
9
 @Repository
10
 public interface SubcategoryRepository extends JpaRepository<Subcategory, Long> {
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
 //    String findSubcategory(long eventID);
14
 //    String findSubcategory(long eventID);
15
 }
15
 }

+ 7
- 4
src/main/java/com/proximity/demo/eventbriteApi/Subcategories/SubcategoryService.java Näytä tiedosto

26
     }
26
     }
27
 
27
 
28
     public Subcategory getSubcategories() {
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
         return null;
36
         return null;
34
     }
37
     }
35
 
38
 

+ 3
- 3
src/main/java/com/proximity/demo/eventbriteApi/Venues/Venue.java Näytä tiedosto

35
     private int age_restriction;
35
     private int age_restriction;
36
     private int capacity;
36
     private int capacity;
37
 
37
 
38
+    @OneToMany(mappedBy = "venue_id", fetch = FetchType.EAGER)
39
+    private Set<Event> event = new HashSet<>();
40
+
38
     public Venue() {
41
     public Venue() {
39
 
42
 
40
     }
43
     }
70
         this.country = (String) address.get("country");
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
     public Long getId() { return id; }
76
     public Long getId() { return id; }
77
 
77
 
78
     public void setId(Long id) { this.id = id; }
78
     public void setId(Long id) { this.id = id; }

+ 9
- 4
src/main/java/com/proximity/demo/eventbriteApi/Venues/VenueController.java Näytä tiedosto

20
     @Autowired
20
     @Autowired
21
     private VenueRepository venueRepository;
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
     @GetMapping("/venue")
34
     @GetMapping("/venue")
30
     public List<Venue> getVenue() {
35
     public List<Venue> getVenue() {

+ 24
- 3
src/main/java/com/proximity/demo/eventbriteApi/Venues/VenueService.java Näytä tiedosto

27
         this.venueRepository = venueRepository;
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
     @Async
38
     @Async
31
     public Venue getEventVenue(){
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
             String url = "https://www.eventbriteapi.com/v3/venues/"
43
             String url = "https://www.eventbriteapi.com/v3/venues/"
36
                     + venue_id
44
                     + venue_id
37
                     + "?token=" + token;
45
                     + "?token=" + token;
41
         return null;
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
     private Venue save(Venue venue) { return this.venueRepository.save(venue); }
65
     private Venue save(Venue venue) { return this.venueRepository.save(venue); }
45
 
66
 
46
     public Venue find(String name) { return this.venueRepository.findByName(venue.getName()); }
67
     public Venue find(String name) { return this.venueRepository.findByName(venue.getName()); }

+ 1
- 0
src/main/resources/application.properties Näytä tiedosto

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