/* ScheduleTogether Backend Copyright (C) 2024, Zervó Zadachin DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License version 3 for more details. This program incorporates external libraries for certain functionalities. These libraries are covered by their respective licenses, and their usage agreements are as outlined in their respective documentation or source code. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package handlers import ( "github.com/kataras/iris/v12" "git.zervo.org/scheduletogether/backend/internal/api/middlewares" "git.zervo.org/scheduletogether/backend/internal/api/services/accounts" perms "git.zervo.org/scheduletogether/backend/pkg/permissions" "git.zervo.org/scheduletogether/backend/pkg/types" ) // AccountHandler_RegisterRoutes registers routes for the AccountHandler func AccountHandler_RegisterRoutes(party iris.Party) { party.Post("/register", AccountRegister_Handler) party.Post("/signin", AccountSignin_Handler) party.Post("/verify", AccountVerify_Handler) party.Use(middlewares.Authenticate()) // only allow authenticated users for following endpoints party.Post("/signout", middlewares.Authorize(perms.SignOut), AccountSignout_Handler) } // AccountRegister_Handler handles the POST /account/register endpoint func AccountRegister_Handler(ctx iris.Context) { var requestBody types.AccountRegisterRequest // Validate the request body against the AccountRegisterRequest schema if err := ctx.ReadJSON(&requestBody); err != nil { ctx.StatusCode(iris.StatusBadRequest) ctx.JSON(types.CommonErrorResponse{ Error: "Request validation failed, please check the request body and try again", }) return } // Call the AccountRegister_Service function to register user accounts.AccountRegister_Service(ctx, requestBody) } func AccountVerify_Handler(ctx iris.Context) { var requestBody types.AccountVerifyRequest // Validate the request body against the AccountVerifyRequest schema if err := ctx.ReadJSON(&requestBody); err != nil { ctx.StatusCode(iris.StatusBadRequest) ctx.JSON(types.CommonErrorResponse{ Error: "Request validation failed, please check the request body and try again", }) return } // Call the AccountVerify_Service function to verify user accounts.AccountVerify_Service(ctx, requestBody) } // AccountSignin_Handler handles the POST /account/signin endpoint func AccountSignin_Handler(ctx iris.Context) { var requestBody types.AccountLoginRequest // Validate the request body against the AccountLoginRequest schema if err := ctx.ReadJSON(&requestBody); err != nil { ctx.StatusCode(iris.StatusBadRequest) ctx.JSON(types.CommonErrorResponse{ Error: "Request validation failed, please check the request body and try again", }) return } // Call the AccountSignin_Service function to signin user accounts.AccountSignin_Service(ctx, requestBody) } // AccountSignout_Handler handles the POST /account/signout endpoint func AccountSignout_Handler(ctx iris.Context) { // Call the AccountSignout_Service function to signout user accounts.AccountSignout_Service(ctx) }