Skip to content

Commit

Permalink
fix: solved mutation hook api v5
Browse files Browse the repository at this point in the history
  • Loading branch information
melistik committed Apr 16, 2024
1 parent 793a220 commit 80d2445
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
// Generated using typescript-generator version 3.1.1185 on 2023-02-27 14:28:43.
// Generated using typescript-generator version 3.2.1263 on 2024-04-16 18:09:05.

export interface Activity {
type: "comment" | "dossier";
id: string;
dated: Date;
user: string;
type: "comment" | "dossier";
id: string;
dated: string;
user: string;
}

export interface CommentActivity extends Activity {
type: "comment";
comment: string;
attachments: string[];
type: "comment";
comment: string;
attachments: string[];
}

export interface PermissionCmd {
objectId: string;
identityIds: string[];
permissionId: number;
}

export interface RecommendationActivity extends Activity {
type: "dossier";
objectId: string;
objectTitle: string;
message: string;
type: "dossier";
objectId: string;
objectTitle: string;
message: string;
}

export interface Tile {
id: string;
type: TileType;
name: string;
description: string;
commentCount: number;
itemCount: number;
userPreference: UserPreference;
created: Date;
lastModified: Date;
id: string;
type: TileType;
name: string;
description: string;
commentCount: number;
itemCount: number;
userPreference: UserPreference;
created: string;
lastModified: string;
}

export type TileType = "search-config" | "pinboard" | "briefing" | "showroom";
export type ActivityUnion = CommentActivity | RecommendationActivity;

export type UserPreference = "favored" | "disfavored";
export enum TileType {
SEARCH_CONFIG = "search-config",
PINBOARD = "pinboard",
BRIEFING = "briefing",
SHOWROOM = "showroom",
}

