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,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Api_HostAddress = http://localhost:5176

GET {{Api_HostAddress}}/weatherforecast/
Accept: application/json

###
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Api.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Shared.Models;

namespace Api.Controllers;

[ApiController]
[Route("api/[controller]")]
public class LayoutController : ControllerBase
{
private readonly AppDbContext _context;

public LayoutController(AppDbContext context)
{
_context = context;
}

[HttpGet]
public async Task<ActionResult<List<LayoutNode>>> Get()
{
try
{
return await _context.OrgChartLayouts.OrderBy(n => n.Id).ToListAsync();
}
catch (Exception ex)
{
return StatusCode(500, $"Internal server error: {ex.Message}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.EntityFrameworkCore;
using Shared.Models; // Or your namespace
using System.Text.Json;

namespace Api.Data;

public class AppDbContext : DbContext
{
public DbSet<LayoutNode> OrgChartLayouts { get; set; } = null!;

public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LayoutNode>()
.ToTable("orgchart_layout")
.HasKey(n => n.Id);

modelBuilder.Entity<LayoutNode>()
.Property(n => n.ParentId)
.HasColumnName("parent_id");

modelBuilder.Entity<LayoutNode>()
.Property(n => n.Role)
.HasColumnName("role")
.IsRequired();

modelBuilder.Entity<LayoutNode>()
.HasIndex(n => n.ParentId);

// Seed data
modelBuilder.Entity<LayoutNode>().HasData(
new LayoutNode { Id = "parent", ParentId = null, Role = "Board" },
new LayoutNode { Id = "1", ParentId = "parent", Role = "General Manager" },
new LayoutNode { Id = "2", ParentId = "1", Role = "Human Resource Manager" },
new LayoutNode { Id = "3", ParentId = "2", Role = "Trainers" },
new LayoutNode { Id = "4", ParentId = "2", Role = "Recruiting Team" },
new LayoutNode { Id = "5", ParentId = "2", Role = "Finance Asst. Manager" },
new LayoutNode { Id = "6", ParentId = "1", Role = "Design Manager" },
new LayoutNode { Id = "7", ParentId = "6", Role = "Design Supervisor" },
new LayoutNode { Id = "8", ParentId = "6", Role = "Development Supervisor" },
new LayoutNode { Id = "9", ParentId = "6", Role = "Drafting Supervisor" },
new LayoutNode { Id = "10", ParentId = "1", Role = "Operations Manager" },
new LayoutNode { Id = "11", ParentId = "10", Role = "Statistics Department" },
new LayoutNode { Id = "12", ParentId = "10", Role = "Logistics Department" },
new LayoutNode { Id = "16", ParentId = "1", Role = "Marketing Manager" },
new LayoutNode { Id = "17", ParentId = "16", Role = "Overseas Sales Manager" },
new LayoutNode { Id = "18", ParentId = "16", Role = "Petroleum Manager" },
new LayoutNode { Id = "20", ParentId = "16", Role = "Service Department Manager" },
new LayoutNode { Id = "21", ParentId = "16", Role = "Quality Control Department" }
);
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace Api.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "orgchart_layout",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
parent_id = table.Column<string>(type: "text", nullable: true),
role = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_orgchart_layout", x => x.Id);
});

migrationBuilder.InsertData(
table: "orgchart_layout",
columns: new[] { "Id", "parent_id", "role" },
values: new object[,]
{
{ "1", "parent", "General Manager" },
{ "10", "1", "Operations Manager" },
{ "11", "10", "Statistics Department" },
{ "12", "10", "Logistics Department" },
{ "16", "1", "Marketing Manager" },
{ "17", "16", "Overseas Sales Manager" },
{ "18", "16", "Petroleum Manager" },
{ "2", "1", "Human Resource Manager" },
{ "20", "16", "Service Department Manager" },
{ "21", "16", "Quality Control Department" },
{ "3", "2", "Trainers" },
{ "4", "2", "Recruiting Team" },
{ "5", "2", "Finance Asst. Manager" },
{ "6", "1", "Design Manager" },
{ "7", "6", "Design Supervisor" },
{ "8", "6", "Development Supervisor" },
{ "9", "6", "Drafting Supervisor" },
{ "parent", null, "Board" }
});

migrationBuilder.CreateIndex(
name: "IX_orgchart_layout_parent_id",
table: "orgchart_layout",
column: "parent_id");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "orgchart_layout");
}
}
}
Loading