Skip to content

Commit

Permalink
update stable full authorzation for box and useer
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunhThanhDe committed Apr 28, 2023
1 parent f23639f commit 5e51591
Show file tree
Hide file tree
Showing 63 changed files with 679 additions and 519 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
72 changes: 45 additions & 27 deletions src/main/java/com/vnptt/tms/api/ApkApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
* Application Programming Interface for apk manager
* include:
* <p>
* - get list apk from database pageable or none
* - get single apk form database by id
* - dowload (get method) apk file by fileDownloadUri
* - show (get method) the apk available on the policy for box and web
* - Map (post method) apk to policy
* - create (post method) apk normal with info add manually
* - create (post method) apk by upload file
* - update (put method) apk infor
* - delete map apk to policy
* - remove (delete method) apk out of database
* <p>
* ...
*/
@CrossOrigin
@RestController
@RequestMapping("TMS/api")
public class ApkApi {
Expand All @@ -25,11 +43,11 @@ public class ApkApi {
private IApkService apkService;

/**
* get all apk infor from server
* get list apk from database
*
* @param page
* @param limit
* @return
* @param page the number of page you want to display
* @param limit the number of element in a page
* @return List apk DTO
*/
@GetMapping(value = "/apk")
public ApkOutput showApk(@RequestParam(value = "page", required = false) Integer page,
Expand All @@ -55,11 +73,11 @@ public ApkOutput showApk(@RequestParam(value = "page", required = false) Integer
}

/**
* dowload apk for box
* dowload apk file
*
* @param fileName
* @param request
* @return
* @param fileName name of apk file
* @param request HTTP Header
* @return file raw
*/
@GetMapping("/downloadFile/{fileName:.+}")
public ResponseEntity<Resource> downloadFile(@PathVariable String fileName, HttpServletRequest request) {
Expand All @@ -86,10 +104,10 @@ public ResponseEntity<Resource> downloadFile(@PathVariable String fileName, Http
}

/**
* find apk with id
* show apk with id
*
* @param id
* @return
* @param id id of apk
* @return apk DTO
*/
@GetMapping(value = "/apk/{id}")
public ApkDTO showApk(@PathVariable("id") Long id) {
Expand All @@ -100,7 +118,7 @@ public ApkDTO showApk(@PathVariable("id") Long id) {
* see the apk available on the policy for box and web
*
* @param policyId device want to search
* @return
* @return List Apk DTO
*/
@GetMapping("/policy/{policyId}/apk")
public ApkOutput showAllApkInPolicy(@PathVariable(value = "policyId") Long policyId) {
Expand All @@ -119,9 +137,9 @@ public ApkOutput showAllApkInPolicy(@PathVariable(value = "policyId") Long polic
/**
* Mapp apk to policy
*
* @param policyId policy has apk
* @param apkId
* @return
* @param policyId policy want to map
* @param apkId apk want to map
* @return apk in policy want to map
*/
@PostMapping(value = "/policy/{policyId}/apk/{apkId}")
public ApkDTO addApplicationToDevice(@PathVariable(value = "policyId") Long policyId,
Expand All @@ -132,8 +150,8 @@ public ApkDTO addApplicationToDevice(@PathVariable(value = "policyId") Long poli
/**
* create apk normal
*
* @param model
* @return
* @param model apk DTO
* @return apk DTO after save on database
*/
@PostMapping(value = "/apk")
public ApkDTO createApk(@RequestBody ApkDTO model) {
Expand All @@ -143,8 +161,8 @@ public ApkDTO createApk(@RequestBody ApkDTO model) {
/**
* upload file to server and save apk info
*
* @param file
* @return
* @param file MultipartFile file apk
* @return apk DTO after apk has upload done in dir (in application.properties)
*/
@PostMapping("/uploadFile")
public ApkDTO uploadFile(@RequestParam("file") MultipartFile file) {
Expand All @@ -154,9 +172,9 @@ public ApkDTO uploadFile(@RequestParam("file") MultipartFile file) {
/**
* update apk info
*
* @param model
* @param id
* @return
* @param model new info of element apk
* @param id id of apk in database
* @return apk DTO after save in database
*/
@PutMapping(value = "/apk/{id}")
public ApkDTO updateApk(@RequestBody ApkDTO model, @PathVariable("id") Long id) {
Expand All @@ -165,11 +183,11 @@ public ApkDTO updateApk(@RequestBody ApkDTO model, @PathVariable("id") Long id)
}

/**
* remove apk in policy
* remove map of apk and policy
*
* @param policyId
* @param apkId
* @return
* @param policyId id of policy want to modify
* @param apkId id of apk want to remove in policy
* @return http status no content 204
*/
@DeleteMapping(value = "/policy/{policyId}/apk/{apkId}")
public ResponseEntity<HttpStatus> removeApkinPolicy(@PathVariable(value = "policyId") Long policyId,
Expand All @@ -181,7 +199,7 @@ public ResponseEntity<HttpStatus> removeApkinPolicy(@PathVariable(value = "polic
/**
* delete apk in database (very dangerous) (only use to test)
*
* @param ids
* @param ids list id apk want to delete ex: [1,2,3]
*/
@DeleteMapping(value = "/apk")
public void removeApk(@RequestBody Long[] ids) {
Expand Down
44 changes: 28 additions & 16 deletions src/main/java/com/vnptt/tms/api/ApplicationApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
* Application Programming Interface for application manager
* include:
* <p>
* - get list application from database pageable or none
* - get single application form database by id
* - show (get method) all apps available on the box
* - post application to database
* - Map (post method) app to device if database don't have app, create and add app to database
* - delete map app no longer on the device
* - remove (delete method) apk out of database
* <p>
* ...
*/
@CrossOrigin
@RestController
@RequestMapping("TMS/api")
Expand All @@ -26,7 +39,7 @@ public class ApplicationApi {
* @param page desired page to display
* @param limit number of elements 1 page
* @param packagename the name of the app you want to find
* @return
* @return List app DTO
*/
@GetMapping(value = "/application")
public ApplicationOutput showApplicationes(@RequestParam(value = "page", required = false) Integer page,
Expand All @@ -49,7 +62,7 @@ public ApplicationOutput showApplicationes(@RequestParam(value = "page", require
}

if (result.getListResult().size() >= 1) {
result.setMessage("Request Success");
result.setMessage("Get List application success");
result.setTotalElement(result.getListResult().size());
} else {
result.setMessage("no matching element found");
Expand All @@ -59,10 +72,10 @@ public ApplicationOutput showApplicationes(@RequestParam(value = "page", require
}

/**
* find applciation with id
* show application with id
*
* @param id
* @return
* @param id id of app want to show
* @return app DTO
*/
@GetMapping(value = "/application/{id}")
public ApplicationDTO showApplication(@PathVariable("id") Long id) {
Expand All @@ -73,7 +86,7 @@ public ApplicationDTO showApplication(@PathVariable("id") Long id) {
* see the apps available on the device for box and web
*
* @param deviceId device want to search
* @return
* @return List application DTO
*/
@GetMapping("/device/{deviceId}/application")
public ApplicationOutput getAllApplicationByDeviceEntityId(@PathVariable(value = "deviceId") Long deviceId) {
Expand All @@ -89,14 +102,13 @@ public ApplicationOutput getAllApplicationByDeviceEntityId(@PathVariable(value =
return result;
}


/**
* unnecessary (only use to test)
* beacause device only use addApplicationToDevice
* because device only use addApplicationToDevice
* add new app to database
*
* @param model dto application
* @return
* @return http status ok 200
*/
@PostMapping(value = "/application")
public ResponseEntity<ApplicationDTO> createApplication(@RequestBody ApplicationDTO model) {
Expand All @@ -105,10 +117,10 @@ public ResponseEntity<ApplicationDTO> createApplication(@RequestBody Application
}

/**
* Mapp app to device for box, if database don't have app, create and add
* Map app to device for box, if database don't have app, create and add
*
* @param deviceId device has app
* @param model dto application (need Id from responce when post new app)
* @param model dto application (need Id from response when post new app)
* @return
*/
@PostMapping(value = "/device/{deviceId}/application")
Expand All @@ -120,7 +132,7 @@ public ApplicationDTO addApplicationToDevice(@PathVariable(value = "deviceId") L
/**
* unnecessary (only use to test)
*
* @param ids
* @param ids list id of app want to delete ex: [1,2,3]
*/
@DeleteMapping(value = "/application")
@PreAuthorize("hasRole('MODERATOR')")
Expand All @@ -131,9 +143,9 @@ public void deleteApplication(@RequestBody Long[] ids) {
/**
* remove app no longer on the device
*
* @param deviceId
* @param applicationId
* @return
* @param deviceId id of device need modify app list
* @param applicationId id of application need remove
* @return http status 204
*/
@DeleteMapping(value = "/device/{deviceId}/application/{applicationId}")
public ResponseEntity<HttpStatus> removeApplicationOnDevice(@PathVariable(value = "deviceId") Long deviceId,
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/vnptt/tms/api/AuthApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

import javax.validation.Valid;

/**
* Application Programming Interface for auth manager
* include:
* <p>
* - signin for everybody with Unauthorization
* - signup for only admin and mod
* <p>
* ...
*/
@CrossOrigin
@RestController
@RequestMapping("/TMS/api/auth")
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/vnptt/tms/api/CommandApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,35 @@ public CommandDTO showCommand(@PathVariable("id") Long id) {
return commandService.findOne(id);
}

/**
* post one model command
*
* @param model
* @return
*/
@PostMapping(value = "/command")
public CommandDTO createCommand(@RequestBody CommandDTO model) {
return commandService.save(model);
}

/**
* modify command
*
* @param model
* @param id
* @return
*/
@PutMapping(value = "/command/{id}")
public CommandDTO updateCommand(@RequestBody CommandDTO model, @PathVariable("id") Long id) {
model.setId(id);
return commandService.save(model);
}

/**
* delete command (only use to test)
*
* @param ids
*/
@DeleteMapping(value = "/Command")
@PreAuthorize("hasRole('MODERATOR')")
public void removeCommand(@RequestBody Long[] ids) {
Expand Down
Loading

0 comments on commit 5e51591

Please sign in to comment.