export type ActivityUnion = CommentActivity | RecommendationActivity;
export enum UserPreference {
FAVORED = "favored",
DISFAVORED = "disfavored",
}
98 changes: 98 additions & 0 deletions commons-rest-openapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-spring</artifactId>
<version>3.2.1263</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
Expand All @@ -56,5 +62,97 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rocketbase.commons</groupId>
<artifactId>commons-rest-tsid</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-tsid</artifactId>
<version>${hypersistence-tsid.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<!--
<build>
<plugins>
<plugin>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>${typescript-generator.version}</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<jsonLibrary>jackson2</jsonLibrary>
<optionalAnnotations>
<optionalAnnotation>jakarta.annotation.Nullable</optionalAnnotation>
</optionalAnnotations>
<optionalProperties>useSpecifiedAnnotations</optionalProperties>
<classPatterns>
<classPattern>io.rocketbase.commons.sample.dto.**</classPattern>
</classPatterns>
<excludeClassPatterns>
<excludeClassPattern>**Builder</excludeClassPattern>
<excludeClassPattern>**BuilderImpl</excludeClassPattern>
<excludeClassPattern>**Deserializer</excludeClassPattern>
<excludeClassPattern>**Serializer</excludeClassPattern>
<excludeClassPattern>**Exception</excludeClassPattern>
<excludeClassPattern>**Visitor</excludeClassPattern>
<excludeClassPattern>org.springframework.boot.autoconfigure.**</excludeClassPattern>
</excludeClassPatterns>
<excludeClasses>
<excludeClass>java.io.Serializable</excludeClass>
<excludeClass>java.lang.Iterable</excludeClass>
</excludeClasses>
<customTypeMappings>
<customTypeMapping>java.net.URL:string</customTypeMapping>
<customTypeMapping>io.hypersistence.tsid.TSID:string</customTypeMapping>
<customTypeMapping>java.time.LocalDate:string</customTypeMapping>
<customTypeMapping>java.time.LocalTime:string</customTypeMapping>
<customTypeMapping>java.time.LocalDateTime:string</customTypeMapping>
<customTypeMapping>java.time.Instant:string</customTypeMapping>
<customTypeMapping><![CDATA[java.util.Map<K,V>:Record<K,V>]]></customTypeMapping>
<customTypeMapping>io.rocketbase.commons.obfuscated.ObfuscatedId:rest.ObfuscatedId
</customTypeMapping>
<customTypeMapping>io.rocketbase.commons.dto.ErrorResponse:rest.ErrorResponse
</customTypeMapping>
<customTypeMapping>
<![CDATA[io.rocketbase.commons.dto.PageableResult<E>:rest.PageableResult<E>]]></customTypeMapping>
<customTypeMapping>io.rocketbase.commons.dto.address.AddressDto:rest.AddressDto
</customTypeMapping>
<customTypeMapping>io.rocketbase.commons.dto.address.ContactDto:rest.ContactDto
</customTypeMapping>
<customTypeMapping>io.rocketbase.commons.dto.address.Gender:rest.Gender</customTypeMapping>
<customTypeMapping>io.rocketbase.commons.translation.Translation:rest.Translation
</customTypeMapping>
</customTypeMappings>
<outputFileType>implementationFile</outputFileType>
<outputFile>${project.build.directory}/typescript-generator/openapi.ts</outputFile>
<outputKind>module</outputKind>
<mapEnum>asEnum</mapEnum>
<nonConstEnums>true</nonConstEnums>
<noEslintDisable>true</noEslintDisable>
<noTslintDisable>true</noTslintDisable>
</configuration>
<dependencies>
<dependency>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-spring</artifactId>
<version>${typescript-generator.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
-->
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export function {{ method.hookName -}}<TData = {{ method.shortReturnType }}, {{
mutationFn: ({% if not method.isVoidShortInputType %}content{% endif %}) => {{ configuredGroupVar -}}.{{- controller.fieldName -}}.{{- method.methodName -}}({% if method.isVoidShortInputType %} {} {% else %} content {% endif %}),
{% if method.invalidateKeysPrepared('content.', 'data.') is not empty %}
onSuccess: async (data, content, context) => {
const invalide = async () => await Promise.all([{% for ik in method.invalidateKeysPrepared('content.', 'data.') %}queryClient.invalidateQueries([{% for k in ik %}`{{ k }}`{% if not loop.last %}, {% endif %}{% endfor %}]){% if not loop.last %}, {% endif %}{% endfor %}]);
const invalide = async () => await Promise.all([{% for ik in method.invalidateKeysPrepared('content.', 'data.') %}
queryClient.invalidateQueries(
{% if reactQueryVersion.name equals "v5" %}{queryKey: [{% for k in ik %}`{{ k }}`{% if not loop.last %}, {% endif %}{% endfor %}]}
{% else %}[{% for k in ik %}`{{ k }}`{% if not loop.last %}, {% endif %}{% endfor %}]{% endif %}
){% if not loop.last %}, {% endif %}{% endfor %}]);

if (onSuccess) {
const result = onSuccess(data, content, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.rocketbase.commons.openapi.sample.dto;

import io.hypersistence.tsid.TSID;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.Set;

@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class PermissionCmd {

@NotNull
protected TSID objectId;

@Size(min = 1)
protected Set<TSID> identityIds;

@NotNull
protected Short permissionId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.rocketbase.commons.openapi.sample.resource;

import io.rocketbase.commons.generator.MutationHook;
import io.rocketbase.commons.openapi.sample.dto.PermissionCmd;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

@SecurityRequirement(name = "OAuth2", scopes = {"user"})
@Tag(name = "permissionCommand", description = "create or update object's permissions")
public interface PermissionApi {

@MutationHook(invalidateKeys = {"element,detail,${body.objectId}", "activities,${body.objectId}"})
@Operation(description = "add/update permission for a set of identities")
@PutMapping(value = {"/element/set-permission"}, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
ResponseEntity<Void> setPermission(@Valid @NotNull @RequestBody PermissionCmd cmd);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.rocketbase.commons.openapi.sample.resource;

import io.rocketbase.commons.openapi.sample.dto.PermissionCmd;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PermissionController implements PermissionApi {
@Override
public ResponseEntity<Void> setPermission(PermissionCmd cmd) {
return null;
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SOFTWARE.
<lombok.version>1.18.32</lombok.version>
<swagger-annotations.version>2.2.21</swagger-annotations.version>
<hypersistence-tsid.version>2.1.1</hypersistence-tsid.version>
<typescript-generator.version>3.2.1263</typescript-generator.version>
</properties>

<dependencyManagement>
Expand Down

0 comments on commit 80d2445

Please sign in to comment.