Bläddra i källkod

updated commit

Joshua Chung 6 år sedan
förälder
incheckning
1c59790eca

+ 23
- 3
pom.xml Visa fil

21
     <properties>
21
     <properties>
22
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
+        <org.mapstruct.version>1.2.0.Final</org.mapstruct.version>
24
         <java.version>1.8</java.version>
25
         <java.version>1.8</java.version>
25
     </properties>
26
     </properties>
26
 
27
 
98
             <artifactId>json</artifactId>
99
             <artifactId>json</artifactId>
99
             <version>20180130</version>
100
             <version>20180130</version>
100
         </dependency>
101
         </dependency>
101
-
102
+        <dependency>
103
+            <groupId>org.mapstruct</groupId>
104
+            <artifactId>mapstruct</artifactId>
105
+            <version>${org.mapstruct.version}</version>
106
+        </dependency>
102
     </dependencies>
107
     </dependencies>
103
 
108
 
104
     <build>
109
     <build>
107
                 <groupId>org.springframework.boot</groupId>
112
                 <groupId>org.springframework.boot</groupId>
108
                 <artifactId>spring-boot-maven-plugin</artifactId>
113
                 <artifactId>spring-boot-maven-plugin</artifactId>
109
             </plugin>
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
         </plugins>
132
         </plugins>
111
     </build>
133
     </build>
112
-
113
-
114
 </project>
134
 </project>

+ 6
- 18
src/main/java/com/proximity/demo/eventbriteApi/Categories/Category.java Visa fil

14
 public class Category {
14
 public class Category {
15
 
15
 
16
     @Id
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
     private String name;
19
     private String name;
23
     private String short_name;
20
     private String short_name;
24
 
21
 
27
     @ManyToMany(mappedBy = "category", fetch = FetchType.EAGER)
24
     @ManyToMany(mappedBy = "category", fetch = FetchType.EAGER)
28
     private Set<Event> events = new HashSet<>();
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
     private Set<Subcategory> subcategories = new HashSet<>();
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
         this.id = id;
31
         this.id = id;
35
         this.name = name;
32
         this.name = name;
36
         this.short_name = short_name;
33
         this.short_name = short_name;
38
         this.subcategories = subcategories;
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
         return id;
39
         return id;
51
     }
40
     }
52
 
41
 
53
-    public void setId(int id) {
42
+    public void setId(long id) {
54
         this.id = id;
43
         this.id = id;
55
     }
44
     }
56
 
45
 
89
     @Override
78
     @Override
