Add contacts, reply/forward, pagination, HTML toggle, Docker Compose for VPS
Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
@@ -276,4 +276,72 @@ public class MailController {
|
||||
Mono.just(org.springframework.http.ResponseEntity.badRequest().body(Map.of("error", e.getMessage()))))
|
||||
);
|
||||
}
|
||||
|
||||
// --- Contacts ---
|
||||
|
||||
@GetMapping("/contacts")
|
||||
public Flux<Object> getContacts(Mono<Authentication> authenticationMono) {
|
||||
return authenticationMono.flatMapMany(auth ->
|
||||
userService.findByEmail(auth.getName())
|
||||
.flatMapMany(user -> mailService.getContacts(user.getId()))
|
||||
);
|
||||
}
|
||||
|
||||
@PostMapping("/contacts")
|
||||
public Mono<Object> addContact(
|
||||
Mono<Authentication> authenticationMono,
|
||||
@RequestBody Mono<Map<String, String>> bodyMono) {
|
||||
return authenticationMono.zipWith(bodyMono)
|
||||
.flatMap(pair -> {
|
||||
String email = pair.getT1().getName();
|
||||
Map<String, String> body = pair.getT2();
|
||||
return userService.findByEmail(email)
|
||||
.flatMap(user -> mailService.addContact(
|
||||
user.getId(),
|
||||
body.get("name"),
|
||||
body.get("email"),
|
||||
body.get("phone"),
|
||||
body.get("company")
|
||||
));
|
||||
})
|
||||
.map(contact -> (Object) org.springframework.http.ResponseEntity.status(HttpStatus.CREATED).body(contact))
|
||||
.onErrorResume(IllegalArgumentException.class, e ->
|
||||
Mono.just((Object) org.springframework.http.ResponseEntity.badRequest().body(Map.of("error", e.getMessage()))));
|
||||
}
|
||||
|
||||
@PutMapping("/contacts/{id}")
|
||||
public Mono<Object> updateContact(
|
||||
@PathVariable Long id,
|
||||
Mono<Authentication> authenticationMono,
|
||||
@RequestBody Mono<Map<String, String>> bodyMono) {
|
||||
return authenticationMono.zipWith(bodyMono)
|
||||
.flatMap(pair -> {
|
||||
String email = pair.getT1().getName();
|
||||
Map<String, String> body = pair.getT2();
|
||||
return userService.findByEmail(email)
|
||||
.flatMap(user -> mailService.updateContact(
|
||||
id, user.getId(),
|
||||
body.get("name"),
|
||||
body.get("email"),
|
||||
body.get("phone"),
|
||||
body.get("company")
|
||||
));
|
||||
})
|
||||
.map(contact -> (Object) org.springframework.http.ResponseEntity.ok().body(contact))
|
||||
.onErrorResume(IllegalArgumentException.class, e ->
|
||||
Mono.just((Object) org.springframework.http.ResponseEntity.badRequest().body(Map.of("error", e.getMessage()))));
|
||||
}
|
||||
|
||||
@DeleteMapping("/contacts/{id}")
|
||||
public Mono<?> deleteContact(
|
||||
@PathVariable Long id,
|
||||
Mono<Authentication> authenticationMono) {
|
||||
return authenticationMono.flatMap(auth ->
|
||||
userService.findByEmail(auth.getName())
|
||||
.flatMap(user -> mailService.deleteContact(id, user.getId())
|
||||
.then(Mono.just(org.springframework.http.ResponseEntity.ok(Map.of("message", "Contact deleted")))))
|
||||
.onErrorResume(IllegalArgumentException.class, e ->
|
||||
Mono.just(org.springframework.http.ResponseEntity.badRequest().body(Map.of("error", e.getMessage()))))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user