ソースを参照

updated commit

Joshua Chung 6 年 前
コミット
1c59790eca

+ 23
- 3
pom.xml ファイルの表示

@@ -21,6 +21,7 @@
21 21
     <properties>
22 22
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23 23
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
+        <org.mapstruct.version>1.2.0.Final</org.mapstruct.version>
24 25
         <java.version>1.8</java.version>
25 26
     </properties>
26 27
 
@@ -98,7 +99,11 @@
98 99
             <artifactId>json</artifactId>
99 100
             <version>20180130</version>
100 101
         </dependency>
101
-
102
+        <dependency>
103
+            <groupId>org.mapstruct</groupId>
104
+            <artifactId>mapstruct</artifactId>
105
+            <version>${org.mapstruct.version}</version>
106
+        </dependency>
102 107
     </dependencies>
103 108
 
104 109
     <build>
@@ -107,8 +112,23 @@
107 112
                 <groupId>org.springframework.boot</groupId>
108 113
                 <artifactId>spring-boot-maven-plugin</artifactId>
109 114
             </plugin>
115
+            <plugin>
116
+                <groupId>org.apache.maven.plugins</groupId>
117
+                <artifactId>maven-compiler-plugin</artifactId>
118
+                <version>3.5.1</version>
119
+                <configuration>
120
+                    <source>8</source> <!-- or higher, depending on your project -->
121
+                    <target>8</target> <!-- or higher, depending on your project -->
122
+                    <annotationProcessorPaths>
123
+                        <path>
124
+                            <groupId>org.mapstruct</groupId>
125
+                            <artifactId>mapstruct-processor</artifactId>
126
+                            <version>${org.mapstruct.version}</version>
127
+                        </path>
128
+                    </annotationProcessorPaths>
129
+                </configuration>
130
+            </plugin>
131
+
110 132
         </plugins>
111 133
     </build>
112
-
113
-
114 134
 </project>

+ 6
- 18
src/main/java/com/proximity/demo/eventbriteApi/Categories/Category.java ファイルの表示

