Skip to content

Commit

Permalink
improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich committed Jul 31, 2024
1 parent 4273d10 commit e7eb581
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
],
"scripts": {
"generate:api:clean": "rimraf webapp/src/app/core/modules/openapi",
"generate:api:application-server-specs": "cd server/application-server && mvn verify -DskipTests=true && node ../../scripts/clean-openapi-specs.js",
"generate:api:application-server-client": "npx openapi-generator-cli generate -i server/application-server/openapi.yaml -g typescript-angular -o webapp/src/app/core/modules/openapi --additional-properties fileNaming=kebab-case,withInterfaces=true --generate-alias-as-model",
"generate:api:application-server-specs": "cd server/application-server && mvn verify -DskipTests=true",
"generate:api": "npm run generate:api:clean && npm run generate:api:application-server-client && npm run generate:api:application-server-specs"
},
"devDependencies": {
Expand Down
25 changes: 25 additions & 0 deletions scripts/clean-openapi-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require("fs");
const path = require("path");

const filePath = path.join(__dirname, "../server/application-server/openapi.yaml");

fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
console.error("Error reading the file:", err);
return;
}

const pattern = /tags:\n\s*-\s*.*?-controller\b/g;

// Function to remove '-controller' from the tag
const updatedContent = data.replace(pattern, (match) => {
return match.replace("-controller", "");
});

fs.writeFile(filePath, updatedContent, "utf8", (err) => {
if (err) {
console.error("Error writing the file:", err);
return;
}
});
});
6 changes: 3 additions & 3 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ paths:
/hello:
get:
tags:
- hello-controller
- hello
operationId: getAllHellos
responses:
"200":
Expand All @@ -29,7 +29,7 @@ paths:
$ref: "#/components/schemas/Hello"
post:
tags:
- hello-controller
- hello
operationId: addHello
responses:
"200":
Expand All @@ -41,7 +41,7 @@ paths:
/admin:
get:
tags:
- admin-controller
- admin
operationId: admin
responses:
"200":
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/app/core/modules/openapi/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
.openapi-generator-ignore
README.md
api.module.ts
api/admin-controller.service.ts
api/admin-controller.serviceInterface.ts
api/admin.service.ts
api/admin.serviceInterface.ts
api/api.ts
api/hello-controller.service.ts
api/hello-controller.serviceInterface.ts
api/hello.service.ts
api/hello.serviceInterface.ts
configuration.ts
encoder.ts
git_push.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import { Observable } from 'rxjs';
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { Configuration } from '../configuration';
import {
AdminControllerServiceInterface
} from './admin-controller.serviceInterface';
AdminServiceInterface
} from './admin.serviceInterface';



@Injectable({
providedIn: 'root'
})
export class AdminControllerService implements AdminControllerServiceInterface {
export class AdminService implements AdminServiceInterface {

protected basePath = 'http://localhost';
public defaultHeaders = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Configuration } from '../configurat



export interface AdminControllerServiceInterface {
export interface AdminServiceInterface {
defaultHeaders: HttpHeaders;
configuration: Configuration;

Expand Down
14 changes: 7 additions & 7 deletions webapp/src/app/core/modules/openapi/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './admin-controller.service';
import { AdminControllerService } from './admin-controller.service';
export * from './admin-controller.serviceInterface';
export * from './hello-controller.service';
import { HelloControllerService } from './hello-controller.service';
export * from './hello-controller.serviceInterface';
export const APIS = [AdminControllerService, HelloControllerService];
export * from './admin.service';
import { AdminService } from './admin.service';
export * from './admin.serviceInterface';
export * from './hello.service';
import { HelloService } from './hello.service';
export * from './hello.serviceInterface';
export const APIS = [AdminService, HelloService];
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import { Hello } from '../model/hello';
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { Configuration } from '../configuration';
import {
HelloControllerServiceInterface
} from './hello-controller.serviceInterface';
HelloServiceInterface
} from './hello.serviceInterface';



@Injectable({
providedIn: 'root'
})
export class HelloControllerService implements HelloControllerServiceInterface {
export class HelloService implements HelloServiceInterface {

protected basePath = 'http://localhost';
public defaultHeaders = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Configuration } from '../configurat



export interface HelloControllerServiceInterface {
export interface HelloServiceInterface {
defaultHeaders: HttpHeaders;
configuration: Configuration;

Expand Down
8 changes: 4 additions & 4 deletions webapp/src/app/example/hello/hello.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, inject } from '@angular/core';
import { injectMutation, injectQuery, injectQueryClient } from '@tanstack/angular-query-experimental';
import { AngularQueryDevtools } from '@tanstack/angular-query-devtools-experimental'
import { lastValueFrom } from 'rxjs';
import { HelloControllerService } from 'app/core/modules/openapi';
import { HelloService } from 'app/core/modules/openapi';
import { AppButtonComponent } from 'app/ui/button/button/button.component';

@Component({
Expand All @@ -12,17 +12,17 @@ import { AppButtonComponent } from 'app/ui/button/button/button.component';
templateUrl: './hello.component.html'
})
export class PokemonComponent {
helloControllerService = inject(HelloControllerService)
helloService = inject(HelloService)
queryClient = injectQueryClient()

query = injectQuery(() => ({
queryKey: ['hellos'],
queryFn: async () => lastValueFrom(this.helloControllerService.getAllHellos()),
queryFn: async () => lastValueFrom(this.helloService.getAllHellos()),
})
);

mutation = injectMutation(() => ({
mutationFn: () => lastValueFrom(this.helloControllerService.addHello()),
mutationFn: () => lastValueFrom(this.helloService.addHello()),
onSuccess: () =>
this.queryClient.invalidateQueries({
queryKey: ['hellos'],
Expand Down

0 comments on commit e7eb581

Please sign in to comment.