mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2026-01-16 11:32:26 +01:00
Merge branch '9-prof-calendars-with-oauth2-login-2' into 'development'
Resolve "prof calendars with oauth2 login" See merge request htwk-software/htwkalender!132
This commit is contained in:
@@ -42,22 +42,25 @@ services:
|
||||
build:
|
||||
dockerfile: Dockerfile
|
||||
context: ./frontend
|
||||
target: prod
|
||||
target: dev
|
||||
args:
|
||||
- COMMIT_HASH=${COMMIT_HASH}
|
||||
# open port 8000
|
||||
volumes:
|
||||
- ./frontend/src/:/app/src
|
||||
- ./frontend/public/:/app/public
|
||||
ports:
|
||||
- "8000:8000"
|
||||
|
||||
rproxy:
|
||||
image: docker.io/bitnami/nginx:1.28
|
||||
image: docker.io/bitnami/nginx:latest
|
||||
volumes:
|
||||
- ./reverseproxy.local.conf:/opt/bitnami/nginx/conf/nginx.conf
|
||||
depends_on:
|
||||
- htwkalender-data-manager
|
||||
- htwkalender-frontend
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "80:80"
|
||||
|
||||
volumes:
|
||||
pb_data:
|
||||
|
||||
@@ -39,9 +39,12 @@ RUN echo "COMMIT_HASH=$COMMIT_HASH" >> .env.commit
|
||||
RUN npm install
|
||||
COPY . ./
|
||||
|
||||
# execute the npm run dev command
|
||||
CMD ["npm", "run", "dev"]
|
||||
|
||||
# production stage
|
||||
# https://hub.docker.com/r/bitnami/nginx -> always run as non-root user
|
||||
FROM docker.io/bitnami/nginx:1.28 AS prod
|
||||
FROM docker.io/bitnami/nginx:latest AS prod
|
||||
|
||||
# copy build files from build container
|
||||
COPY ./nginx.conf /opt/bitnami/nginx/conf/nginx.conf
|
||||
|
||||
7
frontend/package-lock.json
generated
7
frontend/package-lock.json
generated
@@ -18,6 +18,7 @@
|
||||
"@vueuse/core": "^13.0.0",
|
||||
"country-flag-emoji-polyfill": "^0.1.8",
|
||||
"pinia": "^3.0.1",
|
||||
"pocketbase": "^0.26.3",
|
||||
"primeflex": "^3.3.1",
|
||||
"primeicons": "^7.0.0",
|
||||
"primevue": "^3.53.1",
|
||||
@@ -5593,6 +5594,12 @@
|
||||
"@vue/devtools-kit": "^7.7.2"
|
||||
}
|
||||
},
|
||||
"node_modules/pocketbase": {
|
||||
"version": "0.26.3",
|
||||
"resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.26.3.tgz",
|
||||
"integrity": "sha512-5deUKRoEczpxxuHzwr6/DHVmgbggxylEVig8CKN+MjvtYxPUqX/C6puU0yaR2yhTi8zrh7J9s7Ty+qBGwVzWOQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/postcss": {
|
||||
"version": "8.5.3",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.3.tgz",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"@vueuse/core": "^13.0.0",
|
||||
"country-flag-emoji-polyfill": "^0.1.8",
|
||||
"pinia": "^3.0.1",
|
||||
"pocketbase": "^0.26.3",
|
||||
"primeflex": "^3.3.1",
|
||||
"primeicons": "^7.0.0",
|
||||
"primevue": "^3.53.1",
|
||||
|
||||
@@ -44,6 +44,37 @@ export async function createIndividualFeed(modules: Module[]): Promise<string> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function createProfessorFeed(modules: Module[]): Promise<string> {
|
||||
if (import.meta.env.SSR) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
// Dynamic import to avoid circular dependencies or issues if pb is not initialized
|
||||
const { pb } = await import("../service/pocketbase");
|
||||
|
||||
const response = await fetch("/api/professor/feed", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": pb.authStore.token,
|
||||
},
|
||||
body: JSON.stringify(modules),
|
||||
});
|
||||
|
||||
if (
|
||||
response.status === 429 ||
|
||||
response.status === 500 ||
|
||||
response.status != 200
|
||||
) {
|
||||
return Promise.reject(response.statusText);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
|
||||
interface FeedResponse {
|
||||
modules: FeedModule[];
|
||||
collectionId: string;
|
||||
|
||||
40
frontend/src/api/fetchProfessorModules.ts
Normal file
40
frontend/src/api/fetchProfessorModules.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
export interface ApiModule {
|
||||
uuid: string;
|
||||
name: string;
|
||||
course: string;
|
||||
eventType?: string;
|
||||
prof: string;
|
||||
semester: string;
|
||||
confidenceScore?: number;
|
||||
}
|
||||
|
||||
export async function fetchProfessorModules(): Promise<ApiModule[]> {
|
||||
if (import.meta.env.SSR) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
const { pb } = await import("../service/pocketbase");
|
||||
|
||||
if (!pb.authStore.isValid || !pb.authStore.token) {
|
||||
return Promise.reject(new Error("User is not authenticated"));
|
||||
}
|
||||
|
||||
const response = await fetch("/api/professor/modules", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": pb.authStore.token,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = new Error(`HTTP error! status: ${response.status}`);
|
||||
Object.assign(error, { status: response.status });
|
||||
throw error;
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
@@ -17,61 +17,117 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from "vue";
|
||||
import { computed, ref, onMounted, onUnmounted } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useToast } from "primevue/usetoast";
|
||||
import LocaleSwitcher from "./LocaleSwitcher.vue";
|
||||
import DarkModeSwitcher from "./DarkModeSwitcher.vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { pb, login, logout } from "../service/pocketbase";
|
||||
|
||||
const { t } = useI18n({ useScope: "global" });
|
||||
const toast = useToast();
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const isDark = ref(true);
|
||||
const currentUser = ref(pb.authStore.model);
|
||||
|
||||
const items = computed(() => [
|
||||
{
|
||||
label: t("createCalendar"),
|
||||
icon: "pi pi-fw pi-plus",
|
||||
route: "/",
|
||||
},
|
||||
{
|
||||
label: t("editCalendar"),
|
||||
icon: "pi pi-fw pi-pencil",
|
||||
route: "/edit",
|
||||
},
|
||||
{
|
||||
label: t("rooms"),
|
||||
icon: "pi pi-fw pi-angle-down",
|
||||
info: "rooms",
|
||||
items: [
|
||||
{
|
||||
label: t("roomFinderPage.roomSchedule"),
|
||||
icon: "pi pi-fw pi-hourglass",
|
||||
route: "/rooms/occupancy",
|
||||
},
|
||||
{
|
||||
label: t("freeRooms.freeRooms"),
|
||||
icon: "pi pi-fw pi-calendar",
|
||||
route: "/rooms/free",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t("faq"),
|
||||
icon: "pi pi-fw pi-book",
|
||||
route: "/faq",
|
||||
},
|
||||
{
|
||||
label: t("imprint"),
|
||||
icon: "pi pi-fw pi-id-card",
|
||||
url: "https://www.htwk-leipzig.de/hochschule/kontakt/impressum/",
|
||||
},
|
||||
{
|
||||
label: t("privacy"),
|
||||
icon: "pi pi-fw pi-exclamation-triangle",
|
||||
url: "https://www.htwk-leipzig.de/hochschule/kontakt/datenschutzerklaerung/",
|
||||
},
|
||||
]);
|
||||
onMounted(() => {
|
||||
pb.authStore.onChange((_, model) => {
|
||||
currentUser.value = model;
|
||||
});
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
pb.authStore.onChange(() => {});
|
||||
});
|
||||
|
||||
const items = computed(() => {
|
||||
const menuItems = [
|
||||
{
|
||||
label: t("createCalendar"),
|
||||
icon: "pi pi-fw pi-plus",
|
||||
route: "/",
|
||||
},
|
||||
{
|
||||
label: t("editCalendar"),
|
||||
icon: "pi pi-fw pi-pencil",
|
||||
route: "/edit",
|
||||
},
|
||||
{
|
||||
label: t("rooms"),
|
||||
icon: "pi pi-fw pi-angle-down",
|
||||
info: "rooms",
|
||||
items: [
|
||||
{
|
||||
label: t("roomFinderPage.roomSchedule"),
|
||||
icon: "pi pi-fw pi-hourglass",
|
||||
route: "/rooms/occupancy",
|
||||
},
|
||||
{
|
||||
label: t("freeRooms.freeRooms"),
|
||||
icon: "pi pi-fw pi-calendar",
|
||||
route: "/rooms/free",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t("faq"),
|
||||
icon: "pi pi-fw pi-book",
|
||||
route: "/faq",
|
||||
},
|
||||
{
|
||||
label: t("imprint"),
|
||||
icon: "pi pi-fw pi-id-card",
|
||||
url: "https://www.htwk-leipzig.de/hochschule/kontakt/impressum/",
|
||||
},
|
||||
{
|
||||
label: t("privacy"),
|
||||
icon: "pi pi-fw pi-exclamation-triangle",
|
||||
url: "https://www.htwk-leipzig.de/hochschule/kontakt/datenschutzerklaerung/",
|
||||
},
|
||||
];
|
||||
|
||||
if (currentUser.value) {
|
||||
menuItems.push({
|
||||
label: "Professor Dashboard",
|
||||
icon: "pi pi-fw pi-user",
|
||||
route: "/professor/dashboard",
|
||||
});
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
});
|
||||
|
||||
async function handleLogin() {
|
||||
try {
|
||||
await login();
|
||||
toast.add({
|
||||
severity: 'success',
|
||||
summary: t('toast.loginSuccess'),
|
||||
detail: t('toast.loginSuccessDetail'),
|
||||
life: 3000
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
const err = error as { message?: string };
|
||||
if (err?.message && err.message.includes('Login restricted')) {
|
||||
toast.add({
|
||||
severity: 'error',
|
||||
summary: t('toast.loginError'),
|
||||
detail: t('toast.loginRestricted'),
|
||||
life: 5000
|
||||
});
|
||||
} else {
|
||||
toast.add({
|
||||
severity: 'error',
|
||||
summary: t('toast.loginError'),
|
||||
detail: err?.message || t('toast.loginErrorDetail'),
|
||||
life: 5000
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleDarkModeToggled(isDarkVar: boolean) {
|
||||
// Do something with isDark value
|
||||
@@ -143,6 +199,20 @@ function handleDarkModeToggled(isDarkVar: boolean) {
|
||||
@dark-mode-toggled="handleDarkModeToggled"
|
||||
></DarkModeSwitcher>
|
||||
<LocaleSwitcher></LocaleSwitcher>
|
||||
<Button
|
||||
v-if="!currentUser"
|
||||
label="Login"
|
||||
icon="pi pi-sign-in"
|
||||
class="p-button-text"
|
||||
@click="handleLogin"
|
||||
/>
|
||||
<Button
|
||||
v-else
|
||||
label="Logout"
|
||||
icon="pi pi-sign-out"
|
||||
class="p-button-text"
|
||||
@click="logout"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Menubar>
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
"description": "Dein individueller Stundenplan mit Sportevents und Prüfungen. Finde kommende Veranstaltungen oder freie Räume zum Lernen und Arbeiten.",
|
||||
"english": "Englisch",
|
||||
"german": "Deutsch",
|
||||
"toast": {
|
||||
"loginError": "Login fehlgeschlagen",
|
||||
"loginRestricted": "Login nur für Mitarbeitende der HTWK Leipzig.",
|
||||
"loginSuccess": "Login erfolgreich",
|
||||
"loginSuccessDetail": "Du kannst nun deinen Kalender erstellen.",
|
||||
"loginErrorDetail": "Fehler beim Login. Bitte versuche es erneut."
|
||||
},
|
||||
"courseSelection": {
|
||||
"headline": "Willkommen beim HTWKalender",
|
||||
"winterSemester": "Wintersemester",
|
||||
@@ -273,6 +280,18 @@
|
||||
"notFound": "Nicht gefunden, wonach du suchst?",
|
||||
"contact": "Kontakt aufnehmen"
|
||||
},
|
||||
"professor": {
|
||||
"dashboard": "Dashboard",
|
||||
"intro": "Willkommen im HTWKalender Professor, im ersten Schritt wählen Sie Ihre Module aus. Die empfohlenen Module werden automatisch ausgewählt. Weitere Module können manuell angewählt werden.",
|
||||
"nextStep": "Weiter",
|
||||
"name": "Name",
|
||||
"professor": "Professor",
|
||||
"course": "Modul",
|
||||
"semester": "Semester",
|
||||
"match": "Abgleich",
|
||||
"searchByName": "Filtern nach Name",
|
||||
"searchByProfessor": "Filtern nach Professor"
|
||||
},
|
||||
"footer": {
|
||||
"commitInfo": {
|
||||
"tooltip": "Version",
|
||||
@@ -280,9 +299,9 @@
|
||||
"description": "Zeigt die Commit-ID der verwendeten Frontend-Version des HTWKalenders an. Für Debbugger und Entwickler.",
|
||||
"hash": "Commit-Hash",
|
||||
"component": "Komponente",
|
||||
"components":{
|
||||
"components": {
|
||||
"frontend": "Frontend"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,13 @@
|
||||
"description": "Your individual timetable with sports events and exams. Find upcoming events or free rooms for studying and working.",
|
||||
"english": "English",
|
||||
"german": "German",
|
||||
"toast": {
|
||||
"loginError": "login failed",
|
||||
"loginRestricted": "login restricted to htwk employees",
|
||||
"loginSuccess": "login successful",
|
||||
"loginSuccessDetail": "you can now create your calendar.",
|
||||
"loginErrorDetail": "login failed. please try again."
|
||||
},
|
||||
"courseSelection": {
|
||||
"headline": "welcome to HTWKalender",
|
||||
"winterSemester": "winter semester",
|
||||
@@ -273,6 +280,18 @@
|
||||
"notFound": "Not finding what you're looking for?",
|
||||
"contact": "Get in touch"
|
||||
},
|
||||
"professor": {
|
||||
"dashboard": "Dashboard",
|
||||
"intro": "Welcome to the HTWKalender Professor, in the first step you select your modules. The recommended modules are automatically selected. Additional modules can be selected manually.",
|
||||
"nextStep": "Next",
|
||||
"name": "name",
|
||||
"professor": "professor",
|
||||
"course": "course",
|
||||
"semester": "semester",
|
||||
"match": "match",
|
||||
"searchByName": "filter by name",
|
||||
"searchByProfessor": "filter by professor"
|
||||
},
|
||||
"footer": {
|
||||
"commitInfo": {
|
||||
"tooltip": "application version",
|
||||
@@ -280,9 +299,9 @@
|
||||
"description": "Shows the commit id of the deployed frontend version of the HTWKalender. For debuggers and developers.",
|
||||
"hash": "commit hash",
|
||||
"component": "component",
|
||||
"components":{
|
||||
"components": {
|
||||
"frontend": "frontend"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,14 @@ const routes: RouterOptions = {
|
||||
label: "createCalendar",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/professor/dashboard",
|
||||
name: "professor-dashboard",
|
||||
component: () => import("../view/professor/ProfessorDashboard.vue"),
|
||||
meta: {
|
||||
label: "professor.dashboard",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
27
frontend/src/service/pocketbase.ts
Normal file
27
frontend/src/service/pocketbase.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
// const domain = "cal.htwk-leipzig.de";
|
||||
// const baseUri = "https://" + domain;
|
||||
|
||||
// For development, we might want to use the local backend
|
||||
// const backendUrl = import.meta.env.DEV ? 'http://127.0.0.1:8090' : baseUri;
|
||||
// But since we are running in docker, the frontend might be accessing the backend via a different URL or proxy.
|
||||
// The existing code uses relative paths for API calls which go through the reverse proxy.
|
||||
// PocketBase SDK needs a full URL or it defaults to /.
|
||||
// If we are serving frontend from the same domain as backend (via proxy), / is fine.
|
||||
// However, the proxy config shows backend at /api/ and pocketbase at /_/?
|
||||
// Let's check reverseproxy.conf
|
||||
|
||||
export const pb = new PocketBase("/");
|
||||
|
||||
// Note: OAuth2 redirect URL should be configured in Keycloak/OIDC provider as:
|
||||
// Development: http://localhost/callback
|
||||
// Production: https://cal.htwk-leipzig.de/callback
|
||||
|
||||
export const login = async () => {
|
||||
return await pb.collection('users').authWithOAuth2({ provider: 'oidc', scopes: ['openid', 'email', 'profile'] });
|
||||
}
|
||||
|
||||
export const logout = () => {
|
||||
pb.authStore.clear();
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import { defineStore } from "pinia";
|
||||
const moduleStore = defineStore("moduleStore", {
|
||||
state: () => ({
|
||||
modules: new Map<string, Module>(),
|
||||
isProfessorFeed: false,
|
||||
}),
|
||||
actions: {
|
||||
addModule(module: Module) {
|
||||
@@ -55,6 +56,9 @@ const moduleStore = defineStore("moduleStore", {
|
||||
containsModule(module: Module): boolean {
|
||||
return this.modules.has(module.uuid);
|
||||
},
|
||||
setProfessorFeed(isProf: boolean) {
|
||||
this.isProfessorFeed = isProf;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
<script setup lang="ts">
|
||||
import moduleStore from "@/store/moduleStore.ts";
|
||||
import { createIndividualFeed } from "@/api/createFeed.ts";
|
||||
import { createIndividualFeed, createProfessorFeed } from "@/api/createFeed.ts";
|
||||
import { router } from "@/main";
|
||||
import tokenStore from "@/store/tokenStore.ts";
|
||||
import { Ref, computed, inject, ref, onMounted } from "vue";
|
||||
@@ -57,9 +57,14 @@ const requestIsPending = ref(false);
|
||||
|
||||
async function finalStep() {
|
||||
requestIsPending.value = true;
|
||||
const createFeed: Promise<string> = createIndividualFeed(
|
||||
store.getAllModules(),
|
||||
);
|
||||
|
||||
let createFeed: Promise<string>;
|
||||
|
||||
if (store.isProfessorFeed) {
|
||||
createFeed = createProfessorFeed(store.getAllModules());
|
||||
} else {
|
||||
createFeed = createIndividualFeed(store.getAllModules());
|
||||
}
|
||||
|
||||
// Check if createFeed Promise is resolved
|
||||
createFeed.then(async (token: string) => {
|
||||
|
||||
227
frontend/src/view/professor/ProfessorDashboard.vue
Normal file
227
frontend/src/view/professor/ProfessorDashboard.vue
Normal file
@@ -0,0 +1,227 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { pb } from "../../service/pocketbase";
|
||||
import { Module } from "../../model/module";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import Button from "primevue/button";
|
||||
import DataTable from "primevue/datatable";
|
||||
import Column from "primevue/column";
|
||||
import Skeleton from "primevue/skeleton";
|
||||
import InputText from "primevue/inputtext";
|
||||
import { FilterMatchMode } from "primevue/api";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
const { t } = useI18n({ useScope: "global" });
|
||||
const router = useRouter();
|
||||
import { fetchProfessorModules, type ApiModule } from "../../api/fetchProfessorModules";
|
||||
|
||||
type ModuleWithScore = Module & { confidenceScore: number };
|
||||
|
||||
const modules = ref<Module[]>(new Array(10));
|
||||
const selectedModules = ref<Module[]>([]);
|
||||
const loading = ref(true);
|
||||
|
||||
const filters = ref({
|
||||
name: {
|
||||
value: null,
|
||||
matchMode: FilterMatchMode.CONTAINS,
|
||||
},
|
||||
prof: {
|
||||
value: null,
|
||||
matchMode: FilterMatchMode.CONTAINS,
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
// Check if user is authenticated
|
||||
if (!pb.authStore.isValid || !pb.authStore.token) {
|
||||
console.error("User is not authenticated");
|
||||
router.push("/");
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await fetchProfessorModules();
|
||||
|
||||
// Convert API response to Module instances with all required fields
|
||||
const moduleObjects = result.map((apiModule: ApiModule) => new Module(
|
||||
apiModule.uuid,
|
||||
apiModule.name,
|
||||
apiModule.course,
|
||||
apiModule.eventType || "",
|
||||
apiModule.name, // userDefinedName defaults to module name
|
||||
apiModule.prof,
|
||||
apiModule.semester,
|
||||
false, // reminder defaults to false
|
||||
[] // events defaults to empty array
|
||||
));
|
||||
|
||||
// Sort modules by confidence score (highest first)
|
||||
// Note: confidenceScore is not part of Module class, so we need to preserve it
|
||||
const sortedModules = moduleObjects.map((module: Module, index: number) => {
|
||||
const originalData = result[index];
|
||||
return {
|
||||
...module,
|
||||
confidenceScore: originalData.confidenceScore || 0
|
||||
};
|
||||
}).sort((a: ModuleWithScore, b: ModuleWithScore) => {
|
||||
return (b.confidenceScore || 0) - (a.confidenceScore || 0); // Descending order
|
||||
});
|
||||
|
||||
// Clear temporary entries and set actual modules
|
||||
modules.value = sortedModules;
|
||||
|
||||
// Pre-select modules with confidence score >= 0.7 (good match or better)
|
||||
selectedModules.value = sortedModules.filter((m: ModuleWithScore) => (m.confidenceScore || 0) >= 0.7);
|
||||
|
||||
console.log("Modules loaded:", modules.value.length, "Pre-selected:", selectedModules.value.length);
|
||||
} catch (error: unknown) {
|
||||
console.error("Failed to fetch modules", error);
|
||||
const err = error as { status?: number; message?: string };
|
||||
// Clear temporary entries on error
|
||||
modules.value = [];
|
||||
// If unauthorized, redirect to home
|
||||
if (err.status === 401 || err.message?.includes("401")) {
|
||||
pb.authStore.clear();
|
||||
router.push("/");
|
||||
}
|
||||
} finally {
|
||||
// Always disable loading animation
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
const createCalendar = () => {
|
||||
// Similar to course selection, we want to proceed to rename or just view calendar
|
||||
// We can store the selected modules in the store and redirect
|
||||
// But wait, the store is for the "current" calendar creation session.
|
||||
// If we want to use the existing flow:
|
||||
|
||||
// 1. Clear store? Or just add?
|
||||
// Let's assume we want to start fresh or add to existing.
|
||||
// For now, let's just construct the URL parameters or use the store.
|
||||
|
||||
// Actually, the user wants "custom calendar creation process ... selection of modules and the renaming".
|
||||
// So we can redirect to /rename-modules with the selected modules pre-filled in the store.
|
||||
|
||||
import("../../store/moduleStore").then(({ default: useModuleStore }) => {
|
||||
const store = useModuleStore();
|
||||
store.removeAllModules();
|
||||
store.setProfessorFeed(true);
|
||||
selectedModules.value.forEach((m) => store.addModule(m));
|
||||
router.push("/rename-modules");
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="card">
|
||||
<h1>{{ t("professor.dashboard") }}</h1>
|
||||
<p>{{ t("professor.intro") }}</p>
|
||||
|
||||
|
||||
<DataTable
|
||||
v-model:selection="selectedModules"
|
||||
v-model:filters="filters"
|
||||
:value="modules"
|
||||
dataKey="uuid"
|
||||
responsiveLayout="scroll"
|
||||
paginator
|
||||
:rows="10"
|
||||
:rows-per-page-options="[5, 10, 20, 50]"
|
||||
filter-display="row"
|
||||
:show-gridlines="true"
|
||||
:striped-rows="true"
|
||||
>
|
||||
<Column selectionMode="multiple" headerStyle="width: 3em">
|
||||
<template v-if="loading" #body>
|
||||
<Skeleton></Skeleton>
|
||||
</template>
|
||||
</Column>
|
||||
<Column
|
||||
field="name"
|
||||
:header="t('professor.name')"
|
||||
:show-filter-menu="false"
|
||||
:show-clear-button="false"
|
||||
>
|
||||
<template #filter="{ filterModel, filterCallback }">
|
||||
<InputText
|
||||
v-model="filterModel.value"
|
||||
type="text"
|
||||
class="p-column-filter"
|
||||
:placeholder="t('professor.searchByName')"
|
||||
@input="filterCallback()"
|
||||
/>
|
||||
</template>
|
||||
<template v-if="loading" #body>
|
||||
<Skeleton></Skeleton>
|
||||
</template>
|
||||
</Column>
|
||||
<Column
|
||||
field="prof"
|
||||
:header="t('professor.professor')"
|
||||
:show-filter-menu="false"
|
||||
:show-clear-button="false"
|
||||
>
|
||||
<template #filter="{ filterModel, filterCallback }">
|
||||
<InputText
|
||||
v-model="filterModel.value"
|
||||
type="text"
|
||||
class="p-column-filter"
|
||||
:placeholder="t('professor.searchByProfessor')"
|
||||
@input="filterCallback()"
|
||||
/>
|
||||
</template>
|
||||
<template v-if="loading" #body>
|
||||
<Skeleton></Skeleton>
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="course" :header="t('professor.course')">
|
||||
<template v-if="loading" #body>
|
||||
<Skeleton></Skeleton>
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="semester" :header="t('professor.semester')">
|
||||
<template v-if="loading" #body>
|
||||
<Skeleton></Skeleton>
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="confidenceScore" :header="t('professor.match')" sortable>
|
||||
<template #body="slotProps">
|
||||
<div v-if="loading">
|
||||
<Skeleton></Skeleton>
|
||||
</div>
|
||||
<div v-else>
|
||||
<span v-if="slotProps.data.confidenceScore >= 0.9" style="color: green; font-weight: bold;">
|
||||
{{ Math.round(slotProps.data.confidenceScore * 100) }}%
|
||||
</span>
|
||||
<span v-else-if="slotProps.data.confidenceScore >= 0.7" style="color: #4CAF50;">
|
||||
{{ Math.round(slotProps.data.confidenceScore * 100) }}%
|
||||
</span>
|
||||
<span v-else-if="slotProps.data.confidenceScore >= 0.5" style="color: orange;">
|
||||
{{ Math.round(slotProps.data.confidenceScore * 100) }}%
|
||||
</span>
|
||||
<span v-else style="color: #999;">
|
||||
{{ Math.round(slotProps.data.confidenceScore * 100) }}%
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
|
||||
<div class="flex justify-content-end mt-4">
|
||||
<Button
|
||||
:label="t('professor.nextStep')"
|
||||
icon="pi pi-arrow-right"
|
||||
@click="createCalendar"
|
||||
:disabled="selectedModules.length === 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.card {
|
||||
padding: 2rem;
|
||||
}
|
||||
</style>
|
||||
@@ -79,6 +79,7 @@ export default defineConfig({
|
||||
watch: {
|
||||
usePolling: true,
|
||||
},
|
||||
allowedHosts: ["localhost", "127.0.0.1", "::1", "cal.htwk-leipzig.de", "htwkalender-frontend"],
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://localhost:8090/api",
|
||||
|
||||
@@ -25,8 +25,8 @@ http {
|
||||
limit_req_zone $ratelimit_key zone=createFeed:10m rate=1r/m;
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
listen [::]:8080;
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
http2 on;
|
||||
|
||||
location /api/feed {
|
||||
|
||||
@@ -31,6 +31,9 @@ type Feed struct {
|
||||
Created string `protobuf:"bytes,4,opt,name=created,proto3" json:"created,omitempty"`
|
||||
Updated string `protobuf:"bytes,5,opt,name=updated,proto3" json:"updated,omitempty"`
|
||||
Deleted bool `protobuf:"varint,6,opt,name=deleted,proto3" json:"deleted,omitempty"`
|
||||
Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type,omitempty"` // "prof" or "student"
|
||||
User string `protobuf:"bytes,8,opt,name=user,proto3" json:"user,omitempty"` // User ID relation
|
||||
UserEmail string `protobuf:"bytes,9,opt,name=user_email,json=userEmail,proto3" json:"user_email,omitempty"` // User Email for filtering
|
||||
}
|
||||
|
||||
func (x *Feed) Reset() {
|
||||
@@ -107,6 +110,27 @@ func (x *Feed) GetDeleted() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Feed) GetType() string {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetUser() string {
|
||||
if x != nil {
|
||||
return x.User
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetUserEmail() string {
|
||||
if x != nil {
|
||||
return x.UserEmail
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type GetFeedRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -204,7 +228,7 @@ func (x *GetFeedResponse) GetFeed() *Feed {
|
||||
var File_feeds_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_feeds_proto_rawDesc = []byte{
|
||||
0x0a, 0x0b, 0x66, 0x65, 0x65, 0x64, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9c, 0x01,
|
||||
0x0a, 0x0b, 0x66, 0x65, 0x65, 0x64, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe3, 0x01,
|
||||
0x0a, 0x04, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
|
||||
0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73,
|
||||
@@ -214,19 +238,23 @@ var file_feeds_proto_rawDesc = []byte{
|
||||
0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x70, 0x64, 0x61,
|
||||
0x74, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74,
|
||||
0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20,
|
||||
0x01, 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x22, 0x20, 0x0a, 0x0e,
|
||||
0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e,
|
||||
0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2c,
|
||||
0x0a, 0x0f, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x12, 0x19, 0x0a, 0x04, 0x66, 0x65, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x05, 0x2e, 0x46, 0x65, 0x65, 0x64, 0x52, 0x04, 0x66, 0x65, 0x65, 0x64, 0x32, 0x3d, 0x0a, 0x0b,
|
||||
0x46, 0x65, 0x65, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x47,
|
||||
0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0f, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65,
|
||||
0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x68,
|
||||
0x74, 0x77, 0x6b, 0x61, 0x6c, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f,
|
||||
0x6e, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x33,
|
||||
0x01, 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x74, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
||||
0x75, 0x73, 0x65, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x65, 0x6d, 0x61,
|
||||
0x69, 0x6c, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x45, 0x6d,
|
||||
0x61, 0x69, 0x6c, 0x22, 0x20, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x66, 0x65, 0x65, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x46, 0x65, 0x65, 0x64, 0x52, 0x04, 0x66,
|
||||
0x65, 0x65, 0x64, 0x32, 0x3d, 0x0a, 0x0b, 0x46, 0x65, 0x65, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69,
|
||||
0x63, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0f, 0x2e,
|
||||
0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10,
|
||||
0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x22, 0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x68, 0x74, 0x77, 0x6b, 0x61, 0x6c, 0x65, 0x6e, 0x64, 0x65,
|
||||
0x72, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
175
services/common/professor/matching.go
Normal file
175
services/common/professor/matching.go
Normal file
@@ -0,0 +1,175 @@
|
||||
package professor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ExtractNameFromEmail extracts the first and last name from a professor's email.
|
||||
// Expected format: firstname.lastname@htwk-leipzig.de
|
||||
func ExtractNameFromEmail(email string) (firstName, lastName string, err error) {
|
||||
parts := strings.Split(email, "@")
|
||||
if len(parts) != 2 {
|
||||
return "", "", fmt.Errorf("invalid email format")
|
||||
}
|
||||
|
||||
nameParts := strings.Split(parts[0], ".")
|
||||
if len(nameParts) < 2 {
|
||||
return "", "", fmt.Errorf("email does not contain dot separator")
|
||||
}
|
||||
|
||||
// Extract first and last name
|
||||
firstName = nameParts[0]
|
||||
lastName = nameParts[len(nameParts)-1]
|
||||
|
||||
// Capitalize first letter
|
||||
if len(firstName) > 0 {
|
||||
firstName = strings.ToUpper(firstName[:1]) + firstName[1:]
|
||||
}
|
||||
if len(lastName) > 0 {
|
||||
lastName = strings.ToUpper(lastName[:1]) + lastName[1:]
|
||||
}
|
||||
|
||||
return firstName, lastName, nil
|
||||
}
|
||||
|
||||
// CalculateConfidenceScore returns a score from 0.0 to 1.0 indicating how confident we are
|
||||
// that this professor string matches the given first and last name
|
||||
// 1.0 = perfect match (both first and last name exact)
|
||||
// 0.7-0.9 = good match (last name exact, first name fuzzy or present)
|
||||
// 0.4-0.6 = possible match (last name fuzzy or partial)
|
||||
// 0.1-0.3 = weak match (last name substring)
|
||||
// 0.0 = no match
|
||||
func CalculateConfidenceScore(profString, firstName, lastName string) float64 {
|
||||
// Normalize the professor string: remove common titles and split into words
|
||||
profString = strings.ToLower(profString)
|
||||
|
||||
// Remove common titles
|
||||
titles := []string{"prof.", "dr.", "arch.", "ing.", "dipl.", "m.sc.", "b.sc.", "ph.d."}
|
||||
for _, title := range titles {
|
||||
profString = strings.ReplaceAll(profString, title, "")
|
||||
}
|
||||
|
||||
// Split by spaces, hyphens, and other separators
|
||||
words := strings.FieldsFunc(profString, func(r rune) bool {
|
||||
return r == ' ' || r == '-' || r == ',' || r == '.'
|
||||
})
|
||||
|
||||
// Normalize firstName and lastName
|
||||
firstNameLower := strings.ToLower(firstName)
|
||||
lastNameLower := strings.ToLower(lastName)
|
||||
|
||||
lastNameExact := false
|
||||
lastNameFuzzy := false
|
||||
lastNameSubstring := false
|
||||
firstNameExact := false
|
||||
firstNameFuzzy := false
|
||||
|
||||
for _, word := range words {
|
||||
word = strings.TrimSpace(word)
|
||||
if word == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check last name
|
||||
if word == lastNameLower {
|
||||
lastNameExact = true
|
||||
} else if levenshteinDistance(word, lastNameLower) <= 1 && len(lastNameLower) > 3 {
|
||||
lastNameFuzzy = true
|
||||
} else if strings.Contains(word, lastNameLower) || strings.Contains(lastNameLower, word) {
|
||||
lastNameSubstring = true
|
||||
}
|
||||
|
||||
// Check first name
|
||||
if word == firstNameLower {
|
||||
firstNameExact = true
|
||||
} else if levenshteinDistance(word, firstNameLower) <= 1 && len(firstNameLower) > 3 {
|
||||
firstNameFuzzy = true
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate confidence score based on matches
|
||||
score := 0.0
|
||||
|
||||
if lastNameExact {
|
||||
if firstNameExact {
|
||||
score = 1.0 // Perfect match
|
||||
} else if firstNameFuzzy {
|
||||
score = 0.9 // Excellent match
|
||||
} else {
|
||||
score = 0.8 // Good match (last name exact, no first name match)
|
||||
}
|
||||
} else if lastNameFuzzy {
|
||||
if firstNameExact || firstNameFuzzy {
|
||||
score = 0.6 // Decent match (fuzzy last name but first name matches)
|
||||
} else {
|
||||
score = 0.5 // Medium match (fuzzy last name, no first name)
|
||||
}
|
||||
} else if lastNameSubstring {
|
||||
score = 0.2 // Weak match (substring only)
|
||||
}
|
||||
|
||||
return score
|
||||
}
|
||||
|
||||
// MatchesProfessor checks if the professor string matches the given last name (and optional first name)
|
||||
// It uses a simplified check suitable for filtering events where we want high recall but reasonable precision.
|
||||
// It returns true if the confidence score is > 0.
|
||||
func MatchesProfessor(profString, firstName, lastName string) bool {
|
||||
return CalculateConfidenceScore(profString, firstName, lastName) > 0
|
||||
}
|
||||
|
||||
// levenshteinDistance calculates the Levenshtein distance between two strings
|
||||
func levenshteinDistance(s1, s2 string) int {
|
||||
if len(s1) == 0 {
|
||||
return len(s2)
|
||||
}
|
||||
if len(s2) == 0 {
|
||||
return len(s1)
|
||||
}
|
||||
|
||||
// Create a 2D array for dynamic programming
|
||||
d := make([][]int, len(s1)+1)
|
||||
for i := range d {
|
||||
d[i] = make([]int, len(s2)+1)
|
||||
}
|
||||
|
||||
// Initialize first column and row
|
||||
for i := 0; i <= len(s1); i++ {
|
||||
d[i][0] = i
|
||||
}
|
||||
for j := 0; j <= len(s2); j++ {
|
||||
d[0][j] = j
|
||||
}
|
||||
|
||||
// Fill the matrix
|
||||
for i := 1; i <= len(s1); i++ {
|
||||
for j := 1; j <= len(s2); j++ {
|
||||
cost := 0
|
||||
if s1[i-1] != s2[j-1] {
|
||||
cost = 1
|
||||
}
|
||||
|
||||
d[i][j] = min(
|
||||
d[i-1][j]+1, // deletion
|
||||
d[i][j-1]+1, // insertion
|
||||
d[i-1][j-1]+cost, // substitution
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return d[len(s1)][len(s2)]
|
||||
}
|
||||
|
||||
func min(a, b, c int) int {
|
||||
if a < b {
|
||||
if a < c {
|
||||
return a
|
||||
}
|
||||
return c
|
||||
}
|
||||
if b < c {
|
||||
return b
|
||||
}
|
||||
return c
|
||||
}
|
||||
@@ -17,27 +17,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||
_ "htwkalender/data-manager/migrations"
|
||||
"htwkalender/data-manager/model/serviceModel"
|
||||
"htwkalender/data-manager/service"
|
||||
"htwkalender/data-manager/service/events"
|
||||
"htwkalender/data-manager/service/grpc"
|
||||
"htwkalender/data-manager/service/professor"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||
)
|
||||
|
||||
func setupApp() *pocketbase.PocketBase {
|
||||
app := pocketbase.New()
|
||||
courseService := events.NewPocketBaseCourseService(app)
|
||||
eventService := events.NewPocketBaseEventService(app)
|
||||
professorService := professor.NewProfessorService(app)
|
||||
|
||||
services := serviceModel.Service{
|
||||
CourseService: courseService,
|
||||
EventService: eventService,
|
||||
App: app,
|
||||
CourseService: courseService,
|
||||
EventService: eventService,
|
||||
ProfessorService: professorService,
|
||||
App: app,
|
||||
}
|
||||
|
||||
// loosely check if it was executed using "go run"
|
||||
@@ -53,6 +57,7 @@ func setupApp() *pocketbase.PocketBase {
|
||||
})
|
||||
service.AddRoutes(services)
|
||||
service.AddSchedules(services)
|
||||
service.AddHooks(app)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
32
services/data-manager/migrations/1745249436_enable_oauth2.go
Normal file
32
services/data-manager/migrations/1745249436_enable_oauth2.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("users")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Enable OAuth2
|
||||
collection.OAuth2.Enabled = true
|
||||
|
||||
// Optional: Map fields if necessary, for now just enabling it
|
||||
// collection.OAuth2.MappedFields.Name = "name"
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("users")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
collection.OAuth2.Enabled = false
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,791 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
jsonData := `[
|
||||
{
|
||||
"createRule": null,
|
||||
"deleteRule": null,
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"hidden": false,
|
||||
"id": "text3208210256",
|
||||
"max": 15,
|
||||
"min": 15,
|
||||
"name": "id",
|
||||
"pattern": "^[a-z0-9]+$",
|
||||
"presentable": false,
|
||||
"primaryKey": true,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text455797646",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "collectionRef",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text127846527",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "recordRef",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text1582905952",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "method",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate2990389176",
|
||||
"name": "created",
|
||||
"onCreate": true,
|
||||
"onUpdate": false,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate3332085495",
|
||||
"name": "updated",
|
||||
"onCreate": true,
|
||||
"onUpdate": true,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
}
|
||||
],
|
||||
"id": "pbc_2279338944",
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_mfas_collectionRef_recordRef` + "`" + ` ON ` + "`" + `_mfas` + "`" + ` (collectionRef,recordRef)"
|
||||
],
|
||||
"listRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId",
|
||||
"name": "_mfas",
|
||||
"system": true,
|
||||
"type": "base",
|
||||
"updateRule": null,
|
||||
"viewRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId"
|
||||
},
|
||||
{
|
||||
"createRule": null,
|
||||
"deleteRule": null,
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"hidden": false,
|
||||
"id": "text3208210256",
|
||||
"max": 15,
|
||||
"min": 15,
|
||||
"name": "id",
|
||||
"pattern": "^[a-z0-9]+$",
|
||||
"presentable": false,
|
||||
"primaryKey": true,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text455797646",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "collectionRef",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text127846527",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "recordRef",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"cost": 8,
|
||||
"hidden": true,
|
||||
"id": "password901924565",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "password",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "password"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": true,
|
||||
"id": "text3866985172",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "sentTo",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate2990389176",
|
||||
"name": "created",
|
||||
"onCreate": true,
|
||||
"onUpdate": false,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate3332085495",
|
||||
"name": "updated",
|
||||
"onCreate": true,
|
||||
"onUpdate": true,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
}
|
||||
],
|
||||
"id": "pbc_1638494021",
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_otps_collectionRef_recordRef` + "`" + ` ON ` + "`" + `_otps` + "`" + ` (collectionRef, recordRef)"
|
||||
],
|
||||
"listRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId",
|
||||
"name": "_otps",
|
||||
"system": true,
|
||||
"type": "base",
|
||||
"updateRule": null,
|
||||
"viewRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId"
|
||||
},
|
||||
{
|
||||
"createRule": null,
|
||||
"deleteRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId",
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"hidden": false,
|
||||
"id": "text3208210256",
|
||||
"max": 15,
|
||||
"min": 15,
|
||||
"name": "id",
|
||||
"pattern": "^[a-z0-9]+$",
|
||||
"presentable": false,
|
||||
"primaryKey": true,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text455797646",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "collectionRef",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text127846527",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "recordRef",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2462348188",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "provider",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text1044722854",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "providerId",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate2990389176",
|
||||
"name": "created",
|
||||
"onCreate": true,
|
||||
"onUpdate": false,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate3332085495",
|
||||
"name": "updated",
|
||||
"onCreate": true,
|
||||
"onUpdate": true,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
}
|
||||
],
|
||||
"id": "pbc_2281828961",
|
||||
"indexes": [
|
||||
"CREATE UNIQUE INDEX ` + "`" + `idx_externalAuths_record_provider` + "`" + ` ON ` + "`" + `_externalAuths` + "`" + ` (collectionRef, recordRef, provider)",
|
||||
"CREATE UNIQUE INDEX ` + "`" + `idx_externalAuths_collection_provider` + "`" + ` ON ` + "`" + `_externalAuths` + "`" + ` (collectionRef, provider, providerId)"
|
||||
],
|
||||
"listRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId",
|
||||
"name": "_externalAuths",
|
||||
"system": true,
|
||||
"type": "base",
|
||||
"updateRule": null,
|
||||
"viewRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId"
|
||||
},
|
||||
{
|
||||
"createRule": null,
|
||||
"deleteRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId",
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"hidden": false,
|
||||
"id": "text3208210256",
|
||||
"max": 15,
|
||||
"min": 15,
|
||||
"name": "id",
|
||||
"pattern": "^[a-z0-9]+$",
|
||||
"presentable": false,
|
||||
"primaryKey": true,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text455797646",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "collectionRef",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text127846527",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "recordRef",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text4228609354",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "fingerprint",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate2990389176",
|
||||
"name": "created",
|
||||
"onCreate": true,
|
||||
"onUpdate": false,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate3332085495",
|
||||
"name": "updated",
|
||||
"onCreate": true,
|
||||
"onUpdate": true,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
}
|
||||
],
|
||||
"id": "pbc_4275539003",
|
||||
"indexes": [
|
||||
"CREATE UNIQUE INDEX ` + "`" + `idx_authOrigins_unique_pairs` + "`" + ` ON ` + "`" + `_authOrigins` + "`" + ` (collectionRef, recordRef, fingerprint)"
|
||||
],
|
||||
"listRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId",
|
||||
"name": "_authOrigins",
|
||||
"system": true,
|
||||
"type": "base",
|
||||
"updateRule": null,
|
||||
"viewRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId"
|
||||
},
|
||||
{
|
||||
"authAlert": {
|
||||
"emailTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>We noticed a login to your {APP_NAME} account from a new location.</p>\n<p>If this was you, you may disregard this email.</p>\n<p><strong>If this wasn't you, you should immediately change your {APP_NAME} account password to revoke access from all other locations.</strong></p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "Login from a new location"
|
||||
},
|
||||
"enabled": true
|
||||
},
|
||||
"authRule": "",
|
||||
"authToken": {
|
||||
"duration": 86400
|
||||
},
|
||||
"confirmEmailChangeTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>Click on the button below to confirm your new email address.</p>\n<p>\n <a class=\"btn\" href=\"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}\" target=\"_blank\" rel=\"noopener\">Confirm new email</a>\n</p>\n<p><i>If you didn't ask to change your email address, you can ignore this email.</i></p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "Confirm your {APP_NAME} new email address"
|
||||
},
|
||||
"createRule": null,
|
||||
"deleteRule": null,
|
||||
"emailChangeToken": {
|
||||
"duration": 1800
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"hidden": false,
|
||||
"id": "text3208210256",
|
||||
"max": 15,
|
||||
"min": 15,
|
||||
"name": "id",
|
||||
"pattern": "^[a-z0-9]+$",
|
||||
"presentable": false,
|
||||
"primaryKey": true,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"cost": 0,
|
||||
"hidden": true,
|
||||
"id": "password901924565",
|
||||
"max": 0,
|
||||
"min": 8,
|
||||
"name": "password",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "password"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "[a-zA-Z0-9]{50}",
|
||||
"hidden": true,
|
||||
"id": "text2504183744",
|
||||
"max": 60,
|
||||
"min": 30,
|
||||
"name": "tokenKey",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"exceptDomains": null,
|
||||
"hidden": false,
|
||||
"id": "email3885137012",
|
||||
"name": "email",
|
||||
"onlyDomains": null,
|
||||
"presentable": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "email"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "bool1547992806",
|
||||
"name": "emailVisibility",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": true,
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "bool256245529",
|
||||
"name": "verified",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": true,
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate2990389176",
|
||||
"name": "created",
|
||||
"onCreate": true,
|
||||
"onUpdate": false,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate3332085495",
|
||||
"name": "updated",
|
||||
"onCreate": true,
|
||||
"onUpdate": true,
|
||||
"presentable": false,
|
||||
"system": true,
|
||||
"type": "autodate"
|
||||
}
|
||||
],
|
||||
"fileToken": {
|
||||
"duration": 180
|
||||
},
|
||||
"id": "pbc_3142635823",
|
||||
"indexes": [
|
||||
"CREATE UNIQUE INDEX ` + "`" + `idx_tokenKey_pbc_3142635823` + "`" + ` ON ` + "`" + `_superusers` + "`" + ` (` + "`" + `tokenKey` + "`" + `)",
|
||||
"CREATE UNIQUE INDEX ` + "`" + `idx_email_pbc_3142635823` + "`" + ` ON ` + "`" + `_superusers` + "`" + ` (` + "`" + `email` + "`" + `) WHERE ` + "`" + `email` + "`" + ` != ''"
|
||||
],
|
||||
"listRule": null,
|
||||
"manageRule": null,
|
||||
"mfa": {
|
||||
"duration": 1800,
|
||||
"enabled": false,
|
||||
"rule": ""
|
||||
},
|
||||
"name": "_superusers",
|
||||
"oauth2": {
|
||||
"enabled": false,
|
||||
"mappedFields": {
|
||||
"avatarURL": "",
|
||||
"id": "",
|
||||
"name": "",
|
||||
"username": ""
|
||||
}
|
||||
},
|
||||
"otp": {
|
||||
"duration": 180,
|
||||
"emailTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>Your one-time password is: <strong>{OTP}</strong></p>\n<p><i>If you didn't ask for the one-time password, you can ignore this email.</i></p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "OTP for {APP_NAME}"
|
||||
},
|
||||
"enabled": false,
|
||||
"length": 8
|
||||
},
|
||||
"passwordAuth": {
|
||||
"enabled": true,
|
||||
"identityFields": [
|
||||
"email"
|
||||
]
|
||||
},
|
||||
"passwordResetToken": {
|
||||
"duration": 1800
|
||||
},
|
||||
"resetPasswordTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>Click on the button below to reset your password.</p>\n<p>\n <a class=\"btn\" href=\"{APP_URL}/_/#/auth/confirm-password-reset/{TOKEN}\" target=\"_blank\" rel=\"noopener\">Reset password</a>\n</p>\n<p><i>If you didn't ask to reset your password, you can ignore this email.</i></p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "Reset your {APP_NAME} password"
|
||||
},
|
||||
"system": true,
|
||||
"type": "auth",
|
||||
"updateRule": null,
|
||||
"verificationTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>Thank you for joining us at {APP_NAME}.</p>\n<p>Click on the button below to verify your email address.</p>\n<p>\n <a class=\"btn\" href=\"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}\" target=\"_blank\" rel=\"noopener\">Verify</a>\n</p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "Verify your {APP_NAME} email"
|
||||
},
|
||||
"verificationToken": {
|
||||
"duration": 259200
|
||||
},
|
||||
"viewRule": null
|
||||
},
|
||||
{
|
||||
"authAlert": {
|
||||
"emailTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>We noticed a login to your {APP_NAME} account from a new location.</p>\n<p>If this was you, you may disregard this email.</p>\n<p><strong>If this wasn't you, you should immediately change your {APP_NAME} account password to revoke access from all other locations.</strong></p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "Login from a new location"
|
||||
},
|
||||
"enabled": true
|
||||
},
|
||||
"authRule": "",
|
||||
"authToken": {
|
||||
"duration": 604800
|
||||
},
|
||||
"confirmEmailChangeTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>Click on the button below to confirm your new email address.</p>\n<p>\n <a class=\"btn\" href=\"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}\" target=\"_blank\" rel=\"noopener\">Confirm new email</a>\n</p>\n<p><i>If you didn't ask to change your email address, you can ignore this email.</i></p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "Confirm your {APP_NAME} new email address"
|
||||
},
|
||||
"createRule": "",
|
||||
"deleteRule": "id = @request.auth.id",
|
||||
"emailChangeToken": {
|
||||
"duration": 1800
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"autogeneratePattern": "[a-z0-9]{15}",
|
||||
"hidden": false,
|
||||
"id": "text3208210256",
|
||||
"max": 15,
|
||||
"min": 15,
|
||||
"name": "id",
|
||||
"pattern": "^[a-z0-9]+$",
|
||||
"presentable": false,
|
||||
"primaryKey": true,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"cost": 0,
|
||||
"hidden": true,
|
||||
"id": "password901924565",
|
||||
"max": 0,
|
||||
"min": 8,
|
||||
"name": "password",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "password"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "[a-zA-Z0-9]{50}",
|
||||
"hidden": true,
|
||||
"id": "text2504183744",
|
||||
"max": 60,
|
||||
"min": 30,
|
||||
"name": "tokenKey",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"exceptDomains": null,
|
||||
"hidden": false,
|
||||
"id": "email3885137012",
|
||||
"name": "email",
|
||||
"onlyDomains": null,
|
||||
"presentable": false,
|
||||
"required": true,
|
||||
"system": true,
|
||||
"type": "email"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "bool1547992806",
|
||||
"name": "emailVisibility",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": true,
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "bool256245529",
|
||||
"name": "verified",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": true,
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text1579384326",
|
||||
"max": 255,
|
||||
"min": 0,
|
||||
"name": "name",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "file376926767",
|
||||
"maxSelect": 1,
|
||||
"maxSize": 0,
|
||||
"mimeTypes": [
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/svg+xml",
|
||||
"image/gif",
|
||||
"image/webp"
|
||||
],
|
||||
"name": "avatar",
|
||||
"presentable": false,
|
||||
"protected": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"thumbs": null,
|
||||
"type": "file"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate2990389176",
|
||||
"name": "created",
|
||||
"onCreate": true,
|
||||
"onUpdate": false,
|
||||
"presentable": false,
|
||||
"system": false,
|
||||
"type": "autodate"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "autodate3332085495",
|
||||
"name": "updated",
|
||||
"onCreate": true,
|
||||
"onUpdate": true,
|
||||
"presentable": false,
|
||||
"system": false,
|
||||
"type": "autodate"
|
||||
}
|
||||
],
|
||||
"fileToken": {
|
||||
"duration": 180
|
||||
},
|
||||
"id": "_pb_users_auth_",
|
||||
"indexes": [
|
||||
"CREATE UNIQUE INDEX ` + "`" + `idx_tokenKey__pb_users_auth_` + "`" + ` ON ` + "`" + `users` + "`" + ` (` + "`" + `tokenKey` + "`" + `)",
|
||||
"CREATE UNIQUE INDEX ` + "`" + `idx_email__pb_users_auth_` + "`" + ` ON ` + "`" + `users` + "`" + ` (` + "`" + `email` + "`" + `) WHERE ` + "`" + `email` + "`" + ` != ''"
|
||||
],
|
||||
"listRule": "id = @request.auth.id",
|
||||
"manageRule": null,
|
||||
"mfa": {
|
||||
"duration": 1800,
|
||||
"enabled": false,
|
||||
"rule": ""
|
||||
},
|
||||
"name": "users",
|
||||
"oauth2": {
|
||||
"enabled": false,
|
||||
"mappedFields": {
|
||||
"avatarURL": "avatar",
|
||||
"id": "",
|
||||
"name": "name",
|
||||
"username": ""
|
||||
}
|
||||
},
|
||||
"otp": {
|
||||
"duration": 180,
|
||||
"emailTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>Your one-time password is: <strong>{OTP}</strong></p>\n<p><i>If you didn't ask for the one-time password, you can ignore this email.</i></p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "OTP for {APP_NAME}"
|
||||
},
|
||||
"enabled": false,
|
||||
"length": 8
|
||||
},
|
||||
"passwordAuth": {
|
||||
"enabled": true,
|
||||
"identityFields": [
|
||||
"email"
|
||||
]
|
||||
},
|
||||
"passwordResetToken": {
|
||||
"duration": 1800
|
||||
},
|
||||
"resetPasswordTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>Click on the button below to reset your password.</p>\n<p>\n <a class=\"btn\" href=\"{APP_URL}/_/#/auth/confirm-password-reset/{TOKEN}\" target=\"_blank\" rel=\"noopener\">Reset password</a>\n</p>\n<p><i>If you didn't ask to reset your password, you can ignore this email.</i></p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "Reset your {APP_NAME} password"
|
||||
},
|
||||
"system": false,
|
||||
"type": "auth",
|
||||
"updateRule": "id = @request.auth.id",
|
||||
"verificationTemplate": {
|
||||
"body": "<p>Hello,</p>\n<p>Thank you for joining us at {APP_NAME}.</p>\n<p>Click on the button below to verify your email address.</p>\n<p>\n <a class=\"btn\" href=\"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}\" target=\"_blank\" rel=\"noopener\">Verify</a>\n</p>\n<p>\n Thanks,<br/>\n {APP_NAME} team\n</p>",
|
||||
"subject": "Verify your {APP_NAME} email"
|
||||
},
|
||||
"verificationToken": {
|
||||
"duration": 259200
|
||||
},
|
||||
"viewRule": "id = @request.auth.id"
|
||||
}
|
||||
]`
|
||||
|
||||
return app.ImportCollectionsByMarshaledJSON([]byte(jsonData), false)
|
||||
}, func(app core.App) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -27,6 +27,8 @@ type Feed struct {
|
||||
Created types.DateTime `db:"created" json:"created"`
|
||||
Updated types.DateTime `db:"updated" json:"updated"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Type string `db:"type" json:"type"` // "prof" or "student"
|
||||
User string `db:"user" json:"user"` // Relation to users table
|
||||
core.BaseModel
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,13 @@ func (m *Module) SetName(name string) {
|
||||
}
|
||||
|
||||
type ModuleDTO struct {
|
||||
UUID string `json:"uuid" db:"uuid"`
|
||||
Name string `json:"name" db:"Name"`
|
||||
Prof string `json:"prof" db:"Prof"`
|
||||
Course string `json:"course" db:"course"`
|
||||
Semester string `json:"semester" db:"semester"`
|
||||
EventType string `db:"EventType" json:"eventType"`
|
||||
UUID string `json:"uuid" db:"uuid"`
|
||||
Name string `json:"name" db:"Name"`
|
||||
Prof string `json:"prof" db:"Prof"`
|
||||
Course string `json:"course" db:"course"`
|
||||
Semester string `json:"semester" db:"semester"`
|
||||
EventType string `db:"EventType" json:"eventType"`
|
||||
ConfidenceScore float64 `json:"confidenceScore,omitempty"`
|
||||
}
|
||||
|
||||
func (m *ModuleDTO) GetName() string {
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package serviceModel
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"htwkalender/data-manager/service/events"
|
||||
"htwkalender/data-manager/service/professor"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
App *pocketbase.PocketBase
|
||||
EventService events.EventService
|
||||
CourseService events.CourseService
|
||||
App *pocketbase.PocketBase
|
||||
EventService events.EventService
|
||||
CourseService events.CourseService
|
||||
ProfessorService *professor.ProfessorService
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
v1 "htwkalender/data-manager/service/fetch/v1"
|
||||
v2 "htwkalender/data-manager/service/fetch/v2"
|
||||
"htwkalender/data-manager/service/functions/time"
|
||||
"htwkalender/data-manager/service/professor"
|
||||
"htwkalender/data-manager/service/room"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
@@ -231,6 +232,7 @@ func AddRoutes(services serviceModel.Service) {
|
||||
}).Bind(apis.RequireSuperuserAuth())
|
||||
|
||||
addFeedRoutes(se, services.App)
|
||||
professor.RegisterRoutes(se, services.ProfessorService)
|
||||
|
||||
return se.Next()
|
||||
})
|
||||
|
||||
@@ -18,12 +18,13 @@ package db
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"htwkalender/data-manager/model"
|
||||
"time"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/types"
|
||||
"htwkalender/data-manager/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ core.RecordProxy = (*Feed)(nil)
|
||||
@@ -80,6 +81,22 @@ func (f *Feed) GetUpdated() types.DateTime {
|
||||
return f.GetDateTime("updated")
|
||||
}
|
||||
|
||||
func (f *Feed) GetType() string {
|
||||
return f.GetString("type")
|
||||
}
|
||||
|
||||
func (f *Feed) SetType(feedType string) {
|
||||
f.Set("type", feedType)
|
||||
}
|
||||
|
||||
func (f *Feed) GetUser() string {
|
||||
return f.GetString("user")
|
||||
}
|
||||
|
||||
func (f *Feed) SetUser(user string) {
|
||||
f.Set("user", user)
|
||||
}
|
||||
|
||||
func newFeed(record *core.Record) *Feed {
|
||||
return &Feed{
|
||||
BaseRecordProxy: core.BaseRecordProxy{Record: record},
|
||||
@@ -99,6 +116,13 @@ func NewFeed(collection *core.Collection, feed model.Feed) (*Feed, error) {
|
||||
dbFeed.SetModules(feed.Modules)
|
||||
dbFeed.SetRetrieved(feed.Retrieved)
|
||||
dbFeed.SetDeleted(feed.Deleted)
|
||||
// Set type to "student" as default if not specified
|
||||
if feed.Type == "" {
|
||||
dbFeed.SetType("student")
|
||||
} else {
|
||||
dbFeed.SetType(feed.Type)
|
||||
}
|
||||
dbFeed.SetUser(feed.User)
|
||||
|
||||
return dbFeed, nil
|
||||
}
|
||||
@@ -110,6 +134,8 @@ func (f *Feed) ToModel() model.Feed {
|
||||
Created: f.GetCreated(),
|
||||
Updated: f.GetUpdated(),
|
||||
Deleted: f.GetDeleted(),
|
||||
Type: f.GetType(),
|
||||
User: f.GetUser(),
|
||||
BaseModel: core.BaseModel{
|
||||
Id: f.GetId(),
|
||||
},
|
||||
@@ -143,6 +169,8 @@ func FindFeedByToken(app *pocketbase.PocketBase, token string) (*model.Feed, err
|
||||
feed.Modules = record.GetString("modules")
|
||||
feed.Retrieved = record.GetDateTime("retrieved")
|
||||
feed.Deleted = record.GetBool("deleted")
|
||||
feed.Type = record.GetString("type")
|
||||
feed.User = record.GetString("user")
|
||||
|
||||
//update retrieved time if the is not marked as deleted
|
||||
if !record.GetBool("deleted") {
|
||||
|
||||
@@ -2,9 +2,10 @@ package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
pb "htwkalender/common/genproto/modules"
|
||||
"htwkalender/data-manager/service/db"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
)
|
||||
|
||||
type FeedServiceHandler struct {
|
||||
@@ -25,9 +26,17 @@ func (s *FeedServiceHandler) GetFeed(ctx context.Context, in *pb.GetFeedRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Implement your logic here to fetch feed data based on the UUID
|
||||
// Example response
|
||||
pbFeed := feedToProto(feed)
|
||||
|
||||
// If feed has a user linked, fetch the user's email
|
||||
if feed.User != "" {
|
||||
user, err := s.app.FindRecordById("users", feed.User)
|
||||
if err == nil && user != nil {
|
||||
pbFeed.UserEmail = user.Email()
|
||||
}
|
||||
}
|
||||
|
||||
return &pb.GetFeedResponse{
|
||||
Feed: feedToProto(feed),
|
||||
Feed: pbFeed,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -40,5 +40,7 @@ func feedToProto(feed *model.Feed) *pb.Feed {
|
||||
Retrieved: feed.Retrieved.String(),
|
||||
Modules: feed.Modules,
|
||||
Deleted: feed.Deleted,
|
||||
Type: feed.Type,
|
||||
User: feed.User,
|
||||
}
|
||||
}
|
||||
|
||||
34
services/data-manager/service/hooks.go
Normal file
34
services/data-manager/service/hooks.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func AddHooks(app *pocketbase.PocketBase) {
|
||||
app.OnRecordAuthWithOAuth2Request("users").BindFunc(func(e *core.RecordAuthWithOAuth2RequestEvent) error {
|
||||
email := e.OAuth2User.Email
|
||||
|
||||
// If email is not in the main field, try to extract it from RawUser
|
||||
if email == "" {
|
||||
if rawEmail, ok := e.OAuth2User.RawUser["email"].(string); ok {
|
||||
email = rawEmail
|
||||
// Explicitly set the email on the OAuth2User so PocketBase uses it
|
||||
e.OAuth2User.Email = rawEmail
|
||||
}
|
||||
}
|
||||
|
||||
if email == "" {
|
||||
return apis.NewBadRequestError("No email received from OAuth2 provider. Please ensure your account has an email address and the 'email' scope is granted.", nil)
|
||||
}
|
||||
// Restrict login to @htwk-leipzig.de employees only (not students)
|
||||
if !strings.HasSuffix(email, "@htwk-leipzig.de") {
|
||||
return apis.NewBadRequestError("Login restricted to @htwk-leipzig.de emails. Students (@stud.htwk-leipzig.de) are not allowed.", nil)
|
||||
}
|
||||
|
||||
return e.Next()
|
||||
})
|
||||
}
|
||||
@@ -18,17 +18,33 @@ package ical
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"htwkalender/data-manager/model"
|
||||
"htwkalender/data-manager/service/db"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
)
|
||||
|
||||
func CreateIndividualFeed(modules []model.FeedCollection, pb *pocketbase.PocketBase) (string, error) {
|
||||
return CreateIndividualFeedWithType(modules, "", "", pb)
|
||||
}
|
||||
|
||||
// CreateIndividualFeedWithType creates a feed with specified type and user
|
||||
func CreateIndividualFeedWithType(modules []model.FeedCollection, feedType string, userId string, pb *pocketbase.PocketBase) (string, error) {
|
||||
var icalFeed model.Feed
|
||||
jsonModules, _ := json.Marshal(modules)
|
||||
icalFeed.Modules = string(jsonModules)
|
||||
|
||||
// Set feed type (defaults to "student" in SaveFeed if not provided)
|
||||
if feedType != "" {
|
||||
icalFeed.Type = feedType
|
||||
}
|
||||
|
||||
// Set user relation for professor feeds
|
||||
if userId != "" {
|
||||
icalFeed.User = userId
|
||||
}
|
||||
|
||||
collection, dbError := pb.FindCollectionByNameOrId("feeds")
|
||||
if dbError != nil {
|
||||
return "", apis.NewNotFoundError("Collection could not be found", dbError)
|
||||
|
||||
79
services/data-manager/service/professor/professorService.go
Normal file
79
services/data-manager/service/professor/professorService.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package professor
|
||||
|
||||
import (
|
||||
"htwkalender/data-manager/model"
|
||||
"log/slog"
|
||||
|
||||
commonProf "htwkalender/common/professor"
|
||||
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
)
|
||||
|
||||
type ProfessorService struct {
|
||||
app *pocketbase.PocketBase
|
||||
}
|
||||
|
||||
func NewProfessorService(app *pocketbase.PocketBase) *ProfessorService {
|
||||
return &ProfessorService{app: app}
|
||||
}
|
||||
|
||||
func (s *ProfessorService) GetModulesForProfessor(email string) ([]model.ModuleDTO, error) {
|
||||
// Extract name from email
|
||||
firstName, lastName, err := commonProf.ExtractNameFromEmail(email)
|
||||
if err != nil {
|
||||
slog.Warn("Failed to extract name from email", "email", email, "error", err)
|
||||
return []model.ModuleDTO{}, nil
|
||||
}
|
||||
|
||||
slog.Info("Searching for modules for professor", "firstName", firstName, "lastName", lastName, "email", email)
|
||||
|
||||
// First, get all distinct modules with their professors
|
||||
type EventProf struct {
|
||||
Name string `db:"Name" json:"name"`
|
||||
EventType string `db:"EventType" json:"eventType"`
|
||||
Prof string `db:"Prof" json:"prof"`
|
||||
Course string `db:"course" json:"course"`
|
||||
Semester string `db:"semester" json:"semester"`
|
||||
UUID string `db:"uuid" json:"uuid"`
|
||||
}
|
||||
|
||||
var allEvents []EventProf
|
||||
err = s.app.DB().
|
||||
Select("Name", "EventType", "Prof", "course", "semester", "uuid").
|
||||
From("events").
|
||||
Where(dbx.NewExp("Prof != ''")).
|
||||
GroupBy("Name", "course", "Prof").
|
||||
Distinct(true).
|
||||
All(&allEvents)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Filter events by matching professor name and calculate confidence scores
|
||||
var modules []model.ModuleDTO
|
||||
seenModules := make(map[string]bool) // key: Name+Course to avoid duplicates
|
||||
|
||||
for _, event := range allEvents {
|
||||
score := commonProf.CalculateConfidenceScore(event.Prof, firstName, lastName)
|
||||
if score > 0 { // Include all modules with any match
|
||||
key := event.Name + "|" + event.Course
|
||||
if !seenModules[key] {
|
||||
modules = append(modules, model.ModuleDTO{
|
||||
Name: event.Name,
|
||||
EventType: event.EventType,
|
||||
Prof: event.Prof,
|
||||
Course: event.Course,
|
||||
Semester: event.Semester,
|
||||
UUID: event.UUID,
|
||||
ConfidenceScore: score,
|
||||
})
|
||||
seenModules[key] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slog.Info("Found modules for professor", "count", len(modules), "lastName", lastName)
|
||||
return modules, nil
|
||||
}
|
||||
63
services/data-manager/service/professor/routes.go
Normal file
63
services/data-manager/service/professor/routes.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package professor
|
||||
|
||||
import (
|
||||
"htwkalender/data-manager/model"
|
||||
"htwkalender/data-manager/service/ical"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"github.com/pocketbase/pocketbase/apis"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func RegisterRoutes(se *core.ServeEvent, service *ProfessorService) {
|
||||
se.Router.GET("/api/professor/modules", func(e *core.RequestEvent) error {
|
||||
record := e.Auth
|
||||
if record == nil {
|
||||
return apis.NewForbiddenError("Only authenticated users can access this endpoint", nil)
|
||||
}
|
||||
|
||||
email := record.GetString("email")
|
||||
if email == "" {
|
||||
return apis.NewBadRequestError("User has no email", nil)
|
||||
}
|
||||
|
||||
modules, err := service.GetModulesForProfessor(email)
|
||||
if err != nil {
|
||||
return apis.NewBadRequestError("Failed to fetch modules", err)
|
||||
}
|
||||
|
||||
return e.JSON(http.StatusOK, modules)
|
||||
}).Bind(apis.RequireAuth())
|
||||
|
||||
// POST /api/professor/feed - Create a professor-specific feed
|
||||
se.Router.POST("/api/professor/feed", func(e *core.RequestEvent) error {
|
||||
record := e.Auth
|
||||
if record == nil {
|
||||
return apis.NewForbiddenError("Only authenticated users can access this endpoint", nil)
|
||||
}
|
||||
|
||||
userId := record.Id
|
||||
if userId == "" {
|
||||
return apis.NewBadRequestError("User ID not found", nil)
|
||||
}
|
||||
|
||||
// Bind the feed collection from request body
|
||||
var feedCollection []model.FeedCollection
|
||||
err := e.BindBody(&feedCollection)
|
||||
if err != nil {
|
||||
slog.Error("Failed to bind request body", "error", err)
|
||||
return apis.NewBadRequestError("Invalid request body", err)
|
||||
}
|
||||
|
||||
// Create feed with type="prof" and link to authenticated user
|
||||
token, err := ical.CreateIndividualFeedWithType(feedCollection, "prof", userId, service.app)
|
||||
if err != nil {
|
||||
slog.Error("Failed to create professor feed", "error", err, "userId", userId)
|
||||
return apis.NewInternalServerError("Failed to create professor feed", err)
|
||||
}
|
||||
|
||||
slog.Info("Created professor feed", "userId", userId, "token", token)
|
||||
return e.JSON(http.StatusOK, token)
|
||||
}).Bind(apis.RequireAuth())
|
||||
}
|
||||
@@ -27,6 +27,9 @@ type BaseModel struct {
|
||||
type Feed struct {
|
||||
Modules string `db:"modules" json:"modules"`
|
||||
Retrieved JSONTime `db:"retrieved" json:"retrieved"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Type string `db:"type" json:"type"` // "prof" or "student"
|
||||
User string `db:"user" json:"user"` // Relation to users table
|
||||
BaseModel
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,9 @@ type FeedRecord struct {
|
||||
Modules []FeedModule `db:"modules" json:"modules"`
|
||||
Retrieved JSONTime `db:"retrieved" json:"retrieved"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Type string `db:"type" json:"type"` // "prof" or "student"
|
||||
User string `db:"user" json:"user"` // User ID relation
|
||||
UserEmail string `db:"user_email" json:"userEmail"` // User Email for filtering
|
||||
BaseModel
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,13 @@ package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/goccy/go-json"
|
||||
"google.golang.org/grpc"
|
||||
pb "htwkalender/common/genproto/modules"
|
||||
"htwkalender/ical/model"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func GetFeed(feedId string, conn *grpc.ClientConn) (model.FeedRecord, error) {
|
||||
@@ -65,5 +66,8 @@ func protoToFeed(feed *pb.Feed) (model.FeedRecord, error) {
|
||||
Retrieved: model.ToJSONTime(feed.Retrieved),
|
||||
Modules: modules,
|
||||
Deleted: feed.Deleted,
|
||||
Type: feed.Type,
|
||||
User: feed.User,
|
||||
UserEmail: feed.UserEmail,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import (
|
||||
"htwkalender/ical/service/functions"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
commonProf "htwkalender/common/professor"
|
||||
)
|
||||
|
||||
const expirationTime = 5 * time.Minute
|
||||
@@ -59,6 +61,11 @@ func Feed(app model.AppType, token string, userAgent string) (string, string, er
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// Filter by professor if type is "prof"
|
||||
if feed.Type == "prof" && feed.UserEmail != "" {
|
||||
events = filterEventsByProfessor(events, feed.UserEmail)
|
||||
}
|
||||
|
||||
// Sort events by start date
|
||||
events.Sort()
|
||||
|
||||
@@ -126,3 +133,22 @@ func FeedRoom(app model.AppType, room string, userAgent string) (string, string,
|
||||
|
||||
return icalFeed.Content, etag, nil
|
||||
}
|
||||
|
||||
func filterEventsByProfessor(events model.Events, email string) model.Events {
|
||||
if email == "" {
|
||||
return events
|
||||
}
|
||||
|
||||
firstName, lastName, err := commonProf.ExtractNameFromEmail(email)
|
||||
if err != nil {
|
||||
return events
|
||||
}
|
||||
|
||||
var filteredEvents model.Events
|
||||
for _, event := range events {
|
||||
if commonProf.MatchesProfessor(event.Prof, firstName, lastName) {
|
||||
filteredEvents = append(filteredEvents, event)
|
||||
}
|
||||
}
|
||||
return filteredEvents
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ message Feed {
|
||||
string created = 4;
|
||||
string updated = 5;
|
||||
bool deleted = 6;
|
||||
string type = 7; // "prof" or "student"
|
||||
string user = 8; // User ID relation
|
||||
string user_email = 9; // User Email for filtering
|
||||
}
|
||||
|
||||
message GetFeedRequest {
|
||||
|
||||
350
services/protobuf/htwkalender/common/modules/feeds.pb.go
Normal file
350
services/protobuf/htwkalender/common/modules/feeds.pb.go
Normal file
@@ -0,0 +1,350 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.1
|
||||
// protoc v5.27.1
|
||||
// source: feeds.proto
|
||||
|
||||
package modules
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type Feed struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Modules string `protobuf:"bytes,2,opt,name=modules,proto3" json:"modules,omitempty"`
|
||||
Retrieved string `protobuf:"bytes,3,opt,name=retrieved,proto3" json:"retrieved,omitempty"`
|
||||
Created string `protobuf:"bytes,4,opt,name=created,proto3" json:"created,omitempty"`
|
||||
Updated string `protobuf:"bytes,5,opt,name=updated,proto3" json:"updated,omitempty"`
|
||||
Deleted bool `protobuf:"varint,6,opt,name=deleted,proto3" json:"deleted,omitempty"`
|
||||
Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type,omitempty"` // "prof" or "student"
|
||||
User string `protobuf:"bytes,8,opt,name=user,proto3" json:"user,omitempty"` // User ID relation
|
||||
UserEmail string `protobuf:"bytes,9,opt,name=user_email,json=userEmail,proto3" json:"user_email,omitempty"` // User Email for filtering
|
||||
}
|
||||
|
||||
func (x *Feed) Reset() {
|
||||
*x = Feed{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_feeds_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Feed) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Feed) ProtoMessage() {}
|
||||
|
||||
func (x *Feed) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_feeds_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Feed.ProtoReflect.Descriptor instead.
|
||||
func (*Feed) Descriptor() ([]byte, []int) {
|
||||
return file_feeds_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Feed) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetModules() string {
|
||||
if x != nil {
|
||||
return x.Modules
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetRetrieved() string {
|
||||
if x != nil {
|
||||
return x.Retrieved
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetCreated() string {
|
||||
if x != nil {
|
||||
return x.Created
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetUpdated() string {
|
||||
if x != nil {
|
||||
return x.Updated
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetDeleted() bool {
|
||||
if x != nil {
|
||||
return x.Deleted
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Feed) GetType() string {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetUser() string {
|
||||
if x != nil {
|
||||
return x.User
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Feed) GetUserEmail() string {
|
||||
if x != nil {
|
||||
return x.UserEmail
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type GetFeedRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GetFeedRequest) Reset() {
|
||||
*x = GetFeedRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_feeds_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *GetFeedRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetFeedRequest) ProtoMessage() {}
|
||||
|
||||
func (x *GetFeedRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_feeds_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetFeedRequest.ProtoReflect.Descriptor instead.
|
||||
func (*GetFeedRequest) Descriptor() ([]byte, []int) {
|
||||
return file_feeds_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *GetFeedRequest) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type GetFeedResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Feed *Feed `protobuf:"bytes,1,opt,name=feed,proto3" json:"feed,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GetFeedResponse) Reset() {
|
||||
*x = GetFeedResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_feeds_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *GetFeedResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetFeedResponse) ProtoMessage() {}
|
||||
|
||||
func (x *GetFeedResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_feeds_proto_msgTypes[2]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetFeedResponse.ProtoReflect.Descriptor instead.
|
||||
func (*GetFeedResponse) Descriptor() ([]byte, []int) {
|
||||
return file_feeds_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *GetFeedResponse) GetFeed() *Feed {
|
||||
if x != nil {
|
||||
return x.Feed
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_feeds_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_feeds_proto_rawDesc = []byte{
|
||||
0x0a, 0x0b, 0x66, 0x65, 0x65, 0x64, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe3, 0x01,
|
||||
0x0a, 0x04, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
|
||||
0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73,
|
||||
0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x64, 0x18, 0x03, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x76, 0x65, 0x64, 0x12, 0x18,
|
||||
0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x70, 0x64, 0x61,
|
||||
0x74, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74,
|
||||
0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20,
|
||||
0x01, 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x74, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
||||
0x75, 0x73, 0x65, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x65, 0x6d, 0x61,
|
||||
0x69, 0x6c, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x45, 0x6d,
|
||||
0x61, 0x69, 0x6c, 0x22, 0x20, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x66, 0x65, 0x65, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x46, 0x65, 0x65, 0x64, 0x52, 0x04, 0x66,
|
||||
0x65, 0x65, 0x64, 0x32, 0x3d, 0x0a, 0x0b, 0x46, 0x65, 0x65, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69,
|
||||
0x63, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0f, 0x2e,
|
||||
0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10,
|
||||
0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x22, 0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x68, 0x74, 0x77, 0x6b, 0x61, 0x6c, 0x65, 0x6e, 0x64, 0x65,
|
||||
0x72, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_feeds_proto_rawDescOnce sync.Once
|
||||
file_feeds_proto_rawDescData = file_feeds_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_feeds_proto_rawDescGZIP() []byte {
|
||||
file_feeds_proto_rawDescOnce.Do(func() {
|
||||
file_feeds_proto_rawDescData = protoimpl.X.CompressGZIP(file_feeds_proto_rawDescData)
|
||||
})
|
||||
return file_feeds_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_feeds_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_feeds_proto_goTypes = []interface{}{
|
||||
(*Feed)(nil), // 0: Feed
|
||||
(*GetFeedRequest)(nil), // 1: GetFeedRequest
|
||||
(*GetFeedResponse)(nil), // 2: GetFeedResponse
|
||||
}
|
||||
var file_feeds_proto_depIdxs = []int32{
|
||||
0, // 0: GetFeedResponse.feed:type_name -> Feed
|
||||
1, // 1: FeedService.GetFeed:input_type -> GetFeedRequest
|
||||
2, // 2: FeedService.GetFeed:output_type -> GetFeedResponse
|
||||
2, // [2:3] is the sub-list for method output_type
|
||||
1, // [1:2] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
1, // [1:1] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_feeds_proto_init() }
|
||||
func file_feeds_proto_init() {
|
||||
if File_feeds_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_feeds_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Feed); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_feeds_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GetFeedRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_feeds_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GetFeedResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_feeds_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 3,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_feeds_proto_goTypes,
|
||||
DependencyIndexes: file_feeds_proto_depIdxs,
|
||||
MessageInfos: file_feeds_proto_msgTypes,
|
||||
}.Build()
|
||||
File_feeds_proto = out.File
|
||||
file_feeds_proto_rawDesc = nil
|
||||
file_feeds_proto_goTypes = nil
|
||||
file_feeds_proto_depIdxs = nil
|
||||
}
|
||||
105
services/protobuf/htwkalender/common/modules/feeds_grpc.pb.go
Normal file
105
services/protobuf/htwkalender/common/modules/feeds_grpc.pb.go
Normal file
@@ -0,0 +1,105 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v5.27.1
|
||||
// source: feeds.proto
|
||||
|
||||
package modules
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// FeedServiceClient is the client API for FeedService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type FeedServiceClient interface {
|
||||
GetFeed(ctx context.Context, in *GetFeedRequest, opts ...grpc.CallOption) (*GetFeedResponse, error)
|
||||
}
|
||||
|
||||
type feedServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewFeedServiceClient(cc grpc.ClientConnInterface) FeedServiceClient {
|
||||
return &feedServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *feedServiceClient) GetFeed(ctx context.Context, in *GetFeedRequest, opts ...grpc.CallOption) (*GetFeedResponse, error) {
|
||||
out := new(GetFeedResponse)
|
||||
err := c.cc.Invoke(ctx, "/FeedService/GetFeed", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// FeedServiceServer is the server API for FeedService service.
|
||||
// All implementations must embed UnimplementedFeedServiceServer
|
||||
// for forward compatibility
|
||||
type FeedServiceServer interface {
|
||||
GetFeed(context.Context, *GetFeedRequest) (*GetFeedResponse, error)
|
||||
mustEmbedUnimplementedFeedServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedFeedServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedFeedServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedFeedServiceServer) GetFeed(context.Context, *GetFeedRequest) (*GetFeedResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetFeed not implemented")
|
||||
}
|
||||
func (UnimplementedFeedServiceServer) mustEmbedUnimplementedFeedServiceServer() {}
|
||||
|
||||
// UnsafeFeedServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to FeedServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeFeedServiceServer interface {
|
||||
mustEmbedUnimplementedFeedServiceServer()
|
||||
}
|
||||
|
||||
func RegisterFeedServiceServer(s grpc.ServiceRegistrar, srv FeedServiceServer) {
|
||||
s.RegisterService(&FeedService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _FeedService_GetFeed_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetFeedRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(FeedServiceServer).GetFeed(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/FeedService/GetFeed",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(FeedServiceServer).GetFeed(ctx, req.(*GetFeedRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// FeedService_ServiceDesc is the grpc.ServiceDesc for FeedService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var FeedService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "FeedService",
|
||||
HandlerType: (*FeedServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetFeed",
|
||||
Handler: _FeedService_GetFeed_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "feeds.proto",
|
||||
}
|
||||
Reference in New Issue
Block a user