Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: vehicle preferences #3

Open
Jun4928 opened this issue Feb 10, 2024 · 0 comments
Open

feature: vehicle preferences #3

Jun4928 opened this issue Feb 10, 2024 · 0 comments
Assignees
Labels
feature New feature

Comments

@Jun4928
Copy link
Owner

Jun4928 commented Feb 10, 2024

Goals

  • Create endpoints to retrieve and update a user's saved vehicles.
  • Simply use in-memory data

API Spec

below APIs need user authentication first,

  • GET /users/vehicles, retrieve all the stored items
  • GET /users/vehicles/:vehicleId, retrieve the specific stored item
  • POST /users/vehicles, create one
  • PUT /users/vehicles/:vehicleId, replace entire stored item with the new body
  • DELETE /users/vehicles/:vehicleId, delete one

Types

type Vehicle = {
  id: number
  brand: string
  model: string
  year: number
}

Service Interfaces

get-users-vehicles.service

type Input = {
  userId: number
  vehicleId: number | null // when null retrieve all
}

type Output = Promise<Vehicle[]>

create-users-vehicles.service

type Input = {
  userId: number
  vehicle: CreateVehicleData
} 

type Output = Promise<Vehicle>

update-users-vehicles.service

type Input = {
  userId: number
  vehicleId: number
  vehicle: UpdateVehicleData
}

type Output = Promise<Vehicle>

delete-users-vehicles.service

type Input = {
  userId: number
  vehicleId: number
}

type Output = Promise<void>

In-memory database

  • in-memory database implements this interface
export type UserVehicle = {
  userId: number;
  vehicle: Vehicle;
};

export type CreateVehicleData = Omit<Vehicle, "id">;

export type UpdateVehicleData = Omit<Vehicle, "id">;

type Result = {
  succeed: boolean;
  reason: string | null;
};

export interface VehicleDatabase {
  getAll(userId: number): Promise<UserVehicle[]>;

  getOne(userId: number, vehicleId: number): Promise<UserVehicle | null>;

  create(userId: number, vehicle: CreateVehicleData): Promise<UserVehicle>;

  updateOne(
    userId: number,
    vehicleId: number,
    vehicle: UpdateVehicleData,
  ): Promise<UserVehicle | Result>;

  deleteOne(userId: number, vehicleId: number): Promise<Result>;

  clear(): Promise<void>;
}

Tests

  • get-users-vehicles.service.test
  • create-users-vehicles.service.test
  • update-users-vehicles.service.test
  • delete-users-vehicles.service.test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

No branches or pull requests

1 participant