Conversation
…n handlers instead of err.Error()
| // don't forget to use lower for OwnerUsername for normalization | ||
| // 1 (2) 3 4 5 6 7 8 | ||
| // 9 (10) 11 12 13 14 | ||
| // ... | ||
| if j%8 == 2 { | ||
| tempPosArgs = append(tempPosArgs, fmt.Sprintf("lower($%d)", j)) | ||
| } else { | ||
| tempPosArgs = append(tempPosArgs, fmt.Sprintf("$%d", j)) | ||
| } |
There was a problem hiding this comment.
for j := i; j < i+8; j++ {
tempPosArgs = append(tempPosArgs, fmt.Sprintf("$%d", j))
}i think this part can be shorten by this
There was a problem hiding this comment.
I mentioned it in PR description, I wanted to lower it only in sql:
As standart I decided to use
lower()function every time I can, when inserting, selecting data using sql.
It removes a bit load from go serivce and standardizes normalization place.
I got intresting approach in my head:
As, I understand it's better to have one function in project for username normalization.
And use it from everywhere, but I thought it was a problem to use it in migration.
But, eventually goose has ability to create .go files migrations, where we can use our unified function.
Let me know, what do you think, with this approach we can get rid of lower() functions in SQL.
There was a problem hiding this comment.
yea this is a more modular approach and makes sense with our project architecture as well
There was a problem hiding this comment.
fine, starting working on it
There was a problem hiding this comment.
@R7rainz, check out latest commits
I moved two migrations into go format, where used unified function to normalize columns.
Now NormalizeGithubUsername is used all over the project.
5cd9b1f to
86abe5f
Compare
baa8fa4 to
f134fa6
Compare
Changes
Username cases bug fix
Before in out system were a lot of problems with username case:
hurtkiandHURTKI. And they were updating both.How I fixed this:
I clearly set, that domain logic shouldn't know about normalization, but all repos/infrastructures/caches it uses, should work with any case.
So, I refactored:
username_normalized/owner_username_normalizedfields )Postgres tables changes:
Create
github_dataschema to separate github information from our service's data (userstable was very confusing )users -> github_data.users
repositories -> github_data.repositories
users:
repositories:
banners:
As standart I decided to use
lower()function every time I can, when inserting, selecting data using sql.It removes a bit load from go serivce and standardizes normalization place.
HTTP handlers
Clear response errors defined in handlers
Now, handlers, when recognize error, are not using
err.Error()for http response. they determine it themselves.Example:
With this approach domain logic ( usecases ) can be not afraid of wrapping infrastructure or any other error before returning it.
Start of docs
I by my hands started writing docs of api ms in
architecture.md, I highlighted, in my opinion, the most important points, and I will continue to do so in new PRs.Fully updated
api.yamlfile, accoring to current api.Deleted
manual.md, еhere were a lot of confusing things there. This service can be run separately from the others, but it's not as convenient as running everything together in Docker Compose. It might be reworked in the future.Also global repo README.md should be reworked in near future.