Sun「無用」
Sun「無用」
Explore posts from servers
DTDrizzle Team
Created by Sun「無用」 on 9/6/2024 in #help
How to start with drizzle?
I'm reading docs and there doesn't seem to be any form of "how to get started" section or any installation area. It says a lot why to use it, but not how to use it. And the learn tab also didn't have any project starter. Is there no ways to do something like prisma init, that just starts a simple drizzle configuration or some documentation that gives that information?
3 replies
CC#
Created by Sun「無用」 on 9/4/2024 in #help
Get route information on controller
In my response model, I have stuff like method and path of the route. Is there any classes or methods I can call to inject that into the function? Example
class FooController : ControllerBase {
[HttpGet] // I know it's a get here, but not during runtime
async Task<ActionResult<CoolioResponse>> Bar(
// What to inject here? HttpContext?
) {

}
}
class FooController : ControllerBase {
[HttpGet] // I know it's a get here, but not during runtime
async Task<ActionResult<CoolioResponse>> Bar(
// What to inject here? HttpContext?
) {

}
}
50 replies
CC#
Created by Sun「無用」 on 9/3/2024 in #help
Class with same name as namespace
In the same app still (Ilanos), in my Ilanos.Application proj I have a lot of classes that are supposed to use the Joke class. However, for the sake of organization, I'm separating them like this:
|- Ilanos.Application
|- Mappers
|- Joke
|- Ilanos.Application
|- Mappers
|- Joke
The problem of that is the namespace name. The JokeResponseMapper, for example, would be at the namespace Ilanos.Application.Mappers.Joke while the Joke entity/model class is at Ilanos.Core.Entities. The compiler complains that the Ilanos.Application.Mappers.Joke namespace and the Joke class "have the same name", even if they're different, is there a way to keep the organization and have the named classes as they are?
24 replies
CC#
Created by Sun「無用」 on 9/3/2024 in #help
Unable to create DbContext
I'm trying to create by db tables right now, still in the start of a project. I have a ApplicationDbContext in my Infrastructure project and I'm running dotnet ef migrations Initial, that's all. Project is public for now, could be seen here (yes, I know it's messy, I don't like clean architecture, I mostly don't know how to do it, not my style of coding) Error Traceback:
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Ilanos.Infrastructure.ApplicationDbContext]' while attempting to activate 'Ilanos.Infrastructure.ApplicationDbContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Ilanos.Infrastructure.ApplicationDbContext]' while attempting to activate 'Ilanos.Infrastructure.ApplicationDbContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
48 replies
PPrisma
Created by Sun「無用」 on 6/1/2024 in #help-and-questions
Cleaning code
So, just building a basic scoreboard side project, which I need teams and scores for it. Is there any ways to clean up these models? They just seem kinda clunky to me, dunno if I'm the problem here.
model Team {
id String @id @default(uuid()) @map("team_id")
slug String @unique @default(nanoid())
name String

LeftGame Game[] @relation("left_team")
RightGame Game[] @relation("right_team")

@@map("teams")
}

model Game {
id String @id @default(uuid()) @map("game_id")

leftTeamId String
leftTeam Team @relation("left_team", fields: [leftTeamId], references: [id])
leftScore Int @default(0)

rightTeamId String
rightTeam Team @relation("right_team", fields: [rightTeamId], references: [id])
rightScore Int @default(0)

@@map("games")
}
model Team {
id String @id @default(uuid()) @map("team_id")
slug String @unique @default(nanoid())
name String

LeftGame Game[] @relation("left_team")
RightGame Game[] @relation("right_team")

@@map("teams")
}

