Skip to content

Commit 55854f0

Browse files
complete profile functionality
1 parent d6cc4a4 commit 55854f0

File tree

6 files changed

+223
-12
lines changed

6 files changed

+223
-12
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using taskmaster_api.Data.DTOs;
4+
using taskmaster_api.Services.Interface;
5+
6+
namespace taskmaster_api.Controllers
7+
{
8+
[Route("api/[controller]")]
9+
[ApiController]
10+
[Authorize]
11+
public class ProfileController : ApplicationControllerBase
12+
{
13+
private readonly IProfileService _profileService;
14+
15+
public ProfileController(IProfileService profileService)
16+
{
17+
_profileService = profileService;
18+
}
19+
20+
[HttpGet]
21+
public IActionResult GetAllProfiles()
22+
{
23+
return ToHttpResult<List<ProfileDto>>(_profileService.GetAllProfiles());
24+
}
25+
26+
[HttpGet("{id}")]
27+
public IActionResult GetProfile(int id)
28+
{
29+
return ToHttpResult<ProfileDto>(_profileService.GetProfileById(id));
30+
}
31+
32+
[HttpPost]
33+
public IActionResult CreateProfile(ProfileDto profileDto)
34+
{
35+
return ToHttpResult<ProfileDto>(_profileService.CreateProfile(profileDto));
36+
}
37+
38+
[HttpPut("{id}")]
39+
public IActionResult UpdateProfile(int id, ProfileDto profileDto)
40+
{
41+
return ToHttpResult<ProfileDto>(_profileService.UpdateProfile(id, profileDto));
42+
}
43+
44+
[HttpDelete("{id}")]
45+
public IActionResult DeleteProfile(int id)
46+
{
47+
return ToHttpResult(_profileService.DeleteProfile(id));
48+
}
49+
}
50+
}

taskmaster-api/Data/Repositories/TicketRepository.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using Microsoft.EntityFrameworkCore;
2-
using System;
3-
using System.Text;
42
using taskmaster_api.Data.Contexts;
53
using taskmaster_api.Data.Entities;
64
using taskmaster_api.Data.Repositories.Interface;
7-
using static System.Net.Mime.MediaTypeNames;
85

96
namespace taskmaster_api.Data.Repositories
107
{

taskmaster-api/Migrations/20231220055004_InitialCreate.Designer.cs renamed to taskmaster-api/Migrations/20231222081613_InitialCreate.Designer.cs

Lines changed: 66 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

taskmaster-api/Migrations/20231220055004_InitialCreate.cs renamed to taskmaster-api/Migrations/20231222081613_InitialCreate.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,34 @@ protected override void Up(MigrationBuilder migrationBuilder)
245245
onDelete: ReferentialAction.Cascade);
246246
});
247247

248+
migrationBuilder.CreateTable(
249+
name: "Profiles",
250+
columns: table => new
251+
{
252+
Id = table.Column<int>(type: "int", nullable: false)
253+
.Annotation("SqlServer:Identity", "1, 1"),
254+
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
255+
FirstName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
256+
LastName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
257+
AboutMe = table.Column<string>(type: "nvarchar(max)", nullable: true),
258+
Gender = table.Column<string>(type: "nvarchar(1)", maxLength: 1, nullable: true),
259+
DateOfBirth = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
260+
PhoneNumber = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
261+
Photo = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: true),
262+
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
263+
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
264+
},
265+
constraints: table =>
266+
{
267+
table.PrimaryKey("PK_Profiles", x => x.Id);
268+
table.ForeignKey(
269+
name: "FK_Profiles_AspNetUsers_UserId",
270+
column: x => x.UserId,
271+
principalTable: "AspNetUsers",
272+
principalColumn: "Id",
273+
onDelete: ReferentialAction.Cascade);
274+
});
275+
248276
migrationBuilder.CreateTable(
249277
name: "Attachments",
250278
columns: table => new
@@ -371,6 +399,11 @@ protected override void Up(MigrationBuilder migrationBuilder)
371399
name: "IX_Notifications_UserId",
372400
table: "Notifications",
373401
column: "UserId");
402+
403+
migrationBuilder.CreateIndex(
404+
name: "IX_Profiles_UserId",
405+
table: "Profiles",
406+
column: "UserId");
374407
}
375408

