-
Notifications
You must be signed in to change notification settings - Fork 0
feat(Core Resources): add core resources routes #19
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
Open
rspk2207
wants to merge
22
commits into
main
Choose a base branch
from
study-materials
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
071e598
Add files via upload
rspk2207 e88645c
Add files via upload
rspk2207 894fc19
Add files via upload
rspk2207 23901ce
Add files via upload
rspk2207 c4dc65f
Add files via upload
rspk2207 4bc70da
Add files via upload
rspk2207 a5ef490
Add files via upload
rspk2207 6441d61
Add files via upload
rspk2207 c49f5ee
feat(controller): added resource controller
rspk2207 f4251f2
feat(db): migrated database
rspk2207 b485bb5
feat(swagger): updated swaggerui
rspk2207 1edc467
feat(helpers): added resource helper
rspk2207 62fc183
feat(models): added study material and subject models
rspk2207 d001e09
feat(registry): added resource registry
rspk2207 de3deb0
feat(repositories): added resource repository
rspk2207 b67a998
feat(router): added resource routes
rspk2207 069cf2c
feat(schemas): added resource and subject schemas
rspk2207 ad49eea
feat(services): added resource services
rspk2207 d6f69cb
feat(utils): added utilities for operations on documents
rspk2207 6a298e3
feat(docker-compose): updated docker-compose.yml
rspk2207 e57d867
feat(study-materials): added study-material functionality
rspk2207 5872be3
feat(changes): altered get all resources functionality
rspk2207 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,277 @@ | ||
| package controllers | ||
|
|
||
| import ( | ||
| "log" | ||
| "net/http" | ||
|
|
||
| "github.com/ecea-nitt/ecea-server/middlewares" | ||
| "github.com/ecea-nitt/ecea-server/models" | ||
| "github.com/ecea-nitt/ecea-server/services" | ||
| "github.com/fatih/color" | ||
| "github.com/labstack/echo/v4" | ||
| ) | ||
|
|
||
| type studyMaterialController struct { | ||
| rs services.StudyMaterialService | ||
| } | ||
|
|
||
| type StudyMaterialController interface { | ||
| AddStudyMaterial(c echo.Context) error | ||
| GetCategoryStudyMaterials(c echo.Context) error | ||
| GetAllMaterials(c echo.Context) error | ||
| GetStudyMaterial(c echo.Context) error | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a GetAll route Expected Response: |
||
| AddSubject(c echo.Context) error | ||
| // UpdateStudyMaterialSubject(c echo.Context) error | ||
| UpdateStudyMaterialURL(c echo.Context) error | ||
| DeleteStudyMaterial(c echo.Context) error | ||
| } | ||
|
|
||
| func NewStudyMaterialController(rs services.StudyMaterialService) StudyMaterialController { | ||
| return &studyMaterialController{rs} | ||
| } | ||
|
|
||
| // AddStudyMaterial godoc | ||
| // | ||
| // @Summary Add a study material | ||
| // @Description Creates a new study material and adds to Database | ||
| // @Tags StudyMaterial | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param name formData string true "Enter material name" | ||
| // @Param code formData string true "Enter subject code" | ||
| // @Param document formData file true "Upload Document" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/studymaterial/addMaterial [post] | ||
| func (rc *studyMaterialController) AddStudyMaterial(c echo.Context) error { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we will make new route to create a subject remove subject_name just subject_code is neccessary |
||
| request := new(models.StudyMaterialRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(err) | ||
| return err | ||
| } | ||
| file, err := c.FormFile("document") | ||
| if err != nil { | ||
| log.Println(err) | ||
| return err | ||
| } | ||
| log.Println(request) | ||
| err = rc.rs.CreateNewStudyMaterial(*request, file) | ||
| if err != nil { | ||
| log.Println(err) | ||
| return middlewares.Responder(c, http.StatusConflict, "Conflict") | ||
| } | ||
| return middlewares.Responder(c, http.StatusOK, "Success") | ||
| } | ||
|
|
||
| // GetStudyMaterial godoc | ||
| // | ||
| // @Summary Get a study material | ||
| // @Description Fetches a study material and removes form database | ||
| // @Tags StudyMaterial | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param name path string true "Get study material" | ||
| // @Success 200 {object} models.StudyMaterials | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/studymaterial/get/{name} [get] | ||
| func (rc *studyMaterialController) GetStudyMaterial(c echo.Context) error { | ||
| rname := c.Param("name") | ||
| res, err := rc.rs.GetStudyMaterial(rname) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusConflict, "Error Occurred") | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, &res) | ||
| } | ||
|
|
||
| // GetCategoryStudyMaterials godoc | ||
| // | ||
| // @Summary Get study materials from a category | ||
| // @Description Fetches all study materials belonging to a category from Database | ||
| // @Tags StudyMaterial | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param category path models.SubjectCategory true "Get study material from category" | ||
| // @Success 200 {object} []models.StudyMaterials | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/studymaterial/getcat/{category} [get] | ||
| func (rc *studyMaterialController) GetCategoryStudyMaterials(c echo.Context) error { | ||
| /* | ||
| request := new(models.StudyMaterialRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| return err | ||
| } | ||
| */ | ||
| res, err := rc.rs.GetCategoryStudyMaterials(c.Param("category")) | ||
| log.Println(c.Param("category")) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusConflict, "Conflict") | ||
| } | ||
| return middlewares.Responder(c, http.StatusOK, res) | ||
| } | ||
|
|
||
| // UpdateStudyMaterialSubject godoc | ||
| // | ||
| // @Summary Updates a studymaterial's subject name | ||
| // @Description Updates a subject name and updates to Database | ||
| // @Tags StudyMaterial | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param subject formData string true "Edit name" | ||
| // @Param subjectCode formData string true "Enter subject code" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/studymaterial/edit/subject [put] | ||
|
|
||
| /* | ||
| func (rc *studyMaterialController) UpdateStudyMaterialSubject(c echo.Context) error { | ||
|
|
||
| request := new(models.StudyMaterialRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(err) | ||
| return middlewares.Responder(c, http.StatusBadRequest, "Bad Request") | ||
| } | ||
| subject := c.Param("subject") | ||
| subjectCode := c.Param("subjectCode") | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(err) | ||
| return middlewares.Responder(c, http.StatusBadRequest, "Bad Request") | ||
| } | ||
| log.Println(request.Subject, request.SubjectCode) | ||
| err := rc.rs.EditStudyMaterialSubject(request.Subject, request.SubjectCode) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusConflict, err) | ||
| } | ||
| return middlewares.Responder(c, http.StatusOK, "Success") | ||
| } | ||
| */ | ||
|
|
||
| // UpdateStudyMaterialURL godoc | ||
| // | ||
| // @Summary Update a study material's document | ||
| // @Description Update a document and update it on Database | ||
| // @Tags StudyMaterial | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param name formData string true "Enter the name of material" | ||
| // @Param document formData file true "Edit Document" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/studymaterial/edit/document [put] | ||
| func (rc *studyMaterialController) UpdateStudyMaterialURL(c echo.Context) error { | ||
|
|
||
| request := new(models.StudyMaterialRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(err) | ||
| return middlewares.Responder(c, http.StatusBadRequest, "Bad Request") | ||
| } | ||
| /* | ||
| name := c.Param("name") | ||
| request := new(models.StudyMaterialRequest) | ||
| if err := c.Bind(request); err != nil { | ||
| log.Println(err) | ||
| return middlewares.Responder(c, http.StatusBadRequest, "Bad Request") | ||
| } | ||
| */ | ||
| file, err := c.FormFile("document") | ||
| if err != nil { | ||
| log.Println(err) | ||
| return err | ||
| } | ||
|
|
||
| err = rc.rs.EditStudyMaterialURL(request.Name, file) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusConflict, err) | ||
| } | ||
| return middlewares.Responder(c, http.StatusOK, "Success") | ||
| } | ||
|
|
||
| // DeleteStudyMaterial godoc | ||
| // | ||
| // @Summary Deletes a study material | ||
| // @Description Deletes a study material along with its document and remove form Database | ||
| // @Tags StudyMaterial | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param name path string true "Delete study material" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/studymaterial/delete/{name} [delete] | ||
| func (rc *studyMaterialController) DeleteStudyMaterial(c echo.Context) error { | ||
| rname := c.Param("name") | ||
|
|
||
| err := rc.rs.RemoveStudyMaterial(rname) | ||
| log.Println(rname) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusConflict, "Error Occurred") | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, "Success") | ||
| } | ||
|
|
||
| // AddSubject godoc | ||
| // | ||
| // @Summary Add a subject | ||
| // @Description Creates a new subject and adds to Database | ||
| // @Tags StudyMaterial | ||
| // @Accept multipart/form-data | ||
| // @Produce json | ||
| // @Param subject formData string true "Enter subject name" | ||
| // @Param code formData string true "Enter subject code" | ||
| // @Param category formData models.SubjectCategory true "Enter subject category" | ||
| // @Success 200 {object} string | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/studymaterial/addSubject [post] | ||
| func (rc *studyMaterialController) AddSubject(c echo.Context) error { | ||
| response := new(models.StudyMaterialRequest) | ||
| if err := c.Bind(response); err != nil { | ||
| return err | ||
| } | ||
| err := rc.rs.AddSubject(response) | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusConflict, "Error Occurred") | ||
| } | ||
|
|
||
| return middlewares.Responder(c, http.StatusOK, "Success") | ||
| } | ||
|
|
||
| // GetAllStudyMaterials godoc | ||
| // | ||
| // @Summary Get all study materials from each category | ||
| // @Description Fetches all study materials belonging to every category from Database | ||
| // @Tags StudyMaterial | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Success 200 {object} []models.CategoryMaterials | ||
| // @Failure 400 {object} models.Error | ||
| // | ||
| // @Security ApiKeyAuth | ||
| // @Router /v1/studymaterial/getall [get] | ||
| func (rc *studyMaterialController) GetAllMaterials(c echo.Context) error { | ||
| res, err := rc.rs.GetAllMaterials() | ||
| if err != nil { | ||
| log.Println(color.RedString(err.Error())) | ||
| return middlewares.Responder(c, http.StatusConflict, "Conflict") | ||
| } | ||
| return middlewares.Responder(c, http.StatusOK, res) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a separate route for creating
subjectparams are subject_code, subject_name, subject_category