Skip to content

Commit

Permalink
skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Jul 7, 2023
1 parent f4c08a8 commit 9bf0059
Show file tree
Hide file tree
Showing 21 changed files with 816 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ SOFTWARE.
<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>
<checkstyle.version>8.15</checkstyle.version>
<maven-checkstyle-plugin.version>3.2.2</maven-checkstyle-plugin.version>
<cactoos.version>0.55.0</cactoos.version>
<eokson.version>0.3.2</eokson.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -132,6 +134,16 @@ SOFTWARE.
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.github.eo-cqrs</groupId>
<artifactId>eokson</artifactId>
<version>${eokson.version}</version>
</dependency>
<dependency>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<version>${cactoos.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/io/blamer/hub/controller/ChatController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.blamer.hub.controller;

import io.blamer.hub.model.Chats;
import io.blamer.hub.pg.PgChat;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
* Chat Controller.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
@RestController
@RequestMapping("/api/chats")
public class ChatController {

/**
* Chats.
*/
private final Chats chats;

/**
* Ctor.
*
* @param chats Chats
*/
public ChatController(@Qualifier("validated") final Chats chats) {
this.chats = chats;
}

Check warning on line 34 in src/main/java/io/blamer/hub/controller/ChatController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/controller/ChatController.java#L32-L34

Added lines #L32 - L34 were not covered by tests

/**
* Register new Chat ID.
*
* @param chat Chat ID
* @return Mono void publisher
*/
@PostMapping
public Mono<Void> registerChatId(@RequestBody final Long chat) {
return this.chats.add(new PgChat(chat));

Check warning on line 44 in src/main/java/io/blamer/hub/controller/ChatController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/controller/ChatController.java#L44

Added line #L44 was not covered by tests
}
}
38 changes: 38 additions & 0 deletions src/main/java/io/blamer/hub/controller/HubAdvice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.blamer.hub.controller;

import io.blamer.hub.rq.ChatAlreadyExists;
import io.github.eocqrs.eokson.Jocument;
import io.github.eocqrs.eokson.MutableJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
@Slf4j

Check warning on line 16 in src/main/java/io/blamer/hub/controller/HubAdvice.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/controller/HubAdvice.java#L16

Added line #L16 was not covered by tests
@RestControllerAdvice
public class HubAdvice {

Check warning on line 18 in src/main/java/io/blamer/hub/controller/HubAdvice.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/controller/HubAdvice.java#L18

Added line #L18 was not covered by tests

/**
* Handle {@link ChatAlreadyExists}.
*
* @param ex ChatAlreadyExists
* @return ResponseEntity
*/
@ExceptionHandler(ChatAlreadyExists.class)
public ResponseEntity<byte[]> handle(final ChatAlreadyExists ex) {
log.debug("Chat ID already exists", ex);
return new ResponseEntity<>(

Check warning on line 29 in src/main/java/io/blamer/hub/controller/HubAdvice.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/controller/HubAdvice.java#L28-L29

Added lines #L28 - L29 were not covered by tests
new Jocument(
new MutableJson()
.with("code", HttpStatus.CONFLICT.value())
.with("message", ex.getMessage())
).byteArray(),

Check warning on line 34 in src/main/java/io/blamer/hub/controller/HubAdvice.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/controller/HubAdvice.java#L32-L34

Added lines #L32 - L34 were not covered by tests
HttpStatus.CONFLICT
);
}
}
48 changes: 48 additions & 0 deletions src/main/java/io/blamer/hub/controller/TokenController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.blamer.hub.controller;

import io.blamer.hub.model.Tokens;
import io.blamer.hub.rq.RequestToken;
import io.blamer.hub.rq.TokenToAdd;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
* Token controller.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
@RestController
@RequestMapping("/api/tokens")
public class TokenController {

/**
* Tokens.
*/
private final Tokens tokens;

/**
* Ctor.
*
* @param tkns Tokens
*/
public TokenController(final Tokens tkns) {
this.tokens = tkns;
}

Check warning on line 34 in src/main/java/io/blamer/hub/controller/TokenController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/controller/TokenController.java#L32-L34

Added lines #L32 - L34 were not covered by tests

/**
* Registers new Token with Chat ID.
*
* @param request RequestToken
* @return Mono void publisher
* @throws Exception if something went wrong
*/
@PostMapping
Mono<Void> registerToken(@RequestBody final RequestToken request)
throws Exception {
return this.tokens.add(new TokenToAdd(request).value());

Check warning on line 46 in src/main/java/io/blamer/hub/controller/TokenController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/controller/TokenController.java#L46

Added line #L46 was not covered by tests
}
}
7 changes: 7 additions & 0 deletions src/main/java/io/blamer/hub/controller/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Endpoints.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
package io.blamer.hub.controller;
17 changes: 17 additions & 0 deletions src/main/java/io/blamer/hub/model/Chat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.blamer.hub.model;

/**
* Chat.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
public interface Chat {

/**
* Chat ID.
*
* @return Chat ID
*/
long id();
}
20 changes: 20 additions & 0 deletions src/main/java/io/blamer/hub/model/Chats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.blamer.hub.model;

