Skip to content

Commit

Permalink
Merge pull request #11 from cho4036/minor_fix
Browse files Browse the repository at this point in the history
Minor fix
  • Loading branch information
ktkfree authored Apr 3, 2023
2 parents 1165248 + b569f45 commit db6ae34
Show file tree
Hide file tree
Showing 19 changed files with 2,394 additions and 296 deletions.
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

0 comments on commit db6ae34

Please sign in to comment.