Skip to content

Conversation

@pilyang
Copy link
Member

@pilyang pilyang commented Jan 24, 2025

작업 내용

1. 회사들 리스트 조회 api 추가

GET /companies

예시

{
    "companies": [
        {
            "id": 1,
            "name": "카카오",
            "logo_url": "placeholder_logo_url",
            "blog_url": "https://tech.kakao.com/"
        },
        {
            "id": 2,
            "name": "우아한형제들",
            "logo_url": "placeholder_logo_url",
            "blog_url": "https://techblog.woowahan.com/"
        },
        {
            "id": 3,
            "name": "컬리",
            "logo_url": "placeholder_logo_url",
            "blog_url": "https://helloworld.kurly.com/"
        },
        {
            "id": 4,
            "name": "뱅크샐러드",
            "logo_url": "placeholder_logo_url",
            "blog_url": "https://blog.banksalad.com"
        },
        {
            "id": 5,
            "name": "토스",
            "logo_url": "placeholder_logo_url",
            "blog_url": "https://toss.tech/"
        }
    ]
}

rss링크등 정보는 필요 없을것같아서 블로그들 어떤거 있는지 보여줄때, 회사명, 로고, 블로그 주소만 포함하도록 했어요 일단

구조

  • router에서 초기화시 handler들을 추가해도록 했어요.
  • handler direcotory에 handler들을 추가하도록 만들었어요.
  • presentation, service layer가 필요하려나 하긴 했는데,, 일단 간단히 handler에 추가를 했어요.
    • 사실상 최종적으로 나올 api가 3개뿐이어서 그냥 각각 hanlder로 만들면 되지 않을까 하는 생각이었어요.. 이건 아직도 고민이네요

추가 변경사항

아래 내용들 pr분리할까 했는데, 시간이 없고 중간중간 디버깅이 필요해서 작업하면서 같은 pr에 같이 포함했어요.
대신 저도 완벽하게 어케 해야할지는 감이 안와서,, 일단 사용할 수 있게만 만든 상태라 더 좋은 구조같은건 추가로 고민해봐야 될 것 같아용.. 😭

2. 설정파일 가져오는 방식 refactoring

테스트할때 .env파일을 불러오는게 잘 안되었어요 기존 코드대로면
godotenv가 코드가 실행되는 상대위치에서 파일을 읽어들이는데, 테스트코드마다 위치한 디랙터리가 다르다보니, 매번 테스트 코드에서 .env파일 위치를 상대위치로 전달해주거나,, 프로젝트의 절대위치를 가져올 수 있도록 만들어서 읽어야 했어용...

그래서

  1. 프로젝트 절대위치 읽어서 test.env파일을 읽어오도록 하기
  2. 그냥 테스트환경에서는 원하는 환경변수들을 하드코딩해두기

중에서,, 테스트용 환경변수는 따로 중요데이터로 숨겨서 관리할 필요도 없고, testing.T 에서 테스트용 env를 설정할 수 있어서 테스트할때 cnf가져오는 함수를 testutils에 추가했어요. 요기

3. 테스트용 db 설정

testutils/db.go에 테스트 디비 연결코드를 추가했어요.
마찬가지로 트랜잭셔널 테스트를 위해서 추가된 부분도 있는데,, 이렇게 하는게 좋았을지,, 아니면 끝날때마다 태이블 드랍해주는게 좋았을지는 고민이네요...

자세한건 추가 코멘트로 서정하겠지만, transactional로 해서 테스트에서 수동으로 transactional client를 사용하도록 해줘야하는등 좀 신경쓸 부분이 있어용

생각해보니 TransactionalTest를 함수로 만들 수 있을것같아서 함수로 만들어서 적용하기 쉽게 변경했어요!!
이전에 설명 써둔건 resolve함요ㅎㅎㅋㅋㅋㅋㅋ

@pilyang pilyang requested a review from iamjooon2 January 24, 2025 12:42
@github-actions
Copy link

report: Run #52

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
2 2 0 0 0 0 0 84ms

