-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12aad84
commit 451eed1
Showing
17 changed files
with
564 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
trim_trailing_whitespace = true | ||
# from checkstyle: | ||
max_line_length = 120 | ||
ij_continuation_indent_size = 4 | ||
|
||
[{*.yml, *.yaml}] | ||
indent_size = 2 |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/mn/flux/response/bug/EnumTypeConverters.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,17 @@ | ||
package mn.flux.response.bug; | ||
|
||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.core.convert.ConversionContext; | ||
import io.micronaut.core.convert.TypeConverter; | ||
import jakarta.inject.Singleton; | ||
import java.util.Optional; | ||
import mn.flux.response.bug.model.ResourceName; | ||
|
||
@Factory | ||
public class EnumTypeConverters { | ||
@Singleton | ||
@SuppressWarnings({"unused"}) | ||
public TypeConverter<String, ResourceName> stringToResourceNameConverter() { | ||
return (String object, Class<ResourceName> targetType, ConversionContext context) -> Optional.of(ResourceName.fromValue(object)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/mn/flux/response/bug/RevisionController.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,21 @@ | ||
package mn.flux.response.bug; | ||
|
||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Get; | ||
import io.micronaut.http.annotation.PathVariable; | ||
import lombok.RequiredArgsConstructor; | ||
import mn.flux.response.bug.model.ResourceName; | ||
import reactor.core.publisher.Flux; | ||
|
||
@Controller(RevisionController.REVISION_BASE_URI) | ||
@RequiredArgsConstructor | ||
public class RevisionController { | ||
public static final String REVISION_BASE_URI = "/revision"; | ||
|
||
private final RevisionService revisionService; | ||
|
||
@Get("/{resourceName}/{resourceId}") | ||
public Flux<RevisionDto> getAll(@PathVariable ResourceName resourceName, @PathVariable String resourceId) { | ||
return revisionService.findAllBy(resourceId, resourceName); | ||
} | ||
} |
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,38 @@ | ||
package mn.flux.response.bug; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import io.micronaut.core.annotation.Introspected; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import mn.flux.response.bug.model.PublishStatus; | ||
import mn.flux.response.bug.model.ResourceName; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Introspected | ||
public class RevisionDto { | ||
|
||
@NotBlank | ||
private String resourceId; | ||
|
||
@JsonInclude(Include.NON_NULL) | ||
private UUID id; | ||
|
||
@NotNull | ||
private ResourceName resourceName; | ||
|
||
private Instant date; | ||
|
||
private String comment; | ||
|
||
private PublishStatus revisionStatus; | ||
|
||
private Long revisionNumber; | ||
} |
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,15 @@ | ||
package mn.flux.response.bug; | ||
|
||
import mn.flux.response.bug.model.Revision; | ||
import org.mapstruct.Mapper; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Mapper(componentModel = "jsr330") | ||
public abstract class RevisionMapper { | ||
protected abstract RevisionDto toDto(Revision revision); | ||
|
||
public Flux<RevisionDto> toDto(Flux<Revision> revisions) { | ||
return revisions.flatMap(revision -> Mono.just(toDto(revision))); | ||
} | ||
} |
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,20 @@ | ||
package mn.flux.response.bug; | ||
|
||
import jakarta.inject.Singleton; | ||
import lombok.RequiredArgsConstructor; | ||
import mn.flux.response.bug.model.ResourceName; | ||
import mn.flux.response.bug.repository.RevisionDao; | ||
import reactor.core.publisher.Flux; | ||
|
||
@Singleton | ||
@RequiredArgsConstructor | ||
public class RevisionService { | ||
|
||
private final RevisionMapper revisionMapper; | ||
private final RevisionDao revisionDao; | ||
|
||
public Flux<RevisionDto> findAllBy(String resourceId, ResourceName resourceName) { | ||
return Flux.from(revisionDao.findAllBy(resourceId, resourceName)) | ||
.transform(revisionMapper::toDto); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/mn/flux/response/bug/model/PublishStatus.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,28 @@ | ||
package mn.flux.response.bug.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum PublishStatus { | ||
DRAFT("draft"), | ||
PUBLISHED("published"); | ||
|
||
private final String jsonValue; | ||
|
||
@JsonCreator | ||
public static ResourceName fromValue(String value) { | ||
for (ResourceName contentType : ResourceName.values()) { | ||
if (contentType.getJsonValue().equalsIgnoreCase(value)) { | ||
return contentType; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown ResourceName value"); | ||
} | ||
|
||
@JsonValue | ||
public String getJsonValue() { | ||
return jsonValue; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/mn/flux/response/bug/model/ResourceName.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,30 @@ | ||
package mn.flux.response.bug.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import io.micronaut.core.annotation.Introspected; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Introspected | ||
public enum ResourceName { | ||
ARTICLE("articles"), | ||
VIDEO("videos"); | ||
|
||
private final String jsonValue; | ||
|
||
@JsonCreator | ||
public static ResourceName fromValue(String value) { | ||
for (ResourceName contentType : ResourceName.values()) { | ||
if (contentType.getJsonValue().equalsIgnoreCase(value)) { | ||
return contentType; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown ResourceName value"); | ||
} | ||
|
||
@JsonValue | ||
public String getJsonValue() { | ||
return jsonValue; | ||
} | ||
} |
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,40 @@ | ||
package mn.flux.response.bug.model; | ||
|
||
import com.datastax.oss.driver.api.mapper.annotations.ClusteringColumn; | ||
import com.datastax.oss.driver.api.mapper.annotations.Entity; | ||
import com.datastax.oss.driver.api.mapper.annotations.PartitionKey; | ||
import java.time.Instant; | ||
import java.util.UUID; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class Revision { | ||
|
||
@PartitionKey | ||
private String resourceId; | ||
|
||
@ClusteringColumn(1) | ||
private ResourceName resourceName; | ||
|
||
@ClusteringColumn(2) | ||
private UUID id; | ||
|
||
private UUID userId; | ||
|
||
private Instant date; | ||
|
||
private String comment; | ||
|
||
private String revisionData; | ||
|
||
private PublishStatus revisionStatus; | ||
|
||
private Long revisionNumber; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/mn/flux/response/bug/repository/RepositoryConfig.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,28 @@ | ||
package mn.flux.response.bug.repository; | ||
|
||
import com.datastax.oss.driver.api.core.CqlIdentifier; | ||
import com.datastax.oss.driver.api.core.CqlSession; | ||
import com.datastax.oss.driver.api.core.type.codec.ExtraTypeCodecs; | ||
import com.datastax.oss.driver.api.core.type.codec.registry.MutableCodecRegistry; | ||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.context.annotation.Requirements; | ||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Singleton; | ||
import mn.flux.response.bug.model.PublishStatus; | ||
import mn.flux.response.bug.model.ResourceName; | ||
|
||
@Factory | ||
@Requirements(@Requires(beans = SchemaBootstrap.class)) | ||
public class RepositoryConfig { | ||
|
||
@Singleton | ||
@SuppressWarnings({"unused"}) | ||
public RevisionDao revisionDao(CqlSession cqlSession) { | ||
MutableCodecRegistry registry = (MutableCodecRegistry) cqlSession.getContext().getCodecRegistry(); | ||
registry.register(ExtraTypeCodecs.enumNamesOf(ResourceName.class)); | ||
registry.register(ExtraTypeCodecs.enumNamesOf(PublishStatus.class)); | ||
|
||
RevisionDaoFactory revisionDaoFactory = new RevisionDaoFactoryBuilder(cqlSession).build(); | ||
return revisionDaoFactory.createRevisionDao(CqlIdentifier.fromCql(SchemaBootstrap.KEYSPACE_NAME)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/mn/flux/response/bug/repository/RevisionDao.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,19 @@ | ||
package mn.flux.response.bug.repository; | ||
|
||
import com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet; | ||
import com.datastax.dse.driver.api.mapper.reactive.MappedReactiveResultSet; | ||
import com.datastax.oss.driver.api.mapper.annotations.Dao; | ||
import com.datastax.oss.driver.api.mapper.annotations.Insert; | ||
import com.datastax.oss.driver.api.mapper.annotations.Select; | ||
import mn.flux.response.bug.model.ResourceName; | ||
import mn.flux.response.bug.model.Revision; | ||
|
||
@Dao | ||
public interface RevisionDao { | ||
|
||
@Select(orderBy = {"resource_name ASC", "id DESC"}, limit = ":maxResults") | ||
MappedReactiveResultSet<Revision> findAllBy(String resourceId, ResourceName resourceName); | ||
|
||
@Insert | ||
ReactiveResultSet save(Revision revision); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/mn/flux/response/bug/repository/RevisionDaoFactory.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,14 @@ | ||
package mn.flux.response.bug.repository; | ||
|
||
|
||
import com.datastax.oss.driver.api.core.CqlIdentifier; | ||
import com.datastax.oss.driver.api.mapper.annotations.DaoFactory; | ||
import com.datastax.oss.driver.api.mapper.annotations.DaoKeyspace; | ||
import com.datastax.oss.driver.api.mapper.annotations.Mapper; | ||
|
||
@Mapper | ||
public interface RevisionDaoFactory { | ||
|
||
@DaoFactory | ||
RevisionDao createRevisionDao(@DaoKeyspace CqlIdentifier keyspace); | ||
} |
Oops, something went wrong.