ibby
ibby
Explore posts from servers
CC#
Created by ibby on 4/30/2024 in #help
SignInAsync Set-Cookie header not working?
No description
6 replies
CC#
Created by ibby on 4/29/2024 in #help
What should the service layer return back to a controller?
Confused about what the service layer should return to the controller, Dtos? Result object? Is this the correct approach?
public async Task<CreateUserResult> CreateUserAsync(string username, string email, string password)
{
...input validation

username = username.ToLower();
email = email.ToLower();

if (_dbContext.Users.Any(x => x.Username.Equals(username)))
{
return; // Return a result object with a bool flag "IsDuplicateUsername"?
}

if (_dbContext.Users.Any(x => x.Email.Equals(email)))
{
return; // Return a result object with a bool flag "IsDuplicateEmail"?
}

var user = new User(username, email, password.ToHash());

await _dbContext.Users.AddAsync(user);

await _dbContext.SaveChangesAsync();

// return result with everything false?
}
public async Task<CreateUserResult> CreateUserAsync(string username, string email, string password)
{
...input validation

username = username.ToLower();
email = email.ToLower();

if (_dbContext.Users.Any(x => x.Username.Equals(username)))
{
return; // Return a result object with a bool flag "IsDuplicateUsername"?
}

if (_dbContext.Users.Any(x => x.Email.Equals(email)))
{
return; // Return a result object with a bool flag "IsDuplicateEmail"?
}

var user = new User(username, email, password.ToHash());

await _dbContext.Users.AddAsync(user);

await _dbContext.SaveChangesAsync();

// return result with everything false?
}
41 replies
TTCTheo's Typesafe Cult
Created by ibby on 12/19/2023 in #questions
nextjs how to render serverside and then update data client-side based on a filter?
I have this page.tsx rendering on the server:
const PostsPage = async () => {
const posts = await db.post.findMany({
take: 25,
include: {
author: true
}
});

return (
<div>
<div>
<label>Filter verified posts</label>
<input type="checkbox" ... /> // checkbox to filter posts (add query string?)
</div>

<div>
{posts.map(p => (<Post
key={p.id}
id={p.id}
content={p.content}
authorName={p.author.name}
/>))}
</div>
</div>
);
};
const PostsPage = async () => {
const posts = await db.post.findMany({
take: 25,
include: {
author: true
}
});

return (
<div>
<div>
<label>Filter verified posts</label>
<input type="checkbox" ... /> // checkbox to filter posts (add query string?)
</div>

<div>
{posts.map(p => (<Post
key={p.id}
id={p.id}
content={p.content}
authorName={p.author.name}
/>))}
</div>
</div>
);
};
3 replies