Skip to content

Commit

Permalink
Merge pull request #144 from peter-szrnka/143-gms-83-code-smell-cleanup
Browse files Browse the repository at this point in the history
GMS-83 Code smells removed
  • Loading branch information
peter-szrnka authored Dec 5, 2023
2 parents 80003a7 + fe879b2 commit 54e19eb
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
Expand All @@ -27,7 +26,7 @@ public ApiController(ApiService service) {
}

@GetMapping(path = "/api/secret/{secretId}", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public @ResponseBody Map<String, String> getSecret(@RequestHeader(name = API_KEY_HEADER, required = true) String apiKey, @PathVariable(name = "secretId") String secretId) {
public Map<String, String> getSecret(@RequestHeader(name = API_KEY_HEADER) String apiKey, @PathVariable(name = "secretId") String secretId) {
return service.getSecret(new GetSecretRequestDto(apiKey, secretId));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.github.gms.common.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.github.gms.secure.dto.UserInfoDto;
import io.github.gms.secure.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @author Peter Szrnka
Expand All @@ -24,7 +22,7 @@ public InformationController(UserService userService) {
}

@GetMapping("/me")
public @ResponseBody UserInfoDto getUserInfo(HttpServletRequest request) {
public UserInfoDto getUserInfo(HttpServletRequest request) {
return userService.getUserInfo(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
Expand All @@ -35,7 +34,7 @@ public SetupController(UserService userService) {

@PostMapping("/user")
@Audited(operation = EventOperation.SETUP)
public @ResponseBody SaveEntityResponseDto saveAdminUser(@RequestBody SaveUserRequestDto dto) {
public SaveEntityResponseDto saveAdminUser(@RequestBody SaveUserRequestDto dto) {
MDC.put(MdcParameter.USER_NAME.getDisplayName(), "setup");
MDC.put(MdcParameter.USER_ID.getDisplayName(), "0");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package io.github.gms.common.controller;

import io.github.gms.common.dto.SystemStatusDto;
import io.github.gms.secure.service.SystemService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.github.gms.common.dto.SystemStatusDto;
import io.github.gms.secure.service.SystemService;

/**
* @author Peter Szrnka
* @since 1.0
Expand All @@ -22,7 +20,6 @@ public SystemController(SystemService systemService) {
this.systemService = systemService;
}

@ResponseBody
@GetMapping("/status")
public SystemStatusDto status() {
return systemService.getSystemStatus();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
package io.github.gms.secure.controller;

import static io.github.gms.common.util.Constants.ALL_ROLE;
import static io.github.gms.common.util.Constants.ROLE_ADMIN;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.github.gms.common.abstraction.AbstractController;
import io.github.gms.common.enums.EventOperation;
import io.github.gms.common.enums.EventTarget;
Expand All @@ -26,6 +11,19 @@
import io.github.gms.secure.dto.SaveAnnouncementDto;
import io.github.gms.secure.dto.SaveEntityResponseDto;
import io.github.gms.secure.service.AnnouncementService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static io.github.gms.common.util.Constants.ALL_ROLE;
import static io.github.gms.common.util.Constants.ROLE_ADMIN;

/**
* @author Peter Szrnka
Expand All @@ -43,26 +41,26 @@ public AnnouncementController(AnnouncementService service) {
@PostMapping
@PreAuthorize(ROLE_ADMIN)
@Audited(operation = EventOperation.SAVE)
public @ResponseBody SaveEntityResponseDto save(@RequestBody SaveAnnouncementDto dto) {
public SaveEntityResponseDto save(@RequestBody SaveAnnouncementDto dto) {
return service.save(dto);
}

@GetMapping("/{id}")
@PreAuthorize(ALL_ROLE)
public @ResponseBody AnnouncementDto getById(@PathVariable("id") Long id) {
public AnnouncementDto getById(@PathVariable("id") Long id) {
return service.getById(id);
}

@PostMapping("/list")
@PreAuthorize(ALL_ROLE)
public @ResponseBody AnnouncementListDto list(@RequestBody PagingDto dto) {
public AnnouncementListDto list(@RequestBody PagingDto dto) {
return service.list(dto);
}

@DeleteMapping("/{id}")
@PreAuthorize(ROLE_ADMIN)
@Audited(operation = EventOperation.DELETE)
public @ResponseBody ResponseEntity<String> delete(@PathVariable("id") Long id) {
public ResponseEntity<String> delete(@PathVariable("id") Long id) {
service.delete(id);
return new ResponseEntity<>(HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import static io.github.gms.common.util.Constants.ROLE_USER;
Expand All @@ -40,20 +39,20 @@ public ApiKeyController(ApiKeyService service) {
@PostMapping
@PreAuthorize(ROLE_USER)
@Audited(operation = EventOperation.SAVE)
public @ResponseBody SaveEntityResponseDto save(@RequestBody SaveApiKeyRequestDto dto) {
public SaveEntityResponseDto save(@RequestBody SaveApiKeyRequestDto dto) {
return service.save(dto);
}

@GetMapping("/{id}")
@PreAuthorize(ROLE_USER_OR_VIEWER)
@Audited(operation = EventOperation.GET_BY_ID)
public @ResponseBody ApiKeyDto getById(@PathVariable("id") Long id) {
public ApiKeyDto getById(@PathVariable("id") Long id) {
return service.getById(id);
}

@PostMapping("/list")
@PreAuthorize(ROLE_USER_OR_VIEWER)
public @ResponseBody ApiKeyListDto list(@RequestBody PagingDto dto) {
public ApiKeyListDto list(@RequestBody PagingDto dto) {
return service.list(dto);
}

Expand All @@ -66,7 +65,7 @@ public String getValue(@PathVariable("id") Long id) {

@GetMapping("/list_names")
@PreAuthorize(ROLE_USER_OR_VIEWER)
public @ResponseBody IdNamePairListDto getAllApiKeyNames() {
public IdNamePairListDto getAllApiKeyNames() {
return service.getAllApiKeyNames();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package io.github.gms.secure.controller;

import static io.github.gms.common.util.Constants.ROLE_ADMIN;

import io.github.gms.common.abstraction.AbstractController;
import io.github.gms.secure.dto.EventListDto;
import io.github.gms.secure.dto.PagingDto;
import io.github.gms.secure.service.EventService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.github.gms.common.abstraction.AbstractController;
import io.github.gms.secure.dto.EventListDto;
import io.github.gms.secure.dto.PagingDto;
import io.github.gms.secure.service.EventService;
import static io.github.gms.common.util.Constants.ROLE_ADMIN;

/**
* @author Peter Szrnka
Expand All @@ -29,13 +27,13 @@ public EventController(EventService service) {

@PostMapping("/list")
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_VIEWER')")
public @ResponseBody EventListDto list(@RequestBody PagingDto dto) {
public EventListDto list(@RequestBody PagingDto dto) {
return service.list(dto);
}

@PostMapping("/list/{userId}")
@PreAuthorize(ROLE_ADMIN)
public @ResponseBody EventListDto listByUserId(@PathVariable("userId") Long userId, @RequestBody PagingDto dto) {
public EventListDto listByUserId(@PathVariable("userId") Long userId, @RequestBody PagingDto dto) {
return service.listByUser(userId, dto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import static io.github.gms.common.util.Constants.ALL_ROLE;
Expand All @@ -26,7 +25,7 @@ public HomeController(HomeService service) {

@GetMapping("/")
@PreAuthorize(ALL_ROLE)
public @ResponseBody HomeDataResponseDto getHomeData() {
public HomeDataResponseDto getHomeData() {
return service.getHomeData();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package io.github.gms.secure.controller;

import static io.github.gms.common.util.Constants.ROLE_USER;
import static io.github.gms.common.util.Constants.ROLE_USER_OR_VIEWER;

import io.github.gms.common.abstraction.AbstractClientController;
import io.github.gms.common.enums.EventOperation;
import io.github.gms.common.enums.EventTarget;
import io.github.gms.common.types.AuditTarget;
import io.github.gms.common.types.Audited;
import io.github.gms.secure.dto.DownloadFileResponseDto;
import io.github.gms.secure.dto.GetSecureValueDto;
import io.github.gms.secure.dto.IdNamePairListDto;
import io.github.gms.secure.dto.KeystoreDto;
import io.github.gms.secure.dto.KeystoreListDto;
import io.github.gms.secure.dto.PagingDto;
import io.github.gms.secure.dto.SaveEntityResponseDto;
import io.github.gms.secure.service.KeystoreService;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
Expand All @@ -17,23 +27,11 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import io.github.gms.common.abstraction.AbstractClientController;
import io.github.gms.common.enums.EventOperation;
import io.github.gms.common.enums.EventTarget;
import io.github.gms.common.types.AuditTarget;
import io.github.gms.common.types.Audited;
import io.github.gms.secure.dto.DownloadFileResponseDto;
import io.github.gms.secure.dto.GetSecureValueDto;
import io.github.gms.secure.dto.IdNamePairListDto;
import io.github.gms.secure.dto.KeystoreDto;
import io.github.gms.secure.dto.KeystoreListDto;
import io.github.gms.secure.dto.PagingDto;
import io.github.gms.secure.dto.SaveEntityResponseDto;
import io.github.gms.secure.service.KeystoreService;
import static io.github.gms.common.util.Constants.ROLE_USER;
import static io.github.gms.common.util.Constants.ROLE_USER_OR_VIEWER;

/**
* @author Peter Szrnka
Expand All @@ -59,39 +57,39 @@ public KeystoreController(KeystoreService service) {
})
@PreAuthorize(ROLE_USER)
@Audited(operation = EventOperation.SAVE)
public @ResponseBody SaveEntityResponseDto save(@ModelAttribute(name = MULTIPART_MODEL) String model, @RequestPart(name = MULTIPART_FILE, required = false) MultipartFile file) {
public SaveEntityResponseDto save(@ModelAttribute(name = MULTIPART_MODEL) String model, @RequestPart(name = MULTIPART_FILE, required = false) MultipartFile file) {
return service.save(model, file);
}

@GetMapping("/{id}")
@PreAuthorize(ROLE_USER_OR_VIEWER)
@Audited(operation = EventOperation.GET_BY_ID)
public @ResponseBody KeystoreDto getById(@PathVariable("id") Long id) {
public KeystoreDto getById(@PathVariable("id") Long id) {
return service.getById(id);
}

@PostMapping("/list")
@PreAuthorize(ROLE_USER_OR_VIEWER)
public @ResponseBody KeystoreListDto list(@RequestBody PagingDto dto) {
public KeystoreListDto list(@RequestBody PagingDto dto) {
return service.list(dto);
}

@PostMapping("/value")
@PreAuthorize(ROLE_USER_OR_VIEWER)
@Audited(operation = EventOperation.GET_VALUE)
public @ResponseBody String getValue(@RequestBody GetSecureValueDto dto) {
public String getValue(@RequestBody GetSecureValueDto dto) {
return service.getValue(dto);
}

@GetMapping("/list_names")
@PreAuthorize(ROLE_USER_OR_VIEWER)
public @ResponseBody IdNamePairListDto getAllKeystoreNames() {
public IdNamePairListDto getAllKeystoreNames() {
return service.getAllKeystoreNames();
}

@GetMapping("/list_aliases/{keystoreId}")
@PreAuthorize(ROLE_USER_OR_VIEWER)
public @ResponseBody IdNamePairListDto getAllKeystoreAliases(@PathVariable("keystoreId") Long keystoreId) {
public IdNamePairListDto getAllKeystoreAliases(@PathVariable("keystoreId") Long keystoreId) {
return service.getAllKeystoreAliasNames(keystoreId);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.github.gms.secure.controller;

import static io.github.gms.common.util.Constants.ALL_ROLE;

import io.github.gms.common.abstraction.AbstractController;
import io.github.gms.secure.dto.LongValueDto;
import io.github.gms.secure.dto.MarkAsReadRequestDto;
import io.github.gms.secure.dto.MessageListDto;
import io.github.gms.secure.dto.PagingDto;
import io.github.gms.secure.service.MessageService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
Expand All @@ -10,15 +14,9 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.github.gms.common.abstraction.AbstractController;
import io.github.gms.secure.dto.LongValueDto;
import io.github.gms.secure.dto.MarkAsReadRequestDto;
import io.github.gms.secure.dto.MessageListDto;
import io.github.gms.secure.dto.PagingDto;
import io.github.gms.secure.service.MessageService;
import static io.github.gms.common.util.Constants.ALL_ROLE;

/**
* @author Peter Szrnka
Expand All @@ -34,13 +32,13 @@ public MessageController(MessageService service) {

@PostMapping("/list")
@PreAuthorize(ALL_ROLE)
public @ResponseBody MessageListDto list(@RequestBody PagingDto dto) {
public MessageListDto list(@RequestBody PagingDto dto) {
return service.list(dto);
}

@GetMapping("/unread")
@PreAuthorize(ALL_ROLE)
public @ResponseBody LongValueDto unreadMessagesCount() {
public LongValueDto unreadMessagesCount() {
return new LongValueDto(service.getUnreadMessagesCount());
}

Expand Down
Loading

0 comments on commit 54e19eb

Please sign in to comment.