Skip to content
Snippets Groups Projects
Commit 84d6b2c0 authored by Alifia Rahmah's avatar Alifia Rahmah
Browse files

Merge branch 'staging' into 'main'

Staging

See merge request !35
parents 2ec7a4dd b76ebe48
Branches
Tags v1.4.0
1 merge request!35Staging
Pipeline #55025 passed with stages
in 7 minutes and 22 seconds
Showing
with 5230 additions and 277 deletions
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -7,14 +7,14 @@ import ( ...@@ -7,14 +7,14 @@ import (
// Index godoc // Index godoc
// //
// @Tags admin // @Tags admin
// @Summary Add User // @Summary Add User
// @Description Add a user to database // @Description Add a user to database
// @Produce json // @Produce json
// @Accept json // @Accept json
// @Param data body req.AdminAddUserPayload true "Admin Add User Payload" // @Param data body req.AdminAddUserPayload true "Admin Add User Payload"
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Router /admin/user [post] // @Router /admin/user [post]
func (route AdminHandlerImpl) AddUser(w http.ResponseWriter, r *http.Request){ func (route AdminHandlerImpl) AddUser(w http.ResponseWriter, r *http.Request){
payload := req.AdminAddUserPayload{} payload := req.AdminAddUserPayload{}
......
...@@ -7,13 +7,13 @@ import ( ...@@ -7,13 +7,13 @@ import (
// Index godoc // Index godoc
// //
// @Tags admin // @Tags admin
// @Summary Delete User By Id // @Summary Delete User By Id
// @Description Delete a user from database // @Description Delete a user from database
// @Produce json // @Produce json
// @Accept json // @Accept json
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Router /admin/user/{email} [delete] // @Router /admin/user/{email} [delete]
func (route AdminHandlerImpl) DeleteUser(w http.ResponseWriter, r *http.Request){ func (route AdminHandlerImpl) DeleteUser(w http.ResponseWriter, r *http.Request){
email := path.Base(r.URL.Path) email := path.Base(r.URL.Path)
......
...@@ -6,12 +6,12 @@ import ( ...@@ -6,12 +6,12 @@ import (
// Index godoc // Index godoc
// //
// @Tags admin // @Tags admin
// @Summary Get All User // @Summary Get All User
// @Description Get all users from database // @Description Get all users from database
// @Produce json // @Produce json
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Router /admin/user [get] // @Router /admin/user [get]
func (route AdminHandlerImpl) GetAllUser(w http.ResponseWriter, r *http.Request){ func (route AdminHandlerImpl) GetAllUser(w http.ResponseWriter, r *http.Request){
// get all user from service // get all user from service
users, err := route.AdminService.GetAllUser() users, err := route.AdminService.GetAllUser()
......
...@@ -7,12 +7,12 @@ import ( ...@@ -7,12 +7,12 @@ import (
// Index godoc // Index godoc
// //
// @Tags admin // @Tags admin
// @Summary Get User By Email // @Summary Get User By Email
// @Description Get a user from database // @Description Get a user from database
// @Produce json // @Produce json
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Router /admin/user/{email} [get] // @Router /admin/user/{email} [get]
func (route AdminHandlerImpl) GetUserByEmail(w http.ResponseWriter, r *http.Request) { func (route AdminHandlerImpl) GetUserByEmail(w http.ResponseWriter, r *http.Request) {
// email := r.URL.Query().Get("email") // email := r.URL.Query().Get("email")
email := path.Base(r.URL.Path) email := path.Base(r.URL.Path)
......
...@@ -8,14 +8,14 @@ import ( ...@@ -8,14 +8,14 @@ import (
// Index godoc // Index godoc
// //
// @Tags admin // @Tags admin
// @Summary Update User By Id // @Summary Update User By Id
// @Description Update a user from database // @Description Update a user from database
// @Produce json // @Produce json
// @Accept json // @Accept json
// @Param data body req.AdminUpdateUserPayload true "Admin Update User Payload" // @Param data body req.AdminUpdateUserPayload true "Admin Update User Payload"
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Router /admin/user/{email} [patch] // @Router /admin/user/{email} [patch]
func (route AdminHandlerImpl) UpdateUser(w http.ResponseWriter, r *http.Request){ func (route AdminHandlerImpl) UpdateUser(w http.ResponseWriter, r *http.Request){
email := path.Base(r.URL.Path) email := path.Base(r.URL.Path)
// TODO: how to change email // TODO: how to change email
......
...@@ -11,19 +11,19 @@ import ( ...@@ -11,19 +11,19 @@ import (
// Index godoc // Index godoc
// //
// @Tags auth // @Tags auth
// @Summary Login // @Summary Login
// @Description Login and generate new pair of token // @Description Login and generate new pair of token
// @Produce json // @Produce json
// @Accept json // @Accept json
// @Param data body login.LoginRequestPayload true "Login payload" // @Param data body login.LoginRequestPayload true "Login payload"
// @Success 200 {object} web.BaseResponse{data=login.LoginResponsePayload} "Login Success" // @Success 200 {object} web.BaseResponse{data=login.LoginResponsePayload} "Login Success"
// @Failure 400 {object} web.BaseResponse{data=[]string} "Bad Input" // @Failure 400 {object} web.BaseResponse{data=[]string} "Bad Input"
// @Failure 403 {object} web.BaseResponse "Login Credential Error" // @Failure 403 {object} web.BaseResponse "Login Credential Error"
// @Failure 415 {object} web.BaseResponse "Not a json request" // @Failure 415 {object} web.BaseResponse "Not a json request"
// @Failure 422 {object} web.BaseResponse "Invalid JSON input" // @Failure 422 {object} web.BaseResponse "Invalid JSON input"
// @Failure 500 {object} web.BaseResponse "Unknown Internal Error" // @Failure 500 {object} web.BaseResponse "Unknown Internal Error"
// @Router /auth/login [post] // @Router /auth/login [post]
func (a AuthHandlerImpl) Login(w http.ResponseWriter, r *http.Request) { func (a AuthHandlerImpl) Login(w http.ResponseWriter, r *http.Request) {
payload := login.LoginRequestPayload{} payload := login.LoginRequestPayload{}
validate := validator.New() validate := validator.New()
......
...@@ -11,17 +11,17 @@ import ( ...@@ -11,17 +11,17 @@ import (
// Index godoc // Index godoc
// //
// @Tags auth // @Tags auth
// @Summary Refresh Token // @Summary Refresh Token
// @Description Generate new access token // @Description Generate new access token
// @Produce json // @Produce json
// @Accept json // @Accept json
// @Param Authorization header string true "Refresh token" // @Param Authorization header string true "Refresh token"
// @Success 200 {object} web.BaseResponse{data=refresh.RefreshResponsePayload} // @Success 200 {object} web.BaseResponse{data=refresh.RefreshResponsePayload}
// @Failure 400 {object} web.BaseResponse // @Failure 400 {object} web.BaseResponse
// @Failure 401 {object} web.BaseResponse // @Failure 401 {object} web.BaseResponse
// @Failure 500 {object} web.BaseResponse // @Failure 500 {object} web.BaseResponse
// @Router /auth/refresh [post] // @Router /auth/refresh [post]
func (a AuthHandlerImpl) Refresh(w http.ResponseWriter, r *http.Request) { func (a AuthHandlerImpl) Refresh(w http.ResponseWriter, r *http.Request) {
payload := refresh.RefreshRequestPayload{} payload := refresh.RefreshRequestPayload{}
......
...@@ -12,16 +12,16 @@ import ( ...@@ -12,16 +12,16 @@ import (
// Index godoc // Index godoc
// //
// @Tags auth // @Tags auth
// @Summary Register New Account // @Summary Register New Account
// @Description Generate New Account as Member // @Description Generate New Account as Member
// @Produce json // @Produce json
// @Accept json // @Accept json
// @Param data body register.RegisterRequestPayload true "Register Payload" // @Param data body register.RegisterRequestPayload true "Register Payload"
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Failure 400 {object} web.BaseResponse // @Failure 400 {object} web.BaseResponse
// @Failure 500 {object} web.BaseResponse // @Failure 500 {object} web.BaseResponse
// @Router /auth/register [post] // @Router /auth/register [post]
func (a AuthHandlerImpl) Register(w http.ResponseWriter, r *http.Request) { func (a AuthHandlerImpl) Register(w http.ResponseWriter, r *http.Request) {
payload := register.RegisterRequestPayload{} payload := register.RegisterRequestPayload{}
validate := validator.New() validate := validator.New()
......
...@@ -11,16 +11,16 @@ import ( ...@@ -11,16 +11,16 @@ import (
// Index godoc // Index godoc
// //
// @Tags auth // @Tags auth
// @Summary Send Email Verification // @Summary Send Email Verification
// @Description Send Email Verification to user // @Description Send Email Verification to user
// @Produce json // @Produce json
// @Accept json // @Accept json
// @Param data body verification.VerificationSendRequestPayload true "Register Payload" // @Param data body verification.VerificationSendRequestPayload true "Register Payload"
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Failure 400 {object} web.BaseResponse // @Failure 400 {object} web.BaseResponse
// @Failure 500 {object} web.BaseResponse // @Failure 500 {object} web.BaseResponse
// @Router /auth/verify/resend [post] // @Router /auth/verify/resend [post]
func (a AuthHandlerImpl) SendEmailVerify(w http.ResponseWriter, r *http.Request) { func (a AuthHandlerImpl) SendEmailVerify(w http.ResponseWriter, r *http.Request) {
payload := verification.VerificationSendRequestPayload{} payload := verification.VerificationSendRequestPayload{}
validate := validator.New() validate := validator.New()
......
...@@ -11,16 +11,16 @@ import ( ...@@ -11,16 +11,16 @@ import (
// Index godoc // Index godoc
// //
// @Tags auth // @Tags auth
// @Summary Do Email Verification // @Summary Do Email Verification
// @Description Do Email Verification to user // @Description Do Email Verification to user
// @Produce json // @Produce json
// @Accept json // @Accept json
// @Param data body verification.VerificationRequestPayload true "Register Payload" // @Param data body verification.VerificationRequestPayload true "Register Payload"
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Failure 400 {object} web.BaseResponse // @Failure 400 {object} web.BaseResponse
// @Failure 500 {object} web.BaseResponse // @Failure 500 {object} web.BaseResponse
// @Router /auth/verify [post] // @Router /auth/verify [post]
func (a AuthHandlerImpl) EmailVerify(w http.ResponseWriter, r *http.Request) { func (a AuthHandlerImpl) EmailVerify(w http.ResponseWriter, r *http.Request) {
payload := verification.VerificationRequestPayload{} payload := verification.VerificationRequestPayload{}
validate := validator.New() validate := validator.New()
......
...@@ -6,12 +6,12 @@ import ( ...@@ -6,12 +6,12 @@ import (
// Index godoc // Index godoc
// //
// @Tags common // @Tags common
// @Summary Index page // @Summary Index page
// @Description Give server index page response // @Description Give server index page response
// @Produce json // @Produce json
// @Success 200 {object} web.BaseResponse // @Success 200 {object} web.BaseResponse
// @Router / [get] // @Router / [get]
func (route CommonHandlerImpl) Home(w http.ResponseWriter, r *http.Request) { func (route CommonHandlerImpl) Home(w http.ResponseWriter, r *http.Request) {
payload := route.WrapperUtil.SuccessResponseWrap(route.CommonService.Home()) payload := route.WrapperUtil.SuccessResponseWrap(route.CommonService.Home())
route.HttpUtil.WriteSuccessJson(w, payload) route.HttpUtil.WriteSuccessJson(w, payload)
......
...@@ -7,12 +7,27 @@ import ( ...@@ -7,12 +7,27 @@ import (
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"gitlab.informatika.org/ocw/ocw-backend/model/web" "gitlab.informatika.org/ocw/ocw-backend/model/web"
"gitlab.informatika.org/ocw/ocw-backend/model/web/course/add" "gitlab.informatika.org/ocw/ocw-backend/model/web/course"
) )
// Index godoc
//
// @Summary Add a new course
// @Description Add a new course with the given details
// @Tags course
// @Accept json
// @Produce json
// @Param Authorization header string true "AddCourseToken"
// @Param data body course.AddCourseRequestPayload true "Add Course payload"
// @Success 200 {object} web.BaseResponse "Success"
// @Failure 400 {object} web.BaseResponse "Bad Request"
// @Failure 401 {object} web.BaseResponse "Unauthorized"
// @Failure 403 {object} web.BaseResponse "Forbidden"
// @Failure 422 {object} web.BaseResponse "Unprocessable Entity"
// @Failure 500 {object} web.BaseResponse "Internal Server Error"
// @Router /course [put]
func (c CourseHandlerImpl) AddCourse(w http.ResponseWriter, r *http.Request) { func (c CourseHandlerImpl) AddCourse(w http.ResponseWriter, r *http.Request) {
payload := add.AddCourseRequestPayload{} payload := course.AddCourseRequestPayload{}
validate := validator.New()
// Validate payload // Validate payload
if r.Header.Get("Content-Type") != "application/json" { if r.Header.Get("Content-Type") != "application/json" {
...@@ -27,6 +42,7 @@ func (c CourseHandlerImpl) AddCourse(w http.ResponseWriter, r *http.Request) { ...@@ -27,6 +42,7 @@ func (c CourseHandlerImpl) AddCourse(w http.ResponseWriter, r *http.Request) {
return return
} }
validate := validator.New()
if err := validate.Struct(payload); err != nil { if err := validate.Struct(payload); err != nil {
if _, ok := err.(*validator.InvalidValidationError); ok { if _, ok := err.(*validator.InvalidValidationError); ok {
payload := c.WrapperUtil.ErrorResponseWrap(err.Error(), nil) payload := c.WrapperUtil.ErrorResponseWrap(err.Error(), nil)
...@@ -83,4 +99,4 @@ func (c CourseHandlerImpl) AddCourse(w http.ResponseWriter, r *http.Request) { ...@@ -83,4 +99,4 @@ func (c CourseHandlerImpl) AddCourse(w http.ResponseWriter, r *http.Request) {
responsePayload := c.WrapperUtil.SuccessResponseWrap(nil) responsePayload := c.WrapperUtil.SuccessResponseWrap(nil)
c.HttpUtil.WriteSuccessJson(w, responsePayload) c.HttpUtil.WriteSuccessJson(w, responsePayload)
} }
\ No newline at end of file
...@@ -7,11 +7,27 @@ import ( ...@@ -7,11 +7,27 @@ import (
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"gitlab.informatika.org/ocw/ocw-backend/model/web" "gitlab.informatika.org/ocw/ocw-backend/model/web"
"gitlab.informatika.org/ocw/ocw-backend/model/web/course/faculty/add" "gitlab.informatika.org/ocw/ocw-backend/model/web/course/faculty"
) )
// Index godoc
//
// @Summary Add a new faculty
// @Description Adds a new faculty with the given details
// @Tags course
// @Accept json
// @Produce json
// @Param Authorization header string true "AddFacultyToken"
// @Param data body faculty.AddFacultyRequestPayload true "Add Faculty payload"
// @Success 200 {object} web.BaseResponse "Success"
// @Failure 400 {object} web.BaseResponse "Bad Request"
// @Failure 401 {object} web.BaseResponse "Unauthorized"
// @Failure 403 {object} web.BaseResponse "Forbidden"
// @Failure 422 {object} web.BaseResponse "Unprocessable Entity"
// @Failure 500 {object} web.BaseResponse "Internal Server Error"
// @Router /course/faculty [put]
func (c CourseHandlerImpl) AddFaculty(w http.ResponseWriter, r *http.Request) { func (c CourseHandlerImpl) AddFaculty(w http.ResponseWriter, r *http.Request) {
payload := add.AddFacultyRequestPayload{} payload := faculty.AddFacultyRequestPayload{}
validate := validator.New() validate := validator.New()
// Validate payload // Validate payload
......
...@@ -7,11 +7,27 @@ import ( ...@@ -7,11 +7,27 @@ import (
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"gitlab.informatika.org/ocw/ocw-backend/model/web" "gitlab.informatika.org/ocw/ocw-backend/model/web"
"gitlab.informatika.org/ocw/ocw-backend/model/web/course/major/add" "gitlab.informatika.org/ocw/ocw-backend/model/web/course/major"
) )
// Index godoc
//
// @Summary Add Major
// @Description Add a new major to a faculty
// @Tags course
// @Accept json
// @Produce json
// @Param Authorization header string true "AddMajorToken"
// @Param data body major.AddMajorRequestPayload true "Add Major payload"
// @Success 200 {object} web.BaseResponse "Success"
// @Failure 400 {object} web.BaseResponse "Bad Request"
// @Failure 401 {object} web.BaseResponse "Unauthorized"
// @Failure 403 {object} web.BaseResponse "Forbidden"
// @Failure 422 {object} web.BaseResponse "Unprocessable Entity"
// @Failure 500 {object} web.BaseResponse "Internal Server Error"
// @Router /course/major [put]
func (c CourseHandlerImpl) AddMajor(w http.ResponseWriter, r *http.Request) { func (c CourseHandlerImpl) AddMajor(w http.ResponseWriter, r *http.Request) {
payload := add.AddMajorRequestPayload{} payload := major.AddMajorRequestPayload{}
validate := validator.New() validate := validator.New()
// Validate payload // Validate payload
......
...@@ -3,14 +3,32 @@ package course ...@@ -3,14 +3,32 @@ package course
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"path"
"strings" "strings"
"gitlab.informatika.org/ocw/ocw-backend/model/web" "gitlab.informatika.org/ocw/ocw-backend/model/web"
"gitlab.informatika.org/ocw/ocw-backend/model/web/course/delete" "gitlab.informatika.org/ocw/ocw-backend/model/web/course"
) )
// Index godoc
//
// @Summary Delete course by ID
// @Description Delete a course with the specified ID
// @Tags course
// @Accept json
// @Produce json
// @Param id path string true "Course ID"
// @Param Authorization header string true "DeleteCourseToken"
// @Success 200 {object} web.BaseResponse "Success"
// @Failure 400 {object} web.BaseResponse "Bad Request"
// @Failure 401 {object} web.BaseResponse "Unauthorized"
// @Failure 403 {object} web.BaseResponse "Forbidden"
// @Failure 422 {object} web.BaseResponse "Unprocessable Entity"
// @Failure 500 {object} web.BaseResponse "Internal Server Error"
// @Router /course/{id} [delete]
func (c CourseHandlerImpl) DeleteCourse(w http.ResponseWriter, r *http.Request) { func (c CourseHandlerImpl) DeleteCourse(w http.ResponseWriter, r *http.Request) {
payload := delete.DeleteByStringRequestPayload{} payload := course.DeleteByStringRequestPayload{}
payload.ID = path.Base(r.URL.Path)
validateTokenHeader := r.Header.Get("Authorization") validateTokenHeader := r.Header.Get("Authorization")
if validateTokenHeader == "" { if validateTokenHeader == "" {
......
...@@ -6,11 +6,22 @@ import ( ...@@ -6,11 +6,22 @@ import (
"path" "path"
"gitlab.informatika.org/ocw/ocw-backend/model/web" "gitlab.informatika.org/ocw/ocw-backend/model/web"
"gitlab.informatika.org/ocw/ocw-backend/model/web/course/get" "gitlab.informatika.org/ocw/ocw-backend/model/web/course"
) )
// Index godoc
//
// @Summary Get a course by ID
// @Description Retrieve a course by ID
// @Tags course
// @Produce json
// @Param id path string true "ID of the course to retrieve"
// @Success 200 {object} web.BaseResponse "OK"
// @Failure 401 {object} web.BaseResponse "Unauthorized"
// @Failure 500 {object} web.BaseResponse "Internal Server Error"
// @Router /course/{id} [get]
func (c CourseHandlerImpl) GetCourse(w http.ResponseWriter, r *http.Request) { func (c CourseHandlerImpl) GetCourse(w http.ResponseWriter, r *http.Request) {
payload := get.GetByStringRequestPayload{} payload := course.GetByStringRequestPayload{}
payload.ID = path.Base(r.URL.Path) payload.ID = path.Base(r.URL.Path)
packet, err := c.CourseService.GetCourse(payload) packet, err := c.CourseService.GetCourse(payload)
......
...@@ -7,6 +7,16 @@ import ( ...@@ -7,6 +7,16 @@ import (
"gitlab.informatika.org/ocw/ocw-backend/model/web" "gitlab.informatika.org/ocw/ocw-backend/model/web"
) )
// Index godoc
//
// @Summary Get all courses
// @Description Retrieve a list of all available courses.
// @Tags course
// @Produce json
// @Success 200 {object} web.BaseResponse "OK"
// @Failure 401 {object} web.BaseResponse "Unauthorized"
// @Failure 500 {object} web.BaseResponse "Internal Server Error"
// @Router /course [get]
func (c CourseHandlerImpl) GetCourses(w http.ResponseWriter, r *http.Request) { func (c CourseHandlerImpl) GetCourses(w http.ResponseWriter, r *http.Request) {
packet, err := c.CourseService.GetAllCourse() packet, err := c.CourseService.GetAllCourse()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment