initial commit
This commit is contained in:
		
							
								
								
									
										30
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								.dockerignore
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | **/.classpath | ||||||
|  | **/.dockerignore | ||||||
|  | **/.env | ||||||
|  | **/.git | ||||||
|  | **/.gitignore | ||||||
|  | **/.project | ||||||
|  | **/.settings | ||||||
|  | **/.toolstarget | ||||||
|  | **/.vs | ||||||
|  | **/.vscode | ||||||
|  | **/*.*proj.user | ||||||
|  | **/*.dbmdl | ||||||
|  | **/*.jfm | ||||||
|  | **/azds.yaml | ||||||
|  | **/bin | ||||||
|  | **/charts | ||||||
|  | **/docker-compose* | ||||||
|  | **/Dockerfile* | ||||||
|  | **/node_modules | ||||||
|  | **/npm-debug.log | ||||||
|  | **/obj | ||||||
|  | **/secrets.dev.yaml | ||||||
|  | **/values.dev.yaml | ||||||
|  | LICENSE | ||||||
|  | README.md | ||||||
|  | !**/.gitignore | ||||||
|  | !.git/HEAD | ||||||
|  | !.git/config | ||||||
|  | !.git/packed-refs | ||||||
|  | !.git/refs/heads/** | ||||||
							
								
								
									
										8
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | .vs | ||||||
|  | bin | ||||||
|  | obj | ||||||
|  |  | ||||||
|  | appsettings.Development.json | ||||||
|  | *.db | ||||||
|  | *.db-shm | ||||||
|  | *.csproj.user | ||||||
							
								
								
									
										26
									
								
								Controllers/PetController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Controllers/PetController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using pet_companion_api.Services; | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Controllers | ||||||
|  | { | ||||||
|  |     [ApiController] | ||||||
|  |     [Route("api/v1/[controller]")] | ||||||
|  |     public class PetController : ControllerBase | ||||||
|  |     { | ||||||
|  |         private readonly PetService petService; | ||||||
|  |         private readonly ILogger<PetController> logger; | ||||||
|  |         private Guid userId = Guid.Parse("f5f4b3b3-3b7b-4b7b-8b7b-7b7b7b7b7b7b"); | ||||||
|  |  | ||||||
|  |         public PetController(ILogger<PetController> logger, PetService petService) | ||||||
|  |         { | ||||||
|  |             this.logger = logger; | ||||||
|  |             this.petService = petService; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         [HttpGet("")] | ||||||
|  |         public IActionResult GetAllPets() | ||||||
|  |         { | ||||||
|  |             return Ok(petService.GetAllPets(userId)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										16
									
								
								Data/ApplicationDbContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Data/ApplicationDbContext.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | using Microsoft.EntityFrameworkCore; | ||||||
|  | using pet_companion_api.Models; | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Data | ||||||
|  | { | ||||||
|  |     public class ApplicationDbContext : DbContext | ||||||
|  |     { | ||||||
|  |         public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) | ||||||
|  |         { | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public DbSet<Pet> Pets { get; set; } | ||||||
|  |         public DbSet<PetStats> PetStats { get; set; } | ||||||
|  |         public DbSet<Resources> Resources { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										30
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | # See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||||||
|  |  | ||||||
|  | # This stage is used when running from VS in fast mode (Default for Debug configuration) | ||||||
|  | FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base | ||||||
|  | USER app | ||||||
|  | WORKDIR /app | ||||||
|  | EXPOSE 8080 | ||||||
|  | EXPOSE 8081 | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # This stage is used to build the service project | ||||||
|  | FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||||||
|  | ARG BUILD_CONFIGURATION=Release | ||||||
|  | WORKDIR /src | ||||||
|  | COPY ["pet-companion-api.csproj", "."] | ||||||
|  | RUN dotnet restore "./pet-companion-api.csproj" | ||||||
|  | COPY . . | ||||||
|  | WORKDIR "/src/." | ||||||
|  | RUN dotnet build "./pet-companion-api.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||||||
|  |  | ||||||
|  | # This stage is used to publish the service project to be copied to the final stage | ||||||
|  | FROM build AS publish | ||||||
|  | ARG BUILD_CONFIGURATION=Release | ||||||
|  | RUN dotnet publish "./pet-companion-api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||||||
|  |  | ||||||
|  | # This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) | ||||||
|  | FROM base AS final | ||||||
|  | WORKDIR /app | ||||||
|  | COPY --from=publish /app/publish . | ||||||
|  | ENTRYPOINT ["dotnet", "pet-companion-api.dll"] | ||||||
							
								
								
									
										116
									
								
								Migrations/20250201022754_InitialCreate.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								Migrations/20250201022754_InitialCreate.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,116 @@ | |||||||
|  | // <auto-generated /> | ||||||
|  | using Microsoft.EntityFrameworkCore; | ||||||
|  | using Microsoft.EntityFrameworkCore.Infrastructure; | ||||||
|  | using Microsoft.EntityFrameworkCore.Migrations; | ||||||
|  | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||||||
|  | using pet_companion_api.Data; | ||||||
|  |  | ||||||
|  | #nullable disable | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Migrations | ||||||
|  | { | ||||||
|  |     [DbContext(typeof(ApplicationDbContext))] | ||||||
|  |     [Migration("20250201022754_InitialCreate")] | ||||||
|  |     partial class InitialCreate | ||||||
|  |     { | ||||||
|  |         /// <inheritdoc /> | ||||||
|  |         protected override void BuildTargetModel(ModelBuilder modelBuilder) | ||||||
|  |         { | ||||||
|  | #pragma warning disable 612, 618 | ||||||
|  |             modelBuilder.HasAnnotation("ProductVersion", "9.0.1"); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.Pet", b => | ||||||
|  |                 { | ||||||
|  |                     b.Property<string>("Id") | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Class") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Level") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<string>("Name") | ||||||
|  |                         .IsRequired() | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.Property<string>("UserId") | ||||||
|  |                         .IsRequired() | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.HasKey("Id"); | ||||||
|  |  | ||||||
|  |                     b.ToTable("Pets"); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.PetStats", b => | ||||||
|  |                 { | ||||||
|  |                     b.Property<string>("PetId") | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Charisma") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Intelligence") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Strength") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.HasKey("PetId"); | ||||||
|  |  | ||||||
|  |                     b.ToTable("PetStats"); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.Resources", b => | ||||||
|  |                 { | ||||||
|  |                     b.Property<string>("PetId") | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Food") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Gold") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Junk") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Wisdom") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.HasKey("PetId"); | ||||||
|  |  | ||||||
|  |                     b.ToTable("Resources"); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.PetStats", b => | ||||||
|  |                 { | ||||||
|  |                     b.HasOne("pet_companion_api.Models.Pet", null) | ||||||
|  |                         .WithOne("Stats") | ||||||
|  |                         .HasForeignKey("pet_companion_api.Models.PetStats", "PetId") | ||||||
|  |                         .OnDelete(DeleteBehavior.Cascade) | ||||||
|  |                         .IsRequired(); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.Resources", b => | ||||||
|  |                 { | ||||||
|  |                     b.HasOne("pet_companion_api.Models.Pet", null) | ||||||
|  |                         .WithOne("Resources") | ||||||
|  |                         .HasForeignKey("pet_companion_api.Models.Resources", "PetId") | ||||||
|  |                         .OnDelete(DeleteBehavior.Cascade) | ||||||
|  |                         .IsRequired(); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.Pet", b => | ||||||
|  |                 { | ||||||
|  |                     b.Navigation("Resources") | ||||||
|  |                         .IsRequired(); | ||||||
|  |  | ||||||
|  |                     b.Navigation("Stats") | ||||||
|  |                         .IsRequired(); | ||||||
|  |                 }); | ||||||
|  | #pragma warning restore 612, 618 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										83
									
								
								Migrations/20250201022754_InitialCreate.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								Migrations/20250201022754_InitialCreate.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | |||||||
|  | using Microsoft.EntityFrameworkCore.Migrations; | ||||||
|  |  | ||||||
|  | #nullable disable | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Migrations | ||||||
|  | { | ||||||
|  |     /// <inheritdoc /> | ||||||
|  |     public partial class InitialCreate : Migration | ||||||
|  |     { | ||||||
|  |         /// <inheritdoc /> | ||||||
|  |         protected override void Up(MigrationBuilder migrationBuilder) | ||||||
|  |         { | ||||||
|  |             migrationBuilder.CreateTable( | ||||||
|  |                 name: "Pets", | ||||||
|  |                 columns: table => new | ||||||
|  |                 { | ||||||
|  |                     Id = table.Column<string>(type: "TEXT", nullable: false), | ||||||
|  |                     Name = table.Column<string>(type: "TEXT", nullable: false), | ||||||
|  |                     Class = table.Column<int>(type: "INTEGER", nullable: false), | ||||||
|  |                     Level = table.Column<int>(type: "INTEGER", nullable: false), | ||||||
|  |                     UserId = table.Column<string>(type: "TEXT", nullable: false) | ||||||
|  |                 }, | ||||||
|  |                 constraints: table => | ||||||
|  |                 { | ||||||
|  |                     table.PrimaryKey("PK_Pets", x => x.Id); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             migrationBuilder.CreateTable( | ||||||
|  |                 name: "PetStats", | ||||||
|  |                 columns: table => new | ||||||
|  |                 { | ||||||
|  |                     PetId = table.Column<string>(type: "TEXT", nullable: false), | ||||||
|  |                     Intelligence = table.Column<int>(type: "INTEGER", nullable: false), | ||||||
|  |                     Strength = table.Column<int>(type: "INTEGER", nullable: false), | ||||||
|  |                     Charisma = table.Column<int>(type: "INTEGER", nullable: false) | ||||||
|  |                 }, | ||||||
|  |                 constraints: table => | ||||||
|  |                 { | ||||||
|  |                     table.PrimaryKey("PK_PetStats", x => x.PetId); | ||||||
|  |                     table.ForeignKey( | ||||||
|  |                         name: "FK_PetStats_Pets_PetId", | ||||||
|  |                         column: x => x.PetId, | ||||||
|  |                         principalTable: "Pets", | ||||||
|  |                         principalColumn: "Id", | ||||||
|  |                         onDelete: ReferentialAction.Cascade); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             migrationBuilder.CreateTable( | ||||||
|  |                 name: "Resources", | ||||||
|  |                 columns: table => new | ||||||
|  |                 { | ||||||
|  |                     PetId = table.Column<string>(type: "TEXT", nullable: false), | ||||||
|  |                     Wisdom = table.Column<int>(type: "INTEGER", nullable: false), | ||||||
|  |                     Gold = table.Column<int>(type: "INTEGER", nullable: false), | ||||||
|  |                     Food = table.Column<int>(type: "INTEGER", nullable: false), | ||||||
|  |                     Junk = table.Column<int>(type: "INTEGER", nullable: false) | ||||||
|  |                 }, | ||||||
|  |                 constraints: table => | ||||||
|  |                 { | ||||||
|  |                     table.PrimaryKey("PK_Resources", x => x.PetId); | ||||||
|  |                     table.ForeignKey( | ||||||
|  |                         name: "FK_Resources_Pets_PetId", | ||||||
|  |                         column: x => x.PetId, | ||||||
|  |                         principalTable: "Pets", | ||||||
|  |                         principalColumn: "Id", | ||||||
|  |                         onDelete: ReferentialAction.Cascade); | ||||||
|  |                 }); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <inheritdoc /> | ||||||
|  |         protected override void Down(MigrationBuilder migrationBuilder) | ||||||
|  |         { | ||||||
|  |             migrationBuilder.DropTable( | ||||||
|  |                 name: "PetStats"); | ||||||
|  |  | ||||||
|  |             migrationBuilder.DropTable( | ||||||
|  |                 name: "Resources"); | ||||||
|  |  | ||||||
|  |             migrationBuilder.DropTable( | ||||||
|  |                 name: "Pets"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										113
									
								
								Migrations/ApplicationDbContextModelSnapshot.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								Migrations/ApplicationDbContextModelSnapshot.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,113 @@ | |||||||
|  | // <auto-generated /> | ||||||
|  | using Microsoft.EntityFrameworkCore; | ||||||
|  | using Microsoft.EntityFrameworkCore.Infrastructure; | ||||||
|  | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||||||
|  | using pet_companion_api.Data; | ||||||
|  |  | ||||||
|  | #nullable disable | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Migrations | ||||||
|  | { | ||||||
|  |     [DbContext(typeof(ApplicationDbContext))] | ||||||
|  |     partial class ApplicationDbContextModelSnapshot : ModelSnapshot | ||||||
|  |     { | ||||||
|  |         protected override void BuildModel(ModelBuilder modelBuilder) | ||||||
|  |         { | ||||||
|  | #pragma warning disable 612, 618 | ||||||
|  |             modelBuilder.HasAnnotation("ProductVersion", "9.0.1"); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.Pet", b => | ||||||
|  |                 { | ||||||
|  |                     b.Property<string>("Id") | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Class") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Level") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<string>("Name") | ||||||
|  |                         .IsRequired() | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.Property<string>("UserId") | ||||||
|  |                         .IsRequired() | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.HasKey("Id"); | ||||||
|  |  | ||||||
|  |                     b.ToTable("Pets"); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.PetStats", b => | ||||||
|  |                 { | ||||||
|  |                     b.Property<string>("PetId") | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Charisma") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Intelligence") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Strength") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.HasKey("PetId"); | ||||||
|  |  | ||||||
|  |                     b.ToTable("PetStats"); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.Resources", b => | ||||||
|  |                 { | ||||||
|  |                     b.Property<string>("PetId") | ||||||
|  |                         .HasColumnType("TEXT"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Food") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Gold") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Junk") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.Property<int>("Wisdom") | ||||||
|  |                         .HasColumnType("INTEGER"); | ||||||
|  |  | ||||||
|  |                     b.HasKey("PetId"); | ||||||
|  |  | ||||||
|  |                     b.ToTable("Resources"); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.PetStats", b => | ||||||
|  |                 { | ||||||
|  |                     b.HasOne("pet_companion_api.Models.Pet", null) | ||||||
|  |                         .WithOne("Stats") | ||||||
|  |                         .HasForeignKey("pet_companion_api.Models.PetStats", "PetId") | ||||||
|  |                         .OnDelete(DeleteBehavior.Cascade) | ||||||
|  |                         .IsRequired(); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.Resources", b => | ||||||
|  |                 { | ||||||
|  |                     b.HasOne("pet_companion_api.Models.Pet", null) | ||||||
|  |                         .WithOne("Resources") | ||||||
|  |                         .HasForeignKey("pet_companion_api.Models.Resources", "PetId") | ||||||
|  |                         .OnDelete(DeleteBehavior.Cascade) | ||||||
|  |                         .IsRequired(); | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             modelBuilder.Entity("pet_companion_api.Models.Pet", b => | ||||||
|  |                 { | ||||||
|  |                     b.Navigation("Resources") | ||||||
|  |                         .IsRequired(); | ||||||
|  |  | ||||||
|  |                     b.Navigation("Stats") | ||||||
|  |                         .IsRequired(); | ||||||
|  |                 }); | ||||||
|  | #pragma warning restore 612, 618 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										16
									
								
								Models/Pet.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Models/Pet.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | using System.ComponentModel.DataAnnotations; | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Models | ||||||
|  | { | ||||||
|  |     public class Pet | ||||||
|  |     { | ||||||
|  |         [Key] | ||||||
|  |         public string Id { get; set; } | ||||||
|  |         public string Name { get; set; } | ||||||
|  |         public PetClass Class { get; set; } | ||||||
|  |         public PetStats Stats { get; set; } | ||||||
|  |         public Resources Resources { get; set; } | ||||||
|  |         public int Level { get; set; } | ||||||
|  |         public string UserId { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								Models/PetClass.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Models/PetClass.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | namespace pet_companion_api.Models | ||||||
|  | { | ||||||
|  |     public enum PetClass | ||||||
|  |     { | ||||||
|  |         FOREST_SPIRIT, | ||||||
|  |         OCEAN_GUARDIAN, | ||||||
|  |         FIRE_ELEMENTAL, | ||||||
|  |         MYTHICAL_BEAST, | ||||||
|  |         SHADOW_WALKER, | ||||||
|  |         CYBER_PET, | ||||||
|  |         BIO_MECHANICAL | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										12
									
								
								Models/PetClassInfo.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Models/PetClassInfo.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  |  | ||||||
|  | namespace pet_companion_api.Models | ||||||
|  | { | ||||||
|  |     public class PetClassInfo | ||||||
|  |     { | ||||||
|  |         public string Name { get; set; } | ||||||
|  |         public string Description { get; set; } | ||||||
|  |         public string[] Modifiers { get; set; } | ||||||
|  |         public string Color { get; set; } | ||||||
|  |         public string Emoji { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										66
									
								
								Models/PetStats.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								Models/PetStats.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | |||||||
|  | using System.ComponentModel.DataAnnotations; | ||||||
|  | using System.ComponentModel.DataAnnotations.Schema; | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Models | ||||||
|  | { | ||||||
|  |     public class PetStats | ||||||
|  |     { | ||||||
|  |         [Key, ForeignKey("Pet")] | ||||||
|  |         public string PetId { get; set; } | ||||||
|  |         public int Intelligence { get; set; } | ||||||
|  |         public int Strength { get; set; } | ||||||
|  |         public int Charisma { get; set; } | ||||||
|  |  | ||||||
|  |         public PetStats(PetClass petClass) | ||||||
|  |         { | ||||||
|  |             BuildFromClass(petClass); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public void BuildFromClass(PetClass petClass) | ||||||
|  |         { | ||||||
|  |             switch (petClass) | ||||||
|  |             { | ||||||
|  |                 case PetClass.FOREST_SPIRIT: | ||||||
|  |                     Intelligence = 10; | ||||||
|  |                     Strength = 5; | ||||||
|  |                     Charisma = 5; | ||||||
|  |                     break; | ||||||
|  |                 case PetClass.OCEAN_GUARDIAN: | ||||||
|  |                     Intelligence = 5; | ||||||
|  |                     Strength = 10; | ||||||
|  |                     Charisma = 5; | ||||||
|  |                     break; | ||||||
|  |                 case PetClass.FIRE_ELEMENTAL: | ||||||
|  |                     Intelligence = 5; | ||||||
|  |                     Strength = 5; | ||||||
|  |                     Charisma = 10; | ||||||
|  |                     break; | ||||||
|  |                 case PetClass.MYTHICAL_BEAST: | ||||||
|  |                     Intelligence = 7; | ||||||
|  |                     Strength = 7; | ||||||
|  |                     Charisma = 7; | ||||||
|  |                     break; | ||||||
|  |                 case PetClass.SHADOW_WALKER: | ||||||
|  |                     Intelligence = 8; | ||||||
|  |                     Strength = 6; | ||||||
|  |                     Charisma = 6; | ||||||
|  |                     break; | ||||||
|  |                 case PetClass.CYBER_PET: | ||||||
|  |                     Intelligence = 8; | ||||||
|  |                     Strength = 8; | ||||||
|  |                     Charisma = 6; | ||||||
|  |                     break; | ||||||
|  |                 case PetClass.BIO_MECHANICAL: | ||||||
|  |                     Intelligence = 8; | ||||||
|  |                     Strength = 6; | ||||||
|  |                     Charisma = 8; | ||||||
|  |                     break; | ||||||
|  |                 default: | ||||||
|  |                     Intelligence = 5; | ||||||
|  |                     Strength = 5; | ||||||
|  |                     Charisma = 5; | ||||||
|  |                     break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								Models/Resources.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Models/Resources.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | using System.ComponentModel.DataAnnotations; | ||||||
|  | using System.ComponentModel.DataAnnotations.Schema; | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Models | ||||||
|  | { | ||||||
|  |     public class Resources | ||||||
|  |     { | ||||||
|  |         [Key, ForeignKey("Pet")] | ||||||
|  |         public string PetId { get; set; } | ||||||
|  |         public int Wisdom { get; set; } | ||||||
|  |         public int Gold { get; set; } | ||||||
|  |         public int Food { get; set; } | ||||||
|  |         public int Junk { get; set; } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										42
									
								
								Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								Program.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | using Microsoft.EntityFrameworkCore; | ||||||
|  | using pet_companion_api.Data; | ||||||
|  | using pet_companion_api.Repositories; | ||||||
|  | using pet_companion_api.Services; | ||||||
|  |  | ||||||
|  | namespace pet_companion_api | ||||||
|  | { | ||||||
|  |     public class Program | ||||||
|  |     { | ||||||
|  |         public static void Main(string[] args) | ||||||
|  |         { | ||||||
|  |             var builder = WebApplication.CreateBuilder(args); | ||||||
|  |  | ||||||
|  |             // Add services to the container. | ||||||
|  |             builder.Services.AddControllers(); | ||||||
|  |             builder.Services.AddEndpointsApiExplorer(); | ||||||
|  |             builder.Services.AddSwaggerGen(); | ||||||
|  |  | ||||||
|  |             // Configure Entity Framework Core | ||||||
|  |             var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); | ||||||
|  |             builder.Services.AddDbContext<ApplicationDbContext>(options => | ||||||
|  |                 options.UseSqlite(connectionString)); | ||||||
|  |  | ||||||
|  |             builder.Services.AddScoped<PetRepository>(); | ||||||
|  |             builder.Services.AddScoped<PetService>(); | ||||||
|  |  | ||||||
|  |             var app = builder.Build(); | ||||||
|  |  | ||||||
|  |             // Configure the HTTP request pipeline. | ||||||
|  |             if (app.Environment.IsDevelopment()) | ||||||
|  |             { | ||||||
|  |                 app.UseSwagger(); | ||||||
|  |                 app.UseSwaggerUI(); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             app.UseHttpsRedirection(); | ||||||
|  |             app.UseAuthorization(); | ||||||
|  |             app.MapControllers(); | ||||||
|  |             app.Run(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										52
									
								
								Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | |||||||
|  | { | ||||||
|  |   "profiles": { | ||||||
|  |     "http": { | ||||||
|  |       "commandName": "Project", | ||||||
|  |       "launchBrowser": true, | ||||||
|  |       "launchUrl": "swagger", | ||||||
|  |       "environmentVariables": { | ||||||
|  |         "ASPNETCORE_ENVIRONMENT": "Development" | ||||||
|  |       }, | ||||||
|  |       "dotnetRunMessages": true, | ||||||
|  |       "applicationUrl": "http://localhost:5278" | ||||||
|  |     }, | ||||||
|  |     "https": { | ||||||
|  |       "commandName": "Project", | ||||||
|  |       "launchBrowser": true, | ||||||
|  |       "launchUrl": "swagger", | ||||||
|  |       "environmentVariables": { | ||||||
|  |         "ASPNETCORE_ENVIRONMENT": "Development" | ||||||
|  |       }, | ||||||
|  |       "dotnetRunMessages": true, | ||||||
|  |       "applicationUrl": "https://localhost:7084;http://localhost:5278" | ||||||
|  |     }, | ||||||
|  |     "IIS Express": { | ||||||
|  |       "commandName": "IISExpress", | ||||||
|  |       "launchBrowser": true, | ||||||
|  |       "launchUrl": "swagger", | ||||||
|  |       "environmentVariables": { | ||||||
|  |         "ASPNETCORE_ENVIRONMENT": "Development" | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     "Container (Dockerfile)": { | ||||||
|  |       "commandName": "Docker", | ||||||
|  |       "launchBrowser": true, | ||||||
|  |       "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", | ||||||
|  |       "environmentVariables": { | ||||||
|  |         "ASPNETCORE_HTTPS_PORTS": "8081", | ||||||
|  |         "ASPNETCORE_HTTP_PORTS": "8080" | ||||||
|  |       }, | ||||||
|  |       "publishAllPorts": true, | ||||||
|  |       "useSSL": true | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "$schema": "http://json.schemastore.org/launchsettings.json", | ||||||
|  |   "iisSettings": { | ||||||
|  |     "windowsAuthentication": false, | ||||||
|  |     "anonymousAuthentication": true, | ||||||
|  |     "iisExpress": { | ||||||
|  |       "applicationUrl": "http://localhost:10272", | ||||||
|  |       "sslPort": 44315 | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										42
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | # Database Setup and Migration Guide | ||||||
|  |  | ||||||
|  | ## Prerequisites | ||||||
|  | - .NET 8.0 SDK | ||||||
|  | - Entity Framework Core tools | ||||||
|  |  | ||||||
|  | ## Install EF Core Tools | ||||||
|  | ```sh | ||||||
|  | dotnet tool install --global dotnet-ef | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### Creating and Updating Database | ||||||
|  | 1. Create initial migration: | ||||||
|  | dotnet ef migrations add InitialCreate | ||||||
|  |  | ||||||
|  | 2. Apply migrations to create/update database: | ||||||
|  | dotnet ef database update | ||||||
|  |  | ||||||
|  | ### Common Commands | ||||||
|  | 1. Create new migration: | ||||||
|  | dotnet ef migrations add <MigrationName> | ||||||
|  |  | ||||||
|  | 2. Remove last migration: | ||||||
|  | dotnet ef migrations remove | ||||||
|  |  | ||||||
|  | 3. Apply migrations to create/update database: | ||||||
|  | dotnet ef database update | ||||||
|  |  | ||||||
|  | 4. Revert last migration: | ||||||
|  | dotnet ef database update <MigrationName> | ||||||
|  |  | ||||||
|  | 5. List all migrations: | ||||||
|  | dotnet ef migrations list | ||||||
|  |  | ||||||
|  | 6. Script migration: | ||||||
|  | dotnet ef migrations script | ||||||
|  |  | ||||||
|  | 7. Remove all migrations: | ||||||
|  | dotnet ef migrations remove | ||||||
|  |  | ||||||
|  | 8. Drop database: | ||||||
|  | dotnet ef database drop | ||||||
							
								
								
									
										32
									
								
								Repositories/PetRepository.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Repositories/PetRepository.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | |||||||
|  | using Microsoft.EntityFrameworkCore; | ||||||
|  | using pet_companion_api.Data; | ||||||
|  | using pet_companion_api.Models; | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Repositories | ||||||
|  | { | ||||||
|  |     public class PetRepository | ||||||
|  |     { | ||||||
|  |         private readonly ApplicationDbContext _context; | ||||||
|  |  | ||||||
|  |         public PetRepository(ApplicationDbContext context) | ||||||
|  |         { | ||||||
|  |             _context = context; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public IEnumerable<Pet> GetPetsByUserId(string userId) | ||||||
|  |         { | ||||||
|  |             return _context.Pets | ||||||
|  |                 .Where(p => p.UserId == userId) | ||||||
|  |                 .Include(p => p.Stats) | ||||||
|  |                 .Include(p => p.Resources) | ||||||
|  |                 .ToList(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public Pet CreatePet(Pet pet) | ||||||
|  |         { | ||||||
|  |             _context.Pets.Add(pet); | ||||||
|  |             _context.SaveChanges(); | ||||||
|  |             return pet; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										31
									
								
								Services/PetService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								Services/PetService.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | using pet_companion_api.Models; | ||||||
|  | using pet_companion_api.Repositories; | ||||||
|  |  | ||||||
|  | namespace pet_companion_api.Services | ||||||
|  | { | ||||||
|  |     public class PetService | ||||||
|  |     { | ||||||
|  |         private readonly PetRepository petRepository; | ||||||
|  |  | ||||||
|  |         public PetService(PetRepository petRepository) | ||||||
|  |         { | ||||||
|  |             this.petRepository = petRepository; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public IEnumerable<Pet> GetAllPets(Guid userId) | ||||||
|  |         { | ||||||
|  |             return petRepository.GetPetsByUserId(userId.ToString()); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public Pet CreatePet(Guid userId, Pet pet) | ||||||
|  |         { | ||||||
|  |             pet.Id = Guid.NewGuid().ToString(); | ||||||
|  |             pet.UserId = userId.ToString(); | ||||||
|  |             pet.Level = 1; | ||||||
|  |             pet.Stats = new PetStats(pet.Class); | ||||||
|  |             pet.Resources = new Resources(); | ||||||
|  |  | ||||||
|  |             return petRepository.CreatePet(pet); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										12
									
								
								appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								appsettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "DefaultConnection": "Data Source=petcompanion.db" | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										24
									
								
								pet-companion-api.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								pet-companion-api.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | |||||||
|  | <Project Sdk="Microsoft.NET.Sdk.Web"> | ||||||
|  |  | ||||||
|  |   <PropertyGroup> | ||||||
|  |     <TargetFramework>net8.0</TargetFramework> | ||||||
|  |     <Nullable>enable</Nullable> | ||||||
|  |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|  |     <RootNamespace>pet_companion_api</RootNamespace> | ||||||
|  |     <UserSecretsId>fb7dfb2a-4bb7-4cd0-bc10-293410089f4b</UserSecretsId> | ||||||
|  |     <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||||||
|  |     <DockerfileContext>.</DockerfileContext> | ||||||
|  |   </PropertyGroup> | ||||||
|  |  | ||||||
|  |   <ItemGroup> | ||||||
|  |     <PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.1" /> | ||||||
|  |     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1"> | ||||||
|  |       <PrivateAssets>all</PrivateAssets> | ||||||
|  |       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||||||
|  |     </PackageReference> | ||||||
|  |     <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.1" /> | ||||||
|  |     <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" /> | ||||||
|  |     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |  | ||||||
|  | </Project> | ||||||
							
								
								
									
										6
									
								
								pet-companion-api.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								pet-companion-api.http
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | @pet_companion_api_HostAddress = http://localhost:5278 | ||||||
|  |  | ||||||
|  | GET {{pet_companion_api_HostAddress}}/weatherforecast/ | ||||||
|  | Accept: application/json | ||||||
|  |  | ||||||
|  | ### | ||||||
							
								
								
									
										25
									
								
								pet-companion-api.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								pet-companion-api.sln
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  |  | ||||||
|  | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||||
|  | # Visual Studio Version 17 | ||||||
|  | VisualStudioVersion = 17.11.35431.28 | ||||||
|  | MinimumVisualStudioVersion = 10.0.40219.1 | ||||||
|  | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pet-companion-api", "pet-companion-api.csproj", "{FC7D30C5-4ADA-4C80-B3AC-8D3EBBA33696}" | ||||||
|  | EndProject | ||||||
|  | Global | ||||||
|  | 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||||
|  | 		Debug|Any CPU = Debug|Any CPU | ||||||
|  | 		Release|Any CPU = Release|Any CPU | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||||||
|  | 		{FC7D30C5-4ADA-4C80-B3AC-8D3EBBA33696}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{FC7D30C5-4ADA-4C80-B3AC-8D3EBBA33696}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{FC7D30C5-4ADA-4C80-B3AC-8D3EBBA33696}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{FC7D30C5-4ADA-4C80-B3AC-8D3EBBA33696}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(SolutionProperties) = preSolution | ||||||
|  | 		HideSolutionNode = FALSE | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(ExtensibilityGlobals) = postSolution | ||||||
|  | 		SolutionGuid = {1B269ACB-6192-4165-A30A-DED85F4A2877} | ||||||
|  | 	EndGlobalSection | ||||||
|  | EndGlobal | ||||||
		Reference in New Issue
	
	Block a user