import reactor.core.publisher.Mono;

/**
* Chats.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
public interface Chats {

/**
* Add new Chat.
*
* @param chat Chat
* @return Mono void publisher
*/
Mono<Void> add(Chat chat);
}
38 changes: 38 additions & 0 deletions src/main/java/io/blamer/hub/model/Token.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.blamer.hub.model;

/**
* Token.
*
* @author Aliaksei Bialiauski ()
* @since 0.0.0
*/
public interface Token {

/**
* Id.
*
* @return Token id
*/
Long id();

/**
* Value.
*
* @return Token value
*/
String value();

/**
* Alias.
*
* @return Token alias
*/
String alias();

/**
* Chat.
*
* @return Token chat
*/
Chat chat();
}
20 changes: 20 additions & 0 deletions src/main/java/io/blamer/hub/model/Tokens.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.blamer.hub.model;

import reactor.core.publisher.Mono;

/**
* Tokens.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
public interface Tokens {

/**
* Register new token.
*
* @param token Token
* @return Mono void publisher
*/
Mono<Void> add(Token token);
}
31 changes: 31 additions & 0 deletions src/main/java/io/blamer/hub/model/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2023 Blamer.io
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Model.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
package io.blamer.hub.model;
24 changes: 24 additions & 0 deletions src/main/java/io/blamer/hub/pg/PgChat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.blamer.hub.pg;

import io.blamer.hub.model.Chat;
import lombok.RequiredArgsConstructor;

/**
* Chat in PostgreSQL.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
@RequiredArgsConstructor

Check warning on line 12 in src/main/java/io/blamer/hub/pg/PgChat.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/pg/PgChat.java#L12

Added line #L12 was not covered by tests
public class PgChat implements Chat {

/**
* Chat ID.
*/
private final long id;

@Override
public long id() {
return this.id;

Check warning on line 22 in src/main/java/io/blamer/hub/pg/PgChat.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/pg/PgChat.java#L22

Added line #L22 was not covered by tests
}
}
41 changes: 41 additions & 0 deletions src/main/java/io/blamer/hub/pg/PgChats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.blamer.hub.pg;

import io.blamer.hub.model.Chat;
import io.blamer.hub.model.Chats;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

/**
* Chats in PostgreSQL.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.0.0
*/
@Component
public class PgChats implements Chats {

/**
* Database Client.
*/
private final DatabaseClient db;

/**
* Ctor.
*
* @param dbc Database Client.
*/
public PgChats(final DatabaseClient dbc) {
this.db = dbc;
}

Check warning on line 30 in src/main/java/io/blamer/hub/pg/PgChats.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/pg/PgChats.java#L28-L30

Added lines #L28 - L30 were not covered by tests

@Override
public Mono<Void> add(final Chat chat) {
return this.db.sql(

Check warning on line 34 in src/main/java/io/blamer/hub/pg/PgChats.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/pg/PgChats.java#L34

Added line #L34 was not covered by tests
"INSERT INTO chat (id) VALUES (:id)"
).bind("id", chat.id())
.fetch()
.first()
.then();

Check warning on line 39 in src/main/java/io/blamer/hub/pg/PgChats.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/blamer/hub/pg/PgChats.java#L36-L39

Added lines #L36 - L39 were not covered by tests
}
}
Loading

0 comments on commit 9bf0059

Please sign in to comment.