Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6434438023/oph24 8 documentation swagger #11

Merged
merged 4 commits into from
Dec 27, 2023

Conversation

Wer1d
Copy link
Contributor

@Wer1d Wer1d commented Dec 25, 2023

เขียน swagger ของ event , healthcheck and livestreamFlag

Copy link

linear bot commented Dec 25, 2023

@ImSoZRious
Copy link
Member

do a git pull origin beta and resolve the conflict. If you're not sure which one is correct, you can see the code from beta branch.

Copy link
Member

@ImSoZRious ImSoZRious left a comment

Choose a reason for hiding this comment

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

please rebase on origin/beta. I can't read what you've written because code pr is mixed with other.

cmd/main.go Outdated
r.GET("/live", container.FeatureflagHandler.GetLivestreamInfo)
r.GET("/events", container.EventHandler.GetAllEvents)
r.GET("/events/:eventId", container.EventHandler.GetEventById)
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
Copy link
Member

Choose a reason for hiding this comment

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

Check for env it is deployed in

if container.Config.AppConfig.Env != "development" {
    r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}

cmd/main.go Outdated
// @title OPH-66 Backend API
// @version 1.0
// @description This is a sample server celler server.
// @securityDefinitions.basic BasicAuth
Copy link
Member

Choose a reason for hiding this comment

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

We use BearerAuth not BasicAuth

cmd/main.go Outdated
)

// @title OPH-66 Backend API
// @version 1.0
// @description This is a sample server celler server.
Copy link
Member

Choose a reason for hiding this comment

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

Make it little more meaningful.

cmd/main.go Outdated

fmt.Println(container.Config.AppConfig.Port)
Copy link
Member

Choose a reason for hiding this comment

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

Remove this debug

Comment on lines 1 to 17
package response

type featureFlagResponse struct {
Key string `json:"key" example:"livestream"`
Enabled bool `json:"enabled" example:"true"`
ExtraInfo string `json:"extra_info" example:"https://www.youtube.com/watch?v=6n3pFFPSlW4"`
}

type featureFlagErrorResponse struct {
Instance string `json:"instance" example:"/featureflag/live"`
Title string `json:"title" example:"internal-server-error"`
}