376409
/// <inheritdoc />
@@ -403,6 +436,9 @@ protected override void Down(MigrationBuilder migrationBuilder)
403436
migrationBuilder.DropTable(
404437
name: "Notifications");
405438

439+
migrationBuilder.DropTable(
440+
name: "Profiles");
441+
406442
migrationBuilder.DropTable(
407443
name: "Settings");
408444

taskmaster-api/Migrations/ApplicationDbContextModelSnapshot.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,60 @@ protected override void BuildModel(ModelBuilder modelBuilder)
345345
b.ToTable("Notifications");
346346
});
347347

348+
modelBuilder.Entity("taskmaster_api.Data.Entities.ProfileEntity", b =>
349+
{
350+
b.Property<int?>("Id")
351+
.ValueGeneratedOnAdd()
352+
.HasColumnType("int");
353+
354+
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int?>("Id"));
355+
356+
b.Property<string>("AboutMe")
357+
.HasColumnType("nvarchar(max)");
358+
359+
b.Property<DateTime>("CreatedAt")
360+
.HasColumnType("datetime2");
361+
362+
b.Property<string>("DateOfBirth")
363+
.HasMaxLength(20)
364+
.HasColumnType("nvarchar(20)");
365+
366+
b.Property<string>("FirstName")
367+
.IsRequired()
368+
.HasMaxLength(20)
369+
.HasColumnType("nvarchar(20)");
370+
371+
b.Property<string>("Gender")
372+
.HasMaxLength(1)
373+
.HasColumnType("nvarchar(1)");
374+
375+
b.Property<string>("LastName")
376+
.IsRequired()
377+
.HasMaxLength(20)
378+
.HasColumnType("nvarchar(20)");
379+
380+
b.Property<string>("PhoneNumber")
381+
.HasMaxLength(20)
382+
.HasColumnType("nvarchar(20)");
383+
384+
b.Property<string>("Photo")
385+
.HasMaxLength(255)
386+
.HasColumnType("nvarchar(255)");
387+
388+
b.Property<DateTime>("UpdatedAt")
389+
.HasColumnType("datetime2");
390+
391+
b.Property<string>("UserId")
392+
.IsRequired()
393+
.HasColumnType("nvarchar(450)");
394+
395+
b.HasKey("Id");
396+
397+
b.HasIndex("UserId");
398+
399+
b.ToTable("Profiles");
400+
});
401+
348402
modelBuilder.Entity("taskmaster_api.Data.Entities.SettingEntity", b =>
349403
{
350404
b.Property<int?>("Id")
@@ -532,6 +586,17 @@ protected override void BuildModel(ModelBuilder modelBuilder)
532586

533587
b.Navigation("User");
534588
});
589+
590+
modelBuilder.Entity("taskmaster_api.Data.Entities.ProfileEntity", b =>
591+
{
592+
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User")
593+
.WithMany()
594+
.HasForeignKey("UserId")
595+
.OnDelete(DeleteBehavior.Cascade)
596+
.IsRequired();
597+
598+
b.Navigation("User");
599+
});
535600
#pragma warning restore 612, 618
536601
}
537602
}

taskmaster-api/Program.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
using Microsoft.AspNetCore.Authentication.JwtBearer;
2+
using Microsoft.AspNetCore.Identity;
13
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.IdentityModel.Tokens;
5+
using Swashbuckle.AspNetCore.Filters;
6+
using System.Text;
27
using taskmaster_api.Data.Contexts;
38
using taskmaster_api.Data.Repositories;
49
using taskmaster_api.Data.Repositories.Interface;
5-
using taskmaster_api.Services.Interface;
610
using taskmaster_api.Services;
7-
using Microsoft.AspNetCore.Identity;
8-
using Swashbuckle.AspNetCore.Filters;
9-
using Microsoft.AspNetCore.Authentication.JwtBearer;
10-
using Microsoft.IdentityModel.Tokens;
11-
using System.Text;
12-
using Microsoft.Extensions.DependencyInjection;
13-
using System.Configuration;
11+
using taskmaster_api.Services.Interface;
1412

1513
var builder = WebApplication.CreateBuilder(args);
1614

0 commit comments

Comments
 (0)