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

dto mapper 개발 #11

Merged
merged 4 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
658 changes: 649 additions & 9 deletions api/swagger/docs.go

Large diffs are not rendered by default.

655 changes: 648 additions & 7 deletions api/swagger/swagger.json

Large diffs are not rendered by default.

434 changes: 429 additions & 5 deletions api/swagger/swagger.yaml

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions internal/delivery/http/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewAuthHandler(h usecase.IAuthUsecase) IAuthHandler {
// @Accept json
// @Produce json
// @Param body body domain.LoginRequest true "account info"
// @Success 200 {object} domain.User "user detail"
// @Success 200 {object} domain.LoginResponse "user detail"
// @Router /auth/login [post]
func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
input := domain.LoginRequest{}
Expand All @@ -52,13 +52,8 @@ func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
return
}

var out struct {
User domain.User `json:"user"`
}

out.User = user

//_ = h.Repository.AddHistory(user.ID.String(), "", "login", fmt.Sprintf("[%s] 님이 로그인하였습니다.", input.AccountId))
var out domain.LoginResponse
domain.Map(user, &out)

ResponseJSON(w, http.StatusOK, out)

Expand All @@ -80,10 +75,8 @@ func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request) {

func (h *AuthHandler) FindId(w http.ResponseWriter, r *http.Request) {
//TODO implement me
panic("implement me")
}

func (h *AuthHandler) FindPassword(w http.ResponseWriter, r *http.Request) {
//TODO implement me
panic("implement me")
}
49 changes: 20 additions & 29 deletions internal/delivery/http/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ func (h *OrganizationHandler) CreateOrganization(w http.ResponseWriter, r *http.
}

ctx := r.Context()
organization := input.ToOrganization()
organization.Creator = ""
var organization domain.Organization
err = domain.Map(input, &organization)

organizationId, err := h.usecase.Create(ctx, organization)
organizationId, err := h.usecase.Create(ctx, &organization)
if err != nil {
log.Errorf("error is :%s(%T)", err.Error(), err)
ErrorJSON(w, err)
return
}

organization.ID = organizationId
// Admin user 생성
_, err = h.userUsecase.CreateAdmin(organizationId)
if err != nil {
Expand All @@ -64,13 +64,9 @@ func (h *OrganizationHandler) CreateOrganization(w http.ResponseWriter, r *http.
return
}

var out struct {
OrganizationId string `json:"organizationId"`
}

out.OrganizationId = organizationId
var out domain.CreateOrganizationResponse
domain.Map(organization, &out)

//time.Sleep(time.Second * 5) // for test
ResponseJSON(w, http.StatusOK, out)
}

Expand All @@ -80,11 +76,10 @@ func (h *OrganizationHandler) CreateOrganization(w http.ResponseWriter, r *http.
// @Description Get organization list
// @Accept json
// @Produce json
// @Success 200 {object} []domain.Organization
// @Success 200 {object} []domain.ListOrganizationBody
// @Router /organizations [get]
// @Security JWT
func (h *OrganizationHandler) GetOrganizations(w http.ResponseWriter, r *http.Request) {
log.Info("GetOrganization")
organizations, err := h.usecase.Fetch()
if err != nil {
log.Errorf("error is :%s(%T)", err.Error(), err)
Expand All @@ -93,12 +88,11 @@ func (h *OrganizationHandler) GetOrganizations(w http.ResponseWriter, r *http.Re
return
}

var out struct {
Organizations []domain.Organization `json:"organizations"`
}
var out domain.ListOrganizationResponse
out.Organizations = make([]domain.ListOrganizationBody, len(*organizations))

for _, organization := range *organizations {
out.Organizations = append(out.Organizations, organization)
for i, organization := range *organizations {
domain.Map(organization, &out.Organizations[i])
}

ResponseJSON(w, http.StatusOK, out)
Expand All @@ -111,7 +105,7 @@ func (h *OrganizationHandler) GetOrganizations(w http.ResponseWriter, r *http.Re
// @Accept json
// @Produce json
// @Param organizationId path string true "organizationId"
// @Success 200 {object} domain.Organization
// @Success 200 {object} domain.GetOrganizationResponse
// @Router /organizations/{organizationId} [get]
// @Security JWT
func (h *OrganizationHandler) GetOrganization(w http.ResponseWriter, r *http.Request) {
Expand All @@ -130,11 +124,8 @@ func (h *OrganizationHandler) GetOrganization(w http.ResponseWriter, r *http.Req
return
}

var out struct {
Organization domain.Organization `json:"organization"`
}

out.Organization = organization
var out domain.GetOrganizationResponse
domain.Map(organization, &out.Organization)

ResponseJSON(w, http.StatusOK, out)
}
Expand Down Expand Up @@ -190,7 +181,8 @@ func (h *OrganizationHandler) DeleteOrganization(w http.ResponseWriter, r *http.
// @Accept json
// @Produce json
// @Param organizationId path string true "organizationId"
// @Success 200 {object} domain.Organization
// @Param body body domain.UpdateOrganizationRequest true "update organization request"
// @Success 200 {object} domain.UpdateOrganizationResponse
// @Router /organizations/{organizationId} [put]
// @Security JWT
func (h *OrganizationHandler) UpdateOrganization(w http.ResponseWriter, r *http.Request) {
Expand All @@ -208,17 +200,18 @@ func (h *OrganizationHandler) UpdateOrganization(w http.ResponseWriter, r *http.
return
}

err = h.usecase.Update(organizationId, input)
organization, err := h.usecase.Update(organizationId, input)
if err != nil {
log.Errorf("error is :%s(%T)", err.Error(), err)

ErrorJSON(w, err)
return
}

log.Info(input)
var out domain.UpdateOrganizationResponse
domain.Map(organization, &out)

ResponseJSON(w, http.StatusOK, nil)
ResponseJSON(w, http.StatusOK, out)
}

// UpdatePrimaryCluster godoc
Expand Down Expand Up @@ -253,7 +246,5 @@ func (h *OrganizationHandler) UpdatePrimaryCluster(w http.ResponseWriter, r *htt
return
}

log.Info(input)

ResponseJSON(w, http.StatusOK, nil)
}
Loading