diff --git a/.gitignore b/.gitignore index 0a8a77f..60a5d17 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # Log file *.log +*.iml # BlueJ files *.ctxt diff --git a/README.md b/README.md index 2f7a896..ac39593 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,18 @@ -# SocialServiceFinder -My first commit +## SocialServiceFinder + +### [Video Link](https://www.youtube.com/watch?v=DoI5_Ww7daA) + +### Abstract + +There are many people who would like to do community services, but don’t know the places that offer the opportunity for the same. Our project aims to provide a platform not only to people who seek non-profit organizations for any opportunities where they can contribute, but also to encourage more people by rewarding them for doing good deeds. We also plan on helping the organizations that are looking for volunteers to help them. + +We are planning to create a web platform that creates and manages volunteering opportunities (posted by social service organizations). Users can search for an opportunity based on various criterias like location, type of service required, type of organizations listing the opportunities, etc. For motivating the users, rewards from various partner companies will be offered to those who volunteer in these events. We are planning to implement a microservice based architecture using SOLID principles, and create a complete system with a reactive frontend, scalable backend software and a NOSQL database. For internal communication within the services, we will be using Messaging channels between them. We are focusing on microservice based architecture because we want to create a robust, maintainable and a highly scalable system in a way that makes it easy to add more features in the future, supporting Agile methodology. We are also planning to cover the features using functional tests. + +### Setup + +#### Pre-reqs: +1. Java +2. Angular Cli +3. MongoDb +4. Git -#CORS Filter (Change the port number accordingly) -@Bean -public CorsFilter corsFilter() { -CorsConfiguration corsConfiguration = new CorsConfiguration(); -corsConfiguration.setAllowCredentials(true); -corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:4202")); -corsConfiguration.setAllowedHeaders(Arrays.asList("Origin", "Access-Control-Allow-Origin", "Content-Type", -"Accept", "Authorization", "Origin, Accept", "X-Requested-With", -"Access-Control-Request-Method", "Access-Control-Request-Headers")); -corsConfiguration.setExposedHeaders(Arrays.asList("Origin", "Content-Type", "Accept", "Authorization", -"Access-Control-Allow-Origin", "Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")); -corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS")); -UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); -urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); -return new CorsFilter(urlBasedCorsConfigurationSource); -} \ No newline at end of file diff --git a/eventservice/pom.xml b/eventservice/pom.xml new file mode 100644 index 0000000..a228434 --- /dev/null +++ b/eventservice/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.6.2 + + + com.socialservicefinder + eventservice + 0.0.1-SNAPSHOT + eventservice + Event Service Folder for Social Service Finder Project + + 11 + + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.data + spring-data-mongodb + + + junit + junit + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/eventservice/src/main/java/com/socialservicefinder/eventservice/EventServiceApplication.java b/eventservice/src/main/java/com/socialservicefinder/eventservice/EventServiceApplication.java new file mode 100644 index 0000000..5695628 --- /dev/null +++ b/eventservice/src/main/java/com/socialservicefinder/eventservice/EventServiceApplication.java @@ -0,0 +1,33 @@ +package com.socialservicefinder.eventservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +import java.util.Arrays; + +@SpringBootApplication +public class EventServiceApplication { + public static void main(String[] args) { + SpringApplication.run(EventServiceApplication.class, args); + } + //CORS is some mechanism added by mordern browswers. just copy pasting. More Info: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS + @Bean + public CorsFilter corsFilter() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.setAllowCredentials(true); + corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:4200")); + corsConfiguration.setAllowedHeaders(Arrays.asList("Origin", "Access-Control-Allow-Origin", "Content-Type", + "Accept", "Authorization", "Origin, Accept", "X-Requested-With", + "Access-Control-Request-Method", "Access-Control-Request-Headers")); + corsConfiguration.setExposedHeaders(Arrays.asList("Origin", "Content-Type", "Accept", "Authorization", + "Access-Control-Allow-Origin", "Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")); + corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS")); + UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); + urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); + return new CorsFilter(urlBasedCorsConfigurationSource); + } +} diff --git a/eventservice/src/main/java/com/socialservicefinder/eventservice/controller/EventController.java b/eventservice/src/main/java/com/socialservicefinder/eventservice/controller/EventController.java new file mode 100644 index 0000000..840a98f --- /dev/null +++ b/eventservice/src/main/java/com/socialservicefinder/eventservice/controller/EventController.java @@ -0,0 +1,54 @@ +package com.socialservicefinder.eventservice.controller; + +import com.socialservicefinder.eventservice.dto.Event; +import com.socialservicefinder.eventservice.dto.SearchQuery; +import com.socialservicefinder.eventservice.exceptions.InvalidEventException; +import com.socialservicefinder.eventservice.service.EventService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Collections; +import java.util.List; + +@RestController +@RequestMapping(path = "api/v1/event") +public class EventController { + private final EventService eventService; + + @Autowired + public EventController(EventService eventService) { + this.eventService = eventService; + } + + @GetMapping + public List getEvents() { + return eventService.getEvents(); + } + + @PostMapping + public ResponseEntity addEvent(@RequestBody Event event) { + try { + eventService.addEvent(event); + return ResponseEntity.status(HttpStatus.OK).body(null); + } catch (InvalidEventException e) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + } + + @GetMapping + @RequestMapping("/search/") + public List getMatchingEvents(@RequestBody SearchQuery q) { + try { + List events = eventService.getMatchingEvents(q.getQuery()); + System.out.println(q.getQuery()); + return events; + } catch (Exception e) { + return Collections.emptyList(); + } + } + +} diff --git a/eventservice/src/main/java/com/socialservicefinder/eventservice/dto/Event.java b/eventservice/src/main/java/com/socialservicefinder/eventservice/dto/Event.java new file mode 100644 index 0000000..d74e97f --- /dev/null +++ b/eventservice/src/main/java/com/socialservicefinder/eventservice/dto/Event.java @@ -0,0 +1,128 @@ +package com.socialservicefinder.eventservice.dto; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.UUID; + +@Document("events") +public class Event { + @Id + private String id; + private String name; + private String description; + private String phoneNo; + private String address; + private String city; + private long rewards; + private long pinCode; + private String email; + private String POCName; + + @Override + public String toString() { + return "Event [name=" + name + ", description=" + description + ", phoneNo=" + phoneNo + ", email="+email+", POCName"+ POCName + + ", address=" + address + ", city=" + city + ", rewards=" + rewards + ", pinCode=" + + pinCode + "]"; + } + + public Event() { + super(); + } + + public Event(String name, String description, String phoneNo, String address, String city, long rewards, long pinCode, String email, String POCName) { + this.name = name; + this.description = description; + this.phoneNo = phoneNo; + this.address = address; + this.city = city; + this.rewards = rewards; + this.pinCode = pinCode; + this.email = email; + this.POCName = POCName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPOCName() { + return POCName; + } + + public void setPOCName(String POCName) { + this.POCName = POCName; + } + + public void assign_id() { + this.id = UUID.randomUUID().toString(); + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getPhoneNo() { + return phoneNo; + } + + public void setPhoneNo(String phoneNo) { + this.phoneNo = phoneNo; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public long getRewards() { + return rewards; + } + + public void setRewards(long rewards) { + this.rewards = rewards; + } + + public long getPinCode() { + return pinCode; + } + + public void setPinCode(long pinCode) { + this.pinCode = pinCode; + } +} diff --git a/eventservice/src/main/java/com/socialservicefinder/eventservice/dto/SearchQuery.java b/eventservice/src/main/java/com/socialservicefinder/eventservice/dto/SearchQuery.java new file mode 100644 index 0000000..a651e2f --- /dev/null +++ b/eventservice/src/main/java/com/socialservicefinder/eventservice/dto/SearchQuery.java @@ -0,0 +1,18 @@ +package com.socialservicefinder.eventservice.dto; + +public class SearchQuery { + private String query; + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + @Override + public String toString() { + return "Search Query [query=" + query + "]"; + } +} diff --git a/eventservice/src/main/java/com/socialservicefinder/eventservice/exceptions/InvalidEventException.java b/eventservice/src/main/java/com/socialservicefinder/eventservice/exceptions/InvalidEventException.java new file mode 100644 index 0000000..fdf4390 --- /dev/null +++ b/eventservice/src/main/java/com/socialservicefinder/eventservice/exceptions/InvalidEventException.java @@ -0,0 +1,15 @@ +package com.socialservicefinder.eventservice.exceptions; + +public class InvalidEventException extends RuntimeException { + public InvalidEventException() { + super(); + } + + public InvalidEventException(String errorMessage) { + super(errorMessage); + } + + public InvalidEventException(String errorMessage, Throwable throwable) { + super(errorMessage, throwable); + } +} diff --git a/eventservice/src/main/java/com/socialservicefinder/eventservice/repository/EventRepository.java b/eventservice/src/main/java/com/socialservicefinder/eventservice/repository/EventRepository.java new file mode 100644 index 0000000..956f976 --- /dev/null +++ b/eventservice/src/main/java/com/socialservicefinder/eventservice/repository/EventRepository.java @@ -0,0 +1,10 @@ +package com.socialservicefinder.eventservice.repository; + +import com.socialservicefinder.eventservice.dto.Event; +import org.springframework.data.mongodb.repository.MongoRepository; + +import java.util.List; + +public interface EventRepository extends MongoRepository { + List findEventByNameContains(String name); +} diff --git a/eventservice/src/main/java/com/socialservicefinder/eventservice/service/EventService.java b/eventservice/src/main/java/com/socialservicefinder/eventservice/service/EventService.java new file mode 100644 index 0000000..2cdd3ee --- /dev/null +++ b/eventservice/src/main/java/com/socialservicefinder/eventservice/service/EventService.java @@ -0,0 +1,54 @@ +package com.socialservicefinder.eventservice.service; + +import com.mongodb.MongoWriteException; +import com.socialservicefinder.eventservice.dto.Event; +import com.socialservicefinder.eventservice.exceptions.InvalidEventException; +import com.socialservicefinder.eventservice.repository.EventRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@Component +public class EventService { + private EventRepository eventRepository; + private final int NO_OF_TRIES; + + @Autowired + public EventService(EventRepository eventRepository) { + this.eventRepository = eventRepository; + this.NO_OF_TRIES = 5; + } + + public List getEvents() { + return eventRepository.findAll(); + } + + public List getMatchingEvents(String name) { + return eventRepository.findEventByNameContains(name); + } + + public void addEvent(Event e) { + if (e == null || e.getName() == null || e.getAddress() == null || e.getDescription() == null) { + throw new InvalidEventException("name, address or description cannot be null or empty"); + } + insertEvent(e); + } + + public void insertEvent(Event e) { + boolean id_assigned = false; + for (int tries = 0; tries < NO_OF_TRIES; tries++) { + try { + e.assign_id(); + eventRepository.insert(e); + id_assigned = true; + break; + } catch (MongoWriteException ignored) { + } + } + if (!id_assigned) + throw new InvalidEventException("Please try after sometime."); + } +} diff --git a/eventservice/src/main/resources/application.properties b/eventservice/src/main/resources/application.properties new file mode 100644 index 0000000..2091b08 --- /dev/null +++ b/eventservice/src/main/resources/application.properties @@ -0,0 +1,5 @@ +server.port=8091 +spring.data.mongodb.url=mongodb://localhost:27017/socialservicefinder +spring.data.mongodb.database=socialservicefinder +spring.data.mongodb.port=27017 +spring.data.mongodb.host=localhost \ No newline at end of file diff --git a/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationIntegrationTests.java b/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationIntegrationTests.java new file mode 100644 index 0000000..026ade2 --- /dev/null +++ b/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationIntegrationTests.java @@ -0,0 +1,66 @@ +package com.socialservicefinder.eventservice; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.socialservicefinder.eventservice.dto.Event; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; + +@SpringBootTest +@AutoConfigureMockMvc +public class EventServiceApplicationIntegrationTests { + @Autowired + private MockMvc mockMvc; + + @Test + public void shouldReturnDefaultMessage() throws Exception { + this.mockMvc.perform(get("/api/v1/event")).andExpect(status().isOk()); + } + + @Test + public void post_endpoint_should_return_ok() throws Exception { + Event event = new Event("Covid Campaign", "Campaign to raise covid awareness", "9499926608", "3901 Parkview Ln, Apt 8A", "Irvine", 10000, 92612, "abc@gmail.com", "Covid"); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(event); + this.mockMvc.perform( + post("/api/v1/event").contentType(MediaType.APPLICATION_JSON).content(json).characterEncoding("utf-8")) + .andExpect(status().isOk()); + } + + @Test + public void post_endpoint_null_name_should_return_badRequest() throws Exception { + Event event = new Event(null, "Campaign to raise covid awareness", "9499926608", "3901 Parkview Ln, Apt 8A", "Irvine", 10000, 92612, "abc@gmail.com", "Covid"); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(event); + this.mockMvc.perform( + post("/api/v1/event").contentType(MediaType.APPLICATION_JSON).content(json).characterEncoding("utf-8")) + .andExpect(status().isBadRequest()); + } + + @Test + public void post_endpoint_null_description_should_return_badRequest() throws Exception { + Event event = new Event("Covid Campaign", null, "9499926608", "3901 Parkview Ln, Apt 8A", "Irvine", 10000, 92612, "abc@gmail.com", "Covid"); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(event); + this.mockMvc.perform( + post("/api/v1/event").contentType(MediaType.APPLICATION_JSON).content(json).characterEncoding("utf-8")) + .andExpect(status().isBadRequest()); + } + + @Test + public void post_endpoint_null_address_should_return_badRequest() throws Exception { + Event event = new Event("Covid Campaign", "Campaign to raise covid awareness", "9499926608", null, "Irvine", 10000, 92612, "abc@gmail.com", "Covid"); + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(event); + this.mockMvc.perform( + post("/api/v1/event").contentType(MediaType.APPLICATION_JSON).content(json).characterEncoding("utf-8")) + .andExpect(status().isBadRequest()); + } +} \ No newline at end of file diff --git a/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationTestConfiguration.java b/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationTestConfiguration.java new file mode 100644 index 0000000..ba17b3b --- /dev/null +++ b/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationTestConfiguration.java @@ -0,0 +1,18 @@ +package com.socialservicefinder.eventservice; + +import com.socialservicefinder.eventservice.service.EventService; +import org.mockito.Mockito; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; + +@Profile("test") +@Configuration +public class EventServiceApplicationTestConfiguration { + @Bean + @Primary + public EventService nameService() { + return Mockito.mock(EventService.class); + } +} diff --git a/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationTests.java b/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationTests.java new file mode 100644 index 0000000..36871b2 --- /dev/null +++ b/eventservice/src/test/java/com/socialservicefinder/eventservice/EventServiceApplicationTests.java @@ -0,0 +1,47 @@ +package com.socialservicefinder.eventservice; + +import com.socialservicefinder.eventservice.dto.Event; +import com.socialservicefinder.eventservice.service.EventService; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +@ActiveProfiles("test") +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {EventServiceApplication.class}) +class EventServiceApplicationTests { + private static List _events; + @Autowired + private EventService eventService; + + @BeforeEach + public void init() { + _events = List.of( + new Event("Covid Campaign", "Campaign to raise covid awareness", "9499926608", "3901 Parkview Ln, Apt 8A", "Irvine", 10000, 92612, "abc@gmail.com", "Covid"), + new Event("Covid Campaign - I", "Campaign I to raise covid awareness", "9499926608", "3901 Parkview Ln, Apt 8A", "Irvine", 50000, 92612, "abc@gmail.com", "Covid"), + new Event("Covid Campaign - II", "Campaign II to raise covid awareness", "9499926609", "3901 Parkview Ln, Apt 8A", "Irvine", 5000, 92613, "abc@gmail.com", "Covid"), + new Event("Covid Campaign - III", "Campaign III to raise covid awareness", "9499926610", "3901 Parkview Ln, Apt 8A", "Irvine", 45000, 92614, "abc@gmail.com", "Covid")); + } + + @Test + public void getEvents() { + Mockito.when(eventService.getEvents()).thenReturn(_events); + List events = eventService.getEvents(); + Assertions.assertEquals(events, _events); + } + + @Test + public void getMatchingEvents() { + Mockito.when(eventService.getMatchingEvents(Mockito.anyString())).thenReturn(_events); + List events = eventService.getMatchingEvents("Covid"); + Assertions.assertEquals(events, _events); + } +} \ No newline at end of file diff --git a/organizationservice/src/main/java/com/socialservicefinder/organizationservice/OrganizationserviceApplication.java b/organizationservice/src/main/java/com/socialservicefinder/organizationservice/OrganizationserviceApplication.java index f14d327..5dc8771 100644 --- a/organizationservice/src/main/java/com/socialservicefinder/organizationservice/OrganizationserviceApplication.java +++ b/organizationservice/src/main/java/com/socialservicefinder/organizationservice/OrganizationserviceApplication.java @@ -14,13 +14,12 @@ public class OrganizationserviceApplication { public static void main(String[] args) { SpringApplication.run(OrganizationserviceApplication.class, args); } - //CORS is some mechanism added by mordern browswers. just copy pasting. More Info: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS @Bean public CorsFilter corsFilter() { CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.setAllowCredentials(true); - corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:4202")); + corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:4200")); corsConfiguration.setAllowedHeaders(Arrays.asList("Origin", "Access-Control-Allow-Origin", "Content-Type", "Accept", "Authorization", "Origin, Accept", "X-Requested-With", "Access-Control-Request-Method", "Access-Control-Request-Headers")); diff --git a/organizationservice/src/main/java/com/socialservicefinder/organizationservice/controller/OrganizationController.java b/organizationservice/src/main/java/com/socialservicefinder/organizationservice/controller/OrganizationController.java index a468598..1b21d8b 100644 --- a/organizationservice/src/main/java/com/socialservicefinder/organizationservice/controller/OrganizationController.java +++ b/organizationservice/src/main/java/com/socialservicefinder/organizationservice/controller/OrganizationController.java @@ -29,15 +29,13 @@ public OrganizationController(OrganizationService organizationService) { } @PostMapping("/login") - public ResponseEntity authOrganization(@RequestBody Login login){ - try{ + public ResponseEntity authOrganization(@RequestBody Login login) { + try { var organization = organizationService.getAuthOrganization(login); return ResponseEntity.status(HttpStatus.OK).body(organization); - } - catch (InvalidLoginException e){ - return ResponseEntity.status(HttpStatus .BAD_REQUEST).body(null); - } - catch (Exception e){ + } catch (InvalidLoginException e) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); + } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); } } @@ -54,11 +52,9 @@ public ResponseEntity addOrganization(@RequestBody Organization organiza organizationService.addOrganization(organization); ObjectMapper mapper = new ObjectMapper(); return ResponseEntity.status(HttpStatus.OK).body(mapper.writeValueAsString(organization)); - } - catch (InvalidOrganizationException e) { + } catch (InvalidOrganizationException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); - } - catch (Exception e) { + } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); } } diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9edc412 --- /dev/null +++ b/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + pom + com.socialservicefinder + socialservicefinder + 0.0.1-SNAPSHOT + socialservicefinder + Social Service Finder Project using Spring Boot + + 11 + + + organizationservice + userservice + eventservice + + + diff --git a/socialseriveapp/src/app/dashboard/dashboard.component.css b/socialseriveapp/src/app/dashboard/dashboard.component.css index 605a1bb..96aefbe 100644 --- a/socialseriveapp/src/app/dashboard/dashboard.component.css +++ b/socialseriveapp/src/app/dashboard/dashboard.component.css @@ -10,4 +10,56 @@ mat-expansion-panel{ width: 50%; margin: auto; margin-top: 1rem; +} + +.createEventForm{ + width: 40% !important; +} + +.searchForm { + color: #555; + display: flex; + padding: 2px; + border: 1px solid currentColor; + border-radius: 5px; + } + + .searchBar { + border: none; + background: transparent; + margin: 0; + width: 95%; + padding: 7px 8px; + font-size: 14px; + color: inherit; + border: 1px solid transparent; + border-radius: inherit; + } + + .searchBar::placeholder { + color: #bbb; + } + + .searchButton { + text-indent: -999px; + overflow: hidden; + width: 5%; + padding: 0; + margin: 0; + border: 1px solid transparent; + border-radius: inherit; + background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' class='bi bi-search' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'%3E%3C/path%3E%3C/svg%3E") no-repeat center; + cursor: pointer; + opacity: 0.7; + } + + .searchButton:hover { + opacity: 1; + } + +.searchButton:focus, +.searchBar:focus { + box-shadow: 0 0 3px 0 #1183d6; + border-color: #1183d6; + outline: none; } \ No newline at end of file diff --git a/socialseriveapp/src/app/dashboard/dashboard.component.html b/socialseriveapp/src/app/dashboard/dashboard.component.html index 224e758..aadda89 100644 --- a/socialseriveapp/src/app/dashboard/dashboard.component.html +++ b/socialseriveapp/src/app/dashboard/dashboard.component.html @@ -1,24 +1,9 @@ - - User + {{isUser?"User":"Organization"}} {{isUser?user.name:organisation.name}} @@ -26,9 +11,129 @@

