Skip to content

Commit

Permalink
fix: conflits
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomarcelo09 committed Sep 19, 2024
2 parents 13a14b4 + 47a86ee commit 41124a6
Show file tree
Hide file tree
Showing 18 changed files with 982 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @devhatt/hatts @devhatt/petdex-backend-administrators
* @devhatt/hatts @devhatt/petdex-backend-administrators @devhatt/revisores
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang 1.21.5

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ lint:
docker run --rm -v ./:/app -w /app golangci/golangci-lint:v1.59.1 golangci-lint run -v

swag:
swag init -g api/main.go -o swagger/
swag init -g api/main.go -o swagger/ --md swagger/
25 changes: 25 additions & 0 deletions api/controllers/ong.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ func (oc *OngController) Insert(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
}

// List List of Ong information retrieval from query parameters.
// @Summary View list of Ong.
// @Description This endpoint allows you to retrieve a list Ong organized according to query parameters..
// @Description.markdown details
// @Tags Ong
// @Produce json
// @Param limit query string false "Query limits the return of 10 data." example(10)
// @Param sortBy query string false "Property used to sort and organize displayed data" example(name)
// @Param order query string false "Data can be returned in ascending (asc) or descending (desc) order" example des" example(desc)
// @Param offset query string false "Initial position of the offset that marks the beginning of the display of the next elements" default(0)
// @Success 200 {object} dto.OngListMapper
// @Failure 400
// @Failure 500
// @Router /ongs/ [get]
func (oc *OngController) List(w http.ResponseWriter, r *http.Request) {
// pageStr := r.URL.Query().Get("page")
limitStr := r.URL.Query().Get("limit")
Expand Down Expand Up @@ -90,6 +104,17 @@ func (oc *OngController) List(w http.ResponseWriter, r *http.Request) {
}
}

// FindByID Retrieves ONG information from its provided ID.
// @Summary Find ONG by ID
// @Description Retrieves ONG details based on the ONG ID provided as a parameter.
// @Tags Ong
// @Accept json
// @Produce json
// @Param ongID path string true "ID of the ONG to be retrieved"
// @Success 200 {object} dto.OngListMapper
// @Failure 400
// @Failure 500
// @Router /ongs/{ongID} [get]
func (oc *OngController) FindByID(w http.ResponseWriter, r *http.Request) {
IDStr := chi.URLParam(r, "ongID")

Expand Down
36 changes: 36 additions & 0 deletions api/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ func NewUserController(usecase *usecase.UserUsecase) *UserController {
}
}

// Create a user in database
// @Summary Creates user
// @Description Creates user and insert into the database
// @Tags User
// @Accept json
// @Produce json
// @Param userDto body dto.UserInsertDto true "User object information to create"
// @Success 201
// @Failure 400
// @Failure 500
// @Router /user/create-account [post]
func (uc *UserController) Insert(w http.ResponseWriter, r *http.Request) {
var userDto dto.UserInsertDto
err := json.NewDecoder(r.Body).Decode(&userDto)
Expand Down Expand Up @@ -51,6 +62,19 @@ func (uc *UserController) Insert(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusCreated)
}

// User login
// @Summary User login
// @Description Logs in a user and returns a JWT token
// @Tags User
// @Accept json
// @Produce json
// @Param userLoginDto body dto.UserLoginDto true "User login information"
// @Success 200
// @Failure 400
// @Failure 401
// @Failure 500
// @Router /user/login [post]
func (uc *UserController) Login(w http.ResponseWriter, r *http.Request) {
var userLoginDto dto.UserLoginDto
err := json.NewDecoder(r.Body).Decode(&userLoginDto)
Expand Down Expand Up @@ -252,6 +276,18 @@ func (uc *UserController) ChangePassword(w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusOK)
}

// User login with provider
// @Summary User login with provider
// @Description Logs in a user using a specified provider (SSO) and returns a JWT token
// @Tags User
// @Accept json
// @Produce json
// @Param provider path string true "The provider for Single Sign-On (e.g., google, facebook)"
// @Param UserSSODto body dto.UserSSODto true "User login information with SSO"
// @Success 200
// @Failure 400
// @Failure 500
// @Router /user/{provider}/login [post]
func (uc *UserController) ProviderLogin(w http.ResponseWriter, r *http.Request) {
provider := chi.URLParam(r, "provider")

Expand Down
6 changes: 6 additions & 0 deletions entity/dto/link_dto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dto

type LinkDto struct {
URL string `json:"url" example:"https://www.facebook.com/"`
Text string `json:"text" example:"Facebook da Ong"`
}
22 changes: 11 additions & 11 deletions entity/dto/ong_list_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
)