90
     public String toString() {
79
     public String toString() {
91
         return "Category{" +
80
         return "Category{" +
92
-                "categoryid=" + categoryid +
93
                 ", id=" + id +
81
                 ", id=" + id +
94
                 ", name='" + name + '\'' +
82
                 ", name='" + name + '\'' +
95
                 ", short_name='" + short_name + '\'' +
83
                 ", short_name='" + short_name + '\'' +

+ 6
- 0
src/main/java/com/proximity/demo/eventbriteApi/Categories/CategoryController.java Visa fil

3
 import org.springframework.beans.factory.annotation.Autowired;
3
 import org.springframework.beans.factory.annotation.Autowired;
4
 import org.springframework.web.bind.annotation.CrossOrigin;
4
 import org.springframework.web.bind.annotation.CrossOrigin;
5
 import org.springframework.web.bind.annotation.GetMapping;
5
 import org.springframework.web.bind.annotation.GetMapping;
6
+import org.springframework.web.bind.annotation.PathVariable;
6
 import org.springframework.web.bind.annotation.RestController;
7
 import org.springframework.web.bind.annotation.RestController;
7
 
8
 
8
 import java.util.List;
9
 import java.util.List;
22
         categoryService.getCategories();
23
         categoryService.getCategories();
23
         return categoryRepository.findAll();
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 Visa fil

1
 package com.proximity.demo.eventbriteApi.Categories;
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
 import org.springframework.data.jpa.repository.JpaRepository;
4
 import org.springframework.data.jpa.repository.JpaRepository;
5
 import org.springframework.stereotype.Repository;
5
 import org.springframework.stereotype.Repository;
6
 
6
 
7
+import java.util.List;
8
+
7
 @Repository
9
 @Repository
8
 public interface CategoryRepository extends JpaRepository<Category, Long> {
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 Visa fil

20
 public class Event {
20
 public class Event {
21
 
21
 
22
     @Id
22
     @Id
23
-    @GeneratedValue(strategy = GenerationType.AUTO)
24
-    private long eventId;
25
-
26
     private long id;
23
     private long id;
27
     @Column(unique = true)
24
     @Column(unique = true)
28
     private String eventName;
25
     private String eventName;
38
     private String resource_url;
35
     private String resource_url;
39
     private String logo;
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
     public Event() { }
47
     public Event() { }
42
 
48
 
43
     public Event(String eventName, String eventDescription, long category_id, long subcategory_id, long venue_id,
49
     public Event(String eventName, String eventDescription, long category_id, long subcategory_id, long venue_id,
44
                  LocalDateTime startDate, LocalDateTime endDate, String status, Date created, String resource_url,
50
                  LocalDateTime startDate, LocalDateTime endDate, String status, Date created, String resource_url,
45
-                 String logo, Set<Venue> venue) {
51
+                 String logo) {
46
         this.eventName = eventName;
52
         this.eventName = eventName;
47
         this.eventDescription = eventDescription;
53
         this.eventDescription = eventDescription;
48
         this.category_id = category_id;
54
         this.category_id = category_id;
157
 
163
 
158
     public void setCategory(Set<Category> category) { this.category = category; }
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
     @Override
190
     @Override
161
     public String toString() {
191
     public String toString() {
162
         return "Event{" +
192
         return "Event{" +

+ 26
- 0
src/main/java/com/proximity/demo/eventbriteApi/Events/EventController.java Visa fil

1
 package com.proximity.demo.eventbriteApi.Events;
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
 import com.proximity.demo.eventbriteApi.Venues.VenueService;
9
 import com.proximity.demo.eventbriteApi.Venues.VenueService;
5
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.web.bind.annotation.CrossOrigin;
11
 import org.springframework.web.bind.annotation.CrossOrigin;
7
 import org.springframework.web.bind.annotation.GetMapping;
12
 import org.springframework.web.bind.annotation.GetMapping;
13
+import org.springframework.web.bind.annotation.PathVariable;
8
 import org.springframework.web.bind.annotation.RestController;
14
 import org.springframework.web.bind.annotation.RestController;
9
 
15
 
16
+import java.util.ArrayList;
10
 import java.util.List;
17
 import java.util.List;
18
+import java.util.stream.Collectors;
11
 
19
 
12
 @RestController
20
 @RestController
13
 @CrossOrigin
21
 @CrossOrigin
19
     @Autowired
27
     @Autowired
20
     private EventRepository repository;
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
     @GetMapping("/events")
39
     @GetMapping("/events")
23
     public List<Event> getAll(){
40
     public List<Event> getAll(){
24
         eventService.getEventsInPhilly();
41
         eventService.getEventsInPhilly();
25
         return repository.findAll();
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 Visa fil

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 Visa fil

17
 public class Subcategory {
17
 public class Subcategory {
18
 
18
 
19
     @Id
19
     @Id
20
-    @GeneratedValue(strategy = GenerationType.AUTO)
21
-    private int subcategoryid;
22
-
23
     @Column(unique = true)
20
     @Column(unique = true)
24
-    private int id;
21
+    private long id;
25
     private String name;
22
     private String name;
26
     private int parent_id;
23
     private int parent_id;
27
 
24
 
28
     public Subcategory() {}
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
         this.id = id;
28
         this.id = id;
32
         this.name = name;
29
         this.name = name;
33
         this.parent_id = parent_id;
30
         this.parent_id = parent_id;
34
-        this.subToCategory = subToCategory;
35
         this.event = event;
31
         this.event = event;
32
+//        this.category = category;
36
     }
33
     }
37
 
34
 
38
     @JsonProperty("parent_category")
35
     @JsonProperty("parent_category")
40
         this.parent_id = Integer.valueOf((String)parent_category.get("id"));
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
     @ManyToMany(mappedBy = "subcategory")
44
     @ManyToMany(mappedBy = "subcategory")
49
     private Set<Event> event = new HashSet<>();
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
         return id;
49
         return id;
61
     }
50
     }
62
 
51
 
63
-    public void setId(int id) {
52
+    public void setId(long id) {
64
         this.id = id;
53
         this.id = id;
65
     }
54
     }
66
 
55
 
80
         this.parent_id = parent_id;
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
     public Set<Event> getEvent() {
73
     public Set<Event> getEvent() {
92
         return event;
74
         return event;
99
     @Override
81
     @Override
100
     public String toString() {
82
     public String toString() {
101
         return "Subcategory{" +
83
         return "Subcategory{" +
102
-                "subcategoryid=" + subcategoryid +
103
                 ", id=" + id +
84
                 ", id=" + id +
104
                 ", name='" + name + '\'' +
85
                 ", name='" + name + '\'' +
105
                 ", parent_id=" + parent_id +
86
                 ", parent_id=" + parent_id +
106
-                ", subToCategory=" + subToCategory +
107
                 ", event=" + event +
87
                 ", event=" + event +
108
                 '}';
88
                 '}';
109
     }
89
     }

+ 5
- 1
src/main/java/com/proximity/demo/eventbriteApi/Subcategories/SubcategoryRepository.java Visa fil

4
 import org.springframework.data.jpa.repository.JpaRepository;
4
 import org.springframework.data.jpa.repository.JpaRepository;
5
 import org.springframework.stereotype.Repository;
5
 import org.springframework.stereotype.Repository;
6
 
6
 
7
+import java.util.List;
8
+
7
 @Repository
9
 @Repository
8
 public interface SubcategoryRepository extends JpaRepository<Subcategory, Long> {
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 Visa fil

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

+ 27
- 1
src/main/java/com/proximity/demo/eventbriteApi/Venues/VenueRepository.java Visa fil

4
 import org.springframework.data.jpa.repository.JpaRepository;
4
 import org.springframework.data.jpa.repository.JpaRepository;
5
 import org.springframework.stereotype.Repository;
5
 import org.springframework.stereotype.Repository;
6
 
6
 
7
+import java.util.List;
8
+
7
 @Repository
9
 @Repository
8
 public interface VenueRepository extends JpaRepository<Venue, Long> {
10
 public interface VenueRepository extends JpaRepository<Venue, Long> {
9
 
11
 
10
-    Venue findVenueByEvent(Event Event);
12
+    Venue findVenueByEvent(List<Event> Event);
11
 
13
 
12
     Venue findByName(String name);
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
 }