Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions doc/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,132 @@ paths:
$ref: '#/components/responses/429'
'500':
$ref: '#/components/responses/500'
/gate_keepers:
get:
tags:
- Users
summary: Get all gate keepers
operationId: getGateKeepers
parameters:
- name: page
in: query
schema:
$ref: '#/components/schemas/Page'
- name: page_size
in: query
schema:
$ref: '#/components/schemas/PageSize'
- name: status
required: false
in: query
description: Filter gate keepers by status value return all by default
schema:
$ref: '#/components/schemas/EnableStatus'
- name: sex
required: false
in: query
description: Filter gate keepers by sex value return all by default
schema:
$ref: '#/components/schemas/Sex'
- name: first_name
required: false
in: query
description: Filter gate keepers by first name, case is ignored
schema:
type: string
- name: last_name
required: false
in: query
description: Filter gate keepers by last name, case is ignored
schema:
type: string
- name: ref
required: false
in: query
description: Filter gate keeper by ref, case is ignored
schema:
type: string
responses:
'200':
description: List of gate keeper, ordered by ref.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/GateKeeper'
'400':
$ref: '#/components/responses/400'
'403':
$ref: '#/components/responses/403'
'404':
$ref: '#/components/responses/404'
'429':
$ref: '#/components/responses/429'
'500':
$ref: '#/components/responses/500'
put:
tags:
- Users
summary: Create or update gate keepers
operationId: crupdateGateKeepers
requestBody:
description: gate keepers
required: true
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/CrupdateGateKeeper'
responses:
'200':
description: List of gate keepers, ordered by ref.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/GateKeeper'
'400':
$ref: '#/components/responses/400'
'403':
$ref: '#/components/responses/403'
'404':
$ref: '#/components/responses/404'
'429':
$ref: '#/components/responses/429'
'500':
$ref: '#/components/responses/500'
/gate_keepers/{id}:
get:
tags:
- Users
summary: Get gate keeper by id
operationId: getGateKeeperById
parameters:
- name: id
required: true
in: path
schema:
type: string
responses:
'200':
description: The Gate Keeper
content:
application/json:
schema:
$ref: '#/components/schemas/GateKeeper'
'400':
$ref: '#/components/responses/400'
'403':
$ref: '#/components/responses/403'
'404':
$ref: '#/components/responses/404'
'429':
$ref: '#/components/responses/429'
'500':
$ref: '#/components/responses/500'

/staff_members/raw/xlsx:
get:
Expand Down Expand Up @@ -5554,6 +5680,7 @@ components:
- ADMIN
- STAFF_MEMBER
- ORGANIZER
- GATE_KEEPER
bearer:
type: string
UserIdentifier:
Expand Down Expand Up @@ -5709,6 +5836,9 @@ components:
CrupdateOrganizer:
allOf:
- $ref: '#/components/schemas/CrupdateUser'
CrupdateGateKeeper:
allOf:
- $ref: '#/components/schemas/CrupdateUser'
CrupdateWorkStudyStudent:
properties:
id:
Expand Down Expand Up @@ -5801,6 +5931,12 @@ components:
properties:
profile_picture:
type: string
GateKeeper:
allOf:
- $ref: '#/components/schemas/CrupdateUser'
properties:
profile_picture:
type: string
GroupIdentifier:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package school.hei.haapi.endpoint.rest.controller;

import static java.util.stream.Collectors.toUnmodifiableList;
import static school.hei.haapi.model.User.Role.GATE_KEEPER;

import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import school.hei.haapi.endpoint.rest.mapper.SexEnumMapper;
import school.hei.haapi.endpoint.rest.mapper.StatusEnumMapper;
import school.hei.haapi.endpoint.rest.mapper.UserMapper;
import school.hei.haapi.endpoint.rest.model.CrupdateGateKeeper;
import school.hei.haapi.endpoint.rest.model.EnableStatus;
import school.hei.haapi.endpoint.rest.model.GateKeeper;
import school.hei.haapi.endpoint.rest.model.Sex;
import school.hei.haapi.endpoint.rest.validator.CoordinatesValidator;
import school.hei.haapi.model.BoundedPageSize;
import school.hei.haapi.model.PageFromOne;
import school.hei.haapi.model.User;
import school.hei.haapi.service.UserService;

