Skip to content

Commit 24e7dcb

Browse files
Tariq HookTariq Hook
Tariq Hook
authored and
Tariq Hook
committed
added watertrackerapi
1 parent 8d3e094 commit 24e7dcb

37 files changed

+1678
-2
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ build/
3333
.vscode/
3434
**/firebase_config.json
3535
.DS_Store
36-
mvnw**
37-
.mvn**
36+
**/mvnw**
37+
**/.mvn**
38+
**/.idea/**
39+
**/*.iml

WaterTrackerAPI/README.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# WaterTrackerApi
2+
3+
Sample `application.yml`
4+
5+
```
6+
logging:
7+
level:
8+
root: info
9+
com.codedifferently.watertrackerapi: debug
10+
spring:
11+
datasource:
12+
driverClassName: <driver for database>
13+
url: <url to connect to database>
14+
username: <user name for mysql>
15+
password: <password for mysql>
16+
jpa:
17+
show-sql: false
18+
properties:
19+
hibernate:
20+
jdbc: time_zone = EST
21+
security:
22+
firebase-props:
23+
database-url: ${FIREBASE_DATABASE}
24+
enable-strict-server-session: false
25+
enable-check-session-revoked: false
26+
enable-logout-everywhere: false
27+
session-expiry-in-days: 5
28+
cookie-props:
29+
max-age-in-minutes: 7200
30+
http-only: true
31+
secure: true
32+
domain: ${DOMAIN}
33+
path: /
34+
allow-credentials: true
35+
allowed-origins:
36+
- https://${DOMAIN}
37+
- http://localhost:3000
38+
allowed-methods:
39+
- GET
40+
- POST
41+
- PUT
42+
- PATCH
43+
- DELETE
44+
- OPTIONS
45+
allowed-headers:
46+
- Authorization
47+
- Origin
48+
- Content-Type
49+
- Accept
50+
- Accept-Encoding
51+
- Accept-Language
52+
- Access-Control-Allow-Origin
53+
- Access-Control-Allow-Headers
54+
- Access-Control-Request-Method
55+
- X-Requested-With
56+
- X-Auth-Token
57+
- X-Xsrf-Token
58+
- Cache-Control
59+
- Id-Token
60+
allowed-public-apis:
61+
- /favicon.ico
62+
- /session/login
63+
- /info/**
64+
- /**/userprofile/create
65+
exposed-headers:
66+
- X-Xsrf-Token
67+
```

WaterTrackerAPI/pom.xml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.7.2</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.codedifferently</groupId>
12+
<artifactId>water-tracker-api</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>water-tracker-api</name>
15+
<description>water-tracker-api</description>
16+
<properties>
17+
<java.version>11</java.version>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-data-jpa</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-security</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
<!-- https://mvnrepository.com/artifact/com.google.firebase/firebase-admin -->
33+
<dependency>
34+
<groupId>com.google.firebase</groupId>
35+
<artifactId>firebase-admin</artifactId>
36+
<version>8.1.0</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>mysql</groupId>
41+
<artifactId>mysql-connector-java</artifactId>
42+
<scope>runtime</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.projectlombok</groupId>
46+
<artifactId>lombok</artifactId>
47+
<optional>true</optional>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-test</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
</dependencies>
55+
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-maven-plugin</artifactId>
61+
<configuration>
62+
<excludes>
63+
<exclude>
64+
<groupId>org.projectlombok</groupId>
65+
<artifactId>lombok</artifactId>
66+
</exclude>
67+
</excludes>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.codedifferently.watertrackerapi;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class WaterTrackerApiApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(WaterTrackerApiApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.codedifferently.watertrackerapi.domain.core.exceptions;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.web.bind.annotation.ResponseStatus;
5+
6+
@ResponseStatus(value = HttpStatus.CONFLICT)
7+
public class ResourceCreationException extends RuntimeException{
8+
9+
public ResourceCreationException(String message) {
10+
super(message);
11+
}
12+
}
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.codedifferently.watertrackerapi.domain.core.exceptions;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.web.bind.annotation.ResponseStatus;
5+
6+
@ResponseStatus(value = HttpStatus.NOT_FOUND)
7+
public class ResourceNotFoundException extends RuntimeException{
8+
public ResourceNotFoundException(String message) {
9+
super(message);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.codedifferently.watertrackerapi.domain.core.exceptions;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.web.bind.annotation.ResponseStatus;
5+
6+
@ResponseStatus(value = HttpStatus.CONFLICT)
7+
public class ResourceUpdateException extends RuntimeException{
8+
public ResourceUpdateException(String message) {
9+
super(message);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.codedifferently.watertrackerapi.domain.info;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
@RestController
8+
@RequestMapping("info")
9+
public class InfoController {
10+
@GetMapping
11+
public String test(){
12+
return "test";
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.codedifferently.watertrackerapi.domain.userProfiles.controllers;
2+
3+
import com.codedifferently.watertrackerapi.domain.userProfiles.dtos.UserProfileCreateRequest;
4+
import com.codedifferently.watertrackerapi.domain.userProfiles.dtos.UserProfileDTO;
5+
import com.codedifferently.watertrackerapi.domain.userProfiles.models.UserProfile;
6+
import com.codedifferently.watertrackerapi.domain.userProfiles.services.UserProfileService;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.*;
12+
import java.util.Map;
13+
14+
@Slf4j
15+
@RestController
16+
@RequestMapping("/api/v1/userprofile")
17+
public class UserProfileController {
18+
19+
private UserProfileService userProfileService;
20+
21+
@Autowired
22+
public UserProfileController(UserProfileService userProfileService) {
23+
this.userProfileService = userProfileService;
24+
}
25+
26+
@PostMapping("create")
27+
public ResponseEntity<UserProfileDTO> create (@RequestBody UserProfileCreateRequest userDetail){
28+
UserProfileDTO userProfile = userProfileService.create(userDetail);
29+
return new ResponseEntity<>(userProfile, HttpStatus.CREATED);
30+
}
31+
32+
@GetMapping
33+
public ResponseEntity<Iterable<UserProfileDTO>> getAll(){
34+
Iterable<UserProfileDTO> userProfiles = userProfileService.getAll();
35+
return new ResponseEntity<>(userProfiles, HttpStatus.OK);
36+
}
37+
38+
@GetMapping("{id}")
39+
public ResponseEntity<UserProfileDTO> getById(@PathVariable("id") String id){
40+
UserProfileDTO userProfile = userProfileService.getById(id);
41+
return new ResponseEntity<>(userProfile, HttpStatus.OK);
42+
}
43+
44+
@GetMapping("/findByEmail/{email}")
45+
public ResponseEntity<UserProfileDTO> getByEmail(@PathVariable("email")String email){
46+
UserProfileDTO userProfile = userProfileService.getByEmail(email);
47+
return new ResponseEntity<>(userProfile, HttpStatus.OK);
48+
}
49+
50+
@PutMapping("{id}")
51+
public ResponseEntity<UserProfileDTO> update(@PathVariable("id")String id, @RequestBody UserProfile userProfile){
52+
UserProfileDTO userProfileDTO = userProfileService.update(id, userProfile);
53+
return new ResponseEntity<>(userProfileDTO, HttpStatus.ACCEPTED);
54+
}
55+
56+
@DeleteMapping("{id}")
57+
public ResponseEntity delete(@PathVariable("id") String id){
58+
userProfileService.delete(id);
59+
return new ResponseEntity(HttpStatus.NO_CONTENT);
60+
}
61+
62+
@GetMapping("{id}/followers")
63+
public ResponseEntity<Iterable<UserProfileDTO>> getFollowers(@PathVariable("id") String userId){
64+
Iterable<UserProfileDTO> followers = userProfileService.getFollowers(userId);
65+
return new ResponseEntity<>(followers, HttpStatus.OK);
66+
}
67+
68+
@PostMapping("follow")
69+
public ResponseEntity follow(@RequestBody Map<String,String> data){
70+
String userId = data.get("userId");
71+
String followerId = data.get("followerId");
72+
userProfileService.follow(userId, followerId);
73+
return new ResponseEntity(HttpStatus.ACCEPTED);
74+
}
75+
76+
@PostMapping("unfollow")
77+
public ResponseEntity unfollow(@RequestBody Map<String,String> data){
78+
String userId = data.get("userId");
79+
String followerId = data.get("followerId");
80+
userProfileService.unfollow(userId, followerId);
81+
return new ResponseEntity(HttpStatus.ACCEPTED);
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.codedifferently.watertrackerapi.domain.userProfiles.dtos;
2+
3+
import lombok.*;
4+
5+
@Getter
6+
@Setter
7+
@NoArgsConstructor
8+
@RequiredArgsConstructor
9+
@ToString
10+
public class UserProfileCreateRequest {
11+
@NonNull
12+
private String firstName;
13+
14+
@NonNull
15+
private String lastName;
16+
17+
@NonNull
18+
private String email;
19+
20+
@NonNull
21+
private String password;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.codedifferently.watertrackerapi.domain.userProfiles.dtos;
2+
3+
import com.codedifferently.watertrackerapi.domain.userProfiles.models.UserProfile;
4+
import lombok.Getter;
5+
import lombok.ToString;
6+
7+
@Getter
8+
@ToString
9+
public class UserProfileDTO {
10+
private String id;
11+
private String firstName;
12+
private String lastName;
13+
private String email;
14+
private Integer numberOfFollowers;
15+
16+
public UserProfileDTO(UserProfile userProfile){
17+
id = userProfile.getId();
18+
firstName = userProfile.getFirstName();
19+
lastName = userProfile.getLastName();
20+
email = userProfile.getEmail();
21+
numberOfFollowers = userProfile.getFollowers().size();
22+
}
23+
}

0 commit comments

Comments
 (0)