refactor: authentication

This commit is contained in:
Mo
2023-05-12 10:28:18 -05:00
parent d97fb09517
commit 5ca7132c2d
9 changed files with 70 additions and 19 deletions
@@ -0,0 +1,36 @@
import { ItemShare } from '../../ItemShare/Model/ItemShare'
import { Item } from '../../Item/Item'
import { ItemShareServiceInterface } from '../../ItemShare/Service/ItemShareServiceInterface'
import { UseCaseInterface } from '../UseCaseInterface'
export type GetSharedItemResponse =
| {
success: true
item: Item
itemShare: ItemShare
}
| {
success: false
message: string
}
export class GetSharedItemUseCase implements UseCaseInterface {
constructor(private itemShareService: ItemShareServiceInterface) {}
async execute(dto: { shareToken: string }): Promise<GetSharedItemResponse> {
const result = await this.itemShareService.getSharedItem(dto.shareToken)
if (result === null) {
return {
success: false,
message: `Could not get shared item with token ${dto.shareToken}`,
}
}
return {
success: true,
item: result.item,
itemShare: result.itemShare,
}
}
}
@@ -0,0 +1,33 @@
import { ItemShare } from '../../ItemShare/Model/ItemShare'
import { ItemShareServiceInterface } from '../../ItemShare/Service/ItemShareServiceInterface'
import { UseCaseInterface } from '../UseCaseInterface'
export type GetUserItemSharesResponse =
| {
success: true
itemShares: ItemShare[]
}
| {
success: false
message: string
}
export class GetUserItemSharesUseCase implements UseCaseInterface {
constructor(private itemShareService: ItemShareServiceInterface) {}
async execute(dto: { userUuid: string }): Promise<GetUserItemSharesResponse> {
const result = await this.itemShareService.getUserItemShares(dto.userUuid)
if (result === null) {
return {
success: false,
message: `Could not get user item shares for user ${dto.userUuid}`,
}
}
return {
success: true,
itemShares: result,
}
}
}
@@ -0,0 +1,34 @@
import { ItemShare } from '../../ItemShare/Model/ItemShare'
import { ItemShareServiceInterface } from '../../ItemShare/Service/ItemShareServiceInterface'
import { ShareItemDTO } from '../../ItemShare/Service/ShareItemDTO'
import { UseCaseInterface } from '../UseCaseInterface'
export type ShareItemResponse =
| {
success: true
itemShare: ItemShare
}
| {
success: false
message: string
}
export class ShareItemUseCase implements UseCaseInterface {
constructor(private itemShareService: ItemShareServiceInterface) {}
async execute(dto: ShareItemDTO): Promise<ShareItemResponse> {
const result = await this.itemShareService.shareItem(dto)
if (result === null) {
return {
success: false,
message: `Could not share item with uuid ${dto.itemUuid}`,
}
}
return {
success: true,
itemShare: result.itemShare,
}
}
}
@@ -0,0 +1,31 @@
import { ItemShareServiceInterface } from '../../ItemShare/Service/ItemShareServiceInterface'
import { UpdateSharedItemDto } from '../../ItemShare/Service/UpdateSharedItemDto'
import { UseCaseInterface } from '../UseCaseInterface'
export type UpdateSharedItemResponse =
| {
success: true
}
| {
success: false
message: string
}
export class UpdateSharedItemUseCase implements UseCaseInterface {
constructor(private itemShareService: ItemShareServiceInterface) {}
async execute(dto: UpdateSharedItemDto): Promise<UpdateSharedItemResponse> {
const result = await this.itemShareService.updateSharedItem(dto)
if (result === null) {
return {
success: false,
message: `Could not update shared item with token ${dto.shareToken}`,
}
}
return {
success: true,
}
}
}