#273-Create-service-to-enable-connection-to-database #451

Merged
c24elipe merged 9 commits from #273-Create-service-to-enable-connection-to-database into team_2_week_2 2026-04-22 07:57:51 +00:00
Collaborator
  • Added the small feature loginService
    • How it works
      • Endpoints -> AuthService -> DatabaseQueries->DATABASE
      • DATABASE -> DatabaseQueries->AuthService->Endpoint->frontend
    • This is done to separate the different layers.
      • Entrypoint receives requests
      • AuthService should apply all logic
      • DatabaseQueries should only fetch data
  • Tested on my own computer Fedora 43 using curl
  • get container ip using this command
docker inspect -f
'{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
container_name_or_id

  • possible to create a user using endpoint
curl -X POST http://172.18.0.3:8080/auth/SignUp \
  -H "Content-Type: application/json" \
  -d '{
    "Username": "jag orkar inte",
    "Firstname": "Eric",
    "Lastname": "Grandinger",
    "Email": "eric@example.com",
    "Password": "Let me in"
  }'

  • possible to sign in using endpoint
 curl -X POST http://172.18.0.10:8080/auth/login \
  -H "Content-Type: application/json" \
  -d '{"Username": "jag orkar inte", "Password": "Let me in"}'
  }'

  • Acess not granted if wrong password is used
    I know the commit is on the larger side and i am sorry

