# Bang Backend

## rerequisites
 
- dotnet sdk7 installed
- running Postgres compatible database running

## How to start

```bash
cd Api
dotnet run
```

## Access the Graphql Api

- open Api in browser
- navigate to `/graphql`

## Graphql Schema

```graphql
type Query {
  userByCode(userCode: String!): User
  teamByCode(teamCode: String!): Team
}

type Mutation {
  createUser(input: CreateUserInput!): CreateUserPayload!
  startSession(input: StartSessionInput!): StartSessionPayload!
  stopCurrentSession(
    input: StopCurrentSessionInput!
  ): StopCurrentSessionPayload!
  createTeam(input: CreateTeamInput!): CreateTeamPayload!
}

type TeamNotFoundError implements Error {
  message: String!
}

type UserExistsError implements Error {
  message: String!
}

type AlreadySessionError implements Error {
  message: String!
}

type UserNotFoundError implements Error {
  message: String!
}

type NoActiveSessionError implements Error {
  message: String!
}

type DuplicateTeamCodeError implements Error {
  message: String!
}

interface Error {
  message: String!
}

input TeamSettingsInput {
  sessionDurationMinutes: Int!
  shortBreakDurationMinutes: Int!
  longBreakDurationMinutes: Int!
}

type Team {
  teamCode: String!
  name: String!
  settings: TeamSettings!
  users: [User!]!
}

type TimeSpent {
  id: UUID!
  startDate: DateTime!
  endDate: DateTime!
  remarks: String
  userCode: String!
  user: User!
}

type User {
  userCode: String!
  name: String!
  team: Team!
  timeSpent: [TimeSpent!]!
  currentSession: TimeSpent
  latestSession: TimeSpent
}

"""
The `DateTime` scalar represents an ISO-8601 compliant date time type.
"""
scalar DateTime

scalar UUID

type TeamSettings {
  sessionDurationMinutes: Int!
  shortBreakDurationMinutes: Int!
  longBreakDurationMinutes: Int!
}

input CreateUserInput {
  userName: String!
  teamCode: String!
}

union CreateUserError = TeamNotFoundError | UserExistsError

type CreateUserPayload {
  user: User
  errors: [CreateUserError!]
  query: Query!
}

input StartSessionInput {
  userCode: String!
}

union StartSessionError = AlreadySessionError | UserNotFoundError

type StartSessionPayload {
  timeSpent: TimeSpent
  errors: [StartSessionError!]
  query: Query!
}

input StopCurrentSessionInput {
  userCode: String!
}

union StopCurrentSessionError = NoActiveSessionError

type StopCurrentSessionPayload {
  timeSpent: TimeSpent
  errors: [StopCurrentSessionError!]
  query: Query!
}

input CreateTeamInput {
  teamCode: String
  teamName: String!
  settings: TeamSettingsInput!
}

union CreateTeamError = DuplicateTeamCodeError

type CreateTeamPayload {
  team: Team
  errors: [CreateTeamError!]
  query: Query!
}

```