From c87733d85f64f477682866455ad51de2dbdee505 Mon Sep 17 00:00:00 2001 From: Dentsor Date: Sun, 19 Dec 2021 00:43:41 +0100 Subject: [PATCH 1/2] Add additional database models and RequirementController --- .../Controllers/RequirementController.cs | 52 +++ SpeiderappAPI/Database/ApiContext.cs | 2 + .../20211218230949_requirements.Designer.cs | 411 ++++++++++++++++++ .../Migrations/20211218230949_requirements.cs | 23 + .../Migrations/ApiContextModelSnapshot.cs | 17 + SpeiderappAPI/Models/MultipleChoice.cs | 14 + SpeiderappAPI/Models/UserDefined.cs | 11 + 7 files changed, 530 insertions(+) create mode 100644 SpeiderappAPI/Controllers/RequirementController.cs create mode 100644 SpeiderappAPI/Migrations/20211218230949_requirements.Designer.cs create mode 100644 SpeiderappAPI/Migrations/20211218230949_requirements.cs create mode 100644 SpeiderappAPI/Models/MultipleChoice.cs create mode 100644 SpeiderappAPI/Models/UserDefined.cs diff --git a/SpeiderappAPI/Controllers/RequirementController.cs b/SpeiderappAPI/Controllers/RequirementController.cs new file mode 100644 index 0000000..f702fb9 --- /dev/null +++ b/SpeiderappAPI/Controllers/RequirementController.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using SpeiderappAPI.Database; +using SpeiderappAPI.Models; + +namespace SpeiderappAPI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class RequirementController : ControllerBase + { + private readonly ApiContext _context; + + public RequirementController(ApiContext context) + { + _context = context; + } + + // GET: api/Requirement + [HttpGet] + public async Task>> GetRequirements() + { + return await _context.Requirements + .Where(requirement => requirement.Discriminator == "Requirement") + .ToListAsync(); + } + + // GET: api/Requirement/all + [HttpGet("all")] + public async Task>> GetRequirementsAll() + { + return await _context.Requirements.ToListAsync(); + } + + // Get: api/Requirement/ + [HttpGet("{id:long}")] + public async Task> GetRequirement(long id) + { + var requirement = await _context.Requirements.FindAsync(id); + + if (requirement == null) + { + return NotFound(); + } + + return requirement; + } + } +} diff --git a/SpeiderappAPI/Database/ApiContext.cs b/SpeiderappAPI/Database/ApiContext.cs index ea1b705..b6e6b6a 100644 --- a/SpeiderappAPI/Database/ApiContext.cs +++ b/SpeiderappAPI/Database/ApiContext.cs @@ -8,6 +8,8 @@ namespace SpeiderappAPI.Database public class ApiContext : DbContext { public DbSet Badges { get; set; } = null!; + public DbSet MultipleChoices { get; set; } = null!; + public DbSet UserDefineds { get; set; } = null!; public DbSet Requirements { get; set; } = null!; public DbSet RequirementPrerequisites { get; set; } = null!; public DbSet Users { get; set; } = null!; diff --git a/SpeiderappAPI/Migrations/20211218230949_requirements.Designer.cs b/SpeiderappAPI/Migrations/20211218230949_requirements.Designer.cs new file mode 100644 index 0000000..87d11d8 --- /dev/null +++ b/SpeiderappAPI/Migrations/20211218230949_requirements.Designer.cs @@ -0,0 +1,411 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using SpeiderappAPI.Database; + +namespace SpeiderappAPI.Migrations +{ + [DbContext(typeof(ApiContext))] + [Migration("20211218230949_requirements")] + partial class requirements + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.9") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + modelBuilder.Entity("SpeiderappAPI.Models.Category", b => + { + b.Property("CategoryID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("CategoryID"); + + b.ToTable("Categories"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Requirement", b => + { + b.Property("RequirementID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("AuthorID") + .HasColumnType("bigint"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Discriminator") + .IsRequired() + .HasColumnType("text"); + + b.Property("PublishTime") + .HasColumnType("timestamp without time zone"); + + b.HasKey("RequirementID"); + + b.HasIndex("AuthorID"); + + b.ToTable("Requirements"); + + b.HasDiscriminator("Discriminator").HasValue("Requirement"); + + b.HasData( + new + { + RequirementID = -2L, + AuthorID = -1L, + Description = "Actually chop wood", + PublishTime = new DateTime(2021, 10, 7, 19, 0, 0, 0, DateTimeKind.Unspecified) + }, + new + { + RequirementID = -5L, + AuthorID = -1L, + Description = "Stoff-handling", + PublishTime = new DateTime(2021, 10, 6, 0, 0, 0, 0, DateTimeKind.Unspecified) + }, + new + { + RequirementID = -6L, + AuthorID = -3L, + Description = "Sytråd-shopping", + PublishTime = new DateTime(2021, 10, 7, 9, 0, 0, 0, DateTimeKind.Unspecified) + }); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.RequirementPrerequisite", b => + { + b.Property("RequirerID") + .HasColumnType("bigint"); + + b.Property("RequireeID") + .HasColumnType("bigint"); + + b.Property("IsAdvisory") + .HasColumnType("boolean"); + + b.HasKey("RequirerID", "RequireeID"); + + b.HasIndex("RequireeID"); + + b.ToTable("RequirementPrerequisites"); + + b.HasData( + new + { + RequirerID = -1L, + RequireeID = -2L, + IsAdvisory = false + }, + new + { + RequirerID = -4L, + RequireeID = -5L, + IsAdvisory = true + }, + new + { + RequirerID = -4L, + RequireeID = -6L, + IsAdvisory = false + }); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Resource", b => + { + b.Property("ResourceID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Location") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("RequirementID") + .HasColumnType("bigint"); + + b.HasKey("ResourceID"); + + b.HasIndex("RequirementID"); + + b.ToTable("Resources"); + + b.HasData( + new + { + ResourceID = -1L, + Description = "Oversikt over aktiviteter og merker i KMSpeideren", + Location = "https://kmspeider.no/aktivitetsbanken", + Name = "Aktivitetsbanken", + RequirementID = -1L + }); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Tag", b => + { + b.Property("TagID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("CategoryID") + .HasColumnType("bigint"); + + b.Property("Value") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("TagID"); + + b.HasIndex("CategoryID"); + + b.ToTable("Tags"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.TaggedWith", b => + { + b.Property("BadgeID") + .HasColumnType("bigint"); + + b.Property("TagID") + .HasColumnType("bigint"); + + b.HasKey("BadgeID", "TagID"); + + b.HasIndex("TagID"); + + b.ToTable("TaggedWiths"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.User", b => + { + b.Property("UserID") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("UserID"); + + b.ToTable("Users"); + + b.HasData( + new + { + UserID = -1L, + Email = "ocrispe0@jugem.jp", + FirstName = "Ozzie", + LastName = "Crispe" + }, + new + { + UserID = -2L, + Email = "adandye@hexun.com", + FirstName = "Aggi", + LastName = "Dandy" + }, + new + { + UserID = -3L, + Email = "gspottiswood2@psu.com", + FirstName = "Gerry", + LastName = "Spottiswood" + }); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Badge", b => + { + b.HasBaseType("SpeiderappAPI.Models.Requirement"); + + b.Property("Image") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasDiscriminator().HasValue("Badge"); + + b.HasData( + new + { + RequirementID = -1L, + AuthorID = -1L, + Description = "This is a cool badge for chucking wood.", + PublishTime = new DateTime(2021, 10, 8, 0, 0, 0, 0, DateTimeKind.Unspecified), + Image = "3aas!2d=", + Title = "Woodchuck" + }, + new + { + RequirementID = -3L, + AuthorID = -2L, + Description = "Beskrivende test-tekst", + PublishTime = new DateTime(2021, 11, 8, 0, 0, 0, 0, DateTimeKind.Unspecified), + Image = "http://placekitten.com/g/200/300", + Title = "Testing" + }, + new + { + RequirementID = -4L, + AuthorID = -1L, + Description = "Hobby-baserte aktiviteter for alle aldre", + PublishTime = new DateTime(2021, 10, 12, 0, 0, 0, 0, DateTimeKind.Unspecified), + Image = "http://placekitten.com/g/200/200", + Title = "Hobby" + }); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.MultipleChoice", b => + { + b.HasBaseType("SpeiderappAPI.Models.Requirement"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasDiscriminator().HasValue("MultipleChoice"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.UserDefined", b => + { + b.HasBaseType("SpeiderappAPI.Models.Requirement"); + + b.HasDiscriminator().HasValue("UserDefined"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Requirement", b => + { + b.HasOne("SpeiderappAPI.Models.User", "Author") + .WithMany() + .HasForeignKey("AuthorID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.RequirementPrerequisite", b => + { + b.HasOne("SpeiderappAPI.Models.Requirement", "Requiree") + .WithMany("RequiredBy") + .HasForeignKey("RequireeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SpeiderappAPI.Models.Requirement", "Requirer") + .WithMany("Requiring") + .HasForeignKey("RequirerID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Requiree"); + + b.Navigation("Requirer"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Resource", b => + { + b.HasOne("SpeiderappAPI.Models.Requirement", "Requirement") + .WithMany("Resources") + .HasForeignKey("RequirementID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Requirement"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Tag", b => + { + b.HasOne("SpeiderappAPI.Models.Category", "Category") + .WithMany("Tags") + .HasForeignKey("CategoryID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.TaggedWith", b => + { + b.HasOne("SpeiderappAPI.Models.Badge", "Badge") + .WithMany("TaggedWiths") + .HasForeignKey("BadgeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SpeiderappAPI.Models.Tag", "Tag") + .WithMany("TaggedWiths") + .HasForeignKey("TagID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Badge"); + + b.Navigation("Tag"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Category", b => + { + b.Navigation("Tags"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Requirement", b => + { + b.Navigation("RequiredBy"); + + b.Navigation("Requiring"); + + b.Navigation("Resources"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Tag", b => + { + b.Navigation("TaggedWiths"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.Badge", b => + { + b.Navigation("TaggedWiths"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SpeiderappAPI/Migrations/20211218230949_requirements.cs b/SpeiderappAPI/Migrations/20211218230949_requirements.cs new file mode 100644 index 0000000..f1f5b4c --- /dev/null +++ b/SpeiderappAPI/Migrations/20211218230949_requirements.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace SpeiderappAPI.Migrations +{ + public partial class requirements : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Count", + table: "Requirements", + type: "integer", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Count", + table: "Requirements"); + } + } +} diff --git a/SpeiderappAPI/Migrations/ApiContextModelSnapshot.cs b/SpeiderappAPI/Migrations/ApiContextModelSnapshot.cs index b51121d..41ce904 100644 --- a/SpeiderappAPI/Migrations/ApiContextModelSnapshot.cs +++ b/SpeiderappAPI/Migrations/ApiContextModelSnapshot.cs @@ -292,6 +292,23 @@ protected override void BuildModel(ModelBuilder modelBuilder) }); }); + modelBuilder.Entity("SpeiderappAPI.Models.MultipleChoice", b => + { + b.HasBaseType("SpeiderappAPI.Models.Requirement"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasDiscriminator().HasValue("MultipleChoice"); + }); + + modelBuilder.Entity("SpeiderappAPI.Models.UserDefined", b => + { + b.HasBaseType("SpeiderappAPI.Models.Requirement"); + + b.HasDiscriminator().HasValue("UserDefined"); + }); + modelBuilder.Entity("SpeiderappAPI.Models.Requirement", b => { b.HasOne("SpeiderappAPI.Models.User", "Author") diff --git a/SpeiderappAPI/Models/MultipleChoice.cs b/SpeiderappAPI/Models/MultipleChoice.cs new file mode 100644 index 0000000..e10bb14 --- /dev/null +++ b/SpeiderappAPI/Models/MultipleChoice.cs @@ -0,0 +1,14 @@ +using System; + +namespace SpeiderappAPI.Models +{ + public class MultipleChoice : Requirement + { + public MultipleChoice(string description, DateTime publishTime, int count) : base(description, publishTime) + { + Count = count; + } + + public int Count { get; set; } + } +} diff --git a/SpeiderappAPI/Models/UserDefined.cs b/SpeiderappAPI/Models/UserDefined.cs new file mode 100644 index 0000000..8b96f00 --- /dev/null +++ b/SpeiderappAPI/Models/UserDefined.cs @@ -0,0 +1,11 @@ +using System; + +namespace SpeiderappAPI.Models +{ + public class UserDefined : Requirement + { + public UserDefined(string description, DateTime publishTime) : base(description, publishTime) + { + } + } +} From c5f392f23e3346de0cdac6c18e39ec81664b733d Mon Sep 17 00:00:00 2001 From: Dentsor Date: Sun, 19 Dec 2021 22:54:55 +0100 Subject: [PATCH 2/2] Update API-docs in README and comments in controllers Removed test-endpoint in ResourceController --- SpeiderappAPI/Controllers/BadgeController.cs | 6 +- .../Controllers/ResourceController.cs | 20 +---- SpeiderappAPI/Controllers/UserController.cs | 6 +- SpeiderappAPI/README.md | 73 +++++++++++-------- 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/SpeiderappAPI/Controllers/BadgeController.cs b/SpeiderappAPI/Controllers/BadgeController.cs index b401fc3..44216a6 100644 --- a/SpeiderappAPI/Controllers/BadgeController.cs +++ b/SpeiderappAPI/Controllers/BadgeController.cs @@ -27,7 +27,7 @@ public async Task>> GetBadges() return await _context.Badges/* .Include(badge => badge.Resources) */.ToListAsync(); } - // GET: api/Badge/5 + // GET: api/Badge/ [HttpGet("{id:long}")] public async Task> GetBadge(long id) { @@ -41,7 +41,7 @@ public async Task> GetBadge(long id) return badge; } - // PUT: api/Badge/5 + // PUT: api/Badge/ // To protect from over-posting attacks, enable the specific properties you want to bind to, for // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. [HttpPut("{id:long}")] @@ -85,7 +85,7 @@ public async Task> PostBadge(Badge badge) return CreatedAtAction("GetBadge", new { id = badge.RequirementID }, badge); } - // DELETE: api/Badge/5 + // DELETE: api/Badge/ [HttpDelete("{id:long}")] public async Task> DeleteBadge(long id) { diff --git a/SpeiderappAPI/Controllers/ResourceController.cs b/SpeiderappAPI/Controllers/ResourceController.cs index 278baa7..55a5573 100644 --- a/SpeiderappAPI/Controllers/ResourceController.cs +++ b/SpeiderappAPI/Controllers/ResourceController.cs @@ -26,7 +26,7 @@ public async Task>> GetResource() return await _context.Resources.ToListAsync(); } - // GET: api/Resource/5 + // GET: api/Resource/ [HttpGet("{id:long}")] public async Task> GetResource(long id) { @@ -40,21 +40,7 @@ public async Task> GetResource(long id) return resource; } - // GET: api/Resource/badge/5 - [HttpGet("badge/{id:long}")] - public async Task> GetBadgeFor(long id) - { - var resource = await _context.Resources.FindAsync(id); - - if (resource == null) - { - return NotFound(); - } - - return resource.Requirement; - } - - // PUT: api/Resource/5 + // PUT: api/Resource/ // To protect from over-posting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id:long}")] public async Task PutResource(long id, Resource resource) @@ -96,7 +82,7 @@ public async Task> PostResource(Resource resource) return CreatedAtAction("GetResource", new { id = resource.ResourceID }, resource); } - // DELETE: api/Resource/5 + // DELETE: api/Resource/ [HttpDelete("{id}")] public async Task DeleteResource(long id) { diff --git a/SpeiderappAPI/Controllers/UserController.cs b/SpeiderappAPI/Controllers/UserController.cs index 081dd95..be339dd 100644 --- a/SpeiderappAPI/Controllers/UserController.cs +++ b/SpeiderappAPI/Controllers/UserController.cs @@ -26,7 +26,7 @@ public async Task>> GetUsers() return await _context.Users.ToListAsync(); } - // GET: api/User/5 + // GET: api/User/ [HttpGet("{id:long}")] public async Task> GetUser(long id) { @@ -40,7 +40,7 @@ public async Task> GetUser(long id) return user; } - // PUT: api/User/5 + // PUT: api/User/ // To protect from over-posting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 [HttpPut("{id:long}")] public async Task PutUser(long id, User user) @@ -82,7 +82,7 @@ public async Task> PostUser(User user) return CreatedAtAction("GetUser", new { id = user.UserID }, user); } - // DELETE: api/User/5 + // DELETE: api/User/ [HttpDelete("{id:long}")] public async Task DeleteUser(long id) { diff --git a/SpeiderappAPI/README.md b/SpeiderappAPI/README.md index 4810f7a..ef8bbce 100644 --- a/SpeiderappAPI/README.md +++ b/SpeiderappAPI/README.md @@ -2,14 +2,16 @@ Speiderapp API back-end -# How to use +# How to: *develop* -## Setup -Prerequisites: +## Prerequisites: * [.NET 5.0](https://dotnet.microsoft.com/download/dotnet/5.0) * [Node.js](https://nodejs.org/en/) * [Docker](https://docker.com) + +## Clone and run install-script + ```bash # Clone the repo (example uses ssh) git clone git@github.com:dotClique/SpeiderappAPI.git @@ -19,7 +21,8 @@ cd ./SpeiderappAPI yarn install ``` -## Start development server in Docker + +## Prepare and start development server (in Docker) The service is run in Docker. @@ -57,13 +60,26 @@ dotnet format -s info ``` ## Routes -| HTTP Method | Route | Description | -| :---------- | :---------------- | :----------------- | -| GET | /api/Badge | List Badges | -| GET | /api/Badge/\ | Retrieve a badge | -| POST | /api/Badge | Create a new Badge | -| PUT | /api/Badge/\ | Update a Badge | -| DELETE | /api/Badge/\ | Delete a Badge | +| Controller | HTTP Method | Route | Description | +| :-------------------- | :---------- | :---------------------- | :------------------------------- | +| BadgeController | GET | /api/Badge | List Badges | +| BadgeController | GET | /api/Badge/\ | Retrieve a specific badge | +| BadgeController | PUT | /api/Badge/\ | Update a Badge | +| BadgeController | POST | /api/Badge | Create a new Badge | +| BadgeController | DELETE | /api/Badge/\ | Delete a Badge | +| RequirementController | GET | /api/Requirement | List all non-badge Requirements | +| RequirementController | GET | /api/Requirement/all | List all Requirements (any type) | +| RequirementController | GET | /api/Requirement/\ | Retrieve a specific Requirement | +| ResourceController | GET | /api/Resource | List Resources | +| ResourceController | GET | /api/Resource/\ | Retrieve a specific Resource | +| ResourceController | PUT | /api/Resource/\ | Update a Resource | +| ResourceController | POST | /api/Resource | Create a new Resource | +| ResourceController | DELETE | /api/Resource/\ | Delete a Resource | +| UserController | GET | /api/User | List Users | +| UserController | GET | /api/User/\ | Retrieve a specific User | +| UserController | PUT | /api/User/\ | Update a User | +| UserController | POST | /api/User | Create a new User | +| UserController | DELETE | /api/User/\ | Delete a User | ## Local configuration @@ -77,23 +93,6 @@ To override/set development secrets, use: dotnet user-secrets set ``` - -#### Migrations - -Migrations set up and prepare the database for the data models used in Dotnet. -Make sure to run the [database setup](#database) before running migrations. - -```bash -# Make sure tools are installed -dotnet tool restore - -# Create migrations and apply -dotnet ef migrations add --project SpeiderappAPI - -# Update the database -dotnet ef database update --project SpeiderappAPI -``` - ### Production Create ```appsettings.Production.local.json```, and *more instructions to come*. @@ -128,7 +127,7 @@ dotnet format --fix-style info --check ``` ## Creating a controller -Replace **Badge** in the following snippet with whatever model/object you're creating a controller for: +Replace **** in the following snippet with whatever model/object you're creating a controller for: ```bash # Enter the project directory cd SpeiderappAPI @@ -137,6 +136,22 @@ cd SpeiderappAPI dotnet aspnet-codegenerator controller -name Controller -async -api -m -dc ApiContext -outDir Controllers ``` +## Creating migrations + +Migrations set up and prepare the database for the data models used in Dotnet. +Make sure to run the [database setup](#prepare-and-start-development-server-in-docker) before running migrations. + +```bash +# Make sure tools are installed +dotnet tool restore + +# Create migrations and apply +dotnet ef migrations add --project SpeiderappAPI + +# Update the database +dotnet ef database update --project SpeiderappAPI +``` + ## Dependencies/Packages Adding new packages: ```bash