🎉 All tests passed!

Github Test Reporter

@github-actions
Copy link

report: Run #53

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
2 2 0 0 0 0 0 526ms

🎉 All tests passed!

Github Test Reporter

@github-actions
Copy link

report: Run #54

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Pending ⏳ Other ❓ Flaky 🍂 Duration ⏱️
2 2 0 0 0 0 0 561ms

🎉 All tests passed!

Github Test Reporter

Copy link
Member

@iamjooon2 iamjooon2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

주관적인 제 의견으로는, 현재 구조도 충분히 좋은 것 같습니다
아직 비즈니스 로직이 많지 않다보니... 이후에 많아지면 그때 가시죠!(미루기 장인)

질문만 남겼습니다~

cmd/main.go Outdated
routerErr := r.Run(":" + cfg.ServerConfig.Port)
if routerErr != nil {
fmt.Println("Error while running server: ", cfgErr)
fmt.Println("Error while running server: ", routerErr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"github.com/techbloghub/server/config"
_ "github.com/techbloghub/server/ent/runtime"
"github.com/techbloghub/server/internal/database"
"github.com/techbloghub/server/internal/http/router"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[질문]
go/gin에서는 기본적으로 깃허브 레포 통해서 패키지를 관리하나요?! 아니면 따로 설정을 해둔건가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server/go.mod

Lines 1 to 4 in 77db124

module github.com/techbloghub/server
go 1.23.4

요기 보면 처음에 프로젝트 초기화할때 패키지 모듈명을 이런식으로 원격저장소 주소로 해서 초기화를 보통 합니당.

공식문서에 적혀있는 내용

In actual development, the module path will typically be the repository location where your source code will be kept. For example, the module path might be github.com/mymodule. If you plan to publish your module for others to use, the module path must be a location from which Go tools can download your module. For more about naming a module with a module path, see Managing dependencies.

링크

요거 물어본거가 맞는거겠죠..?ㅎㅎㅎ

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 맞습니다 ㅎㅎㅎㅎ

func createServer(cfg *config.Config) (*gin.Engine, *ent.Client, error) {
client, err := database.ConnectDatabase(cfg)
if err != nil {
return nil, nil, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리턴 여러개는 더 익숙해저야겠다ㅋㅋㅋㅋㅋㅋㅋ

)

func TestListCompanies(t *testing.T) {
testutils.TransactionalTest(t, func(t *testing.T, client *ent.Client) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testUtils.TransactionalTest 좋은데요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 문제될법한 케이스나 좀 더 고민을 해볼 필요는 있을 수 있지만,,, 일단 간단하게 먼저 만들어봤어용

나중에 트랜잭션 관리할때도 withTrnasaction등으로 관리할 수 있는 함수 만들던가 해볼께요.
아마 entgo 공식문서에서도 관련 내용 본것같아서 그 포멧 그대로 가져와볼수도 있고

Comment on lines +9 to +19
func NewTestConfig(t *testing.T) (*config.Config, error) {
t.Setenv("ENV", "test")
t.Setenv("PORT", "8081")
t.Setenv("POSTGRES_HOST", "localhost")
t.Setenv("POSTGRES_USER", "example-user")
t.Setenv("POSTGRES_PASSWORD", "password")
t.Setenv("POSTGRES_DB", "tbh-db")
t.Setenv("POSTGRES_PORT", "5433")

return config.NewConfig()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기가 언급해주신 부분이구만요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 일단 테스트용 그냥 하드코딩 하고,, t.Setenv가 테스트 종료후에 원래값으로 바꿔주는것도 있네용

@iamjooon2 iamjooon2 changed the title 회상들 리스트 조회 api 추가 & 테스트 db config설정 회사들 리스트 조회 api 추가 & 테스트 db config설정 Jan 28, 2025
@pilyang pilyang merged commit 4750c9a into main Jan 28, 2025
2 checks passed
@iamjooon2 iamjooon2 deleted the feat/company-info-api branch January 28, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants