Skip to content

Commit e798ba8

Browse files
committed
first commit
0 parents  commit e798ba8

21 files changed

+659
-0
lines changed

.gitignore

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
8+
9+
10+
### Maven ###
11+
.mvn/
12+
mvnw.cmd
13+
mvnw
14+
15+
### STS ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### IntelliJ IDEA ###
25+
.idea
26+
*.iws
27+
*.iml
28+
*.ipr
29+
30+
### NetBeans ###
31+
/nbproject/private/
32+
/nbbuild/
33+
/dist/
34+
/nbdist/
35+
/.nb-gradle/
36+
build/
37+
!**/src/main/**/build/
38+
!**/src/test/**/build/
39+
40+
### VS Code ###
41+
.vscode/
42+
43+
44+
45+
### User based ###
46+
serviceaccount.json

pom.xml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.4.0</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>main</groupId>
12+
<artifactId>lab-management</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<packaging>war</packaging>
15+
<name>lab-management</name>
16+
<description>Learning project for SWE course</description>
17+
18+
<properties>
19+
<java.version>11</java.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-web</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.auth0</groupId>
29+
<artifactId>java-jwt</artifactId>
30+
<version>3.11.0</version>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>com.google.firebase</groupId>
35+
<artifactId>firebase-admin</artifactId>
36+
<version>6.15.0</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-tomcat</artifactId>
42+
<scope>provided</scope>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-test</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.google.cloud</groupId>
52+
<artifactId>google-cloud-firestore</artifactId>
53+
<version>2.1.0</version>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-maven-plugin</artifactId>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package lab.management.Controllers;
2+
3+
import org.springframework.web.bind.annotation.DeleteMapping;
4+
import org.springframework.web.bind.annotation.PathVariable;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
import lab.management.Services.AnnouncementService;
8+
9+
@RestController
10+
public class DeleteController {
11+
12+
13+
14+
@DeleteMapping("/api/announcement/{id}")
15+
public String deleteAnnouncement(@PathVariable String id){
16+
17+
return AnnouncementService.deleteAnnouncement(id);
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package lab.management.Controllers;
2+
3+
import java.util.Dictionary;
4+
import java.util.List;
5+
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestBody;
8+
import org.springframework.web.bind.annotation.RequestParam;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
import lab.management.Errors.HTTPError;
12+
import lab.management.Errors.NotFound;
13+
import lab.management.Errors.ServerError;
14+
import lab.management.Services.AnnouncementService;
15+
import lab.management.Services.UserService;
16+
17+
18+
19+
@RestController
20+
public class GetControllers {
21+
22+
23+
@GetMapping("/")
24+
public String home() {
25+
return "Test";
26+
}
27+
28+
@GetMapping("/error")
29+
public String error() {
30+
return "Some error occured";
31+
}
32+
33+
@GetMapping("/api/announcement/all")
34+
public List<Object> getAllAnnouncements() {
35+
36+
return AnnouncementService.getAll();
37+
}
38+
39+
@GetMapping("/api/announcement")
40+
public Object getAnnouncement(@RequestParam String id){
41+
Object result = AnnouncementService.getAnnoucement(id);
42+
if(result.equals(new HTTPError(500, "Server Error")) | result.equals(new HTTPError(404, "Not found"))){
43+
System.out.println("Error");
44+
}
45+
46+
return result;
47+
}
48+
49+
50+
@GetMapping(value="/api/user")
51+
public String getMethodName(@RequestBody Dictionary<Object, Object> user) {
52+
String result = null;
53+
try{
54+
result = UserService.signin(user);
55+
} catch(NotFound error){
56+
result = "User not found";
57+
} catch(ServerError error){
58+
result = "Server Error";
59+
}
60+
61+
return result;
62+
}
63+
64+
65+
}
66+
67+
68+
69+
70+
71+
72+
73+
74+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package lab.management.Controllers;
2+
3+
import org.springframework.web.bind.annotation.PostMapping;
4+
import org.springframework.web.bind.annotation.RequestBody;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
import lab.management.Errors.NotAllowed;
8+
import lab.management.Errors.ServerError;
9+
import lab.management.Models.Announcement;
10+
import lab.management.Models.Users;
11+
import lab.management.Services.AnnouncementService;
12+
import lab.management.Services.UserService;
13+
14+
@RestController
15+
public class PostControllers {
16+
17+
@PostMapping("/api/announcement")
18+
public String postAnnouncement(@RequestBody Announcement toSaveAnnouncement) {
19+
20+
return AnnouncementService.saveAnnouncement(toSaveAnnouncement);
21+
22+
}
23+
24+
25+
@PostMapping("/api/users")
26+
public String newUser(@RequestBody Users user){
27+
28+
String result = null;
29+
30+
try{
31+
UserService.signup(user);
32+
} catch(ServerError error){
33+
System.out.println(error);
34+
result = "Failed";
35+
} catch(NotAllowed error){
36+
result = "Some error occured";
37+
System.out.println(error);
38+
}
39+
40+
41+
return result;
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package lab.management.Controllers;
2+
3+
import org.springframework.web.bind.annotation.PathVariable;
4+
import org.springframework.web.bind.annotation.PutMapping;
5+
import org.springframework.web.bind.annotation.RequestBody;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
import lab.management.Models.Announcement;
9+
import lab.management.Services.AnnouncementService;
10+
11+
@RestController
12+
public class PutController {
13+
14+
15+
@PutMapping("/api/announcement/{id}")
16+
public String updateAnnouncement(@PathVariable String id, @RequestBody Announcement toUpdate){
17+
return AnnouncementService.updateAnnouncement(id, toUpdate);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package lab.management.Errors;
2+
3+
public class HTTPError extends Throwable{
4+
/**
5+
*
6+
*/
7+
private static final long serialVersionUID = 1L;
8+
public Integer code;
9+
public String message;
10+
11+
12+
public HTTPError(Integer code, String message){
13+
this.code = code;
14+
this.message = message;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package lab.management.Errors;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.web.bind.annotation.ResponseStatus;
5+
6+
@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE)
7+
public class NotAllowed extends HTTPError {
8+
9+
/**
10+
*
11+
*/
12+
private static final long serialVersionUID = 1L;
13+
14+
public NotAllowed(){
15+
super(406, "Not Acceptable");
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package lab.management.Errors;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.web.bind.annotation.ResponseStatus;
5+
6+
@ResponseStatus(code = HttpStatus.NOT_FOUND)
7+
public class NotFound extends HTTPError {
8+
9+
/**
10+
*
11+
*/
12+
private static final long serialVersionUID = 1L;
13+
14+
public NotFound() {
15+
super(404, "Not found");
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package lab.management.Errors;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.web.bind.annotation.ResponseStatus;
5+
6+
@ResponseStatus(code = HttpStatus.NOT_FOUND)
7+
public class ServerError extends HTTPError{
8+
9+
/**
10+
*
11+
*/
12+
private static final long serialVersionUID = 1L;
13+
14+
public ServerError() {
15+
super(500, "Server Error");
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package lab.management;
2+
3+
import com.google.auth.oauth2.GoogleCredentials;
4+
import com.google.firebase.FirebaseApp;
5+
import com.google.firebase.FirebaseOptions;
6+
import org.springframework.stereotype.Service;
7+
8+
import javax.annotation.PostConstruct;
9+
import java.io.FileInputStream;
10+
11+
@Service
12+
public class FBInitialize {
13+
14+
@PostConstruct
15+
public void initialize() {
16+
try {
17+
FileInputStream serviceAccount =
18+
new FileInputStream("./serviceaccount.json");
19+
20+
FirebaseOptions options = FirebaseOptions.builder()
21+
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
22+
.setDatabaseUrl("https://springboot-swe.firebaseio.com/")
23+
.build();
24+
25+
FirebaseApp.initializeApp(options);
26+
27+
} catch (Exception e) {
28+
e.printStackTrace();
29+
}
30+
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package lab.management;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class LabManagementApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(LabManagementApplication.class, args);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)