@RestController
@AllArgsConstructor
public class GateKeeperController {
private final UserService userService;
private final StatusEnumMapper statusEnumMapper;
private final SexEnumMapper sexEnumMapper;
private final UserMapper userMapper;
private final CoordinatesValidator validator;

@GetMapping("/gate_keepers")
public List<GateKeeper> getGateKeepers(
@RequestParam PageFromOne page,
@RequestParam("page_size") BoundedPageSize pageSize,
@RequestParam(name = "status", required = false) EnableStatus status,
@RequestParam(name = "sex", required = false) Sex sex,
@RequestParam(value = "first_name", required = false, defaultValue = "") String firstName,
@RequestParam(value = "last_name", required = false, defaultValue = "") String lastName,
@RequestParam(value = "ref", required = false, defaultValue = "") String ref) {
User.Status domainStatus = statusEnumMapper.toDomainStatus(status);
User.Sex domainSexEnum = sexEnumMapper.toDomainSexEnum(sex);
return userService
.getByCriteria(
GATE_KEEPER, firstName, lastName, ref, page, pageSize, domainStatus, domainSexEnum)
.stream()
.map(userMapper::toRestGateKeeper)
.collect(toUnmodifiableList());
}

@GetMapping("/gate_keepers/{id}")
public GateKeeper getGateKeeperById(@PathVariable String id) {
return userMapper.toRestGateKeeper(userService.findById(id));
}

@PutMapping("/gate_keepers")
public List<GateKeeper> crupdateGateKeepers(
@RequestBody List<CrupdateGateKeeper> crupdateGateKeeper) {
crupdateGateKeeper.forEach(gateKeeper -> validator.accept(gateKeeper.getCoordinates()));
return userService
.saveAll(
crupdateGateKeeper.stream().map(userMapper::toDomain).collect(toUnmodifiableList()))
.stream()
.map(userMapper::toRestGateKeeper)
.collect(toUnmodifiableList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public GetStudentGrade toRestStudentExamGrade(User student, Exam exam) {
exam.getGrades().stream()
.filter(grade -> grade.getStudent().getId().equals(student.getId()))
.findFirst();
school.hei.haapi.model.Grade grade = optionalGrade.get();
var getStudentGrade = new GetStudentGrade().grade(toRest(grade));
var getStudentGrade = new GetStudentGrade().grade(optionalGrade.map(this::toRest).orElse(null));
getStudentGrade.setStudent(userMapper.toRestStudent(student));
return getStudentGrade;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package school.hei.haapi.endpoint.rest.mapper;

import static school.hei.haapi.endpoint.rest.mapper.FileInfoMapper.ONE_DAY_DURATION_AS_LONG;
import static school.hei.haapi.model.User.Role.GATE_KEEPER;
import static school.hei.haapi.model.User.Role.ORGANIZER;

import java.util.HashMap;
Expand Down Expand Up @@ -260,6 +261,34 @@ public Organizer toRestOrganizer(User user) {
return organizer;
}

public GateKeeper toRestGateKeeper(User user) {
GateKeeper gateKeeper = new GateKeeper();
String profilePictureKey = user.getProfilePictureKey();
String url =
profilePictureKey != null
? fileService.getPresignedUrl(profilePictureKey, ONE_DAY_DURATION_AS_LONG)
: null;

gateKeeper.setId(user.getId());
gateKeeper.setFirstName(user.getFirstName());
gateKeeper.setLastName(user.getLastName());
gateKeeper.setEmail(user.getEmail());
gateKeeper.setRef(user.getRef());
gateKeeper.setStatus(statusEnumMapper.toRestStatus(user.getStatus()));
gateKeeper.setPhone(user.getPhone());
gateKeeper.setEntranceDatetime(user.getEntranceDatetime());
gateKeeper.setBirthDate(user.getBirthDate());
gateKeeper.setSex(sexEnumMapper.toRestSexEnum(user.getSex()));
gateKeeper.setAddress(user.getAddress());
gateKeeper.setBirthPlace(user.getBirthPlace());
gateKeeper.setNic(user.getNic());
gateKeeper.setProfilePicture(url);
gateKeeper.setCoordinates(
new Coordinates().longitude(user.getLongitude()).latitude(user.getLatitude()));
gateKeeper.setHighSchoolOrigin(user.getHighSchoolOrigin());
return gateKeeper;
}

public User toDomain(CrupdateManager manager) {
return User.builder()
.role(User.Role.MANAGER)
Expand Down Expand Up @@ -384,6 +413,28 @@ public User toDomain(CrupdateMonitor monitor) {
.build();
}

public User toDomain(CrupdateGateKeeper gateKeeper) {
return User.builder()
.role(GATE_KEEPER)
.id(gateKeeper.getId())
.firstName(gateKeeper.getFirstName())
.lastName(gateKeeper.getLastName())
.email(gateKeeper.getEmail())
.ref(gateKeeper.getRef())
.status(statusEnumMapper.toDomainStatus(gateKeeper.getStatus()))
.phone(gateKeeper.getPhone())
.entranceDatetime(gateKeeper.getEntranceDatetime())
.birthDate(gateKeeper.getBirthDate())
.sex(sexEnumMapper.toDomainSexEnum(gateKeeper.getSex()))
.address(gateKeeper.getAddress())
.nic(gateKeeper.getNic())
.birthPlace(gateKeeper.getBirthPlace())
.longitude(gateKeeper.getCoordinates().getLongitude())
.latitude(gateKeeper.getCoordinates().getLatitude())
.highSchoolOrigin(gateKeeper.getHighSchoolOrigin())
.build();
}

public User toDomain(CrupdateOrganizer organizer) {
return User.builder()
.role(ORGANIZER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ req, res, null, forbiddenWithRemoteInfo(req))))
antMatcher(GET, "/organizers/*"),
antMatcher(PUT, "/organizers"),
antMatcher(POST, "/organizers/*/picture/raw"),
antMatcher(GET, "/gate_keepers"),
antMatcher(GET, "/gate_keepers/*"),
antMatcher(PUT, "/gate_keepers"),
antMatcher(PUT, STUDENT_COURSE),
nonAccessibleBySuspendedUserPath)),
AnonymousAuthenticationFilter.class)
Expand Down Expand Up @@ -727,6 +730,17 @@ req, res, null, forbiddenWithRemoteInfo(req))))
new SelfMatcher(POST, "/organizers/*/picture/raw", "organizers"))
.hasRole(ORGANIZER.getRole())
//
// Gate keeper resources
//
.requestMatchers(GET, "/gate_keepers")
.hasAnyRole(ADMIN.getRole(), MANAGER.getRole())
.requestMatchers(new SelfMatcher(GET, "/gate_keepers/*", "gate_keepers"))
.hasAnyRole(GATE_KEEPER.getRole())
.requestMatchers(GET, "/gate_keepers/*")
.hasAnyRole(ADMIN.getRole(), MANAGER.getRole())
.requestMatchers(PUT, "/gate_keepers")
.hasAnyRole(ADMIN.getRole(), MANAGER.getRole())
//
// Letter resources
//
.requestMatchers(GET, "/students/letters")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public enum Role implements GrantedAuthority {
TEACHER,
STAFF_MEMBER,
MANAGER,
ORGANIZER;
ORGANIZER,
GATE_KEEPER;

public String getRole() {
return name();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/school/hei/haapi/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public enum Role {
STUDENT,
TEACHER,
MANAGER,
ORGANIZER;
ORGANIZER,
GATE_KEEPER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public OcsData createShareLink(String path) throws JsonProcessingException {
Integer permission =
switch (currentUser.getRole()) {
case ADMIN, MANAGER -> 15;
case STUDENT, TEACHER, MONITOR, STAFF_MEMBER, ORGANIZER -> 1;
case STUDENT, TEACHER, MONITOR, STAFF_MEMBER, ORGANIZER, GATE_KEEPER -> 1;
};

HttpHeaders headers = new HttpHeaders();
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/db/migration/V43_60__Update_user_role.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
alter type "role" add value 'ORGANIZER';
alter type "role" add value 'ORGANIZER';
alter type "role" add value 'GATE_KEEPER';
Loading