✨ Public contacts
This commit is contained in:
@@ -214,6 +214,7 @@ public class AccountContact : ModelBase
|
|||||||
public AccountContactType Type { get; set; }
|
public AccountContactType Type { get; set; }
|
||||||
public Instant? VerifiedAt { get; set; }
|
public Instant? VerifiedAt { get; set; }
|
||||||
public bool IsPrimary { get; set; } = false;
|
public bool IsPrimary { get; set; } = false;
|
||||||
|
public bool IsPublic { get; set; } = false;
|
||||||
[MaxLength(1024)] public string Content { get; set; } = string.Empty;
|
[MaxLength(1024)] public string Content { get; set; } = string.Empty;
|
||||||
|
|
||||||
public Guid AccountId { get; set; }
|
public Guid AccountId { get; set; }
|
||||||
|
@@ -25,6 +25,7 @@ public class AccountController(
|
|||||||
var account = await db.Accounts
|
var account = await db.Accounts
|
||||||
.Include(e => e.Badges)
|
.Include(e => e.Badges)
|
||||||
.Include(e => e.Profile)
|
.Include(e => e.Profile)
|
||||||
|
.Include(e => e.Contacts.Where(c => c.IsPublic))
|
||||||
.Where(a => a.Name == name)
|
.Where(a => a.Name == name)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
if (account is null) return new NotFoundResult();
|
if (account is null) return new NotFoundResult();
|
||||||
|
@@ -653,6 +653,50 @@ public class AccountCurrentController(
|
|||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("contacts/{id:guid}/public")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<AccountContact>> SetPublicContact(Guid id)
|
||||||
|
{
|
||||||
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||||
|
|
||||||
|
var contact = await db.AccountContacts
|
||||||
|
.Where(c => c.AccountId == currentUser.Id && c.Id == id)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
if (contact is null) return NotFound();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
contact = await accounts.SetContactMethodPublic(currentUser, contact, true);
|
||||||
|
return Ok(contact);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("contacts/{id:guid}/public")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult<AccountContact>> UnsetPublicContact(Guid id)
|
||||||
|
{
|
||||||
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||||
|
|
||||||
|
var contact = await db.AccountContacts
|
||||||
|
.Where(c => c.AccountId == currentUser.Id && c.Id == id)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
if (contact is null) return NotFound();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
contact = await accounts.SetContactMethodPublic(currentUser, contact, false);
|
||||||
|
return Ok(contact);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpDelete("contacts/{id:guid}")]
|
[HttpDelete("contacts/{id:guid}")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
@@ -557,6 +557,14 @@ public class AccountService(
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<AccountContact> SetContactMethodPublic(Account account, AccountContact contact, bool isPublic)
|
||||||
|
{
|
||||||
|
contact.IsPublic = isPublic;
|
||||||
|
db.AccountContacts.Update(contact);
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task DeleteContactMethod(Account account, AccountContact contact)
|
public async Task DeleteContactMethod(Account account, AccountContact contact)
|
||||||
{
|
{
|
||||||
|
1751
DysonNetwork.Pass/Migrations/20250808152851_AddPublicContact.Designer.cs
generated
Normal file
1751
DysonNetwork.Pass/Migrations/20250808152851_AddPublicContact.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,29 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Pass.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddPublicContact : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "is_public",
|
||||||
|
table: "account_contacts",
|
||||||
|
type: "boolean",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "is_public",
|
||||||
|
table: "account_contacts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -351,6 +351,10 @@ namespace DysonNetwork.Pass.Migrations
|
|||||||
.HasColumnType("boolean")
|
.HasColumnType("boolean")
|
||||||
.HasColumnName("is_primary");
|
.HasColumnName("is_primary");
|
||||||
|
|
||||||
|
b.Property<bool>("IsPublic")
|
||||||
|
.HasColumnType("boolean")
|
||||||
|
.HasColumnName("is_public");
|
||||||
|
|
||||||
b.Property<int>("Type")
|
b.Property<int>("Type")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("type");
|
.HasColumnName("type");
|
||||||
|
Reference in New Issue
Block a user