about that :(

+ Added the small feature loginService + How it works + Endpoints -> AuthService -> DatabaseQueries->DATABASE + DATABASE -> DatabaseQueries->AuthService->Endpoint->frontend + This is done to separate the different layers. + Entrypoint receives requests + AuthService should apply all logic + DatabaseQueries should only fetch data + Tested on my own computer Fedora 43 using curl + get container ip using this command ``` bash docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id ``` + possible to create a user using endpoint ``` bash curl -X POST http://172.18.0.3:8080/auth/SignUp \ -H "Content-Type: application/json" \ -d '{ "Username": "jag orkar inte", "Firstname": "Eric", "Lastname": "Grandinger", "Email": "eric@example.com", "Password": "Let me in" }' ``` + possible to sign in using endpoint ``` bash curl -X POST http://172.18.0.10:8080/auth/login \ -H "Content-Type: application/json" \ -d '{"Username": "jag orkar inte", "Password": "Let me in"}' }' ``` + Acess not granted if wrong password is used I know the commit is on the larger side and i am sorry about that :(
+ Added the small feature loginService
  + How it works
    + Endpoints -> AuthService -> DatabaseQueries->DATABASE
    + DATABASE -> DatabaseQueries->AuthService->Endpoint->frontend
  + This is done to separate the different layers.
    + Entrypoint receives requests
    + AuthService should apply all logic
    + DatabaseQueries should only fetch data
+ Tested on my own computer Fedora 43 using curl
+ get container ip using this command
``` bash
docker inspect -f
'{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
container_name_or_id

```
  + possible to create a user using endpoint
``` bash
curl -X POST http://172.18.0.3:8080/auth/SignUp \
  -H "Content-Type: application/json" \
  -d '{
    "Username": "jag orkar inte",
    "Firstname": "Eric",
    "Lastname": "Grandinger",
    "Email": "eric@example.com",
    "Password": "Let me in"
  }'

```
+ possible to sign in using endpoint
``` bash
 curl -X POST http://172.18.0.10:8080/auth/login \
  -H "Content-Type: application/json" \
  -d '{"Username": "jag orkar inte", "Password": "Let me in"}'
  }'

```
+ Acess not granted if wrong password is used
I know the commit is on the larger side and i am sorry

about that :(
+ Removed un used "using"
+ Removed research urls
+ Constants now use PascalCase
+ Unittest for login
+ Unittest for signeUp not implemented
  + Need dependency moq which has not been approved
Collaborator

WINDOWS 11

I've maybe done something wrong but I get this when trying to sign up an account:

image

**WINDOWS 11** I've maybe done something wrong but I get this when trying to sign up an account: ![image](/attachments/98dedf8b-f23c-4b26-bb81-f03f0f082639)
Collaborator

I have tested compiling and running the application. It runs successfully

I have tested compiling and running the application. It runs successfully
Author
Collaborator

@b24hugst wrote in #451 (comment):

WINDOWS 11

I've maybe done something wrong but I get this when trying to sign up an account:

image

The error suggest that the problem is related to trying to login to the database scram-sha-256 postgresql. The code i wrote fetches the login cridentials from the .env file

  static string DbUser = Environment.GetEnvironmentVariable("DATABASE_USER");
  static string DbPassword = Environment.GetEnvironmentVariable("DATABASE_PASSWORD");
  string ConnectionString = $"Host=PostgreSQL;Port=5432;Database=users;Username={DbUser};Password={DbPassword}";

My .env file has the following structure

DATABASE_USER=[USER]
DATABASE_PASSWORD=[PASSWORD]

The structure the you recive back .

errorMessage IsSuccess
errorMessage False

Suggests that your reach the endpoint put.

@b24hugst wrote in https://git.webug.se/Andras/BoundlessFlowCampus2K/pulls/451#issuecomment-4588: > **WINDOWS 11** > > I've maybe done something wrong but I get this when trying to sign up an account: > > [![image](/attachments/98dedf8b-f23c-4b26-bb81-f03f0f082639)](/Andras/BoundlessFlowCampus2K/attachments/98dedf8b-f23c-4b26-bb81-f03f0f082639) The error suggest that the problem is related to trying to login to the database [scram-sha-256 postgresql](https://www.postgresql.org/docs/current/auth-password.html). The code i wrote fetches the login cridentials from the .env file ``` C# static string DbUser = Environment.GetEnvironmentVariable("DATABASE_USER"); static string DbPassword = Environment.GetEnvironmentVariable("DATABASE_PASSWORD"); string ConnectionString = $"Host=PostgreSQL;Port=5432;Database=users;Username={DbUser};Password={DbPassword}"; ``` My .env file has the following structure ```.env DATABASE_USER=[USER] DATABASE_PASSWORD=[PASSWORD] ``` The structure the you recive back . | errorMessage | IsSuccess | |---------|---------| | errorMessage | False | Suggests that your reach the endpoint put.
Collaborator

Did @c24elipe run on Windows? Otherwise it would be good to have one more person try on a windows machine to see if it's just me or not. I have correct .env file and all but I can't seem to get it to work for some reason although everything looks clean.

Did @c24elipe run on Windows? Otherwise it would be good to have one more person try on a windows machine to see if it's just me or not. I have correct .env file and all but I can't seem to get it to work for some reason although everything looks clean.
Collaborator

@b24hugst, I used Arch Linux. That may be where problems stem...

@b24hugst, I used Arch Linux. That may be where problems stem...
a24noabe left a comment
Collaborator

This is long sorry

Windows 11

Theres an issue with the windows rebuild where the path to the dockerfile is wrong. Accessing the service from curl on powershell doesn't work unless port forwarding. Even when port forwarding I only get a proper response in "localhost:5011/". /auth/login and /auth/SignUp respond with 400 Bad Request.
image
Also worth noting is that curl by default in powershell is an alias for Invoke-WebRequest. You can remove this alias by running

Remove-Item alias:curl

in powershell. curl will then use the windows variant which is also bad but works.
Anyways the way to access loginService will be through endpoint. When executing the commands listed by Erik in the initial PR inside the entryPoint container everything works well. In order to execute commands in a container you can run

docker exec -it entryPoint /bin/sh

And heres how the response looks from the container:
image

I noticed that when signing up the same user twice, the service returns an error from what looks like postgres:
image
It doesn't show any user data but it exposes a constraint in the users table. We should probably introduce some error handling to give an empty http 500 error

Summa summarum

I think if you change the WindowsRebuild to build properly, everything will be fine. It works!! It's just windows thats stupid

This is long sorry ## Windows 11 Theres an issue with the windows rebuild where the path to the dockerfile is wrong. Accessing the service from curl on powershell doesn't work unless port forwarding. Even when port forwarding I only get a proper response in "localhost:5011/". /auth/login and /auth/SignUp respond with 400 Bad Request. ![image](/attachments/5c5f4f63-9e8b-403b-8275-b139cd804d00) Also worth noting is that [curl by default in powershell is an alias for Invoke-WebRequest](https://curl.se/windows/microsoft.html). You can remove this alias by running ``` Remove-Item alias:curl ``` in powershell. curl will then use the windows variant which is also bad but works. Anyways the way to access loginService will be through endpoint. When executing the commands listed by Erik in the initial PR inside the entryPoint container everything works well. In order to execute commands in a container you can run ``` docker exec -it entryPoint /bin/sh ``` And heres how the response looks from the container: ![image](/attachments/c9efb798-bb1d-43df-98f5-99d2ebd10684) I noticed that when signing up the same user twice, the service returns an error from what looks like postgres: ![image](/attachments/51898a37-31fe-4d62-acd7-ea0868fd5efa) It doesn't show any user data but it exposes a constraint in the users table. We should probably introduce some error handling to give an empty http 500 error ## Summa summarum I think if you change the WindowsRebuild to build properly, everything will be fine. It works!! It's just windows thats stupid
Collaborator

@a24noabe the images are not loading, could you take a look at it?

@a24noabe the images are not loading, could you take a look at it?
Collaborator

Ran the WindowsRebuild.bat and everything checked out as expected.

Ran the WindowsRebuild.bat and everything checked out as expected.
c24elipe merged commit a05eb83596 into team_2_week_2 2026-04-22 07:57:51 +00:00
c24elipe deleted branch #273-Create-service-to-enable-connection-to-database 2026-04-22 07:57:54 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K!451
No description provided.