Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Portal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Labrador
Portal
Merge requests
!5
Resolve "Create and test Building & Room controller"
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Resolve "Create and test Building & Room controller"
6-create-and-test-building-room-controller
into
development
Overview
0
Commits
2
Pipelines
6
Changes
12
Merged
Resolve "Create and test Building & Room controller"
Sára Juhošová
requested to merge
6-create-and-test-building-room-controller
into
development
Jul 4, 2020
Overview
0
Commits
2
Pipelines
6
Changes
12
Closes
#6 (closed)
Edited
Jul 4, 2020
by
Sára Juhošová
0
0
Merge request reports
Compare
development
version 1
fd46168b
Jul 4, 2020
development (base)
and
latest version
latest version
b18307dc
2 commits,
Jul 4, 2020
version 1
fd46168b
1 commit,
Jul 4, 2020
12 files
+
783
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
12
src/main/java/nl/tudelft/portal/controller/BuildingController.java
0 → 100644
+
132
−
0
View file @ b18307dc
Edit in single-file editor
Open in Web IDE
/*
* Portal - A site for direct access to the Labrador system as a teacher or admin
* Copyright (C) 2020- Delft University of Technology
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package
nl.tudelft.portal.controller
;
import
java.util.List
;
import
javax.transaction.Transactional
;
import
javax.validation.Valid
;
import
nl.tudelft.labracore.api.BuildingControllerApi
;
import
nl.tudelft.labracore.api.dto.BuildingCreateDTO
;
import
nl.tudelft.labracore.api.dto.BuildingDetailsDTO
;
import
nl.tudelft.labracore.api.dto.BuildingPatchDTO
;
import
nl.tudelft.labracore.api.dto.BuildingSummaryDTO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.*
;
/**
* The controller for performing CRUD operations on buildings.
*/
@Controller
@Transactional
@RequestMapping
(
"building"
)
public
class
BuildingController
{
@Autowired
private
BuildingControllerApi
buildingApi
;
/**
* Provides the details of a building based on an id.
*
* @param id the id of the desired building
* @param model the model to add the data into
* @return the page to be loaded
*/
@GetMapping
(
"{id}"
)
public
String
getBuilding
(
@PathVariable
Long
id
,
Model
model
)
{
BuildingDetailsDTO
building
=
buildingApi
.
getBuildingById
(
id
).
block
();
model
.
addAttribute
(
"building"
,
building
);
return
"building/view"
;
}
/**
* Returns a list of all the existing buildings.
*
* @param model the model to add the data into
* @return the page to be loaded
*/
@GetMapping
(
"all"
)
public
String
getAllBuildings
(
Model
model
)
{
List
<
BuildingSummaryDTO
>
buildings
=
buildingApi
.
getAllBuildings
().
collectList
().
block
();
model
.
addAttribute
(
"buildings"
,
buildings
);
return
"building/list"
;
}
/**
* Provides an empty BuildingCreateDTO so a new building can be created.
*
* @param model the model to add the data into
* @return the page to be loaded
*/
@GetMapping
public
String
getEmptyBuilding
(
Model
model
)
{
BuildingCreateDTO
create
=
new
BuildingCreateDTO
();
model
.
addAttribute
(
"building"
,
create
);
return
"building/create"
;
}
/**
* Creates a new building.
*
* @param create the createDTO which holds the data about the new building
* @return the page to be loaded
*/
@PostMapping
public
String
createBuilding
(
@Valid
@ModelAttribute
(
"building"
)
BuildingCreateDTO
create
)
{
Long
id
=
buildingApi
.
addBuilding
(
create
).
block
();
return
"redirect:/building/"
+
id
;
}
/**
* Provides the details of a building so it can be edited.
*
* @param id the id of the building
* @param model the model to add the data into
* @return the page to be loaded
*/
@GetMapping
(
"{id}/edit"
)
public
String
editBuilding
(
@PathVariable
Long
id
,
Model
model
)
{
BuildingDetailsDTO
building
=
buildingApi
.
getBuildingById
(
id
).
block
();
model
.
addAttribute
(
"building"
,
building
);
return
"building/edit"
;
}
/**
* Patches a specific building.
*
* @param id the id of the building to patch
* @param patch the dto that contains the patch data
* @return the page to be loaded
*/
@PatchMapping
(
"{id}"
)
public
String
patchBuilding
(
@PathVariable
Long
id
,
@Valid
@ModelAttribute
BuildingPatchDTO
patch
)
{
buildingApi
.
patchBuilding
(
id
,
patch
);
return
"redirect:/building/"
+
id
;
}
}
Loading