Skip to content

Commit

Permalink
Merge pull request #23 from DeeJayTC/vnext
Browse files Browse the repository at this point in the history
Vnext
  • Loading branch information
DeeJayTC committed May 6, 2022
2 parents fbd62d2 + db673fa commit 9217b55
Show file tree
Hide file tree
Showing 47 changed files with 1,150 additions and 431 deletions.
6 changes: 6 additions & 0 deletions sample/ApiGeneratorSampleApp/ApiGeneratorSampleApI.csproj
Expand Up @@ -46,4 +46,10 @@
</None>
</ItemGroup>

<ItemGroup>
<Content Update="ApiDefinition.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions sample/ApiGeneratorSampleApp/ApiGeneratorSampleApI.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

177 changes: 109 additions & 68 deletions sample/ApiGeneratorSampleApp/Model/Car.cs
@@ -1,70 +1,111 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TCDev.ApiGenerator.Attributes;
using TCDev.ApiGenerator.Interfaces;
//using System;
//using System.Collections.Generic;
//using System.ComponentModel.DataAnnotations;
//using System.ComponentModel.DataAnnotations.Schema;
//using TCDev.ApiGenerator.Attributes;
//using TCDev.ApiGenerator.Interfaces;

//namespace ApiGeneratorSampleApI.Model
//{

// [Api("/students")]
// public class Student: IObjectBase<int>
// {
// public int Id { get; set; }
// public string FirstName { get; set; }
// public string LastName { get; set; }
// public DateTime DateOfBirth { get; set; }

// public void BeforeDelete(Student student)
// {
// // Before Delete hook to make custom validations
// }

// }


// [Api("/teachers")]
// public class Teacher : IObjectBase<int>
// {
// public int Id { get; set; }
// public string FirstName { get; set; }
// public string LastName { get; set; }
// public DateTime DateOfBirth { get; set; }

// public void BeforeCreate(Teacher newTeacher)
// {
// // Before Create hook to make custom validations
// }
// }


// [Api("/courses")]
// public class Course : IObjectBase<int>
// {
// public int Id { get; set; }
// public List<Student> Students { get; set; }
// public Teacher Teacher { get; set; }
// public List<DateTime> Schedule { get; set; }
// }




// [Api("/car"]
// public class Car : IObjectBase<Guid>
// {
// [Key]
// [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
// [SwaggerIgnore]
// public Guid Id { get; set; } = Guid.NewGuid();


// [EmailAddress]
// public string Name { get; set; }

// public string Description { get; set; }

// public string Color { get; set; }

// public Make? Make { get; set; }

// public Model? Model { get; set; }
// }


// [Api("/carMakes",
// authorize: true,
// requiredReadScopes: new string[] { "make.read" },
// requiredWriteScopes: new string[] { "make.write" })]
// public class Make : IObjectBase<Guid>
// {
// [Key]
// [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
// [SwaggerIgnore]
// public Guid Id { get; set; } = Guid.NewGuid();
// public string Name { get; set; }

// public string Description { get; set; }


// public Model? Model { get; set; }
// }



// [Api("/carModel",
// authorize: true,
// requiredReadScopes: new string[] { "model.read" },
// requiredWriteScopes: new string[] { "model.write" })]
// public class Model : IObjectBase<Guid>, I
// {
// [Key]
// [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
// [SwaggerIgnore]
// public Guid Id { get; set; } = Guid.NewGuid();
// public string Name { get; set; }

namespace ApiGeneratorSampleApI.Model
{
// public string Description { get; set; }
// }

[Api("/car",
authorize: true,
requiredReadScopes: new string[] { "car.read" },
requiredWriteScopes: new string[] { "car.write" })]
public class Car : IObjectBase<Guid>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[SwaggerIgnore]
public Guid Id { get; set; } = Guid.NewGuid();


[EmailAddress]
public string Name { get; set; }

public string Description { get; set; }

public string Color { get; set; }

public Make? Make { get; set; }

public Model? Model { get; set; }
}


[Api("/carMakes",
authorize: true,
requiredReadScopes: new string[] { "make.read" },
requiredWriteScopes: new string[] { "make.write" })]
public class Make : IObjectBase<Guid>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[SwaggerIgnore]
public Guid Id { get; set; } = Guid.NewGuid();
public string Name { get; set; }

