Skip to content

Commit

Permalink
Implemented: apis should use plurals #183
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed Jan 14, 2025
1 parent ade6ccf commit 9308027
Show file tree
Hide file tree
Showing 94 changed files with 203 additions and 178 deletions.
2 changes: 1 addition & 1 deletion app/components/ving/Dropzone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import '../node_modules/dropzone/dist/dropzone.css'
Dropzone.autoDiscover = false;
const getSignedURL = async (file) => {
const response = await useRest(`/api/${useRestVersion()}/s3file?includeMeta=true`, {
const response = await useRest(`/api/${useRestVersion()}/s3files?includeMeta=true`, {
method: 'POST', body: {
contentType: file.type,
filename: file.name,
Expand Down
4 changes: 2 additions & 2 deletions app/composables/ving/useAdminLinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
export default () => {
const links = computed(() => {
const out = [
{ label: 'Cron Jobs', to: '/cronjob', icon: 'ph:clock' },
{ label: 'Cron Jobs', to: '/cronjobs', icon: 'ph:clock' },
{ label: 'System Wide Alert', to: '/system-wide-alert', icon: 'ph:megaphone' },
{ label: 'Users', to: '/user/admin', icon: 'ph:users' },
{ label: 'Users', to: '/users/admin', icon: 'ph:users' },
];
return out;
});
Expand Down
8 changes: 4 additions & 4 deletions app/composables/ving/useCurrentUser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { isUndefined } from '#ving/utils/identify.mjs';

export const useCurrentUser = () => useVingRecord({
id: 'currentUser',
fetchApi: `/api/${useRestVersion()}/user/whoami`,
createApi: `/api/${useRestVersion()}/user`,
fetchApi: `/api/${useRestVersion()}/users/whoami`,
createApi: `/api/${useRestVersion()}/users`,
query: { includeOptions: true, includeMeta: true, includeLinks: true },
extendedActions: {
async login(login, password) {
const response = await useRest(`/api/${useRestVersion()}/session`, {
const response = await useRest(`/api/${useRestVersion()}/sessions`, {
method: 'post',
body: {
login,
Expand All @@ -24,7 +24,7 @@ export const useCurrentUser = () => useVingRecord({
},

async logout() {
const response = await useRest(`/api/${useRestVersion()}/session`, {
const response = await useRest(`/api/${useRestVersion()}/sessions`, {
method: 'delete',
});
this.setState({});
Expand Down
2 changes: 1 addition & 1 deletion app/composables/ving/useMessageBus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function useMessageBus() {
const reconnect = () => setTimeout(tryToSetup, wait);

const setupBusHandler = () => {
bus = new EventSource(`/api/${useRestVersion()}/user/messagebus`);
bus = new EventSource(`/api/${useRestVersion()}/users/messagebus`);
bus.onmessage = (event) => {
const message = JSON.parse(event.data);
switch (message.type) {
Expand Down
2 changes: 1 addition & 1 deletion app/composables/ving/useRest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* The `error` is `null` unless there is an error, and the `data` contains an object response from the endpoint.
* @example
* const response = await useRest('/api/v1/user/xxx')
* const response = await useRest('/api/v1/users/xxx')
*/
export default async function (url, behavior = {}) {
const notify = useNotify();
Expand Down
2 changes: 1 addition & 1 deletion app/composables/ving/useUserSettingsButtons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default () => {
const currentUser = useCurrentUser();
const buttons = computed(() => {
const out = [
{ label: 'Sign Out', to: '/user/logout', icon: 'ph:door', severity: 'primary' },
{ label: 'Sign Out', to: '/users/logout', icon: 'ph:door', severity: 'primary' },
];
if (currentUser.props?.admin)
out.push({ label: 'Admin', to: '/admin', icon: 'ph:users', severity: 'secondary' });
Expand Down
8 changes: 4 additions & 4 deletions app/composables/ving/useUserSettingsLinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export default () => {
const currentUser = useCurrentUser();
const links = computed(() => {
const out = [
{ label: 'Profile', to: '/user/settings', icon: 'ph:user' },
{ label: 'Account', to: '/user/settings/account', icon: 'ph:key' },
{ label: 'Preferences', to: '/user/settings/preferences', icon: 'ph:sliders' },
{ label: 'Profile', to: '/users/settings', icon: 'ph:user' },
{ label: 'Account', to: '/users/settings/account', icon: 'ph:key' },
{ label: 'Preferences', to: '/users/settings/preferences', icon: 'ph:sliders' },
];
if (currentUser?.props?.developer == true)
out.push({ label: 'API Keys', to: '/user/settings/apikeys', icon: 'ph:lock' });
out.push({ label: 'API Keys', to: '/users/settings/apikeys', icon: 'ph:lock' });
return out;
});
return links;
Expand Down
2 changes: 1 addition & 1 deletion app/composables/ving/useVingKind.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class VingKind {
* @param {object} options Modify the behavior of this call.
* @returns {Promise<object>} A promise containing the response to the call.
* @example
* const result = Users.call('post', '/user/xxx/send-reset-password', {os:'Windows'});
* const result = Users.call('post', '/users/xxx/send-reset-password', {os:'Windows'});
*/
async call(method, url, query = {}, options = {}) {
const response = await useRest(url, {
Expand Down
4 changes: 2 additions & 2 deletions app/composables/ving/useVingRecord.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import { isObject, isUndefined } from '#ving/utils/identify.mjs';
* @example
* const user = useVingRecord({
* id : 'xxx',
* fetchApi: '/api/v1/user/xxx',
* createApi: '/api/v1/user',
* fetchApi: '/api/v1/users/xxx',
* createApi: '/api/v1/users',
* query : { includeMeta : true },
* });
* await user.fetch();
Expand Down
8 changes: 4 additions & 4 deletions app/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<InputText placeholder="Search (non-functional)" type="text" class="w-8rem sm:w-auto" />
</InputGroup>
<SplitButton v-if="currentUser.props?.id" :model="userMenu" text>
<NuxtLink to="/user/settings" class="flex items-center">
<NuxtLink to="/users/settings" class="flex items-center">
<Avatar :image="currentUser.links?.avatarImage?.href" alt="user avatar" shape="circle" />
<span class="ml-2">
{{ currentUser.meta?.displayName }}
Expand All @@ -41,7 +41,7 @@
</NuxtLink>
</template>
</SplitButton>
<NuxtLink v-else to="/user/login" class="flex p-3 items-center text-nowrap">
<NuxtLink v-else to="/users/login" class="flex p-3 items-center text-nowrap">
<Icon name="fa6-solid:door-open" class="mr-2" />
Sign In
</NuxtLink>
Expand Down Expand Up @@ -82,8 +82,8 @@ const topNav = [
const userMenu = computed(() => {
const out = [
{ label: 'Settings', to: '/user/settings', icon: 'fa6-solid:sliders' },
{ label: 'Sign Out', to: '/user/logout', icon: 'fa6-solid:door-closed' },
{ label: 'Settings', to: '/users/settings', icon: 'fa6-solid:sliders' },
{ label: 'Sign Out', to: '/users/logout', icon: 'fa6-solid:door-closed' },
];
if (currentUser.props.admin)
out.unshift({ label: 'Admin', to: '/admin', icon: 'prime:user-plus' });
Expand Down
6 changes: 3 additions & 3 deletions app/middleware/auth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
const currentUser = useCurrentUser();
const isAuthenticated = await currentUser.isAuthenticated();
if (!isAuthenticated) {
return await navigateTo(`/user/login?redirectAfter=${to.fullPath}`);
return await navigateTo(`/users/login?redirectAfter=${to.fullPath}`);
}
else if (!currentUser.props?.verifiedEmail) {
if (to.fullPath != '/user/logout') {
return await navigateTo(`/user/must-verify-email?redirectAfter=${to.fullPath}`);
if (to.fullPath != '/users/logout') {
return await navigateTo(`/users/must-verify-email?redirectAfter=${to.fullPath}`);
}
}
});
2 changes: 1 addition & 1 deletion app/pages/admin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

</template>
<script setup>
navigateTo('/user/admin');
navigateTo('/users/admin');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const notify = useNotify();
const id = route.params.id.toString();
const cronjob = useVingRecord({
id,
fetchApi: `/api/${useRestVersion()}/cronjob/${id}`,
createApi: `/api/${useRestVersion()}/cronjob`,
fetchApi: `/api/${useRestVersion()}/cronjobs/${id}`,
createApi: `/api/${useRestVersion()}/cronjobs`,
query: { includeMeta: true, includeOptions: true },
onUpdate() {
notify.success('Updated Cron Job.');
Expand Down
7 changes: 5 additions & 2 deletions app/pages/cronjob/index.vue → app/pages/cronjobs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ definePageMeta({
middleware: ['auth', 'admin']
});
const cronjobs = useVingKind({
listApi: `/api/${useRestVersion()}/cronjob`,
createApi: `/api/${useRestVersion()}/cronjob`,
listApi: `/api/${useRestVersion()}/cronjobs`,
createApi: `/api/${useRestVersion()}/cronjobs`,
query: { includeMeta: true, sortBy: 'schedule', sortOrder: 'asc' },
newDefaults: { schedule: '* * * * *', handler: 'Test', enabled: true },
onCreate(props) {
navigateTo(props.links.edit.href)
},
});
await Promise.all([
cronjobs.search(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
const route = useRoute();
const user = useVingRecord({
fetchApi: `/api/${useRestVersion()}/user/${route.params.id}`,
createApi: `/api/${useRestVersion()}/user`,
fetchApi: `/api/${useRestVersion()}/users/${route.params.id}`,
createApi: `/api/${useRestVersion()}/users`,
query: { includeMeta: true, includeOptions: true },
});
await user.fetch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img :src="config.public.site.logoUrl" :alt="config.public.site.name" height="50" class="mb-3">
<h1 class="text-900 text-3xl font-medium mb-3 mt-0">Reset Password</h1>
<span class="text-600 font-medium line-height-3">Remember your account?</span>
<NuxtLink to="/user/login" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Sign in
<NuxtLink to="/users/login" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Sign in
</NuxtLink>
</div>
<PanelZone>
Expand Down Expand Up @@ -41,14 +41,14 @@ const config = useRuntimeConfig();
const notify = useNotify();
async function resetPassword() {
notify.info('Please wait while we reset your password...');
const response = await useRest(`/api/${useRestVersion()}/user/${route.params.id}/reset-password`, {
const response = await useRest(`/api/${useRestVersion()}/users/${route.params.id}/reset-password`, {
method: 'post',
query: { includeOptions: true },
body: { code: newPassword.code, password: newPassword.password },
});
if (!response.error) {
notify.success('Password changed.');
await navigateTo('/user/login');
await navigateTo('/users/login');
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const notify = useNotify();
const id = route.params.id.toString();
const user = useVingRecord({
id,
fetchApi: `/api/${useRestVersion()}/user/${id}`,
createApi: `/api/${useRestVersion()}/user`,
fetchApi: `/api/${useRestVersion()}/users/${id}`,
createApi: `/api/${useRestVersion()}/users`,
query: { includeMeta: true, includeOptions: true },
onUpdate() {
notify.success('Updated user.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ definePageMeta({
});
const users = useVingKind({
listApi: `/api/${useRestVersion()}/user`,
createApi: `/api/${useRestVersion()}/user`,
listApi: `/api/${useRestVersion()}/users`,
createApi: `/api/${useRestVersion()}/users`,
query: { includeMeta: true, sortBy: 'username', sortOrder: 'asc' },
newDefaults: { username: '', realName: '', email: '' },
onCreate(props) {
navigateTo(props.links.edit.href)
},
});
await users.search();
Expand Down
2 changes: 1 addition & 1 deletion app/pages/user/create.vue → app/pages/users/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img :src="config.public.site.logoUrl" :alt="config.public.site.name" class="inline-block h-16 mb-3">
<h1 class="text-900 text-3xl font-medium mb-3 mt-0">Create an Account</h1>
<span class="text-600 font-medium line-height-3">Already have an account?</span>
<NuxtLink to="/user/login" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Sign in
<NuxtLink to="/users/login" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Sign in
</NuxtLink>
</div>
<PanelZone>
Expand Down
4 changes: 2 additions & 2 deletions app/pages/user/login.vue → app/pages/users/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img :src="config.public.site.logoUrl" :alt="config.public.site.name" class="inline-block h-16 mb-3">
<h1 class="text-900 text-3xl font-medium mb-3 mt-0">Welcome Back</h1>
<span class="text-600 font-medium line-height-3">Don't have an account?</span>
<NuxtLink to="/user/create" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Create one today!
<NuxtLink to="/users/create" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Create one today!
</NuxtLink>
</div>
<PanelZone>
Expand All @@ -22,7 +22,7 @@

<div class="mt-3">
<span class="text-600 font-medium line-height-3">Forgot your password?</span>
<NuxtLink to="/user/reset-password" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Reset
<NuxtLink to="/users/reset-password" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Reset
your
password.
</NuxtLink>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<img :src="config.public.site.logoUrl" :alt="config.public.site.name" class="inline-block h-16 mb-3">
<h1 class="text-900 text-3xl font-medium mb-3 mt-0">Send Password Reset</h1>
<span class="text-600 font-medium line-height-3">Remember your account?</span>
<NuxtLink to="/user/login" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Sign in
<NuxtLink to="/users/login" class="font-medium no-underline ml-2 text-blue-500 cursor-pointer">Sign in
</NuxtLink>
</div>
<PanelZone info="Where should we send the password reset email?">
Expand Down Expand Up @@ -33,7 +33,7 @@ const email = ref('')
const notify = useNotify();
async function sendPasswordReset() {
const parser = new ua(navigator.userAgent);
const response = await useRest(`/api/${useRestVersion()}/user/send-password-reset`, {
const response = await useRest(`/api/${useRestVersion()}/users/send-password-reset`, {
method: 'post',
query: { includeOptions: true },
body: { browser: parser.getBrowser().name, os: parser.getOS().name, email: email.value }
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const links = useUserSettingsLinks();
const buttons = useUserSettingsButtons();
const apikeys = useVingKind({
listApi: currentUser.links?.apikeys.href,
createApi: `/api/${useRestVersion()}/apikey`,
createApi: `/api/${useRestVersion()}/apikeys`,
query: { includeMeta: true, sortBy: 'name', sortOrder: 'asc' },
newDefaults: { name: 'My New API Key', reason: '', url: 'http://', userId: currentUser.props?.id },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<FormInput type="markdown" @change="currentUser.save('bio')" label="Bio" v-model="currentUser.props.bio" name="bio" class="mb-4" />

<NuxtLink :to="'/user/' + currentUser.props.id + '/profile'">
<NuxtLink :to="currentUser.links.profile.href">
View your profile as others see it
</NuxtLink>
</PanelZone>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (await currentUser.isAuthenticated()) {
}
}
else {
await navigateTo('/user/login')
await navigateTo('/users/login')
}
</script>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9308027

Please sign in to comment.