Skip to content

Commit

Permalink
Updated entities (#38)
Browse files Browse the repository at this point in the history
* feat: updated entities

* chore: Changed postgres version

* feat: Changed member joined date to localdate

* fix: removed auth call to authelia api

* added dtos

* started login and auth logic

* feat: docker-compose

* Added TokenService

---------

Co-authored-by: Ivan Farfan <ivanfarfan@ses-miyengar-lab-13.mynetworksettings.com>
Co-authored-by: miguel-merlin <mmerlin@stevens.edu>
  • Loading branch information
3 people authored Nov 23, 2024
1 parent af640e7 commit 0e1f38e
Show file tree
Hide file tree
Showing 36 changed files with 1,141 additions and 596 deletions.
74 changes: 19 additions & 55 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,75 +1,39 @@
plugins {
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"
id 'jacoco'
id 'application'
id 'java'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
}

group = 'com.sitblueprint'
version = '0.0.1-SNAPSHOT'
mainClassName = 'com.sitblueprint.admin.BlueprintAdmin'

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

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

repositories {
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
}
mavenCentral()
}

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'
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'
}

jacocoTestReport {
dependsOn test
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.10
}
}
}
}
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()
finalizedBy jacocoTestCoverageVerification
useJUnitPlatform()
}
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
postgres:
image: postgres:10.5
image: postgres:latest
restart: always
environment:
- POSTGRES_USER=blueprint_admin_backend
Expand All @@ -14,4 +14,4 @@ services:
- '5432:5432'
volumes:
- ./postgres-data:/var/lib/postgresql/data
- ./initdb:/docker-entrypoint-initdb.d
- ./initdb:/docker-entrypoint-initdb.d
8 changes: 4 additions & 4 deletions initdb/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
email VARCHAR(255) UNIQUE,
password VARCHAR(255) NOT NULL,
is_active BOOLEAN,
date_joined TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
date_joined DATE DEFAULT CURRENT_DATE NOT NULL,
PRIMARY KEY (id)
);

Expand All @@ -45,7 +45,7 @@
team_lead_id BIGINT,
project_manager_id BIGINT,
designer_id BIGINT,
date_created TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
date_created DATE DEFAULT CURRENT_DATE NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (organization_id) REFERENCES organizations(id),
FOREIGN KEY (team_lead_id) REFERENCES members(id),
Expand Down Expand Up @@ -81,8 +81,8 @@

-- Insert sample teams
INSERT INTO teams (organization_id, name, team_lead_id, project_manager_id, designer_id, date_created) VALUES
(1, 'Frontend Team', NULL, NULL, NULL, '2021-09-01 00:00:00'),
(2, 'Backend Team', NULL, NULL, NULL, '2024-10-01 00:00:00');
(1, 'Frontend Team', NULL, NULL, NULL, '2021-09-01'),
(2, 'Backend Team', NULL, NULL, NULL, '2024-10-01');

-- Insert sample members
INSERT INTO members (team_id, name, username, email, password, is_active) VALUES
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.sitblueprint.admin.controller.exceptions;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import lombok.Setter;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class ApiError {
private LocalDateTime timestamp;
private int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@

import java.time.LocalDateTime;
import java.util.NoSuchElementException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {
@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);
}
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(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
@@ -0,0 +1,66 @@
package com.sitblueprint.admin.controller.users;

import com.sitblueprint.admin.dtos.member.MemberDTO;
import com.sitblueprint.admin.service.users.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/member")
public class MemberController {

MemberService memberService;

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

@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");
}
}

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

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

@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("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);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sitblueprint.admin.controller.users;

import com.sitblueprint.admin.model.users.Team;
import com.sitblueprint.admin.model.users.User;
import com.sitblueprint.admin.model.users.Member;
import com.sitblueprint.admin.service.users.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
Expand All @@ -13,41 +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 User getTeamLeadById(@PathVariable("teamId") String teamId) {
return teamService.getTeamLeadById(Long.parseLong(teamId));
}

@GetMapping("productManager/{teamId}")
public User getProductManagerById(@PathVariable("teamId") String teamId) {
return teamService.getProductManagerById(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));
}
}
Loading

0 comments on commit 0e1f38e

Please sign in to comment.