@@ -14,11 +14,8 @@ import java.util.Set;
14 14
 public class Category {
15 15
 
16 16
     @Id
17
-    @GeneratedValue(strategy = GenerationType.AUTO)
18
-    private int categoryid;
19
-
20
-    @Column(unique = true)
21
-    private int id;
17
+    @Column(unique = true, nullable = false)
18
+    private long id;
22 19
     private String name;
23 20
     private String short_name;
24 21
 
@@ -27,10 +24,10 @@ public class Category {
27 24
     @ManyToMany(mappedBy = "category", fetch = FetchType.EAGER)
28 25
     private Set<Event> events = new HashSet<>();
29 26
 
30
-    @OneToMany(mappedBy = "subToCategory", fetch = FetchType.EAGER)
27
+    @OneToMany(mappedBy = "parent_id", fetch = FetchType.EAGER)
31 28
     private Set<Subcategory> subcategories = new HashSet<>();
32 29
 
33
-    public Category(int id, String name, String short_name, Set<Event> events, Set<Subcategory> subcategories) {
30
+    public Category(long id, String name, String short_name, Set<Event> events, Set<Subcategory> subcategories) {
34 31
         this.id = id;
35 32
         this.name = name;
36 33
         this.short_name = short_name;
@@ -38,19 +35,11 @@ public class Category {
38 35
         this.subcategories = subcategories;
39 36
     }
40 37
 
41
-    public int getCategoryid() {
42
-        return categoryid;
43
-    }
44
-
45
-    public void setCategoryid(int categoryid) {
46
-        this.categoryid = categoryid;
47
-    }
48
-
49
-    public int getId() {
38
+    public long getId() {
50 39
         return id;
51 40
     }
52 41
 
53
-    public void setId(int id) {
42
+    public void setId(long id) {
54 43
         this.id = id;
55 44
     }
56 45
 
@@ -89,7 +78,6 @@ public class Category {
89 78
     @Override
90 79
     public String toString() {
91 80
         return "Category{" +
92
-                "categoryid=" + categoryid +
93 81
                 ", id=" + id +
94 82
                 ", name='" + name + '\'' +
95 83
                 ", short_name='" + short_name + '\'' +

+ 6
- 0
src/main/java/com/proximity/demo/eventbriteApi/Categories/CategoryController.java ファイルの表示

@@ -3,6 +3,7 @@ package com.proximity.demo.eventbriteApi.Categories;
3 3
 import org.springframework.beans.factory.annotation.Autowired;
4 4
 import org.springframework.web.bind.annotation.CrossOrigin;
5 5
 import org.springframework.web.bind.annotation.GetMapping;
6
+import org.springframework.web.bind.annotation.PathVariable;
6 7
 import org.springframework.web.bind.annotation.RestController;
7 8
 
8 9
 import java.util.List;
@@ -22,4 +23,9 @@ public class CategoryController {
22 23
         categoryService.getCategories();
23 24
         return categoryRepository.findAll();
24 25
     }
26
+//
27
+//    @GetMapping("/categories/{id}")
28
+//    public Category find(@PathVariable long id){
29
+//        return categoryRepository.findById(id).get();
30
+//    }
25 31
 }

+ 6
- 1
src/main/java/com/proximity/demo/eventbriteApi/Categories/CategoryRepository.java ファイルの表示

@@ -1,10 +1,15 @@
1 1
 package com.proximity.demo.eventbriteApi.Categories;
2 2
 
3
-import com.proximity.demo.eventbriteApi.Subcategories.Subcategory;
3
+import com.proximity.demo.eventbriteApi.Events.Event;
4 4
 import org.springframework.data.jpa.repository.JpaRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+import java.util.List;
8
+
7 9
 @Repository
8 10
 public interface CategoryRepository extends JpaRepository<Category, Long> {
9 11
 
12
+//    Category findCategoryByEvent(List<Event> event);
13
+
14
+//    String findCategory(Long id);
10 15
 }

+ 34
- 4
src/main/java/com/proximity/demo/eventbriteApi/Events/Event.java ファイルの表示

@@ -20,9 +20,6 @@ import java.util.Set;
20 20
 public class Event {
21 21
 
22 22
     @Id
23
-    @GeneratedValue(strategy = GenerationType.AUTO)
24
-    private long eventId;
25
-
26 23
     private long id;
27 24
     @Column(unique = true)
28 25
     private String eventName;
@@ -38,11 +35,20 @@ public class Event {
38 35
     private String resource_url;
39 36
     private String logo;
40 37
 
38
+    @Transient
39
+    private Category oneCategory;
40
+
41
+    @Transient
42
+    private Subcategory oneSubcategory;
43
+
44
+    @Transient
45
+    private Venue oneVenue;
46
+
41 47
     public Event() { }
42 48
 
43 49
     public Event(String eventName, String eventDescription, long category_id, long subcategory_id, long venue_id,
44 50
                  LocalDateTime startDate, LocalDateTime endDate, String status, Date created, String resource_url,
45
-                 String logo, Set<Venue> venue) {
51
+                 String logo) {
46 52
         this.eventName = eventName;
47 53
         this.eventDescription = eventDescription;
48 54
         this.category_id = category_id;
@@ -157,6 +163,30 @@ public class Event {
157 163
 
158 164
     public void setCategory(Set<Category> category) { this.category = category; }
159 165
 
166
+    public Category getOneCategory() {
167
+        return oneCategory;
168
+    }
169
+
170
+    public void setOneCategory(Category oneCategory) {
171
+        this.oneCategory = oneCategory;
172
+    }
173
+
174
+    public Subcategory getOneSubcategory() {
175
+        return oneSubcategory;
176
+    }
177
+
178
+    public void setOneSubcategory(Subcategory oneSubcategory) {
179
+        this.oneSubcategory = oneSubcategory;
180
+    }
181
+
182
+    public Venue getOneVenue() {
183
+        return oneVenue;
184
+    }
185
+
186
+    public void setOneVenue(Venue oneVenue) {
187
+        this.oneVenue = oneVenue;
188
+    }
189
+
160 190
     @Override
161 191
     public String toString() {
162 192
         return "Event{" +

+ 26
- 0
src/main/java/com/proximity/demo/eventbriteApi/Events/EventController.java ファイルの表示

@@ -1,13 +1,21 @@
1 1
 package com.proximity.demo.eventbriteApi.Events;
2 2
 
3 3
 
4
+import com.proximity.demo.eventbriteApi.Categories.CategoryRepository;
5
+import com.proximity.demo.eventbriteApi.Subcategories.Subcategory;
6
+import com.proximity.demo.eventbriteApi.Subcategories.SubcategoryRepository;
7
+import com.proximity.demo.eventbriteApi.Venues.Venue;
8
+import com.proximity.demo.eventbriteApi.Venues.VenueRepository;
4 9
 import com.proximity.demo.eventbriteApi.Venues.VenueService;
5 10
 import org.springframework.beans.factory.annotation.Autowired;
6 11
 import org.springframework.web.bind.annotation.CrossOrigin;
7 12
 import org.springframework.web.bind.annotation.GetMapping;
13
+import org.springframework.web.bind.annotation.PathVariable;
8 14
 import org.springframework.web.bind.annotation.RestController;
9 15
 
16
+import java.util.ArrayList;
10 17
 import java.util.List;
18
+import java.util.stream.Collectors;
11 19
 
12 20
 @RestController
13 21
 @CrossOrigin
@@ -19,9 +27,27 @@ public class EventController {
19 27
     @Autowired
20 28
     private EventRepository repository;
21 29
 
30
+    @Autowired
31
+    private VenueRepository venueRepository;
32
+
33
+    @Autowired
34
+    private CategoryRepository categoryRepository;
35
+
36
+    @Autowired
37
+    private SubcategoryRepository subcategoryRepository;
38
+
22 39
     @GetMapping("/events")
23 40
     public List<Event> getAll(){
24 41
         eventService.getEventsInPhilly();
25 42
         return repository.findAll();
26 43
     }
44
+
45
+    @GetMapping("/events/{id}")
46
+    public Event getEvent(@PathVariable long id) {
47
+        Event event = repository.findById(id).get();
48
+        event.setOneVenue(venueRepository.findById(event.getVenue_id()).orElse(null));
49
+        event.setOneCategory(categoryRepository.findById(event.getCategory_id()).orElse(null));
50
+        event.setOneSubcategory(subcategoryRepository.findById(event.getSubcategory_id()).orElse(null));
51
+        return event;
52
+    }
27 53
 }

+ 67
- 0
src/main/java/com/proximity/demo/eventbriteApi/Marker/MarkerDTO.java ファイルの表示

@@ -0,0 +1,67 @@
1
+package com.proximity.demo.eventbriteApi.Marker;
2
+
3
+import com.proximity.demo.eventbriteApi.Categories.Category;
4
+import com.proximity.demo.eventbriteApi.Categories.CategoryRepository;
5
+import com.proximity.demo.eventbriteApi.Events.Event;
6
+import com.proximity.demo.eventbriteApi.Events.EventRepository;
7
+import com.proximity.demo.eventbriteApi.Subcategories.Subcategory;
8
+import com.proximity.demo.eventbriteApi.Subcategories.SubcategoryRepository;
9
+import com.proximity.demo.eventbriteApi.Venues.Venue;
10
+import com.proximity.demo.eventbriteApi.Venues.VenueRepository;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+
13
+import javax.persistence.Entity;
14
+import java.time.LocalDate;
15
+import java.time.LocalDateTime;
16
+import java.util.Collection;
17
+import java.util.Collections;
18
+import java.util.List;
19
+
20
+
21
+//@Entity
22
+public class MarkerDTO {
23
+
24
+    @Autowired
25
+    EventRepository er;
26
+
27
+    @Autowired
28
+    VenueRepository vr;
29
+
30
+    @Autowired
31
+    CategoryRepository cr;
32
+
33
+    @Autowired
34
+    SubcategoryRepository sr;
35
+
36
+    private Event event;
37
+    private Venue venue;
38
+    private Category category;
39
+    private Subcategory subcategory;
40
+
41
+    public MarkerDTO(Event event, Venue venue, Category category, Subcategory subcategory) {
42
+        this.event = event;
43
+        this.venue = venue;
44
+        this.category = category;
45
+        this.subcategory = subcategory;
46
+    }
47
+
48
+    public Event getEvent() { return event; }
49
+
50
+//    public void setEvent(Event event) { this.event = er.findAll(); }
51
+
52
+    public Venue getVenue() { return venue; }
53
+
54
+    public void setVenue(Venue venue) { this.venue = vr.findVenueByEvent(Collections.singletonList(getEvent())); }
55
+
56
+    public Category getCategory() { return category; }
57
+
58
+    public void setCategory(Category category) { this.category = null;
59
+//            cr.findCategoryByEvent(Collections.singletonList(getEvent()));
60
+ }
61
+
62
+    public Subcategory getSubcategory() { return subcategory; }
63
+
64
+    public void setSubcategory(Subcategory subcategory) { this.subcategory = sr.findSubcategoryByEvent(Collections.singletonList(getEvent())); }
65
+}
66
+
67
+

+ 8
- 28
src/main/java/com/proximity/demo/eventbriteApi/Subcategories/Subcategory.java ファイルの表示

@@ -17,22 +17,19 @@ import java.util.Set;
17 17
 public class Subcategory {
18 18
 
19 19
     @Id
20
-    @GeneratedValue(strategy = GenerationType.AUTO)
21
-    private int subcategoryid;
22
-
23 20
     @Column(unique = true)
24
-    private int id;
21
+    private long id;
25 22
     private String name;
26 23
     private int parent_id;
27 24
 
28 25
     public Subcategory() {}
29 26
 
30
-    public Subcategory(int id, String name, int parent_id, Category subToCategory, Set<Event> event) {
27
+    public Subcategory(long id, String name, int parent_id, Set<Event> event) {
31 28
         this.id = id;
32 29
         this.name = name;
33 30
         this.parent_id = parent_id;
34
-        this.subToCategory = subToCategory;
35 31
         this.event = event;
32
+//        this.category = category;
36 33
     }
37 34
 
38 35
     @JsonProperty("parent_category")
@@ -40,27 +37,19 @@ public class Subcategory {
40 37
         this.parent_id = Integer.valueOf((String)parent_category.get("id"));
41 38
     }
42 39
 
43
-    @ManyToOne(fetch = FetchType.EAGER)
44
-    @JoinColumn(name = "category_id")
45
-    @JsonIgnore
46
-    private Category subToCategory;
40
+//    @ManyToOne(fetch = FetchType.EAGER)
41
+//    @JoinColumn(name = "parent_id")
42
+//    private Category category;
47 43
 
48 44
     @ManyToMany(mappedBy = "subcategory")
49 45
     private Set<Event> event = new HashSet<>();
50 46
 
51
-    public int getSubcategoryid() {
52
-        return subcategoryid;
53
-    }
54
-
55
-    public void setSubcategoryid(int subcategoryid) {
56
-        this.subcategoryid = subcategoryid;
57
-    }
58 47
 
59
-    public int getId() {
48
+    public long getId() {
60 49
         return id;
61 50
     }
62 51
 
63
-    public void setId(int id) {
52
+    public void setId(long id) {
64 53
         this.id = id;
65 54
     }
66 55
 
@@ -80,13 +69,6 @@ public class Subcategory {
80 69
         this.parent_id = parent_id;
81 70
     }
82 71
 
83
-    public Category getSubToCategory() {
84
-        return subToCategory;
85
-    }
86
-
87
-    public void setSubToCategory(Category subToCategory) {
88
-        this.subToCategory = subToCategory;
89
-    }
90 72
 
91 73
     public Set<Event> getEvent() {
92 74
         return event;
@@ -99,11 +81,9 @@ public class Subcategory {
99 81
     @Override
100 82
     public String toString() {
101 83
         return "Subcategory{" +
102
-                "subcategoryid=" + subcategoryid +
103 84
                 ", id=" + id +
104 85
                 ", name='" + name + '\'' +
105 86
                 ", parent_id=" + parent_id +
106
-                ", subToCategory=" + subToCategory +
107 87
                 ", event=" + event +
108 88
                 '}';
109 89
     }

+ 5
- 1
src/main/java/com/proximity/demo/eventbriteApi/Subcategories/SubcategoryRepository.java ファイルの表示

@@ -4,8 +4,12 @@ import com.proximity.demo.eventbriteApi.Events.Event;
4 4
 import org.springframework.data.jpa.repository.JpaRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+import java.util.List;
8
+
7 9
 @Repository
8 10
 public interface SubcategoryRepository extends JpaRepository<Subcategory, Long> {
9 11
 
10
-    Subcategory findSubcategoryByEvent(Event event);
12
+    Subcategory findSubcategoryByEvent(List<Event> event);
13
+
14
+//    String findSubcategory(long eventID);
11 15
 }

+ 0
- 3
src/main/java/com/proximity/demo/eventbriteApi/Venues/Venue.java ファイルの表示

@@ -16,9 +16,6 @@ import java.util.Set;
16 16
 public class Venue implements Serializable {
17 17
 
18 18
     @Id
19
-    @GeneratedValue(strategy = GenerationType.AUTO)
20
-    private Long venueid;
21
-
22 19
     @Column(unique = true)
23 20
     private long id;
24 21
     private String name;

+ 27
- 1
src/main/java/com/proximity/demo/eventbriteApi/Venues/VenueRepository.java ファイルの表示

@@ -4,10 +4,36 @@ import com.proximity.demo.eventbriteApi.Events.Event;
4 4
 import org.springframework.data.jpa.repository.JpaRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+import java.util.List;
8
+
7 9
 @Repository
8 10
 public interface VenueRepository extends JpaRepository<Venue, Long> {
9 11
 
10
-    Venue findVenueByEvent(Event Event);
12
+    Venue findVenueByEvent(List<Event> Event);
11 13
 
12 14
     Venue findByName(String name);
15
+
16
+//    List<Venue> findVenuesByEvent(List<Event> event);
17
+//
18
+//    String findByName(long id);
19
+//
20
+//    String findByAddress1(long id);
21
+//
22
+//    String findByAddress2(long id);
23
+//
24
+//    String findVenueCity(long id);
25
+//
26
+//    String findVenuePostalCode(long id);
27
+//
28
+//    String findVenueLat(long id);
29
+//
30
+//    String findVenuelng(long id);
31
+//
32
+//    String findVenueLocalized(long id);
33
+//
34
+//    String findVenueURL(long id);
35
+//
36
+//    int findVenueAgeRestriction(long id);
37
+//
38
+//    int findVenueCapacity(long id);
13 39
 }