-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[759]Create webhook #822
Merged
Merged
[759]Create webhook #822
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c6df056
[759]Create webhook
thinhpham-nashtech e09344a
Create webhook
minhtranq-nashtechglobal 8ea3fea
Fix comment
thinhpham-nashtech ddeba51
Fix comment
thinhpham-nashtech 9616ef4
Fix comment
thinhpham-nashtech 7ea1312
#759 Create webhook
minhtranq-nashtechglobal c81468b
#759 Create webhook
minhtranq-nashtechglobal 22faeff
Fix comment
thinhpham-nashtech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,59 @@ | ||
name: webhook service ci | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
paths: | ||
- "webhook/**" | ||
- ".github/workflows/actions/action.yaml" | ||
- ".github/workflows/webhook-ci.yaml" | ||
- "pom.xml" | ||
pull_request: | ||
branches: ["main"] | ||
paths: | ||
- "webhook/**" | ||
- ".github/workflows/actions/action.yaml" | ||
- ".github/workflows/webhook-ci.yaml" | ||
- "pom.xml" | ||
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: Webhook-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
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
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); | ||
listCheckEvent = []; | ||
if (events !== undefined && latestCheckedEvent.length === 0) { | ||
events.map((item: any) => { | ||
listCheckEvent.push(item); | ||
}); | ||
setLatestCheckedEvent(listCheckEvent); | ||
} | ||
}); | ||
}, []); | ||
|
||
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]); | ||
listCheckEvent = [webhookEvent, ...latestCheckedEvent]; | ||
} | ||
} else { | ||
latestCheckedEvent = latestCheckedEvent.filter((item) => item.id !== checkedEventId); | ||
listCheckEvent = Array.from(new Set(latestCheckedEvent)); | ||
setLatestCheckedEvent(listCheckEvent); | ||
} | ||
setValue('events', listCheckEvent); | ||
}; | ||
|
||
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; |
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
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,9 @@ | ||
import { WebhookEvent } from '../models/Event'; | ||
import apiClientService from '@commonServices/ApiClientService'; | ||
|
||
const baseUrl = '/api/webhook/backoffice/events'; | ||
|
||
export async function getEvents(): Promise<WebhookEvent[]> { | ||
const response = await fetch('/api/webhook/backoffice/events'); | ||
return (await apiClientService.get(baseUrl)).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,32 @@ | ||
import { Webhook } from '../models/Webhook'; | ||
import apiClientService from '@commonServices/ApiClientService'; | ||
|
||
const baseUrl = '/api/webhook/backoffice/webhooks'; | ||
|
||
export async function getWebhooks(pageNo: number, pageSize: number) { | ||
const url = `${baseUrl}/paging?pageNo=${pageNo}&pageSize=${pageSize}`; | ||
return (await apiClientService.get(url)).json(); | ||
} | ||
|
||
export async function createWebhook(webhook: Webhook) { | ||
return await apiClientService.post(baseUrl, JSON.stringify(webhook)); | ||
} | ||
|
||
export async function getWebhook(id: number) { | ||
const url = `${baseUrl}/${id}`; | ||
return (await apiClientService.get(url)).json(); | ||
} | ||
|
||
export async function deleteWebhook(id: number) { | ||
const url = `${baseUrl}/${id}`; | ||
const response = await apiClientService.delete(url); | ||
if (response.status === 204) return response; | ||
else return await response.json(); | ||
} | ||
|
||
export async function updateWebhook(id: number, webhook: Webhook) { | ||
const url = `${baseUrl}/${id}`; | ||
const response = await apiClientService.put(url, JSON.stringify(webhook)); | ||
if (response.status === 204) return response; | ||
else return await response.json(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add - "pom.xml"