Skip to content

Commit

Permalink
feat(docs): add swagger generator (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
akwanmaroso authored Jan 4, 2025
1 parent 70a08f3 commit 0463b06
Show file tree
Hide file tree
Showing 22 changed files with 3,622 additions and 17 deletions.
13 changes: 12 additions & 1 deletion app/events/delivery/http/create_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import (
"github.com/sirupsen/logrus"
)

// CreateEvent
// @Summary Create Event
// @Description This endpoint create event
// @Tags Event
// @Accept json
// @Produce json
// @Param request body domain.CreateEventPayload true "Body"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.HttpResponse
// @Router /api/events [post]
func (h Handler) CreateEvent(w http.ResponseWriter, r *http.Request) {
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
Expand All @@ -21,7 +32,7 @@ func (h Handler) CreateEvent(w http.ResponseWriter, r *http.Request) {
return
}

var payload domain.CreateEvenPayload
var payload domain.CreateEventPayload
if err := json.Unmarshal(bodyBytes, &payload); err != nil {
logrus.Error("failed to unmarshal : ", err)
utils.Response(domain.HttpResponse{
Expand Down
12 changes: 11 additions & 1 deletion app/events/delivery/http/get_event_by_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import (
"github.com/sirupsen/logrus"
)

// GetEventByID
// @Summary Get Detail Event by ID
// @Description This endpoint use to get event by id
// @Tags Event
// @Accept json
// @Produce json
// @Param id path string true "id"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.Event
// @Router /api/events/:id [get]
func (h Handler) GetEventByID(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
idString := vars["id"]
Expand All @@ -25,7 +36,6 @@ func (h Handler) GetEventByID(w http.ResponseWriter, r *http.Request) {
}

data, err := h.usecase.GetEventByID(r.Context(), uint(value))

if err != nil {
logrus.Error("failed to get event : ", err)
utils.Response(domain.HttpResponse{
Expand Down
18 changes: 18 additions & 0 deletions app/events/delivery/http/list_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ import (
"github.com/sirupsen/logrus"
)

// GetEvents
// @Summary Get Events
// @Description This endpoint use to get events by filter
// @Tags Event
// @Accept json
// @Produce json
// @Param limit query string true "string"
// @Param page query string true "string"
// @Param orderBy query string false "string"
// @Param start_date query string false "string"
// @Param end_date query string false "string"
// @Param title query string false "string"
// @Param type query string false "string"
// @Param status query string false "string"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} []domain.Event
// @Router /api/events [get]
func (h Handler) GetEvents(w http.ResponseWriter, r *http.Request) {
flterPagination, err := domain.GetPaginationFromCtx(r)
if err != nil {
Expand Down
18 changes: 16 additions & 2 deletions app/events/delivery/http/list_event_pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ import (
"github.com/sirupsen/logrus"
)

// ListEventPay
// @Summary Get List event pay
// @Description This endpoint use to get list of event pay
// @Tags Event
// @Accept json
// @Produce json
// @Param limit query string true "string"
// @Param page query string true "string"
// @Param event_id query string false "string"
// @Param start_date query string false "string"
// @Param end_date query string false "string"
// @Param status query string false "string"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} []domain.EventPay
// @Router /api/events/pays [get]
func (h Handler) ListEventPay(w http.ResponseWriter, r *http.Request) {
flterPagination, err := domain.GetPaginationFromCtx(r)
if err != nil {
Expand All @@ -22,7 +38,6 @@ func (h Handler) ListEventPay(w http.ResponseWriter, r *http.Request) {

startDate, _ := utils.ParseDate(r.URL.Query().Get("start_date"))
endDate, _ := utils.ParseDate(r.URL.Query().Get("end_date"))

eventIDs := r.URL.Query().Get("event_id")

var eventID uint
Expand All @@ -47,7 +62,6 @@ func (h Handler) ListEventPay(w http.ResponseWriter, r *http.Request) {
EndDate: endDate,
FilterPagination: flterPagination,
})

if err != nil {
logrus.Error("failed to list event : ", err)
utils.Response(domain.HttpResponse{
Expand Down
16 changes: 16 additions & 0 deletions app/events/delivery/http/list_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ import (
"github.com/sirupsen/logrus"
)

// ListRegistration
// @Summary Get List Register user to event
// @Description This endpoint use to get list of user that register on event
// @Tags Event
// @Accept json
// @Produce json
// @Param limit query string true "string"
// @Param page query string true "string"
// @Param event_id query string false "string"
// @Param start_date query string false "string"
// @Param end_date query string false "string"
// @Param status query string false "string"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} []domain.RegistrationEvent
// @Router /api/events/registrations [get]
func (h Handler) ListRegistration(w http.ResponseWriter, r *http.Request) {
flterPagination, err := domain.GetPaginationFromCtx(r)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions app/events/delivery/http/pay_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import (
"github.com/sirupsen/logrus"
)

// PayEvent
// @Summary Pay Event
// @Description This endpoint pay the event
// @Tags Event
// @Accept json
// @Produce json
// @Param request body domain.EventPayPayload true "Body"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.HttpResponse
// @Router /api/events/pay [post]
func (h Handler) PayEvent(w http.ResponseWriter, r *http.Request) {
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions app/events/delivery/http/pay_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import (
"github.com/sirupsen/logrus"
)

// PayProcess
// @Summary Pay Process
// @Description This endpoint use to confirm payment
// @Tags Event
// @Accept json
// @Produce json
// @Param request body domain.PayProcessPayload true "Body"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.HttpResponse
// @Router /api/events/pays [post]
func (h Handler) PayProcess(w http.ResponseWriter, r *http.Request) {
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions app/events/delivery/http/register_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import (
"github.com/sirupsen/logrus"
)

// RegisterEvent
// @Summary Register Event
// @Description This endpoint use to register event
// @Tags Event
// @Accept json
// @Produce json
// @Param request body domain.RegisterEventPayload true "Body"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.HttpResponse
// @Router /api/events/registrations [post]
func (h Handler) RegisterEvent(w http.ResponseWriter, r *http.Request) {
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions app/events/delivery/http/registration_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import (
"github.com/sirupsen/logrus"
)

// RegistrationStatus
// @Summary Register Status
// @Description This endpoint use to check registration status
// @Tags Event
// @Accept json
// @Produce json
// @Param order_no path string true "ABCXX"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.RegisterStatusResponse
// @Router /api/events/registartions/:order_no [get]
func (h Handler) RegistrationStatus(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
order_no := vars["order_no"]
Expand Down
2 changes: 1 addition & 1 deletion app/events/usecase/create_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/sirupsen/logrus"
)

func (uc usecase) CreateEvent(ctx context.Context, payload domain.CreateEvenPayload) error {
func (uc usecase) CreateEvent(ctx context.Context, payload domain.CreateEventPayload) error {
dataImage, err := uc.imageRepository.GetImage(ctx, payload.FileName)
if err != nil {
logrus.Error("failed to create event", dataImage)
Expand Down
11 changes: 11 additions & 0 deletions app/users/delivery/http/delete_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import (
"github.com/sirupsen/logrus"
)

// DeleteUser
// @Summary Delete User
// @Description This endpoint use to delete user
// @Tags User
// @Accept json
// @Produce json
// @Param id query string false "string"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.HttpResponse
// @Router /api/users [delete]
func (h Handler) DeleteUser(w http.ResponseWriter, r *http.Request) {
userIDStr := r.URL.Query().Get("id")
userID, _ := strconv.ParseUint(userIDStr, 10, 64)
Expand Down
10 changes: 10 additions & 0 deletions app/users/delivery/http/get_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import (
"github.com/sirupsen/logrus"
)

// GetUsers
// @Summary Get Users
// @Description This endpoint use to get users by filter
// @Tags User
// @Accept json
// @Produce json
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} []domain.User
// @Router /api/users [get]
func (h Handler) GetUsers(w http.ResponseWriter, r *http.Request) {
users, err := h.usecase.GetUsers(r.Context())

Expand Down
11 changes: 11 additions & 0 deletions app/users/delivery/http/login_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import (
"github.com/hammer-code/lms-be/utils"
)

// Login
// @Summary Login
// @Description This endpoint use to login
// @Tags Auth
// @Accept json
// @Produce json
// @Param request body domain.Login true "Body"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Failure 200 {object} domain.HttpResponse
// @Router /api/auth/login [post]
func (h Handler) Login(w http.ResponseWriter, r *http.Request) {
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions app/users/delivery/http/logout_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import (
"net/http"
)

// Logout
// @Summary Logout
// @Description This endpoint use to logout
// @Tags Auth
// @Accept json
// @Produce json
// @Param request body domain.Login true "Body"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Failure 200 {object} domain.HttpResponse
// @Router /api/auth/logout [post]
func (h Handler) Logout(w http.ResponseWriter, r *http.Request) {
token := utils.ExtractBearerToken(r)

Expand Down
13 changes: 12 additions & 1 deletion app/users/delivery/http/register_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import (
"github.com/sirupsen/logrus"
)

// Register
// @Summary Register
// @Description This endpoint use to register
// @Tags Auth
// @Accept json
// @Produce json
// @Param request body domain.Register true "Body"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.User
// @Router /api/auth/register [post]
func (h Handler) Register(w http.ResponseWriter, r *http.Request) {
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
Expand Down Expand Up @@ -46,7 +57,7 @@ func (h Handler) Register(w http.ResponseWriter, r *http.Request) {
utils.Response(resp, w)
return
}

utils.Response(domain.HttpResponse{
Code: 200,
Message: "success",
Expand Down
17 changes: 13 additions & 4 deletions app/users/delivery/http/update_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import (
"github.com/sirupsen/logrus"
)

// UpdateProfileUser
// @Summary Update User
// @Description This endpoint use to update profile user
// @Tags User
// @Accept json
// @Produce json
// @Param request body domain.UserUpdateProfile true "Body"
// @Failure 400 {object} domain.HttpResponse
// @Failure 500 {object} domain.HttpResponse
// @Success 200 {object} domain.HttpResponse
// @Router /api/users [put]
func (h Handler) UpdateProfileUser(w http.ResponseWriter, r *http.Request) {
authorizationHeader := r.Header.Get("Authorization")
if authorizationHeader == "" {
Expand All @@ -22,17 +33,15 @@ func (h Handler) UpdateProfileUser(w http.ResponseWriter, r *http.Request) {
return
}

claims, err:=jwt.ParseToken(authorizationHeader, config.GetConfig().JWT_SECRET_KEY)
if err !=nil{
claims, err := jwt.ParseToken(authorizationHeader, config.GetConfig().JWT_SECRET_KEY)
if err != nil {
utils.Response(domain.HttpResponse{
Code: 500,
Message: err.Error(),
}, w)
return
}



bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
utils.Response(domain.HttpResponse{
Expand Down
Loading

0 comments on commit 0463b06

Please sign in to comment.