model Game {
id String @id @default(uuid()) @map("game_id")

leftTeamId String
leftTeam Team @relation("left_team", fields: [leftTeamId], references: [id])
leftScore Int @default(0)

rightTeamId String
rightTeam Team @relation("right_team", fields: [rightTeamId], references: [id])
rightScore Int @default(0)

@@map("games")
}
2 replies
CC#
Created by Sun「無用」 on 5/30/2024 in #help
Testing practices and libraries
I'm just starting with testing, I'm not that much of a fan, most of the time for me it wasn't needed. But'll just try it just in case I actually need it in the future (probably never :d) What libraries should I use to make testing less bad? And what practices are recommeded when testing?
3 replies
CC#
Created by Sun「無用」 on 5/26/2024 in #help
Typed ids to plain id
My model is something like
// BaseEntity<UserId> has UserId Id
public class User : BaseEntity<UserId> {
public required string Name { get; init; ]
}
// BaseEntity<UserId> has UserId Id
public class User : BaseEntity<UserId> {
public required string Name { get; init; ]
}
How would I transform that UserId into a type that's valid in the database, like the Guid or int that's inside of the UserId?
36 replies
CC#
Created by Sun「無用」 on 5/25/2024 in #help
Transforming own type into ProblemDetails
So, I really like using application/problem+json to specify my results and for that I have my own ProblemResponse<T> type
public class ProblemResponse<T>
{
public required string Type { get; init; }
public required int Status { get; init; }
public required string Title { get; init; }
public required string Detail { get; init; }
public required string UriPath { get; init; }
public required string Method { get; init; }
public required T? Extensions { get; init; }
}
public class ProblemResponse<T>
{
public required string Type { get; init; }
public required int Status { get; init; }
public required string Title { get; init; }
public required string Detail { get; init; }
public required string UriPath { get; init; }
public required string Method { get; init; }
public required T? Extensions { get; init; }
}
Which has all the specification fields + extensions The thing is that dotnet's ProblemDetails type is not generic in any way, it uses a dictionary. The type could be shortened to this
public class ProblemDetails {
public string? Type { get; set; }
public string? Title { get; set; }
public int? Status { get; set; }
public string? Detail { get; set; }
public string? Instance { get; set; }
[JsonExtensionData]
public IDictionary<string, object?> Extensions { get; set; }
}
public class ProblemDetails {
public string? Type { get; set; }
public string? Title { get; set; }
public int? Status { get; set; }
public string? Detail { get; set; }
public string? Instance { get; set; }
[JsonExtensionData]
public IDictionary<string, object?> Extensions { get; set; }
}
Is there any ways to transform from my type to theirs? or do I just use my type and not use the application/problem+json header? sry for the long text
1 replies
CC#
Created by Sun「無用」 on 5/25/2024 in #help
Basic project structure for api/frontend
I've a small project I wanna build, but it'll need a frontend and a backend. I'd like to learn some Blazor, so I'll use that as Frontend and normal asp.net w/controllers for backend. I'm kinda stuck on project naming and organization though, do I use something like clean architecture, even if my project is way too small for that or do I just use like a *.Api, *.Blazor and *.Common? What should be the recommended there to keep it simple as much as possible?
51 replies
HHono
Created by Sun「無用」 on 5/5/2024 in #help
Setting up Client Components
I'm trying to setup a simple counter client component, code can be seen below. Code is minimal so it's easy to test it (first time using client components on hono) When using the example given in the docs, an "obvious" error that document is not defined would happen, since I'm in the server. Code:
function Counter({start}) {
const [count, setCount] = useState(start ?? 0);

useEffect(() => {
console.log(`Count is now ${count}`)
}, [count]);

return (
<button onClick={() => setCount((c) => c + 1)}>
{count}
</button>
)
}

app.get("/counter", async (c) => [
const counterState = await db.getCounterState()

// Does not update properly, just stays at 0 forever.
return c.html(<Counter start={counterState} />);
})
function Counter({start}) {
const [count, setCount] = useState(start ?? 0);

useEffect(() => {
console.log(`Count is now ${count}`)
}, [count]);

return (
<button onClick={() => setCount((c) => c + 1)}>
{count}
</button>
)
}

app.get("/counter", async (c) => [
const counterState = await db.getCounterState()

// Does not update properly, just stays at 0 forever.
return c.html(<Counter start={counterState} />);
})
5 replies
CC#
Created by Sun「無用」 on 6/21/2023 in #help
✅ ef not being able to update database migrations
I've been trying to learn aspnet and done just the basics of it. But when using dotnet ef database update, after adding a migration, the same SQLite Error 1: 'no such table: __EFMigrationsHistory'. happens, eventhough that table is being created (or was supposed to be created) on the initial migration. I only have 1 service and 1 model now, so that error makes no sense for me, as it's the only language that happened for me.
58 replies
CC#
Created by Sun「無用」 on 6/21/2023 in #help
How to get configurations variables?
I'm new to asp.net, been trying to create some apis. For now, I'm trying to get the db connection string, out of the appsettings.json. Is that possible or would I need to use something like .env variables with some extra configuration?
8 replies
SSolidJS
Created by Sun「無用」 on 3/17/2023 in #support
createResource returning undefined when data is fetched
I'm just learning solid and did something like a hook? maybe? dunno. Anyways, I'm just calling createResource with a fetch on it and returning it's json. But, for any reason, that fn is returning undefined, even when the data is properly fetched("tested" by logging the json). Code:
const useFetch = <T>(p: UseFetchParams) => {
const [url] = createSignal(createUrl(p));

const [data] = createResource<T>(async () => {
return await fetch(url()).then(async (res) => (await res.json()) as T);
});

return { data, didFetch: data() !== undefined };
};
const useFetch = <T>(p: UseFetchParams) => {
const [url] = createSignal(createUrl(p));

const [data] = createResource<T>(async () => {
return await fetch(url()).then(async (res) => (await res.json()) as T);
});

return { data, didFetch: data() !== undefined };
};
105 replies
CC#
Created by Sun「無用」 on 12/12/2022 in #help
❔ Errors when everything looks ok.
So, I'm dumb a aspnet api, with controllers, using sqlite. There are no syntax errors in the code, since it compiles, but when I try to do anything(any request), the same giant error appears. Error given on the file.
129 replies