initial data model work

This commit is contained in:
Alan Moon 2025-03-03 12:35:08 -08:00
parent 4922223bb2
commit 21b7cd9694
8 changed files with 1453 additions and 15 deletions

View File

@ -1147,7 +1147,7 @@ public class ContentController : Controller {
[Route("ContentWebService.asmx/GetBuddyList")] [Route("ContentWebService.asmx/GetBuddyList")]
public IActionResult GetBuddyList() { public IActionResult GetBuddyList() {
// TODO: this is a placeholder // TODO: this is a placeholder
return Ok(new BuddyList { Buddy = new Buddy[0] }); return Ok(new BuddyList { Buddy = new Schema.Buddy[0] });
} }
[HttpPost] [HttpPost]

View File

@ -35,21 +35,9 @@ public class MessagingController : Controller {
// clients (at least older ones) don't send what typeID the message is, its encoded in data // clients (at least older ones) don't send what typeID the message is, its encoded in data
ArrayOfKeyValuePairOfStringString arrayOfKeyValuePairOfStringString = XmlUtil.DeserializeXml<ArrayOfKeyValuePairOfStringString>(data); ArrayOfKeyValuePairOfStringString arrayOfKeyValuePairOfStringString = XmlUtil.DeserializeXml<ArrayOfKeyValuePairOfStringString>(data);
MessageTypeID typeID = MessageTypeID.Unknown; MessageTypeID typeID = (MessageTypeID)int.Parse(arrayOfKeyValuePairOfStringString.KeyValuePairOfStringString![0].Value ?? "0");
string typeText = "";
switch(arrayOfKeyValuePairOfStringString.KeyValuePairOfStringString[0]?.Value)
{
case "Drawing":
typeID = MessageTypeID.GreetingCard;
typeText = "Card";
break;
case "Photo":
typeID = MessageTypeID.Photo;
typeText = "PhotoBomb";
break;
}
var msg = messagingService.AddMessageToViking(viking, toViking, MessageType.Data, typeID, MessageLevel.WhiteList, data, "[[Line1]]=[[{{BuddyUserName}}]] has sent you a " + typeText + "!", "[[Line1]]=[[{{BuddyUserName}}]] has sent you a " + typeText + "!"); var msg = messagingService.AddMessageToViking(viking, toViking, MessageType.Data, typeID, MessageLevel.WhiteList, data, "[[Line1]]=[[{{BuddyUserName}}]] has sent you a {{MessageType}}!", "[[Line1]]=[[{{BuddyUserName}}]] has sent you a {{MessageType}}!");
if (msg != null) return Ok(true); if (msg != null) return Ok(true);
else return Ok(false); else return Ok(false);
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace sodoff.Migrations
{
/// <inheritdoc />
public partial class Buddies : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Buddy",
columns: table => new
{
VikingId = table.Column<int>(type: "INTEGER", nullable: false),
BuddyVikingId = table.Column<int>(type: "INTEGER", nullable: false),
BuddyStatus1 = table.Column<int>(type: "INTEGER", nullable: false),
BuddyStatus2 = table.Column<int>(type: "INTEGER", nullable: false),
IsBestFriend1 = table.Column<bool>(type: "INTEGER", nullable: false),
IsBestFriend2 = table.Column<bool>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Buddy", x => x.VikingId);
table.ForeignKey(
name: "FK_Buddy_Vikings_BuddyVikingId",
column: x => x.BuddyVikingId,
principalTable: "Vikings",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Buddy_Vikings_VikingId",
column: x => x.VikingId,
principalTable: "Vikings",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Buddy_BuddyVikingId",
table: "Buddy",
column: "BuddyVikingId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Buddy");
}
}
}

View File

@ -70,6 +70,33 @@ namespace sodoff.Migrations
b.ToTable("AchievementTaskState"); b.ToTable("AchievementTaskState");
}); });
modelBuilder.Entity("sodoff.Model.Buddy", b =>
{
b.Property<int>("VikingId")
.HasColumnType("INTEGER");
b.Property<int>("BuddyStatus1")
.HasColumnType("INTEGER");
b.Property<int>("BuddyStatus2")
.HasColumnType("INTEGER");
b.Property<int>("BuddyVikingId")
.HasColumnType("INTEGER");
b.Property<bool>("IsBestFriend1")
.HasColumnType("INTEGER");
b.Property<bool>("IsBestFriend2")
.HasColumnType("INTEGER");
b.HasKey("VikingId");
b.HasIndex("BuddyVikingId");
b.ToTable("Buddy");
});
modelBuilder.Entity("sodoff.Model.Dragon", b => modelBuilder.Entity("sodoff.Model.Dragon", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -849,6 +876,25 @@ namespace sodoff.Migrations
b.Navigation("Viking"); b.Navigation("Viking");
}); });
modelBuilder.Entity("sodoff.Model.Buddy", b =>
{
b.HasOne("sodoff.Model.Viking", "BuddyViking")
.WithMany("BuddyList")
.HasForeignKey("BuddyVikingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("sodoff.Model.Viking", "Viking")
.WithMany("BuddiesMade")
.HasForeignKey("VikingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("BuddyViking");
b.Navigation("Viking");
});
modelBuilder.Entity("sodoff.Model.Dragon", b => modelBuilder.Entity("sodoff.Model.Dragon", b =>
{ {
b.HasOne("sodoff.Model.Viking", "Viking") b.HasOne("sodoff.Model.Viking", "Viking")
@ -1206,6 +1252,10 @@ namespace sodoff.Migrations
b.Navigation("AchievementTaskStates"); b.Navigation("AchievementTaskStates");
b.Navigation("BuddiesMade");
b.Navigation("BuddyList");
b.Navigation("Dragons"); b.Navigation("Dragons");
b.Navigation("GameData"); b.Navigation("GameData");

22
src/Model/Buddy.cs Normal file
View File

@ -0,0 +1,22 @@
using System;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using sodoff.Schema;
namespace sodoff.Model;
[PrimaryKey(nameof(VikingId))]
public class Buddy
{
public int VikingId { get; set; }
public int BuddyVikingId { get; set; }
public BuddyStatus BuddyStatus1 { get; set; }
public BuddyStatus BuddyStatus2 { get; set; }
public bool IsBestFriend1 { get; set; }
public bool IsBestFriend2 { get; set; }
public virtual Viking? Viking { get; set; }
public virtual Viking? BuddyViking { get; set; }
}

View File

@ -167,6 +167,12 @@ public class DBContext : DbContext {
builder.Entity<Viking>().HasMany(v => v.MessagesMade) builder.Entity<Viking>().HasMany(v => v.MessagesMade)
.WithOne(r => r.Viking); .WithOne(r => r.Viking);
builder.Entity<Viking>().HasMany(v => v.BuddyList)
.WithOne(r => r.BuddyViking);
builder.Entity<Viking>().HasMany(v => v.BuddiesMade)
.WithOne(r => r.Viking);
// Dragons // Dragons
builder.Entity<Dragon>().HasOne(d => d.Viking) builder.Entity<Dragon>().HasOne(d => d.Viking)
.WithMany(e => e.Dragons) .WithMany(e => e.Dragons)
@ -331,5 +337,14 @@ public class DBContext : DbContext {
.WithOne(e => e.ParentMessage) .WithOne(e => e.ParentMessage)
.HasForeignKey(e => e.ParentMessageId) .HasForeignKey(e => e.ParentMessageId)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
// Buddies
builder.Entity<Buddy>().HasOne(r => r.BuddyViking)
.WithMany(e => e.BuddyList)
.HasForeignKey(e => e.BuddyVikingId);
builder.Entity<Buddy>().HasOne(r => r.Viking)
.WithMany(e => e.BuddiesMade)
.HasForeignKey(e => e.VikingId);
} }
} }

View File

@ -47,6 +47,8 @@ public class Viking {
public virtual ICollection<UserBan> UserBans { get; set; } = null!; public virtual ICollection<UserBan> UserBans { get; set; } = null!;
public virtual ICollection<Message> MessageBoard { get; set; } = null!; public virtual ICollection<Message> MessageBoard { get; set; } = null!;
public virtual ICollection<Message> MessagesMade { get; set; } = null!; public virtual ICollection<Message> MessagesMade { get; set; } = null!;
public virtual ICollection<Buddy> BuddyList { get; set; } = null!;
public virtual ICollection<Buddy> BuddiesMade { get; set; } = null!;
public DateTime? CreationDate { get; set; } public DateTime? CreationDate { get; set; }
public DateTime? BirthDate { get; set; } public DateTime? BirthDate { get; set; }