public string Description { get; set; }


public Model? Model { get; set; }
}



[Api("/carModel",
authorize: true,
requiredReadScopes: new string[] { "model.read" },
requiredWriteScopes: new string[] { "model.write" })]
public class Model : IObjectBase<Guid>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[SwaggerIgnore]
public Guid Id { get; set; } = Guid.NewGuid();
public string Name { get; set; }

public string Description { get; set; }
}

}
//}
36 changes: 18 additions & 18 deletions sample/ApiGeneratorSampleApp/Model/MinimalSample.cs
@@ -1,20 +1,20 @@
// TCDev.de 2022/03/24
// ApiGeneratorSampleApI.MinimalSample.cs
// https://github.com/DeeJayTC/net-dynamic-api
//// TCDev.de 2022/03/24
//// ApiGeneratorSampleApI.MinimalSample.cs
//// https://github.com/DeeJayTC/net-dynamic-api

using TCDev.ApiGenerator.Attributes;
using TCDev.ApiGenerator.Interfaces;
//using TCDev.ApiGenerator.Attributes;
//using TCDev.ApiGenerator.Interfaces;

namespace ApiGeneratorSampleApI.Model
{
/// <summary>
/// This is the minimal sample, yes this is a working api ;)
/// </summary>
[Api("/minimal")]
public class MinimalSample : IObjectBase<int>
{
public string Name { get; set; }
public int Value { get; set; }
public int Id { get; set; }
}
}
//namespace ApiGeneratorSampleApI.Model
//{
// /// <summary>
// /// This is the minimal sample, yes this is a working api ;)
// /// </summary>
// [Api("/minimal")]
// public class MinimalSample : IObjectBase<int>
// {
// public string Name { get; set; }
// public int Value { get; set; }
// public int Id { get; set; }
// }
//}
71 changes: 64 additions & 7 deletions sample/ApiGeneratorSampleApp/Model/Person.cs
Expand Up @@ -2,19 +2,76 @@
// Apache 2.0 License
// https://www.github.com/deejaytc/dotnet-utils

using Innofactor.EfCoreJsonValueConverter;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TCDev.ApiGenerator.Attributes;
using TCDev.ApiGenerator.Data;
using TCDev.ApiGenerator.Interfaces;
using TCDev.ApiGenerator.Schema.Interfaces;

namespace ApiGeneratorSampleApI.Model
{
[Api("/people")]
public class Person : IObjectBase<Guid>
//[Api("/people")]
//public class Person : IObjectBase<Guid>, IBeforeCreate<Person>
//{
// public string Name { get; set; }
// public DateTime Date { get; set; }
// public string Description { get; set; }

// [Auth(AllowedRoles = new string[] { "admin" })]
// public int Age { get; set; }


// public Guid Id { get; set; }

// public Task<Person> BeforeCreate(Person newItem, GenericDbContext db, HttpContext context)
// {
// throw new NotImplementedException();
// }
//}

[Api("/students")]
public class Student : IObjectBase<int>
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }

public void BeforeDelete(Student student)
{
// Before Delete hook to make custom validations
}

}

[Api("/teachers")]
public class Teacher : IObjectBase<int>
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }

public void BeforeCreate(Teacher newTeacher)
{
// Before Create hook to make custom validations
}
}

[Api("/courses")]
public class Course : IObjectBase<int>
{
public string Name { get; set; }
public DateTime Date { get; set; }
public string Description { get; set; }
public int Age { get; set; }
public Guid Id { get; set; }
public int Id { get; set; }
public List<Student> Students { get; set; }
public Teacher Teacher { get; set; }

[JsonField]
public List<DateTime> Schedule { get; set; }
}


}
2 changes: 1 addition & 1 deletion sample/ApiGeneratorSampleApp/Program.cs
Expand Up @@ -11,7 +11,7 @@
builder.Services.AddControllers();

builder.Services.AddApiGeneratorIdentity(builder.Configuration);
builder.Services.AddApiGeneratorServices(builder.Configuration, Assembly.GetExecutingAssembly());
await builder.Services.AddApiGeneratorServices(builder.Configuration, Assembly.GetExecutingAssembly());

var app = builder.Build();

Expand Down

0 comments on commit 9217b55

Please sign in to comment.