-
Notifications
You must be signed in to change notification settings - Fork 416
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
642cc92
commit 1272e4a
Showing
81 changed files
with
2,461 additions
and
4 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,58 @@ | ||
name: webhook service ci | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
paths: | ||
- "webhook/**" | ||
- ".github/workflows/actions/action.yaml" | ||
- ".github/workflows/webhook-ci.yaml" | ||
pull_request: | ||
branches: ["main"] | ||
paths: | ||
- "webhook/**" | ||
- ".github/workflows/actions/action.yaml" | ||
- ".github/workflows/webhook-ci.yaml" | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
Build: | ||
runs-on: ubuntu-latest | ||
env: | ||
FROM_ORIGINAL_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name == github.repository || github.ref == 'refs/heads/main' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
- uses: ./.github/workflows/actions | ||
- name: Run Maven Build Command | ||
run: mvn clean install -DskipTests -f webhook | ||
- name: Run Maven Test | ||
run: mvn test -f webhook | ||
- name: Unit Test Results | ||
uses: dorny/test-reporter@v1 | ||
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' && (success() || failure()) }} | ||
with: | ||
name: Tax-Service-Unit-Test-Results | ||
path: "webhook/**/surefire-reports/*.xml" | ||
reporter: java-junit | ||
- name: Analyze with sonar cloud | ||
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }} | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
run: mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -f webhook | ||
- name: Log in to the Container registry | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and push Docker images | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ./webhook | ||
push: true | ||
tags: ghcr.io/nashtech-garage/yas-webhook:latest |
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
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
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
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
84 changes: 84 additions & 0 deletions
84
backoffice/modules/webhook/components/EventInformation.tsx
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,84 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { UseFormGetValues, UseFormSetValue } from 'react-hook-form'; | ||
|
||
import { WebhookEvent } from '@webhookModels/Event'; | ||
import { Webhook } from '@webhookModels/Webhook'; | ||
import { getEvents } from '@webhookServices/EventService'; | ||
|
||
type Props = { | ||
events?: WebhookEvent[]; | ||
setValue: UseFormSetValue<Webhook>; | ||
getValue: UseFormGetValues<Webhook>; | ||
}; | ||
|
||
const EventInformation = ({ events, setValue, getValue: _getValue }: Props) => { | ||
const [allEvents, setAllEvents] = useState<WebhookEvent[]>([]); | ||
let [latestCheckedEvent, setLatestCheckedEvent] = useState<WebhookEvent[]>([]); | ||
let listCheckEvent: WebhookEvent[] = []; | ||
|
||
useEffect(() => { | ||
getEvents().then((data) => { | ||
setAllEvents(data); | ||
if (events !== undefined && latestCheckedEvent.length === 0) { | ||
events.map((item: any) => { | ||
latestCheckedEvent.push(item); | ||
}); | ||
setLatestCheckedEvent(latestCheckedEvent); | ||
} | ||
}); | ||
}, []); | ||
|
||
function checkedTrue(id: number) { | ||
const found = latestCheckedEvent.find((element) => element.id === id); | ||
if (found === undefined) return false; | ||
return true; | ||
} | ||
|
||
const onUpdateCheckedEvent = (e: any) => { | ||
const checkedEventId = Number(e.target.value); | ||
if (e.target.checked) { | ||
const webhookEvent = allEvents.find((element) => element.id === checkedEventId); | ||
if (webhookEvent !== undefined) { | ||
setLatestCheckedEvent([webhookEvent, ...latestCheckedEvent]); | ||
latestCheckedEvent = [webhookEvent, ...latestCheckedEvent]; | ||
} | ||
} else { | ||
latestCheckedEvent = latestCheckedEvent.filter((item) => item.id !== checkedEventId); | ||
setLatestCheckedEvent(latestCheckedEvent); | ||
} | ||
setValue('events', latestCheckedEvent); | ||
}; | ||
|
||
return ( | ||
<div className="choice-event"> | ||
<ul style={{ listStyleType: 'none' }}> | ||
{allEvents.map((event, index) => ( | ||
<li key={event.id}> | ||
<input | ||
value={event.id || ''} | ||
type="checkbox" | ||
name="event" | ||
checked={checkedTrue(event.id) === true ? true : false} | ||
id={`checkbox-${event.id}`} | ||
onChange={onUpdateCheckedEvent} | ||
/> | ||
<label | ||
htmlFor={`checkbox-${event.id}`} | ||
style={{ | ||
paddingLeft: '15px', | ||
fontSize: '1rem', | ||
paddingTop: '10px', | ||
paddingBottom: '5px', | ||
}} | ||
> | ||
{' '} | ||
{event.name} | ||
</label> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EventInformation; |
47 changes: 47 additions & 0 deletions
47
backoffice/modules/webhook/components/WebhookInformation.tsx
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,47 @@ | ||
import { FieldErrorsImpl, UseFormRegister, UseFormSetValue, UseFormTrigger } from 'react-hook-form'; | ||
import { CheckBox } from 'common/items/Input'; | ||
import { Input } from 'common/items/Input'; | ||
import { Webhook } from '../models/Webhook'; | ||
import { ContentType } from '@webhookModels/ContentType'; | ||
|
||
type Props = { | ||
register: UseFormRegister<Webhook>; | ||
errors: FieldErrorsImpl<Webhook>; | ||
setValue: UseFormSetValue<Webhook>; | ||
trigger: UseFormTrigger<Webhook>; | ||
webhook?: Webhook; | ||
}; | ||
|
||
const WebhookInformation = ({ register, errors, setValue, trigger, webhook }: Props) => { | ||
|
||
return ( | ||
<> | ||
<Input | ||
labelText="Payload URL" | ||
field="payloadUrl" | ||
defaultValue={webhook?.payloadUrl} | ||
register={register} | ||
registerOptions={{ | ||
required: { value: true, message: 'Payload URL is required' }, | ||
}} | ||
error={errors.payloadUrl?.message} | ||
/> | ||
<Input | ||
labelText="Content Type" | ||
field="contentType" | ||
defaultValue={ContentType.APPLICATION_JSON} | ||
register={register} | ||
disabled={true} | ||
/> | ||
<Input labelText="Secret" field="secret" defaultValue={webhook?.secret} register={register} /> | ||
<CheckBox | ||
labelText="Active" | ||
field="isActive" | ||
register={register} | ||
defaultChecked={webhook?.isActive} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default WebhookInformation; |
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,3 @@ | ||
export enum ContentType { | ||
APPLICATION_JSON = 'application/json' | ||
} |
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,4 @@ | ||
export type WebhookEvent = { | ||
id: number; | ||
name: string; | ||
}; |
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,10 @@ | ||
import { WebhookEvent } from "./Event"; | ||
|
||
export type Webhook = { | ||
id: number; | ||
payloadUrl: string; | ||
secret: string; | ||
contentType: string; | ||
isActive: boolean; | ||
events: WebhookEvent[]; | ||
}; |
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,7 @@ | ||
import { WebhookEvent } from '../models/Event'; | ||
|
||
|
||
export async function getEvents(): Promise<WebhookEvent[]> { | ||
const response = await fetch('/api/webhook/backoffice/events'); | ||
return await response.json(); | ||
} |
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 @@ | ||
import { Webhook } from '../models/Webhook'; | ||
|
||
export async function getWebhooks(pageNo: number, pageSize: number) { | ||
const url = `/api/webhook/backoffice/webhooks/paging?pageNo=${pageNo}&pageSize=${pageSize}`; | ||
const response = await fetch(url); | ||
return await response.json(); | ||
} | ||
|
||
export async function getWebhook(id: number): Promise<Webhook> { | ||
const response = await fetch('/api/webhook/backoffice/webhooks/' + id); | ||
return await response.json(); | ||
} | ||
|
||
export async function createWebhook(webhook: Webhook) { | ||
const response = await fetch('/api/webhook/backoffice/webhooks', { | ||
method: 'POST', | ||
body: JSON.stringify(webhook), | ||
headers: { 'Content-type': 'application/json; charset=UTF-8' }, | ||
}); | ||
return response; | ||
} | ||
export async function updateWebhook(id: number, webhook: Webhook) { | ||
const response = await fetch('/api/webhook/backoffice/webhooks/' + id, { | ||
method: 'PUT', | ||
body: JSON.stringify(webhook), | ||
headers: { 'Content-type': 'application/json; charset=UTF-8' }, | ||
}); | ||
if (response.status === 204) return response; | ||
else return await response.json(); | ||
} | ||
export async function deleteWebhook(id: number) { | ||
const response = await fetch('/api/webhook/backoffice/webhooks/' + id, { | ||
method: 'DELETE', | ||
headers: { 'Content-type': 'application/json; charset=UTF-8' }, | ||
}); | ||
if (response.status === 204) return response; | ||
else return await response.json(); | ||
} |
Oops, something went wrong.