type OngListMapper struct {
ID uniqueEntityId.ID `json:"id" db:"id"`
UserId uniqueEntityId.ID `json:"userId" db:"userId"`
Name string `json:"name" db:"name"`
Address string `json:"address" db:"address"`
City string `json:"city" db:"city"`
State string `json:"state" db:"state"`
Phone string `json:"phone" db:"phone"`
OpeningHours string `json:"openingHours" db:"openingHours"`
AdoptionPolicy string `json:"adoptionPolicy" db:"adoptionPolicy"`
Links string `json:"links" db:"links"`
}
ID uniqueEntityId.ID `json:"id" db:"id"`
UserID uniqueEntityId.ID `json:"userId" db:"userId"`
Name string `json:"name" db:"name"`
Address string `json:"address" db:"address"`
City string `json:"city" db:"city"`
State string `json:"state" db:"state"`
Phone string `json:"phone" db:"phone"`
OpeningHours string `json:"openingHours" db:"openingHours"`
AdoptionPolicy string `json:"adoptionPolicy" db:"adoptionPolicy"`
Links string `json:"links" db:"links"`
}
12 changes: 3 additions & 9 deletions entity/dto/ong_update_dto.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package dto

type Link struct {
URL string `json:"url" example:"https://www.facebook.com/"`
Text string `json:"text" example:"Facebook da Ong"`
}

type OngUpdateDto struct {
Phone string `json:"phone" db:"phone" example:"119596995887"`
User UserUpdateDto
OpeningHours string `json:"openingHours" example:"08:00"`
AdoptionPolicy string `json:"adoptionPolicy" example:"não pode rato"`
Links []Link `json:"links"`
OpeningHours string `json:"openingHours" example:"08:00"`
AdoptionPolicy string `json:"adoptionPolicy" example:"não pode rato"`
Links []LinkDto `json:"links"`
}

22 changes: 11 additions & 11 deletions entity/dto/user_insert.dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (
var userTypes = []string{"juridica", "fisica"}

type UserInsertDto struct {
Name string `json:"name"`
Type string `json:"type"`
Document string `json:"document"`
AvatarURL string `json:"avatar_url"`
Email string `json:"email"`
Phone string `json:"phone"`
Pass string `json:"pass"`
BirthDate *time.Time `json:"birthdate"`
City string `json:"city"`
State string `json:"state"`
Role string `json:"role"`
Name string `json:"name" example:"Claúdio"`
Type string `json:"type" example:"fisica"`
Document string `json:"document" example:"12345678900"`
AvatarURL string `json:"avatar_url" example:"https://example.com/avatar.jpg"`
Email string `json:"email" example:"[email protected]"`
Phone string `json:"phone" example:"21912345678"`
Pass string `json:"pass" example:"Senhasegur@123"`
BirthDate *time.Time `json:"birthdate" example:"2006-01-02T15:04:05Z"`
City string `json:"city" example:"São Paulo"`
State string `json:"state" example:"São Paulo"`
Role string `json:"role" example:"developer"`
}

func (u *UserInsertDto) Validate() error {
Expand Down
43 changes: 26 additions & 17 deletions infra/db/ong_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,31 @@ func (or *OngRepository) List(limit, offset int, sortBy, order string) (ongs []*

return ongs, nil
}


func (or *OngRepository) FindByID(ID uniqueEntityId.ID) (*entity.Ong, error) {
var ong entity.Ong

err := or.dbconnection.Get(&ong, `SELECT
l.id,
l.userId,
l.links,
l.openingHours,
l.adoptionPolicy
FROM
legal_persons l
WHERE
l.id = ?`, ID)

func (or *OngRepository) FindByID(ID uniqueEntityId.ID) (*dto.OngListMapper, error) {
var ong dto.OngListMapper

query := `
SELECT
legal_persons.id,
legal_persons.userId,
legal_persons.phone,
legal_persons.openingHours,
legal_persons.links,
users.name,
addresses.address,
addresses.city,
addresses.state
FROM
legal_persons
INNER JOIN
users ON legal_persons.userId = users.id
INNER JOIN
addresses ON legal_persons.userId = addresses.userId
WHERE
legal_persons.id = ?`

err := or.dbconnection.Get(&ong, query, ID)

if err != nil {
logger.Error("error on ong repository: ", err)
Expand All @@ -102,7 +112,6 @@ WHERE
return &ong, nil
}


func (or *OngRepository) Update(id uniqueEntityId.ID, ongToUpdate entity.Ong) error {

query := "UPDATE legal_persons SET"
Expand Down Expand Up @@ -163,4 +172,4 @@ func (or *OngRepository) Delete(id uniqueEntityId.ID) error {
}

return nil
}
}
2 changes: 1 addition & 1 deletion interfaces/ong_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type OngRepository interface {
Save(ong *entity.Ong) error
List(limit, offset int, sortBy, order string) (ongs []*dto.OngListMapper, err error)
FindByID(ID uniqueEntityId.ID) (*dto.OngListMapper, error)
Update(id uniqueEntityId.ID, ong entity.Ong) error
FindByID(ID uniqueEntityId.ID) (*entity.Ong, error)
Delete(id uniqueEntityId.ID) error
}
10 changes: 5 additions & 5 deletions mocks/pet-dex-backend/v2/interfaces/mock_OngRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions swagger/details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Samples requests

```
GET /api/ongs/
GET /api/ongs?limite=10&offset=2
GET /api/ongs?sortBy=name&order=asc
```
Loading

0 comments on commit 41124a6

Please sign in to comment.