Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace api_cinema_challenge.DTO.Calls;

public class CustomerPost
{
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
}
10 changes: 10 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTO/Calls/CustomerPut.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace api_cinema_challenge.DTO.Calls;

public class CustomerPut
{
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
}
51 changes: 51 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTO/Calls/MoviePost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using api_cinema_challenge.DTO.Calls;
using api_cinema_challenge.Models;

namespace api_cinema_challenge.DTO;

/*
Create a new movie. Optionally, a screenings array can be provided to create screenings when the movie gets created. If no screenings array is provided, the movie should be created as normal.
Request Body schema: application/json
title
required

string
rating
required

string
description
required

string
runtimeMins
required

integer
Array of objects

{

"title": "Dodgeball",
"rating": "PG-13",
"description": "The greatest movie ever made.",
"runtimeMins": 126,
"screenings":

[

{}
]

}
*/
public class MoviePost
{
public string Title { get; set; }
public string Rating { get; set; }
public string Description { get; set; }
public int RuntimeMins { get; set; }
public IEnumerable<ScreeningPost> Screenings { get; set; }
}

11 changes: 11 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTO/Calls/MoviePut.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace api_cinema_challenge.DTO.Calls;

public class MoviePut
{
public string Title { get; set; }
public string Rating { get; set; }
public string Description { get; set; }
public int RuntimeMins { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace api_cinema_challenge.DTO.Calls;

public class ScreeningPost
{
public int ScreenNumber { get; set; }
public int Capacity { get; set; }
public DateTime StartsAt { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace api_cinema_challenge.DTO.Calls;

public class TicketPost
{
public int NumSeats { get; set; }
}
15 changes: 15 additions & 0 deletions api-cinema-challenge/api-cinema-challenge/DTO/Payload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace api_cinema_challenge.DTO;

public class Payload<T>
{
public string Message { get; set; }
public T Data { get; set; }

public Payload(T data)
{
Message = "success";
Data = data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace api_cinema_challenge.DTO.Responses;

public class CustomerDTO
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace api_cinema_challenge.DTO.Responses;

public class MovieDTO
{
public int Id { get; set; }
public string Title { get; set; }
public string Rating { get; set; }
public string Description { get; set; }
public int RuntimeMins { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace api_cinema_challenge.DTO.Responses;

public class ScreeningDTO
{
public int MovieId { get; set; }
public int ScreenNumber { get; set; }
public int Capacity { get; set; }
public DateTime StartsAt { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using api_cinema_challenge.Models;

namespace api_cinema_challenge.DTO.Responses;

public class TicketDTO
{

public int Id { get; set; }
public int NumSeats { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
17 changes: 14 additions & 3 deletions api-cinema-challenge/api-cinema-challenge/Data/CinemaContext.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Microsoft.EntityFrameworkCore;
using api_cinema_challenge.Models;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;

namespace api_cinema_challenge.Data
{
public class CinemaContext : DbContext
{
private string _connectionString;
public CinemaContext(DbContextOptions<CinemaContext> options) : base(options)
public CinemaContext()
{
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
_connectionString = configuration.GetValue<string>("ConnectionStrings:DefaultConnectionString")!;
Expand All @@ -20,7 +21,17 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{


CinemaData cd = new CinemaData();
modelBuilder.Entity<Movie>().HasData(cd.Movies);
modelBuilder.Entity<Customer>().HasData(cd.Customers);
modelBuilder.Entity<Screening>().HasData(cd.Screenings);
modelBuilder.Entity<Ticket>().HasData(cd.Tickets);
}

public DbSet<Customer> Customers { get; set; }
public DbSet<Movie> Movies { get; set; }
public DbSet<Screening> Screenings { get; set; }
public DbSet<Ticket> Tickets { get; set; }
}
}
Loading