Skip to content

Commit

Permalink
feat: format
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-merlin committed Nov 23, 2024
1 parent 0e1f38e commit 5358b27
Show file tree
Hide file tree
Showing 29 changed files with 677 additions and 773 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ docker-compose up -d
```
Run the application. (You have to run the ```admin/BlueprintAdmin.java``` this is the entry point of the Spring application).

You can also run the server directly from the terminal
You can also run the server directly from the terminal


## Available Endpoints
Expand Down
57 changes: 38 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
id 'java'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
id "com.diffplug.spotless" version "5.16.0"
}

group = 'com.sitblueprint'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
sourceCompatibility = '17'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

spotless {
// optional: limit format enforcement to just the files changed by this feature branch
// ratchetFrom 'origin/main'
format 'misc', {
// define the files to apply `misc` to
target '*.gradle', '*.md', '.gitignore'
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces(3) // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
setEncoding('utf-8')
}
java {
eclipse() // I like eclipse formatting over google
// googleJavaFormat('1.11.0').aosp().reflowLongStrings(), this is the other option
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.data:spring-data-rest-hal-explorer'
implementation "org.springframework.boot:spring-boot-starter-security"
implementation 'org.hibernate:hibernate-validator:6.0.13.Final'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'org.postgresql:postgresql:42.2.23'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.data:spring-data-rest-hal-explorer'
implementation "org.springframework.boot:spring-boot-starter-security"
implementation 'org.hibernate:hibernate-validator:6.0.13.Final'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'org.postgresql:postgresql:42.2.23'
}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@

@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(ServiceException.class)
public ResponseEntity<ApiError> handleServiceException(ServiceException e, WebRequest request) {
ApiError apiError = new ApiError(LocalDateTime.now(), HttpStatus.INTERNAL_SERVER_ERROR.value(),
"Internal Server Error", e.getMessage(), request.getDescription(false));
return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(ServiceException.class)
public ResponseEntity<ApiError> handleServiceException(ServiceException e, WebRequest request) {
ApiError apiError = new ApiError(LocalDateTime.now(), HttpStatus.INTERNAL_SERVER_ERROR.value(),
"Internal Server Error", e.getMessage(), request.getDescription(false));
return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(NoSuchElementException.class)
public ResponseEntity<ApiError> handleNoSuchElementException(NoSuchElementException e, WebRequest request) {
ApiError apiError = new ApiError(LocalDateTime.now(), HttpStatus.NOT_FOUND.value(),
"Not Found Error", e.getMessage(), request.getDescription(false));
return new ResponseEntity<>(apiError, HttpStatus.NOT_FOUND);
}
@ExceptionHandler(NoSuchElementException.class)
public ResponseEntity<ApiError> handleNoSuchElementException(NoSuchElementException e, WebRequest request) {
ApiError apiError = new ApiError(LocalDateTime.now(), HttpStatus.NOT_FOUND.value(), "Not Found Error",
e.getMessage(), request.getDescription(false));
return new ResponseEntity<>(apiError, HttpStatus.NOT_FOUND);
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ApiError> handleGenericException(Exception e, WebRequest request) {
ApiError apiError = new ApiError(LocalDateTime.now(), HttpStatus.INTERNAL_SERVER_ERROR.value(),
"Internal Server Error", e.getMessage(), request.getDescription(false));
return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiError> handleGenericException(Exception e, WebRequest request) {
ApiError apiError = new ApiError(LocalDateTime.now(), HttpStatus.INTERNAL_SERVER_ERROR.value(),
"Internal Server Error", e.getMessage(), request.getDescription(false));
return new ResponseEntity<>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,55 @@
@RequestMapping("/api/v1/member")
public class MemberController {

MemberService memberService;
MemberService memberService;

@Autowired
public MemberController(MemberService memberService) {
this.memberService = memberService;
}
@Autowired
public MemberController(MemberService memberService) {
this.memberService = memberService;
}

@GetMapping
public List<MemberDTO> getAllMembers() {
return memberService.getAllMembers();
}
@GetMapping
public List<MemberDTO> getAllMembers() {
return memberService.getAllMembers();
}

@GetMapping("/{memberId}")
public ResponseEntity<?> getMember(@PathVariable("memberId") Long memberId) {
try {
MemberDTO member = memberService.getMemberById(memberId);
return ResponseEntity.ok(member);
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().body("Invalid member id format");
}
}
@GetMapping("/{memberId}")
public ResponseEntity<?> getMember(@PathVariable("memberId") Long memberId) {
try {
MemberDTO member = memberService.getMemberById(memberId);
return ResponseEntity.ok(member);
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().body("Invalid member id format");
}
}

@PostMapping
public MemberDTO createMember(@RequestBody MemberDTO member) {
return memberService.createMember(member);
}
@PostMapping
public MemberDTO createMember(@RequestBody MemberDTO member) {
return memberService.createMember(member);
}

@PutMapping
public MemberDTO updateMember(@RequestBody MemberDTO member) {
return memberService.updateMember(member);
}
@PutMapping
public MemberDTO updateMember(@RequestBody MemberDTO member) {
return memberService.updateMember(member);
}

@DeleteMapping
public void deleteMember(String memberId) {
memberService.deleteMemberById(Long.parseLong(memberId));
}
@DeleteMapping
public void deleteMember(String memberId) {
memberService.deleteMemberById(Long.parseLong(memberId));
}

@PostMapping("enable/{memberId}")
public void enableMember(@PathVariable("memberId") String memberId) {
memberService.enableMemberById(Long.parseLong(memberId));
}
@PostMapping("enable/{memberId}")
public void enableMember(@PathVariable("memberId") String memberId) {
memberService.enableMemberById(Long.parseLong(memberId));
}

@PostMapping("disable/{memberId}")
public void disableMember(@PathVariable("memberId") String memberId) {
memberService.disableMemberById(Long.parseLong(memberId));
}
@PostMapping("disable/{memberId}")
public void disableMember(@PathVariable("memberId") String memberId) {
memberService.disableMemberById(Long.parseLong(memberId));
}

@PutMapping("reset_password")
public void resetPassword(@RequestBody String memberId, @RequestBody String newPassword) {
memberService.resetPassword(Long.parseLong(memberId), newPassword);
}
@PutMapping("reset_password")
public void resetPassword(@RequestBody String memberId, @RequestBody String newPassword) {
memberService.resetPassword(Long.parseLong(memberId), newPassword);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,46 @@
@RequestMapping("/api/v1/team/")
public class TeamController {

@Autowired
TeamService teamService;

@GetMapping("all")
public List<Team> getAllTeams() {
return teamService.getAllTeams();
}

@GetMapping
public Team getTeam(@Param("teamId") String teamId) {
return teamService.getTeamById(Long.parseLong(teamId));
}

@PostMapping
public Team createTeam(@RequestBody Team team) {
return teamService.createTeam(team);
}

@PutMapping
public Team updateTeam(@RequestBody Team team) {
return teamService.updateTeam(team);
}

@DeleteMapping
public void deleteTeam(String teamId) {
teamService.deleteTeam(Long.parseLong(teamId));
}

@GetMapping("teamLead/{teamId}")
public Member getTeamLeadById(@PathVariable("teamId") String teamId) {
return teamService.getTeamLeadById(Long.parseLong(teamId));
}

@GetMapping("productManager/{teamId}")
public Member getProductManagerById(@PathVariable("teamId") String teamId) {
return teamService.getProjectManagerById(Long.parseLong(teamId));
}

@GetMapping("designer/{teamId}")
public Member getDesignerById(@PathVariable("teamId") String teamId) {
return teamService.getDesignerById(Long.parseLong(teamId));
}
@Autowired
TeamService teamService;

@GetMapping("all")
public List<Team> getAllTeams() {
return teamService.getAllTeams();
}

@GetMapping
public Team getTeam(@Param("teamId") String teamId) {
return teamService.getTeamById(Long.parseLong(teamId));
}

@PostMapping
public Team createTeam(@RequestBody Team team) {
return teamService.createTeam(team);
}

@PutMapping
public Team updateTeam(@RequestBody Team team) {
return teamService.updateTeam(team);
}

@DeleteMapping
public void deleteTeam(String teamId) {
teamService.deleteTeam(Long.parseLong(teamId));
}

@GetMapping("teamLead/{teamId}")
public Member getTeamLeadById(@PathVariable("teamId") String teamId) {
return teamService.getTeamLeadById(Long.parseLong(teamId));
}

@GetMapping("productManager/{teamId}")
public Member getProductManagerById(@PathVariable("teamId") String teamId) {
return teamService.getProjectManagerById(Long.parseLong(teamId));
}

@GetMapping("designer/{teamId}")
public Member getDesignerById(@PathVariable("teamId") String teamId) {
return teamService.getDesignerById(Long.parseLong(teamId));
}
}
40 changes: 16 additions & 24 deletions src/main/java/com/sitblueprint/admin/dtos/member/MemberDTO.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sitblueprint.admin.dtos.member;


import com.sitblueprint.admin.model.users.Member;
import com.sitblueprint.admin.model.users.Role;
import java.time.LocalDate;
Expand All @@ -18,28 +17,21 @@
@NoArgsConstructor
@AllArgsConstructor
public class MemberDTO {
private Long id;
private String name;
private String username;
private String email;
private boolean isActive;
private LocalDate dateJoined;
private Set<RoleDTO> roles;
TeamSummaryDTO team;
private Long id;
private String name;
private String username;
private String email;
private boolean isActive;
private LocalDate dateJoined;
private Set<RoleDTO> roles;
TeamSummaryDTO team;

public Member toEntity() {
return Member.builder()
.id(this.id)
.name(this.name)
.username(this.username)
.email(this.email)
.dateJoined(this.dateJoined)
.isActive(this.isActive)
.roles(this.roles.stream()
.map(roleDTO -> Role.builder()
.id(roleDTO.getId())
.name(roleDTO.getName())
.build()).collect(Collectors.toSet()))
.build();
}
public Member toEntity() {
return Member.builder().id(this.id).name(this.name).username(this.username).email(this.email)
.dateJoined(this.dateJoined).isActive(this.isActive)
.roles(this.roles.stream()
.map(roleDTO -> Role.builder().id(roleDTO.getId()).name(roleDTO.getName()).build())
.collect(Collectors.toSet()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
@AllArgsConstructor
@Builder
public class OrganizationSummaryDTO {
private Long id;
private String name;
private Long id;
private String name;
}
Loading

0 comments on commit 5358b27

Please sign in to comment.