Cyno

joined 1 year ago
[–] [email protected] 1 points 5 months ago* (last edited 5 months ago) (1 children)
  1. but if I do it on the repository layer I have to have a separate method for every possible filter combination, right? if i want to do it on the service layer i have to return an IQueryable which is also allegedly a bad practice (and i might as well return the entire dbset at that point)? also, should the repository be aware of my application (or even view) layer dto models?
  2. this means the service has direct access to the database (dbcontext in this case)? or do you expose opening a transaction through some repository too?
[–] [email protected] 1 points 5 months ago (1 children)

Additional question - I said at first that the "Service" should be doing the mandatory checks like uniqueness validation or whether the fields are filled in properly with good values, but is even that a good approach?

Instead of implementing this in every service that might create a new Movie (and it could be from different sources - import from file, different APIs, background worker, etc), wouldn't it make more sense to add these checks to the repository itself so they always gets called?

Alternatively, do we have to handle a constraint violation in every service or could we just have the repository return a result with failure if it happens?

In short, once I start thinking in this way I start to wonder why even have a separation between repository and service.

[–] [email protected] 3 points 5 months ago* (last edited 5 months ago) (2 children)

I'm not that familiar with newer c# code and only recently started with result pattern but tbh, I can't tell what is this code supposed to do. Does opt resolve to true or false in this case? Why do you want TestStringFail to always execute, and what should it return? Why is opt.None true when it was initialized with a valid string value, what does None even mean in this context?

[–] [email protected] 1 points 6 months ago* (last edited 6 months ago)

Saying I learned it is a stretch, we still dont use it at my workplace and I just read some random guides and tried it on my personal projects. I also wouldn't know about using it in frontend, I mostly just use it to make it easier to test my backend (c#) methods during development without having to struggle with setting up reproduction steps and go through the entire frontend every time.

https://learn.microsoft.com/en-us/visualstudio/test/quick-start-test-driven-development-with-test-explorer?view=vs-2022

[–] [email protected] 1 points 6 months ago

Good point, that sounds nicer than just encoding the name for sure, thanks

[–] [email protected] 1 points 6 months ago

Sure, but whoever's fault it was didn't really matter to me at the time. I just remember being annoyed at everyone constantly praising linux and saying how easy it is nowadays while I'm just jumping from one issue into another, that experience made me delay moving my main PC to it since I also have an nvidia GPU there. Had to go through like 3 different ways of installing drivers, various weird containers or bottles or wine and lutris or proton just for it all to constantly freeze or crash my PC.

It was a Dell laptop, not sure about specs but it's at least a few years old model, nothing too high end. The plan was to keep it as a small home server for hosting various stuff, services, media in the end, with varying success.

[–] [email protected] 5 points 6 months ago (2 children)

I was so excited about Mint, seemed like the perfect distro to try but then I had nothing but issues on an laptop with nvidia. PopOS worked better right out of the box though

[–] [email protected] 1 points 6 months ago* (last edited 6 months ago) (2 children)

A bit late to this thread but what helped me a lot was when I started doing TDD. By testing my code against tests before its fully done or even implemented in the main app codebase (so to speak), I could break down individual tasks in it more easily and see how its interior parts work. It seemed easier to separate it into SRP areas since they'd have to stick to the unit test for that responsibility. Do keep in mind you can take it too far and overengineer it in this way but it was a good kick in the butt to get me to think in a different way.

[–] [email protected] 1 points 6 months ago

By automating it you mean something a store procedure that returns the ID and increments the count at the same time or is there a more sophisticated way of doing it?

[–] [email protected] 1 points 6 months ago (1 children)

In the context of this small app im writing category is unique by name already so I can just use that if I wanted to go the string route, but agreed - yours is probably the standard way, youtube/reddit do it like that after all.

I'm still wondering about the technical implementation of it - where would you generate the string? Manually in backend before each save, probably using a locking mechanism to prevent accidentally creating 2 identical IDs at the same time? I'd have to do a db hit to make sure it doesn't exist already every time, right? Maybe I just try to insert and see if it crashes due to the uniqueness index? Maybe I use a store procedure in the database to get a unique ID? Do I just hash the timestamp or sth like that?

Whether I generate a number or a string, feels like I always open it up to many issues.

[–] [email protected] 1 points 6 months ago (2 children)

This is something I've been considering too, since the name is in this case unique per user I can just use it for everything in frontend rather than the ID. It's not always a good solution though so I was wondering how would I solve it with IDs alone

[–] [email protected] 1 points 6 months ago

Deletions would work the same way as with a regular autoincrementing ID, it just always goes up. All it matters is that it doesn't expose how many other IDs are in the DB

view more: ‹ prev next ›