mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
Refactor data layer, add business layer
This commit is contained in:
36
DataLayer/scripts/crud/USP_CreateUserAccount.sql
Normal file
36
DataLayer/scripts/crud/USP_CreateUserAccount.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
CREATE OR ALTER PROCEDURE usp_CreateUserAccount
|
||||
(
|
||||
@UserAccountId UNIQUEIDENTIFIER = NULL,
|
||||
@Username VARCHAR(64),
|
||||
@FirstName NVARCHAR(128),
|
||||
@LastName NVARCHAR(128),
|
||||
@DateOfBirth DATETIME,
|
||||
@Email VARCHAR(128)
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
SET XACT_ABORT ON
|
||||
BEGIN TRANSACTION
|
||||
|
||||
INSERT INTO UserAccount
|
||||
(
|
||||
UserAccountID,
|
||||
Username,
|
||||
FirstName,
|
||||
LastName,
|
||||
DateOfBirth,
|
||||
Email
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
COALESCE(@UserAccountId, NEWID()),
|
||||
@Username,
|
||||
@FirstName,
|
||||
@LastName,
|
||||
@DateOfBirth,
|
||||
@Email
|
||||
);
|
||||
COMMIT TRANSACTION
|
||||
END;
|
||||
23
DataLayer/scripts/crud/USP_DeleteUserAccount.sql
Normal file
23
DataLayer/scripts/crud/USP_DeleteUserAccount.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
CREATE OR ALTER PROCEDURE usp_DeleteUserAccount
|
||||
(
|
||||
@UserAccountId UNIQUEIDENTIFIER
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
SET XACT_ABORT ON
|
||||
BEGIN TRANSACTION
|
||||
|
||||
IF NOT EXISTS (SELECT 1 FROM UserAccount WHERE UserAccountId = @UserAccountId)
|
||||
BEGIN
|
||||
RAISERROR('UserAccount with the specified ID does not exist.', 16,
|
||||
1);
|
||||
ROLLBACK TRANSACTION
|
||||
RETURN
|
||||
END
|
||||
|
||||
DELETE FROM UserAccount
|
||||
WHERE UserAccountId = @UserAccountId;
|
||||
COMMIT TRANSACTION
|
||||
END;
|
||||
17
DataLayer/scripts/crud/USP_GetAllUserAccounts.sql
Normal file
17
DataLayer/scripts/crud/USP_GetAllUserAccounts.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
CREATE OR ALTER PROCEDURE usp_GetAllUserAccounts
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT UserAccountID,
|
||||
Username,
|
||||
FirstName,
|
||||
LastName,
|
||||
Email,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
DateOfBirth,
|
||||
Timer
|
||||
FROM dbo.UserAccount;
|
||||
END;
|
||||
21
DataLayer/scripts/crud/USP_GetUserAccountByEmail.sql
Normal file
21
DataLayer/scripts/crud/USP_GetUserAccountByEmail.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
CREATE OR ALTER PROCEDURE usp_GetUserAccountByEmail
|
||||
(
|
||||
@Email VARCHAR(128)
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT UserAccountID,
|
||||
Username,
|
||||
FirstName,
|
||||
LastName,
|
||||
Email,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
DateOfBirth,
|
||||
Timer
|
||||
FROM dbo.UserAccount
|
||||
WHERE Email = @Email;
|
||||
END;
|
||||
21
DataLayer/scripts/crud/USP_GetUserAccountById.sql
Normal file
21
DataLayer/scripts/crud/USP_GetUserAccountById.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
CREATE OR ALTER PROCEDURE usp_GetUserAccountById
|
||||
(
|
||||
@UserAccountId UNIQUEIDENTIFIER
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT UserAccountID,
|
||||
Username,
|
||||
FirstName,
|
||||
LastName,
|
||||
Email,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
DateOfBirth,
|
||||
Timer
|
||||
FROM dbo.UserAccount
|
||||
WHERE UserAccountID = @UserAccountId;
|
||||
END;
|
||||
21
DataLayer/scripts/crud/USP_GetUserAccountByUsername.sql
Normal file
21
DataLayer/scripts/crud/USP_GetUserAccountByUsername.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
CREATE OR ALTER PROCEDURE usp_GetUserAccountByUsername
|
||||
(
|
||||
@Username VARCHAR(64)
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
SELECT UserAccountID,
|
||||
Username,
|
||||
FirstName,
|
||||
LastName,
|
||||
Email,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
DateOfBirth,
|
||||
Timer
|
||||
FROM dbo.UserAccount
|
||||
WHERE Username = @Username;
|
||||
END;
|
||||
35
DataLayer/scripts/crud/USP_UpdateUserAccount.sql
Normal file
35
DataLayer/scripts/crud/USP_UpdateUserAccount.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
CREATE OR ALTER PROCEDURE usp_UpdateUserAccount
|
||||
(
|
||||
@Username VARCHAR(64),
|
||||
@FirstName NVARCHAR(128),
|
||||
@LastName NVARCHAR(128),
|
||||
@DateOfBirth DATETIME,
|
||||
@Email VARCHAR(128),
|
||||
@UserAccountId UNIQUEIDENTIFIER
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
SET XACT_ABORT ON
|
||||
BEGIN TRANSACTION
|
||||
|
||||
IF NOT EXISTS (SELECT 1 FROM UserAccount WHERE UserAccountId = @UserAccountId)
|
||||
BEGIN
|
||||
RAISERROR('UserAccount with the specified ID does not exist.', 16,
|
||||
1);
|
||||
ROLLBACK TRANSACTION
|
||||
RETURN
|
||||
END
|
||||
|
||||
UPDATE UserAccount
|
||||
SET
|
||||
Username = @Username,
|
||||
FirstName = @FirstName,
|
||||
LastName = @LastName,
|
||||
DateOfBirth = @DateOfBirth,
|
||||
Email = @Email
|
||||
WHERE UserAccountId = @UserAccountId;
|
||||
|
||||
COMMIT TRANSACTION
|
||||
END;
|
||||
Reference in New Issue
Block a user