Email: {{isUser?user.email :organisation.email}}

Phone No: {{isUser?user.phoneNo :organisation.phoneNo}}

-

Date of Birth: {{isUser?user.dob :organisation.dob}}

+

Date of Birth: {{isUser?user.dob :organisation.dob}}

Address: {{isUser?user.address :organisation.address}}

Preference: {{user.preferences}}

Organisation Type: {{organisation.organizationType}}

-
\ No newline at end of file + + + + + + + + + + Click on the button to create an event + + + + Create Event +
+ + Event Name + + + + + Event Description + +
+ + + Rewards + + + + + Address + + + + City + + + + Zip Code + + + + Start Date + + + + + + + End Date + + + + Invalid Date + + +
+ Point of Contact (POC) Details: + + Name + + + + Contact + + Should be 10 digits + + + + + Email: + + + + + + +
+
+
+
+ +
+ +
+
+

MY EVENTS

+
+
+ +
+
+ +
+
+
+

SEARCH FOR EVENTS

+
+
+ + +
+
+ + +
+ {{eventResult}} +
+ + \ No newline at end of file diff --git a/socialseriveapp/src/app/dashboard/dashboard.component.ts b/socialseriveapp/src/app/dashboard/dashboard.component.ts index 90e1d45..938fae8 100644 --- a/socialseriveapp/src/app/dashboard/dashboard.component.ts +++ b/socialseriveapp/src/app/dashboard/dashboard.component.ts @@ -1,5 +1,12 @@ import { Component, OnInit } from '@angular/core'; +import { + MatSnackBar, + MatSnackBarHorizontalPosition, + MatSnackBarVerticalPosition, +} from '@angular/material/snack-bar'; +import { Event } from '../users/models/Event'; import { Organiser } from '../users/models/Organiser'; +import { SearchQuery } from '../users/models/SearchQuery'; import { User } from '../users/models/User'; import { DashboardService } from '../users/services/dashboardservice/dashboard.service'; @@ -8,19 +15,95 @@ import { DashboardService } from '../users/services/dashboardservice/dashboard.s templateUrl: './dashboard.component.html', styleUrls: ['./dashboard.component.css'] }) + export class DashboardComponent implements OnInit { user!: User; isUser!: boolean; organisation!: Organiser; panelOpenState = false; - constructor(private dashboardService: DashboardService) { } + createEventObject!: Event; + createEventFormPanelOpenState = false; + eventName: string=""; + eventDescription: string=""; + eventRewards: string=""; + eventLocation: string=""; + eventPOCName: string=""; + eventPOCContact: string=""; + eventPOCEmail: string=""; + eventCity: string=""; + eventZip: string=""; + searchEventsQuery: string=""; + eventResult: string=""; + searchQueryObject!:SearchQuery; + startDate!: Date; + endDate!: Date; + horizontalPosition: MatSnackBarHorizontalPosition = 'center'; + verticalPosition: MatSnackBarVerticalPosition = 'top'; + events!: Event; + constructor(private dashboardService: DashboardService, private _snackBar: MatSnackBar) { } ngOnInit(): void { - this.isUser = this.dashboardService.isUser; + this.isUser = JSON.parse(localStorage.getItem('status') || '{}'); if(this.isUser) - this.user = this.dashboardService.getUser(); + this.user = JSON.parse(localStorage.getItem('userDetails') || '{}'); else - this.organisation = this.dashboardService.getOrganiser(); + this.organisation = JSON.parse(localStorage.getItem('orgDetails') || '{}'); + } + + createEvent(): void{ + this.createEventObject ={ + name: this.eventName, + description: this.eventDescription, + rewards: Number(this.eventRewards), + address: this.eventLocation, + POCName: this.eventPOCName, + phoneNo: Number(this.eventPOCContact), + email: this.eventPOCEmail, + city: this.eventCity, + pinCode: Number(this.eventZip), + startDate: this.startDate, + endDate: this.endDate + } + + console.log(this.createEventObject); + + this.dashboardService.createEvent(this.createEventObject).subscribe((res)=>{ + this._snackBar.open('Event Created!!', "",{ + horizontalPosition: this.horizontalPosition, + verticalPosition: this.verticalPosition, + duration: 2000, + }); + }, + (err)=>{ + this._snackBar.open('Failure: In Event Creation!!', "",{ + horizontalPosition: this.horizontalPosition, + verticalPosition: this.verticalPosition, + duration: 2000, + }); + } + ) } -} + searchEvents(): void{ + this.searchQueryObject={ + query: this.searchEventsQuery + } + console.log(this.searchQueryObject); + this.dashboardService.searchEvents(this.searchQueryObject).subscribe((res)=>{ + this.eventResult=JSON.stringify(res); + console.log(res); + this.searchEventsQuery=""; + },(err)=>{ + this.searchEventsQuery=""; + this._snackBar.open('Search Fetch Failed!!', "",{ + horizontalPosition: this.horizontalPosition, + verticalPosition: this.verticalPosition, + duration: 2000, + }); + }); + } + + isNumber(contact: any): boolean { + return !isNaN(contact); + } +} \ No newline at end of file diff --git a/socialseriveapp/src/app/homepage/contactus/contactus.component.css b/socialseriveapp/src/app/homepage/contactus/contactus.component.css index e69de29..aa0caf3 100644 --- a/socialseriveapp/src/app/homepage/contactus/contactus.component.css +++ b/socialseriveapp/src/app/homepage/contactus/contactus.component.css @@ -0,0 +1,21 @@ +.form-input-field{ + position: relative; + width: 100%; +} + +#bannerimage { + width: 100%; + background-image: url(../../../assets/contact_us.jpg); + height: 50%; + background-position: center; + } + + +.section-heading{ + text-align: center; + +} + +.margin-top-sm{ + margin-top: 2%; +} \ No newline at end of file diff --git a/socialseriveapp/src/app/homepage/contactus/contactus.component.html b/socialseriveapp/src/app/homepage/contactus/contactus.component.html index bbafbec..702784a 100644 --- a/socialseriveapp/src/app/homepage/contactus/contactus.component.html +++ b/socialseriveapp/src/app/homepage/contactus/contactus.component.html @@ -1 +1,63 @@ -

