Add contacts, reply/forward, pagination, HTML toggle, Docker Compose for VPS

Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
2026-11-05 01:28:24 +01:00
co-authored by Junie
parent 0339413d6e
commit a23a020138
14 changed files with 570 additions and 12 deletions
@@ -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()))))
);
}
}