From 1b1a8236fcf1affed261ab21252c5adb631eb10a Mon Sep 17 00:00:00 2001 From: Bradley Griffel Date: Wed, 9 Oct 2024 12:52:59 -0400 Subject: [PATCH 01/20] added npo class --- src/main/java/com/sitblueprint/admin/model/npos/NPO.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/com/sitblueprint/admin/model/npos/NPO.java diff --git a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java new file mode 100644 index 0000000..e0f6aa4 --- /dev/null +++ b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java @@ -0,0 +1,4 @@ +package com.sitblueprint.admin.model.npos; + +public class NPO { +} From 75b8656c1310fa29db1f71c087b4fe43e884fc76 Mon Sep 17 00:00:00 2001 From: Daniel Ingwer Date: Wed, 9 Oct 2024 13:01:15 -0400 Subject: [PATCH 02/20] added name property to NPO model --- src/main/java/com/sitblueprint/admin/model/npos/NPO.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java index e0f6aa4..629e852 100644 --- a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java +++ b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java @@ -1,4 +1,5 @@ package com.sitblueprint.admin.model.npos; public class NPO { + private String name; } From e87f6595b621270ef76f0ba8dd0714b7f2c8167a Mon Sep 17 00:00:00 2001 From: Bradley Griffel Date: Wed, 9 Oct 2024 19:04:20 -0400 Subject: [PATCH 03/20] started adding the assigned team in NPO --- .../com/sitblueprint/admin/model/npos/NPO.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java index 629e852..0cf67b8 100644 --- a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java +++ b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java @@ -1,5 +1,19 @@ package com.sitblueprint.admin.model.npos; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import com.sitblueprint.admin.model.users.Team; + public class NPO { private String name; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn() + private Team team_assigned; + + + + } From 1511757e1982bbc87b18a1631193c73a3d033655 Mon Sep 17 00:00:00 2001 From: Daniel Ingwer Date: Wed, 16 Oct 2024 18:41:17 -0400 Subject: [PATCH 04/20] created npo model --- .../com/sitblueprint/admin/model/npos/NPO.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java index 0cf67b8..b4c624a 100644 --- a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java +++ b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java @@ -6,14 +6,21 @@ import lombok.NoArgsConstructor; import com.sitblueprint.admin.model.users.Team; +import java.time.LocalDate; + +@Entity public class NPO { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + private String name; @OneToOne(fetch = FetchType.LAZY) - @JoinColumn() - private Team team_assigned; - - + @JoinColumn(name = "team_id") + private Team teamAssigned; + private String url; + private LocalDate dateOfRecruitment; } From 23559031df64e8e246d72cb16a1173d77c2cbce8 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 30 Oct 2024 18:16:05 -0400 Subject: [PATCH 05/20] Created Files for NPO Endpoints --- .../sitblueprint/admin/controller/users/NPOController.java | 6 ++++++ .../com/sitblueprint/admin/service/users/NPOService.java | 4 ++++ .../sitblueprint/admin/service/users/NPOServiceImpl.java | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 src/main/java/com/sitblueprint/admin/controller/users/NPOController.java create mode 100644 src/main/java/com/sitblueprint/admin/service/users/NPOService.java create mode 100644 src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java diff --git a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java new file mode 100644 index 0000000..4419cb4 --- /dev/null +++ b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java @@ -0,0 +1,6 @@ +package com.sitblueprint.admin.controller.users; + + + +public class NPOController { +} diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOService.java b/src/main/java/com/sitblueprint/admin/service/users/NPOService.java new file mode 100644 index 0000000..9e4502b --- /dev/null +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOService.java @@ -0,0 +1,4 @@ +package com.sitblueprint.admin.service.users; + +public interface NPOService { +} diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java new file mode 100644 index 0000000..12fdc1d --- /dev/null +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java @@ -0,0 +1,4 @@ +package com.sitblueprint.admin.service.users; + +public class NPOServiceImpl { +} From 117398e525497613f9f75919e41acdc7010a785d Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 30 Oct 2024 18:29:44 -0400 Subject: [PATCH 06/20] Created NPORepository and templates for service CRUD implementation --- .../admin/repository/users/NPORepository.java | 8 +++++++ .../admin/service/users/NPOService.java | 16 ++++++++++++- .../admin/service/users/NPOServiceImpl.java | 23 ++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/sitblueprint/admin/repository/users/NPORepository.java diff --git a/src/main/java/com/sitblueprint/admin/repository/users/NPORepository.java b/src/main/java/com/sitblueprint/admin/repository/users/NPORepository.java new file mode 100644 index 0000000..a68ef43 --- /dev/null +++ b/src/main/java/com/sitblueprint/admin/repository/users/NPORepository.java @@ -0,0 +1,8 @@ +package com.sitblueprint.admin.repository.users; + +import com.sitblueprint.admin.model.npos.NPO; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +public interface NPORepository extends JpaRepository { +} diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOService.java b/src/main/java/com/sitblueprint/admin/service/users/NPOService.java index 9e4502b..9561b62 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOService.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOService.java @@ -1,4 +1,18 @@ package com.sitblueprint.admin.service.users; +import com.sitblueprint.admin.model.npos.NPO; +import com.sitblueprint.admin.model.users.Team; + +import java.util.List; + public interface NPOService { -} + List getAllNPOs(); + + NPO getNPOById(Long id); + + NPO createNPO(NPO npo); + + NPO updateNPO(NPO npo); + + void deleteNPOById(Long id); +} \ No newline at end of file diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java index 12fdc1d..af16f17 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java @@ -1,4 +1,25 @@ package com.sitblueprint.admin.service.users; -public class NPOServiceImpl { +import com.sitblueprint.admin.model.npos.NPO; + +public class NPOServiceImpl implements NPOService { + List getAllNPOs() { + + } + + NPO getNPOById(Long id) { + + } + + NPO createNPO(NPO npo) { + + } + + NPO updateNPO(NPO npo) { + + } + + void deleteNPOById(Long id) { + + } } From a750109a98438f827438d3378f356b9db0f526a8 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 30 Oct 2024 18:32:05 -0400 Subject: [PATCH 07/20] Added public access modifier --- .../admin/service/users/NPOServiceImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java index af16f17..7473d90 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java @@ -2,24 +2,26 @@ import com.sitblueprint.admin.model.npos.NPO; +import java.util.List; + public class NPOServiceImpl implements NPOService { - List getAllNPOs() { + public List getAllNPOs() { } - NPO getNPOById(Long id) { + public NPO getNPOById(Long id) { } - NPO createNPO(NPO npo) { + public NPO createNPO(NPO npo) { } - NPO updateNPO(NPO npo) { + public NPO updateNPO(NPO npo) { } - void deleteNPOById(Long id) { + public void deleteNPOById(Long id) { } } From 67e6fcf855995845d56f390acbc46cce97f29744 Mon Sep 17 00:00:00 2001 From: Daniel Ingwer Date: Wed, 30 Oct 2024 18:45:55 -0400 Subject: [PATCH 08/20] commited first 3 methods of NPOServiceImpl --- .../admin/service/users/NPOServiceImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java index 7473d90..305536a 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java @@ -1,16 +1,26 @@ package com.sitblueprint.admin.service.users; import com.sitblueprint.admin.model.npos.NPO; +import com.sitblueprint.admin.repository.users.NPORepository; import java.util.List; public class NPOServiceImpl implements NPOService { - public List getAllNPOs() { + NPORepository npoRepository; + + public NPOServiceImpl(NPORepository npoRepository) { + this.npoRepository = npoRepository; } - public NPO getNPOById(Long id) { + @Override + public List getAllNPOs() { + return npoRepository.findAll(); + } + @Override + public NPO getNPOById(Long id) { + return npoRepository.findById(id).orElse(null); } public NPO createNPO(NPO npo) { From 2d2601d3d7fb57183b2e3149c98d94db4e7b6bd2 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 30 Oct 2024 18:54:51 -0400 Subject: [PATCH 09/20] Controller template, fixes in NPO model --- .../admin/controller/users/NPOController.java | 19 +++++++++++++++++++ .../sitblueprint/admin/model/npos/NPO.java | 5 +++++ .../admin/repository/users/NPORepository.java | 1 + 3 files changed, 25 insertions(+) diff --git a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java index 4419cb4..c47069a 100644 --- a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java +++ b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java @@ -1,6 +1,25 @@ package com.sitblueprint.admin.controller.users; +import com.sitblueprint.admin.model.npos.NPO; +import com.sitblueprint.admin.service.users.NPOService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.repository.query.Param; +import org.springframework.web.bind.annotation.*; +import java.util.List; +@RestController +@RequestMapping("/api/v1/npos/") public class NPOController { + + @Autowired + NPOService npoService; + + public List getAllNPOs() {} + + public NPO getNPOById() {} + + public NPO createNPO() {} + + public void deleteNPO() {} } diff --git a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java index b4c624a..2c7abc0 100644 --- a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java +++ b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java @@ -9,6 +9,10 @@ import java.time.LocalDate; @Entity +@Table(name = "npos") +@Data +@NoArgsConstructor +@AllArgsConstructor public class NPO { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -22,5 +26,6 @@ public class NPO { private String url; + @Column(nullable = false) private LocalDate dateOfRecruitment; } diff --git a/src/main/java/com/sitblueprint/admin/repository/users/NPORepository.java b/src/main/java/com/sitblueprint/admin/repository/users/NPORepository.java index a68ef43..9390a6a 100644 --- a/src/main/java/com/sitblueprint/admin/repository/users/NPORepository.java +++ b/src/main/java/com/sitblueprint/admin/repository/users/NPORepository.java @@ -4,5 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +@Repository public interface NPORepository extends JpaRepository { } From 9d73f330a24f807382c4302b9f6878fe025fcf03 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Thu, 31 Oct 2024 14:41:33 -0400 Subject: [PATCH 10/20] Implemented NPOs Controller, Marked NPO Service as @Service --- .../admin/controller/users/NPOController.java | 12 ++++++++---- .../admin/service/users/NPOServiceImpl.java | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java index c47069a..1a52fb2 100644 --- a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java +++ b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java @@ -15,11 +15,15 @@ public class NPOController { @Autowired NPOService npoService; - public List getAllNPOs() {} + @GetMapping("all") + public List getAllNPOs() { return npoService.getAllNPOs(); } - public NPO getNPOById() {} + @GetMapping + public NPO getNPOById(@Param("npoId") String npoId) { return npoService.getNPOById(Long.parseLong(npoId)); } - public NPO createNPO() {} + @PostMapping + public NPO createNPO(@RequestBody NPO npo) { return npoService.createNPO(npo); } - public void deleteNPO() {} + @DeleteMapping + public void deleteNPO(String npoId) { npoService.deleteNPOById(Long.parseLong(npoId)); } } diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java index 7473d90..e2e544a 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java @@ -1,9 +1,11 @@ package com.sitblueprint.admin.service.users; import com.sitblueprint.admin.model.npos.NPO; +import org.springframework.stereotype.Service; import java.util.List; +@Service public class NPOServiceImpl implements NPOService { public List getAllNPOs() { From 65baeec5e037141146d676b0b5c6eb6922a02c79 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Thu, 31 Oct 2024 14:54:33 -0400 Subject: [PATCH 11/20] Fixed NPOs model to better fit schema, Resolved init.sql syntax errors --- initdb/init.sql | 5 ++--- src/main/java/com/sitblueprint/admin/model/npos/NPO.java | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/initdb/init.sql b/initdb/init.sql index 76fd60f..9628475 100644 --- a/initdb/init.sql +++ b/initdb/init.sql @@ -43,14 +43,14 @@ create table npos ( foreign key (team_id) references teams(id), project_proposal_url varchar(255) not null, date_of_recruitment timestamp not null -) +); create table blogs ( id bigint primary key generated always as identity, author varchar(255) not null, title varchar(255) not null, date_created timestamp not null -) +); alter table users add constraint fk_team_id @@ -64,7 +64,6 @@ alter table teams add constraint fk_team_manager_id foreign key (team_manager_id) references users(id); - -- Insert users into the users table insert into users (name, username, email, password, has_blueprint_email, is_enabled, date_joined, team_id) values ('John Doe', 'john_doe', 'john@example.com', 'password123', 'yes', true, CURRENT_TIMESTAMP, null), diff --git a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java index 2c7abc0..f2af5a6 100644 --- a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java +++ b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java @@ -18,12 +18,14 @@ public class NPO { @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; + @Column(nullable = false) private String name; @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "team_id") private Team teamAssigned; + @Column(nullable = false) private String url; @Column(nullable = false) From f7f9e55109f94a985adbe54b9b80b9be97b0ca62 Mon Sep 17 00:00:00 2001 From: Daniel Ingwer Date: Wed, 6 Nov 2024 18:12:07 -0500 Subject: [PATCH 12/20] completed NPOServiceImpl.java --- .../admin/service/users/NPOServiceImpl.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java index 305536a..1c69f38 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java @@ -3,6 +3,8 @@ import com.sitblueprint.admin.model.npos.NPO; import com.sitblueprint.admin.repository.users.NPORepository; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; public class NPOServiceImpl implements NPOService { @@ -23,15 +25,19 @@ public NPO getNPOById(Long id) { return npoRepository.findById(id).orElse(null); } + @Override public NPO createNPO(NPO npo) { - + npo.setDateOfRecruitment(LocalDate.now()); + return npoRepository.save(npo); } + @Override public NPO updateNPO(NPO npo) { - + return npoRepository.saveAndFlush(npo); } + @Override public void deleteNPOById(Long id) { - + npoRepository.deleteById(id); } } From 9a83ad46a1fafd068a04400a276ffcde480e4207 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 6 Nov 2024 18:15:34 -0500 Subject: [PATCH 13/20] Added update NPO route for NPO Controller --- .../com/sitblueprint/admin/controller/users/NPOController.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java index 1a52fb2..08131ca 100644 --- a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java +++ b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java @@ -24,6 +24,9 @@ public class NPOController { @PostMapping public NPO createNPO(@RequestBody NPO npo) { return npoService.createNPO(npo); } + @PutMapping + public NPO updateNPO(@RequestBody NPO npo) { return npoService.updateNPO(npo); } + @DeleteMapping public void deleteNPO(String npoId) { npoService.deleteNPOById(Long.parseLong(npoId)); } } From 82dbbaae00dcdfd01eb94b03d5d77a3404725c52 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 6 Nov 2024 18:54:47 -0500 Subject: [PATCH 14/20] Edited SQL init file to allow for testing. Moved NPO FK declaration --- initdb/init.sql | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/initdb/init.sql b/initdb/init.sql index 9628475..46ba20e 100644 --- a/initdb/init.sql +++ b/initdb/init.sql @@ -40,7 +40,8 @@ create table teams ( create table npos ( id bigint primary key generated always as identity, name varchar(255) not null, - foreign key (team_id) references teams(id), + --foreign key (team_id) references teams(id), + team_id bigint, project_proposal_url varchar(255) not null, date_of_recruitment timestamp not null ); @@ -64,12 +65,17 @@ alter table teams add constraint fk_team_manager_id foreign key (team_manager_id) references users(id); +alter table npos + add constraint fk_team_id + foreign key (team_id) references teams(id); + -- Insert users into the users table insert into users (name, username, email, password, has_blueprint_email, is_enabled, date_joined, team_id) values ('John Doe', 'john_doe', 'john@example.com', 'password123', 'yes', true, CURRENT_TIMESTAMP, null), ('Jane Smith', 'jane_smith', 'jane@example.com', 'password456', 'no', true, CURRENT_TIMESTAMP, null), ('Michael Johnson', 'michael_johnson', 'michael@example.com', 'password789', 'yes', true, CURRENT_TIMESTAMP, null); +/* -- Teams Insert insert into teams (name, team_lead_id, team_manager_id, date_created, team_class) values ('Team Alpha', 1, 2, CURRENT_TIMESTAMP, 1), @@ -79,6 +85,18 @@ insert into teams (name, team_lead_id, team_manager_id, date_created, team_class ('Team Epsilon', 9, 10, CURRENT_TIMESTAMP, 1), ('Team Zeta', 11, 12, CURRENT_TIMESTAMP, 2), ('Team Theta', 13, 14, CURRENT_TIMESTAMP, 1); +*/ + +-- Temporary Teams table for NPO testing +-- Above Table caused FK violations +insert into teams (name, team_lead_id, team_manager_id, date_created, team_class) values +('Team Alpha', 1, 2, CURRENT_TIMESTAMP, 1), +('Team Beta', 3, 2, CURRENT_TIMESTAMP, 2), +('Team Gamma', 1, 3, CURRENT_TIMESTAMP, 1), +('Team Delta', 1, 1, CURRENT_TIMESTAMP, 2), +('Team Epsilon', 2, 2, CURRENT_TIMESTAMP, 1), +('Team Zeta', 1, 1, CURRENT_TIMESTAMP, 2), +('Team Theta', 3, 3, CURRENT_TIMESTAMP, 1); -- User_Roles Insert insert into user_roles (user_id, role_id) values From fefca49bf0356a137c3c1ec9269b8939985867af Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 18:17:36 -0500 Subject: [PATCH 15/20] Resolve PR comment: /api/v1/npos/{id} mapping --- .../sitblueprint/admin/controller/users/NPOController.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java index 08131ca..68d5b54 100644 --- a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java +++ b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java @@ -3,7 +3,6 @@ import com.sitblueprint.admin.model.npos.NPO; import com.sitblueprint.admin.service.users.NPOService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.repository.query.Param; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -18,8 +17,8 @@ public class NPOController { @GetMapping("all") public List getAllNPOs() { return npoService.getAllNPOs(); } - @GetMapping - public NPO getNPOById(@Param("npoId") String npoId) { return npoService.getNPOById(Long.parseLong(npoId)); } + @GetMapping("/{id}") + public NPO getNPOById(@PathVariable("id") String npoId) { return npoService.getNPOById(Long.parseLong(npoId)); } @PostMapping public NPO createNPO(@RequestBody NPO npo) { return npoService.createNPO(npo); } From 93f3588a40ba8733778ee4c9b362049b11edb719 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 18:24:09 -0500 Subject: [PATCH 16/20] Commented out setting Date of Recruitment in CRUD --- .../com/sitblueprint/admin/service/users/NPOServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java index d82b732..9ca774b 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java @@ -29,7 +29,7 @@ public NPO getNPOById(Long id) { @Override public NPO createNPO(NPO npo) { - npo.setDateOfRecruitment(LocalDate.now()); + //npo.setDateOfRecruitment(LocalDate.now()); return npoRepository.save(npo); } From bd55346ef297938b9e4511efd7d4b9ee5710f3f2 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 18:27:50 -0500 Subject: [PATCH 17/20] Changed field name to align with npos schema --- src/main/java/com/sitblueprint/admin/model/npos/NPO.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java index f2af5a6..da6afa1 100644 --- a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java +++ b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java @@ -26,7 +26,7 @@ public class NPO { private Team teamAssigned; @Column(nullable = false) - private String url; + private String projectProposalUrl; @Column(nullable = false) private LocalDate dateOfRecruitment; From 75e8639a84aa9208f213ac67580521bc26a58a35 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 18:38:35 -0500 Subject: [PATCH 18/20] Resolved init.sql merge conflict; adjusted NPOS syntax to align with general style. --- initdb/init.sql | 117 +++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 56 deletions(-) diff --git a/initdb/init.sql b/initdb/init.sql index d0745b6..9f1aa12 100644 --- a/initdb/init.sql +++ b/initdb/init.sql @@ -53,69 +53,74 @@ FOREIGN KEY (designer_id) REFERENCES members(id) ); -create table npos ( - id bigint primary key generated always as identity, - name varchar(255) not null, - --foreign key (team_id) references teams(id), - team_id bigint, - project_proposal_url varchar(255) not null, - date_of_recruitment timestamp not null +CREATE TABLE npos ( + id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, + name VARCHAR(255) NOT NULL, + team_id BIGINT, + project_proposal_url VARCHAR(255) not null, + date_of_recruitment TIMESTAMP NOT NULL +) + +-- Create member_roles table (to handle many-to-many relationship between members and roles) +CREATE TABLE member_roles ( + member_id BIGINT NOT NULL, + role_id BIGINT NOT NULL, + PRIMARY KEY (member_id, role_id), + FOREIGN KEY (member_id) REFERENCES members(id), + FOREIGN KEY (role_id) REFERENCES roles(id) ); - -- Create member_roles table (to handle many-to-many relationship between members and roles) - CREATE TABLE member_roles ( - member_id BIGINT NOT NULL, - role_id BIGINT NOT NULL, - PRIMARY KEY (member_id, role_id), - FOREIGN KEY (member_id) REFERENCES members(id), - FOREIGN KEY (role_id) REFERENCES roles(id) - ); - --Create blogs table - CREATE TABLE blogs ( - id BIGINT GENERATED ALWAYS AS IDENTITY, - author VARCHAR(255) NOT NULL, - title VARCHAR(255) NOT NULL, - date_created TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, - PRIMARY KEY (id) - ); +--Create blogs table +CREATE TABLE blogs ( + id BIGINT GENERATED ALWAYS AS IDENTITY, + author VARCHAR(255) NOT NULL, + title VARCHAR(255) NOT NULL, + date_created TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, + PRIMARY KEY (id) +); - ALTER TABLE members - ADD CONSTRAINT fk_team_id FOREIGN KEY (team_id) REFERENCES teams(id); +ALTER TABLE members +ADD CONSTRAINT fk_team_id FOREIGN KEY (team_id) REFERENCES teams(id); - -- Insert sample organizations - INSERT INTO organizations (name, team_lead_id, project_manager_id) VALUES - ('Strawberry Fields', NULL, NULL), - ('Fields of Gold', NULL, NULL); +-- Insert sample organizations +INSERT INTO organizations (name, team_lead_id, project_manager_id) VALUES +('Strawberry Fields', NULL, NULL), +('Fields of Gold', NULL, NULL); - -- 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'); +-- 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'); alter table npos add constraint fk_team_id foreign key (team_id) references teams(id); - -- Insert sample members - INSERT INTO members (team_id, name, username, email, password, is_active) VALUES - (1, 'John Doe', 'jdoe', 'jdoe@stevens.edu', 'password', TRUE), - (2, 'Jane Smith', 'janesmith', 'janesmith@stevens.edu', 'password2', TRUE), - (2, 'Sophia Johnson', 'sophiaj', 'sophiaj@stevens.edu', 'a1234', FALSE); - - -- Insert sample member roles - INSERT INTO member_roles (member_id, role_id) VALUES - (1, 1), -- John Doe as E-BOARD member. - (1, 5), -- John Doe as PROJECT_MANAGER. - (2, 2), -- Jane Smith as TEAM_LEAD. - (3, 3); -- Sophia Johnson as DEVELOPER. - - -- Insert sample blogs - INSERT INTO blogs (author, title, date_created) VALUES - ('John Doe', 'Welcome to the Team!', '2021-09-01 00:00:00'), - ('Jane Smith', 'New Project Launch', '2024-10-01 00:00:00'); - - -- Update Team table to set team_lead_id, project_manager_id and designer_id after members have been inserted - UPDATE teams SET team_lead_id = 2, project_manager_id = 2, designer_id = 3 WHERE id = 1; - UPDATE teams SET team_lead_id = 1, project_manager_id = 1, designer_id = 3 WHERE id = 2; - UPDATE organizations SET team_lead_id = 2, project_manager_id = 2 WHERE id = 1; - UPDATE organizations SET team_lead_id = 1, project_manager_id = 2 WHERE id = 2; + +ALTER TABLE npos + ADD CONSTRAINT fk_team_id + FOREIGN KEY (team_id) references teams(id); + +-- Insert sample members +INSERT INTO members (team_id, name, username, email, password, is_active) VALUES +(1, 'John Doe', 'jdoe', 'jdoe@stevens.edu', 'password', TRUE), +(2, 'Jane Smith', 'janesmith', 'janesmith@stevens.edu', 'password2', TRUE), +(2, 'Sophia Johnson', 'sophiaj', 'sophiaj@stevens.edu', 'a1234', FALSE); + +-- Insert sample member roles +INSERT INTO member_roles (member_id, role_id) VALUES +(1, 1), -- John Doe as E-BOARD member. +(1, 5), -- John Doe as PROJECT_MANAGER. +(2, 2), -- Jane Smith as TEAM_LEAD. +(3, 3); -- Sophia Johnson as DEVELOPER. + +-- Insert sample blogs +INSERT INTO blogs (author, title, date_created) VALUES +('John Doe', 'Welcome to the Team!', '2021-09-01 00:00:00'), +('Jane Smith', 'New Project Launch', '2024-10-01 00:00:00'); + +-- Update Team table to set team_lead_id, project_manager_id and designer_id after members have been inserted +UPDATE teams SET team_lead_id = 2, project_manager_id = 2, designer_id = 3 WHERE id = 1; +UPDATE teams SET team_lead_id = 1, project_manager_id = 1, designer_id = 3 WHERE id = 2; +UPDATE organizations SET team_lead_id = 2, project_manager_id = 2 WHERE id = 1; +UPDATE organizations SET team_lead_id = 1, project_manager_id = 2 WHERE id = 2; From ac26f28d63b0e08cbe9f570595ec1852602f0301 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 18:41:08 -0500 Subject: [PATCH 19/20] Removed duplicate alter statement --- initdb/init.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/initdb/init.sql b/initdb/init.sql index 9f1aa12..a79f4fc 100644 --- a/initdb/init.sql +++ b/initdb/init.sql @@ -92,10 +92,6 @@ INSERT INTO teams (organization_id, name, team_lead_id, project_manager_id, desi (1, 'Frontend Team', NULL, NULL, NULL, '2021-09-01 00:00:00'), (2, 'Backend Team', NULL, NULL, NULL, '2024-10-01 00:00:00'); -alter table npos - add constraint fk_team_id - foreign key (team_id) references teams(id); - ALTER TABLE npos ADD CONSTRAINT fk_team_id FOREIGN KEY (team_id) references teams(id); From 4922c43a7a2db72c1d82fedd06037c7d82284ae3 Mon Sep 17 00:00:00 2001 From: Butter - ThinkWin Date: Wed, 20 Nov 2024 18:43:13 -0500 Subject: [PATCH 20/20] Run ./gradlew :spotlessApply --- README.md | 2 +- .../admin/controller/users/NPOController.java | 44 ++++++++----- .../sitblueprint/admin/model/npos/NPO.java | 24 +++---- .../admin/service/users/NPOService.java | 10 +-- .../admin/service/users/NPOServiceImpl.java | 62 +++++++++---------- 5 files changed, 76 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index ca7a471..409485c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java index 68d5b54..135e969 100644 --- a/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java +++ b/src/main/java/com/sitblueprint/admin/controller/users/NPOController.java @@ -11,21 +11,31 @@ @RequestMapping("/api/v1/npos/") public class NPOController { - @Autowired - NPOService npoService; - - @GetMapping("all") - public List getAllNPOs() { return npoService.getAllNPOs(); } - - @GetMapping("/{id}") - public NPO getNPOById(@PathVariable("id") String npoId) { return npoService.getNPOById(Long.parseLong(npoId)); } - - @PostMapping - public NPO createNPO(@RequestBody NPO npo) { return npoService.createNPO(npo); } - - @PutMapping - public NPO updateNPO(@RequestBody NPO npo) { return npoService.updateNPO(npo); } - - @DeleteMapping - public void deleteNPO(String npoId) { npoService.deleteNPOById(Long.parseLong(npoId)); } + @Autowired + NPOService npoService; + + @GetMapping("all") + public List getAllNPOs() { + return npoService.getAllNPOs(); + } + + @GetMapping("/{id}") + public NPO getNPOById(@PathVariable("id") String npoId) { + return npoService.getNPOById(Long.parseLong(npoId)); + } + + @PostMapping + public NPO createNPO(@RequestBody NPO npo) { + return npoService.createNPO(npo); + } + + @PutMapping + public NPO updateNPO(@RequestBody NPO npo) { + return npoService.updateNPO(npo); + } + + @DeleteMapping + public void deleteNPO(String npoId) { + npoService.deleteNPOById(Long.parseLong(npoId)); + } } diff --git a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java index da6afa1..3d62a8e 100644 --- a/src/main/java/com/sitblueprint/admin/model/npos/NPO.java +++ b/src/main/java/com/sitblueprint/admin/model/npos/NPO.java @@ -14,20 +14,20 @@ @NoArgsConstructor @AllArgsConstructor public class NPO { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; - @Column(nullable = false) - private String name; + @Column(nullable = false) + private String name; - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "team_id") - private Team teamAssigned; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "team_id") + private Team teamAssigned; - @Column(nullable = false) - private String projectProposalUrl; + @Column(nullable = false) + private String projectProposalUrl; - @Column(nullable = false) - private LocalDate dateOfRecruitment; + @Column(nullable = false) + private LocalDate dateOfRecruitment; } diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOService.java b/src/main/java/com/sitblueprint/admin/service/users/NPOService.java index 9561b62..5c6e098 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOService.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOService.java @@ -6,13 +6,13 @@ import java.util.List; public interface NPOService { - List getAllNPOs(); + List getAllNPOs(); - NPO getNPOById(Long id); + NPO getNPOById(Long id); - NPO createNPO(NPO npo); + NPO createNPO(NPO npo); - NPO updateNPO(NPO npo); + NPO updateNPO(NPO npo); - void deleteNPOById(Long id); + void deleteNPOById(Long id); } \ No newline at end of file diff --git a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java index 9ca774b..272cb01 100644 --- a/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java +++ b/src/main/java/com/sitblueprint/admin/service/users/NPOServiceImpl.java @@ -11,35 +11,35 @@ @Service public class NPOServiceImpl implements NPOService { - NPORepository npoRepository; - - public NPOServiceImpl(NPORepository npoRepository) { - this.npoRepository = npoRepository; - } - - @Override - public List getAllNPOs() { - return npoRepository.findAll(); - } - - @Override - public NPO getNPOById(Long id) { - return npoRepository.findById(id).orElse(null); - } - - @Override - public NPO createNPO(NPO npo) { - //npo.setDateOfRecruitment(LocalDate.now()); - return npoRepository.save(npo); - } - - @Override - public NPO updateNPO(NPO npo) { - return npoRepository.saveAndFlush(npo); - } - - @Override - public void deleteNPOById(Long id) { - npoRepository.deleteById(id); - } + NPORepository npoRepository; + + public NPOServiceImpl(NPORepository npoRepository) { + this.npoRepository = npoRepository; + } + + @Override + public List getAllNPOs() { + return npoRepository.findAll(); + } + + @Override + public NPO getNPOById(Long id) { + return npoRepository.findById(id).orElse(null); + } + + @Override + public NPO createNPO(NPO npo) { + // npo.setDateOfRecruitment(LocalDate.now()); + return npoRepository.save(npo); + } + + @Override + public NPO updateNPO(NPO npo) { + return npoRepository.saveAndFlush(npo); + } + + @Override + public void deleteNPOById(Long id) { + npoRepository.deleteById(id); + } }