Contact Us

+ +
+ + + + + About us + +
+ + There are many people who would like to do community services, but don't know the places that + offer the + opportunity for the same. We aim to provide a platform not only to people who seek non-profit + organizations for any opportunities where they can contribute, but also to encourage more people + by + rewarding them for doing good deeds. We plan on helping the organizations that are looking for + volunteers to help them. + +
+ +
+ + + Locate Us Near You + +
+ + Central Offices + + + IRVINE REGISTERED OFFICE #1
+
+ Donald Bren School of Computer and Information Sciences, + Irvine, CA-92697
+ Contact: +1 949-824-7427
+ Email: info@uci.edi + +
+
+ IRVINE REGISTERED OFFICE #2
+
+ 3901 Parkview Ln + Irvine, CA-92612
+ Contact: +1 949-994-2615
+ Email: info@uci.edi +
+
+ + + International Affiliation + +
+ +
    +
  • We have affiliations with 1000+ NGO accross United States and India.
  • +
  • We are focusing on different community issues like environment change, water health and hygiene, quality education and poverty elevation issues.
  • +
  • We are collaborating local youth clubs, women groups for better society across the above mentioned countries.
  • +
  • Please feel free to reach out to us at info@uci.edi and we will get back to you shortly.
  • +
+
+
+
+ \ No newline at end of file diff --git a/socialseriveapp/src/app/homepage/contactus/contactus.component.ts b/socialseriveapp/src/app/homepage/contactus/contactus.component.ts index 9d2b309..b7c1d4f 100644 --- a/socialseriveapp/src/app/homepage/contactus/contactus.component.ts +++ b/socialseriveapp/src/app/homepage/contactus/contactus.component.ts @@ -6,9 +6,8 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./contactus.component.css'] }) export class ContactusComponent implements OnInit { - + constructor() { } - ngOnInit(): void { } } diff --git a/socialseriveapp/src/app/login/login.component.ts b/socialseriveapp/src/app/login/login.component.ts index 536383d..ef544fe 100644 --- a/socialseriveapp/src/app/login/login.component.ts +++ b/socialseriveapp/src/app/login/login.component.ts @@ -44,6 +44,8 @@ export class LoginComponent implements OnInit { if(this.userType == "User"){ this.loginserviceService.loginUser(this.loginObject).subscribe((res)=>{ + localStorage.setItem('userDetails', JSON.stringify(res)); + localStorage.setItem('status',JSON.stringify(true)); this.dashboardService.setUser(res); this.router.navigateByUrl("/dashboard"); @@ -58,7 +60,8 @@ export class LoginComponent implements OnInit { } else if(this.userType == "Organiser"){ this.loginserviceService.loginOrganiser(this.loginObject).subscribe((res)=>{ - + localStorage.setItem('orgDetails', JSON.stringify(res)); + localStorage.setItem('status',JSON.stringify(false)); this.dashboardService.setOrgniser(res); this.router.navigateByUrl("/dashboard"); diff --git a/socialseriveapp/src/app/registration-form/registration-form.component.html b/socialseriveapp/src/app/registration-form/registration-form.component.html index c744a07..827ce64 100644 --- a/socialseriveapp/src/app/registration-form/registration-form.component.html +++ b/socialseriveapp/src/app/registration-form/registration-form.component.html @@ -1,5 +1,6 @@ - User Registration + User Registration + Organization Registration
@@ -8,12 +9,13 @@
- First Name + First Name + Name - + Last Name
@@ -26,7 +28,7 @@
- + Date of Birth diff --git a/socialseriveapp/src/app/registration-form/registration-form.component.ts b/socialseriveapp/src/app/registration-form/registration-form.component.ts index 239f64e..56979be 100644 --- a/socialseriveapp/src/app/registration-form/registration-form.component.ts +++ b/socialseriveapp/src/app/registration-form/registration-form.component.ts @@ -80,7 +80,7 @@ export class RegistrationFormComponent implements OnInit { } else if (this.userType == "Organiser") { this.organiser = { - name: `${this.fName} ${this.lName}`, + name: this.fName, email: this.email, dob: this.dob, phoneNo: this.phNo, diff --git a/socialseriveapp/src/app/users/models/Event.ts b/socialseriveapp/src/app/users/models/Event.ts new file mode 100644 index 0000000..0f2a1ad --- /dev/null +++ b/socialseriveapp/src/app/users/models/Event.ts @@ -0,0 +1,13 @@ +export interface Event{ + name: string; + description: string; + rewards: number; + address: string; + POCName: string; + phoneNo: number; + email: string; + city: string; + pinCode: number; + startDate: Date; + endDate: Date; +} \ No newline at end of file diff --git a/socialseriveapp/src/app/users/models/SearchQuery.ts b/socialseriveapp/src/app/users/models/SearchQuery.ts new file mode 100644 index 0000000..cda4e27 --- /dev/null +++ b/socialseriveapp/src/app/users/models/SearchQuery.ts @@ -0,0 +1,3 @@ +export interface SearchQuery{ + query: string; +} \ No newline at end of file diff --git a/socialseriveapp/src/app/users/models/user.ts b/socialseriveapp/src/app/users/models/User.ts similarity index 100% rename from socialseriveapp/src/app/users/models/user.ts rename to socialseriveapp/src/app/users/models/User.ts diff --git a/socialseriveapp/src/app/users/services/dashboardservice/dashboard.service.ts b/socialseriveapp/src/app/users/services/dashboardservice/dashboard.service.ts index fe2f34a..93c0901 100644 --- a/socialseriveapp/src/app/users/services/dashboardservice/dashboard.service.ts +++ b/socialseriveapp/src/app/users/services/dashboardservice/dashboard.service.ts @@ -2,6 +2,11 @@ import { Injectable } from '@angular/core'; import { UserregistrationService } from '../userregistrationservice/userregistration.service'; import { User } from '../../models/User'; import { Organiser } from '../../models/Organiser'; +import { Observable } from 'rxjs'; +import { Event } from '../../models/Event'; +import { HttpClient } from '@angular/common/http'; +import { environment } from 'src/environments/environment'; +import { SearchQuery } from '../../models/SearchQuery'; @Injectable({ providedIn: 'root' @@ -10,12 +15,13 @@ export class DashboardService { private user!: User; public isUser!: boolean; private organisation!: Organiser; - - constructor() { } + private apiServerUrlUser = environment.baseUrlEvent; + constructor(private http: HttpClient) { } public setUser(user :User){ - this.user = user; - this.isUser = true; + this.user = JSON.parse(localStorage.getItem('userDetails') || '{}'); + this.isUser = JSON.parse(localStorage.getItem('status') || '{}'); + console.log(this.user); } public setOrgniser(organiser :Organiser){ @@ -30,4 +36,14 @@ export class DashboardService { public getOrganiser():Organiser{ return this.organisation; } + + public createEvent(Event: Event): Observable{ + var url=`${this.apiServerUrlUser}/event`; + return this.http.post(url, Event); + } + + public searchEvents(SearchQuery: SearchQuery): Observable{ + var url=`${this.apiServerUrlUser}/event/search/`; + return this.http.post(url, SearchQuery); + } } diff --git a/socialseriveapp/src/assets/contact_us.jpg b/socialseriveapp/src/assets/contact_us.jpg new file mode 100644 index 0000000..431be99 Binary files /dev/null and b/socialseriveapp/src/assets/contact_us.jpg differ diff --git a/socialseriveapp/src/environments/environment.ts b/socialseriveapp/src/environments/environment.ts index 9437e42..b1a7ef5 100644 --- a/socialseriveapp/src/environments/environment.ts +++ b/socialseriveapp/src/environments/environment.ts @@ -6,6 +6,7 @@ export const environment = { production: false, baseUrlUser: `http://localhost:8080/api/v1`, baseUrlOrg:`http://localhost:8090/api/v1`, + baseUrlEvent: `http://localhost:8091/api/v1` }; diff --git a/userservice/src/main/java/com/socialservicefinder/userservice/UserserviceApplication.java b/userservice/src/main/java/com/socialservicefinder/userservice/UserserviceApplication.java index 53e515d..94b68bf 100644 --- a/userservice/src/main/java/com/socialservicefinder/userservice/UserserviceApplication.java +++ b/userservice/src/main/java/com/socialservicefinder/userservice/UserserviceApplication.java @@ -21,7 +21,7 @@ public static void main(String[] args) { public CorsFilter corsFilter() { CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.setAllowCredentials(true); - corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:4202")); + corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:4200")); corsConfiguration.setAllowedHeaders(Arrays.asList("Origin", "Access-Control-Allow-Origin", "Content-Type", "Accept", "Authorization", "Origin, Accept", "X-Requested-With", "Access-Control-Request-Method", "Access-Control-Request-Headers"));