type featureFlagInvalidResponse struct {
Instance string `json:"instance" example:"/featureflag/live"`
Title string `json:"title" example:"invalid-feature-flag-key"`
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be more appropiate to put this in each /internal/X. For example,

// internal/feature_flag/feature_flag.dto.go
type featureFlagResponse struct {
	Key    string `json:"key" example:"livestream"`
	Enabled bool `json:"enabled" example:"true"`
	ExtraInfo string `json:"extra_info" example:"https://www.youtube.com/watch?v=6n3pFFPSlW4"`
}

type featureFlagErrorResponse struct {
	Instance string `json:"instance" example:"/featureflag/live"`	
	Title    string `json:"title" example:"internal-server-error"`
}

type featureFlagInvalidResponse struct {
	Instance string `json:"instance" example:"/featureflag/live"`
	Title    string `json:"title" example:"invalid-feature-flag-key"`
}

@ImSoZRious
Copy link
Member

This is roughly your git branch situation

gitGraph
    commit
    commit
    branch develop
    checkout main
    commit id: "feat: event"
    checkout develop
    merge main
    commit
    checkout main
    commit id: "fix: featureflag"
    checkout develop
    merge main
    commit
    commit
    commit
    checkout main
    merge develop
Loading

You can see that from you branch perspective, you have commit other code as well.

To fix this (not easy tho), you need to rebase your code on origin beta

git rebase -i origin beta

then resolve every conflict

after that your git history should look like this

gitGraph
    commit
    commit
    checkout main
    commit id: "feat: event"
    commit id: "fix: featureflag"
    branch develop
    commit
    commit
    commit
    commit
    checkout main
    merge develop
Loading

To prevent this from happening again you can do

git config --global pull.rebase true

ref

@Wer1d Wer1d force-pushed the 6434438023/oph24-8-documentation-swagger branch from 76070b0 to 05651f0 Compare December 26, 2023 08:38
Copy link
Member

@ImSoZRious ImSoZRious left a comment

Choose a reason for hiding this comment

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

please rebase on origin/beta. I can't read what you've written because code pr is mixed with other.

cfgldr/cfgldr.go Outdated
@@ -26,6 +26,7 @@ type RedisConfig struct {
}

func LoadConfig() (*Config, error) {

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

.env.example Outdated
Comment on lines 1 to 8
DB_URL=postgres://postgres:[email protected]:5432/postgres

REDIS_ADDR=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=123456

APP_PORT=3000
APP_ENV=development
Copy link
Member

Choose a reason for hiding this comment

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

Bring back .env.example

Comment on lines 7 to 10
type eventInvalidResponse struct {
Instance string `json:"instance" example:"/events/:eventId"`
Title string `json:"title" example:"invalid-event-id"`
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type eventInvalidResponse struct {
Instance string `json:"instance" example:"/events/:eventId"`
Title string `json:"title" example:"invalid-event-id"`
}
//nolint:all
type EventInvalidResponse struct {
Instance string `json:"instance" example:"/events/:eventId"`
Title string `json:"title" example:"invalid-event-id"`
}

Comment on lines 12 to 15
type eventErrorResponse struct {
Instance string `json:"instance" example:"/events/:eventId"`
Title string `json:"title" example:"internal-server-error"`
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type eventErrorResponse struct {
Instance string `json:"instance" example:"/events/:eventId"`
Title string `json:"title" example:"internal-server-error"`
}
//nolint:all
type EventErrorResponse struct {
Instance string `json:"instance" example:"/events/:eventId"`
Title string `json:"title" example:"internal-server-error"`
}

Comment on lines 22 to 33
type EventDTO struct {
Id string `json:"id" example:"first-event"`
Name NameEventBilingual `json:"name" `
FacultyCode int `json:"-" `
Faculty Faculty `json:"faculty"`
Department DepartmentBilingual `json:"department" `
RequireRegistration bool `json:"require_registration" example:"true"`
MaxCapacity int `json:"max_capacity" example:"100"`
Schedules []Schedule `json:"schedules" `
Location LocationBilingual `json:"location"`
Description DescriptionBilingual `json:"description,omitempty"`
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type EventDTO struct {
Id string `json:"id" example:"first-event"`
Name NameEventBilingual `json:"name" `
FacultyCode int `json:"-" `
Faculty Faculty `json:"faculty"`
Department DepartmentBilingual `json:"department" `
RequireRegistration bool `json:"require_registration" example:"true"`
MaxCapacity int `json:"max_capacity" example:"100"`
Schedules []Schedule `json:"schedules" `
Location LocationBilingual `json:"location"`
Description DescriptionBilingual `json:"description,omitempty"`
}
type EventDTO struct {
Id string `json:"id" example:"first-event"`
Name NameEventBilingual `json:"name"`
FacultyCode int `json:"-"`
Faculty Faculty `json:"faculty"`
Department DepartmentBilingual `json:"department"`
RequireRegistration bool `json:"require_registration" example:"true"`
MaxCapacity int `json:"max_capacity" example:"100"`
Schedules []Schedule `json:"schedules"`
Location LocationBilingual `json:"location"`
Description DescriptionBilingual `json:"description,omitempty"`
}

Comment on lines 34 to 44
// GetAllEvents godoc
// @summary Get all events
// @description Get all events as array of events
// @id GetAllEvents
// @produce json
// @tags event
// @Security Bearer
// @router /events [get]
// @success 200 {object} event.EventAll
// @Failure 500 {object} event.eventAllErrorResponse
// @Failure 404 {object} event.eventInvalidResponse
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// GetAllEvents godoc
// @summary Get all events
// @description Get all events as array of events
// @id GetAllEvents
// @produce json
// @tags event
// @Security Bearer
// @router /events [get]
// @success 200 {object} event.EventAll
// @Failure 500 {object} event.eventAllErrorResponse
// @Failure 404 {object} event.eventInvalidResponse
// GetAllEvents godoc
// @summary Get all events
// @description Get all events as array of events
// @id GetAllEvents
// @produce json
// @tags event
// @Security Bearer
// @router /events [get]
// @success 200 {object} event.EventAll
// @Failure 500 {object} event.eventAllErrorResponse
// @Failure 404 {object} event.eventInvalidResponse

Comment on lines 79 to 90
// GetEvent godoc
// @summary get event by id
// @description Get event by id
// @id GetEventById
// @produce json
// @tags event
// @Security Bearer
// @param eventId path string true "event id"
// @router /events/{eventId} [get]
// @success 200 {object} event.EventDTO
// @Failure 500 {object} event.eventErrorResponse
// @Failure 404 {object} event.eventInvalidResponse
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// GetEvent godoc
// @summary get event by id
// @description Get event by id
// @id GetEventById
// @produce json
// @tags event
// @Security Bearer
// @param eventId path string true "event id"
// @router /events/{eventId} [get]
// @success 200 {object} event.EventDTO
// @Failure 500 {object} event.eventErrorResponse
// @Failure 404 {object} event.eventInvalidResponse
// GetEvent godoc
// @summary get event by id
// @description Get event by id
// @id GetEventById
// @produce json
// @tags event
// @Security Bearer
// @param eventId path string true "event id"
// @router /events/{eventId} [get]
// @success 200 {object} event.EventDTO
// @Failure 500 {object} event.eventErrorResponse
// @Failure 404 {object} event.eventInvalidResponse

Comment on lines 29 to 39
// GetLivestreamInfo godoc
// @summary Get livestream flag
// @description Get livestream flag
// @id GetLivestreamInfo
// @produce json
// @tags LiveStream
// @Security Bearer
// @router /live [get]
// @success 200 {object} featureflag.response
// @Failure 500 {object} featureflag.errorResponse
// @Failure 404 {object} featureflag.invalidResponse
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// GetLivestreamInfo godoc
// @summary Get livestream flag
// @description Get livestream flag
// @id GetLivestreamInfo
// @produce json
// @tags LiveStream
// @Security Bearer
// @router /live [get]
// @success 200 {object} featureflag.response
// @Failure 500 {object} featureflag.errorResponse
// @Failure 404 {object} featureflag.invalidResponse
// GetLivestreamInfo godoc
// @summary Get livestream flag
// @description Get livestream flag
// @id GetLivestreamInfo
// @produce json
// @tags FeatureFlag
// @Security Bearer
// @router /live [get]
// @success 200 {object} featureflag.response
// @Failure 500 {object} featureflag.errorResponse
// @Failure 404 {object} featureflag.invalidResponse

Comment on lines 3 to 7
type response struct {
Key string `json:"key" example:"livestream"`
Enabled bool `json:"enabled" example:"true"`
ExtraInfo string `json:"extra_info" example:"https://www.youtube.com/watch?v=6n3pFFPSlW4"`
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type response struct {
Key string `json:"key" example:"livestream"`
Enabled bool `json:"enabled" example:"true"`
ExtraInfo string `json:"extra_info" example:"https://www.youtube.com/watch?v=6n3pFFPSlW4"`
}
type response struct {
Key string `json:"key" example:"livestream"`
Enabled bool `json:"enabled" example:"true"`
ExtraInfo string `json:"extra_info" example:"https://www.youtube.com/watch?v=6n3pFFPSlW4"`
}

Comment on lines 20 to 28
// HealthCheck godoc
// @summary Health Check
// @description Health Check for the service
// @id HealthCheck
// @produce plain
// @tags healthcheck
// @Security Bearer
// @router /_hc [get]
// @Success 200 {string} string "OK"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// HealthCheck godoc
// @summary Health Check
// @description Health Check for the service
// @id HealthCheck
// @produce plain
// @tags healthcheck
// @Security Bearer
// @router /_hc [get]
// @Success 200 {string} string "OK"
// HealthCheck godoc
// @summary Health Check
// @description Health Check for the service
// @id HealthCheck
// @produce plain
// @tags healthcheck
// @Security Bearer
// @router /_hc [get]
// @Success 200 {string} string "OK"

Copy link
Member

@ImSoZRious ImSoZRious left a comment

Choose a reason for hiding this comment

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

Also add more doc on new route

@Wer1d Wer1d force-pushed the 6434438023/oph24-8-documentation-swagger branch from 05651f0 to 5a8bd3e Compare December 26, 2023 16:54
Wer1d and others added 4 commits December 28, 2023 01:09
parent 3afc3f0
author Wer1d <[email protected]> 1703441246 +0700
committer Wer1d <[email protected]> 1703441246 +0700

refactor: delete godotenv

feat : add swagger

fix: change BasicAuth to Bearer

fix: delete import godotenv

docs: auth docs

docs: add user-not-found

feat: config cors (#15)

feat: Register + Login OIDC (#4)

* feat: Register + Login OIDC

* fix: fix user model

* fix: combine login &register, add apperror, normalize database, getUser by header

* fix: add atlas migrate, move logic from handler to service, use dto, add logic update

* fix: repository, typo, ip/op type

* fix: update init sql

* refactor: remove migrate.md

* fix:typo, config linters

* refactor: run lint-fix

* fix: normalize round, department, section

* fix: model dep and section

* refactor:linter-fix

* refactor: lint-fix

* fix: add fk in init sql, remove update in register, move convert to util file

* fix: init sql , remove endpoint,  change id to composit key

* refactor: auth handler

feat: document swagger

fix: change BasicAuth to Bearer

docs: auth docs

docs: all

refactor: go mod tidy
@ImSoZRious ImSoZRious force-pushed the 6434438023/oph24-8-documentation-swagger branch from ef848ec to 40a35d9 Compare December 27, 2023 18:39
@ImSoZRious ImSoZRious merged commit 06522b4 into beta Dec 27, 2023
1 check passed
@ImSoZRious ImSoZRious deleted the 6434438023/oph24-8-documentation-swagger branch December 27, 2023 18:40
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.

2 participants