-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from SwevenSoftware/feature/refactor
Feature/refactor
- Loading branch information
Showing
16 changed files
with
164 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
build | ||
log | ||
log* | ||
db | ||
.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# BlockCOVID-server | ||
Modulo Server per il progetto di SWE 2020/2021 - BlockCOVID | ||
|
||
## Come usare mongo | ||
Sono inclusi degli script per utilizzare mongo per testare come si comporta: | ||
- **Avvio**: `./spawnMongo.sh`, spawna un'istanza di `mongod` che lavora sulla cartella locale `./db` e raccoglie i log nel file `log`. Fallisce se ci sono altre istanze già attive. | ||
- **Stop**: `./killMongo.sh`, termina l'istanza di `mongod` avviata con `spawnMongo.sh`. Attenzione che fallisce con tutte le altre istanze di mongodb. | ||
- **Una volta avviato**: è possibile utilizzare la shell tramite il comando `mongo`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
plugins { | ||
id 'org.springframework.boot' version '2.4.2' | ||
id 'io.spring.dependency-management' version '1.0.11.RELEASE' | ||
id 'java' | ||
id 'org.springframework.boot' version '2.4.2' | ||
id 'io.spring.dependency-management' version '1.0.11.RELEASE' | ||
id 'java' | ||
} | ||
|
||
group = 'it.sweven.blockcovid' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = '14' | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testImplementation 'io.projectreactor:reactor-test' | ||
// Spring dependencies | ||
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
// MongoDB Drivers | ||
implementation 'org.mongodb:mongodb-driver-reactivestreams' | ||
// reactivex reactive streams | ||
implementation 'io.reactivex.rxjava2:rxjava' | ||
implementation 'io.reactivex:rxjava-reactive-streams' | ||
|
||
// TESTS | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testImplementation 'io.projectreactor:reactor-test' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
mongod --shutdown -dbpath db/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = 'demo' | ||
rootProject.name = 'blockcovid' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/bin/sh | ||
|
||
mongod --fork --dbpath ./db/ --logpath ./log | ||
echo `pwd` | ||
[ ! -d db/ ] && mkdir db/ | ||
mongod --fork --dbpath db/ --logpath log |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package it.sweven.blockcovid; | ||
|
||
/* Spring Annotations */ | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
/* Bean factory annotations */ | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/* Reactor core imports */ | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
/* Our own imports */ | ||
import it.sweven.blockcovid.entities.User; | ||
import it.sweven.blockcovid.repositories.UserRepository; | ||
|
||
@RestController | ||
class Router { | ||
|
||
@Autowired | ||
private final UserRepository repository; | ||
|
||
Router(UserRepository repo) { | ||
this.repository = repo; | ||
} | ||
|
||
@GetMapping("/") | ||
String hello() { | ||
return "Pagina iniziale!!\n"; | ||
} | ||
|
||
@GetMapping("/init") | ||
String init() { | ||
repository.save(new User("Gianni", "password")); | ||
repository.save(new User("Annaclara", "password")); | ||
repository.save(new User("Mario", "password")); | ||
repository.save(new User("Genni", "password")); | ||
|
||
return "Init avvenuto"; | ||
} | ||
|
||
@GetMapping("/user/{name}") | ||
Mono<User> name(@PathVariable String name) { | ||
return repository.findById(name); | ||
} | ||
|
||
@PostMapping("/user/new") | ||
@ResponseBody | ||
Mono<User> insert(@RequestBody User newUser) { | ||
return repository.save(newUser); | ||
} | ||
|
||
@GetMapping("/user/all") | ||
Flux<User> all(){ | ||
return repository.findAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package it.sweven.blockcovid; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration; | ||
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories; | ||
|
||
import com.mongodb.reactivestreams.client.MongoClient; | ||
import com.mongodb.reactivestreams.client.MongoClients; | ||
|
||
@Configuration | ||
@EnableReactiveMongoRepositories(basePackages = "it.sweven.blockcovid.repositories") | ||
public class ServerConfig extends AbstractReactiveMongoConfiguration { | ||
|
||
@Override | ||
public MongoClient reactiveMongoClient() { | ||
return MongoClients.create(); | ||
} | ||
|
||
@Override | ||
protected String getDatabaseName() { | ||
return "blockcovid-reactive"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package it.sweven.blockcovid.entities; | ||
|
||
/* Java utilities */ | ||
import java.util.Set; | ||
|
||
/* Spring utilities */ | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
@Document | ||
public class User { | ||
|
||
private @Id String name; | ||
private String password; | ||
// private Token token; | ||
// private Set<Authorization> authorizations; | ||
|
||
public User(String name, String password) { | ||
this.name = name; | ||
this.password = password; | ||
} | ||
|
||
// public boolean isUser() { return false; } | ||
|
||
// public boolean isAdmin() { return false; } | ||
|
||
public String getName() { return name; } | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("{'name': '%s', 'password': '%s'}", | ||
name, password); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/it/sweven/blockcovid/repositories/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package it.sweven.blockcovid.repositories; | ||
|
||
/* Spring imports */ | ||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository; | ||
|
||
/* Our imports */ | ||
import it.sweven.blockcovid.entities.User; | ||
|
||
public interface UserRepository extends ReactiveMongoRepository<User, String> { | ||
/* l'implementazione può rimanere vuota, La classe di base si | ||
* occupa di fare tutto */ | ||
} |