Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created NPO Service #23

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1b1a823
added npo class
Mush222 Oct 9, 2024
75b8656
added name property to NPO model
Dingwer Oct 9, 2024
7471e16
Merge branch 'main' of https://github.com/stevensblueprint/blueprint_…
Mush222 Oct 9, 2024
e87f659
started adding the assigned team in NPO
Mush222 Oct 9, 2024
1511757
created npo model
Dingwer Oct 16, 2024
2355903
Created Files for NPO Endpoints
butterman0423 Oct 30, 2024
117398e
Created NPORepository and templates for service
butterman0423 Oct 30, 2024
a750109
Added public access modifier
butterman0423 Oct 30, 2024
67e6fcf
commited first 3 methods of NPOServiceImpl
Dingwer Oct 30, 2024
2d2601d
Controller template, fixes in NPO model
butterman0423 Oct 30, 2024
57c0f0a
Merge branch 'feature/npos' of github.com:stevensblueprint/blueprint_…
butterman0423 Oct 30, 2024
9d73f33
Implemented NPOs Controller, Marked NPO Service as @Service
butterman0423 Oct 31, 2024
65baeec
Fixed NPOs model to better fit schema, Resolved init.sql syntax errors
butterman0423 Oct 31, 2024
f7f9e55
completed NPOServiceImpl.java
Dingwer Nov 6, 2024
19adc8e
Merge branch 'dev/feature/npos' into feature/npos
butterman0423 Nov 6, 2024
fa63ccf
Merge branch 'feature/npos' of github.com:stevensblueprint/blueprint_…
butterman0423 Nov 6, 2024
9a83ad4
Added update NPO route for NPO Controller
butterman0423 Nov 6, 2024
82dbbaa
Edited SQL init file to allow for testing. Moved NPO FK declaration
butterman0423 Nov 6, 2024
fefca49
Resolve PR comment: /api/v1/npos/{id} mapping
butterman0423 Nov 20, 2024
93f3588
Commented out setting Date of Recruitment in CRUD
butterman0423 Nov 20, 2024
bd55346
Changed field name to align with npos schema
butterman0423 Nov 20, 2024
32ea709
Merge branch 'main' into dev/feature/npos
butterman0423 Nov 20, 2024
75e8639
Resolved init.sql merge conflict; adjusted NPOS syntax to align with …
butterman0423 Nov 20, 2024
ac26f28
Removed duplicate alter statement
butterman0423 Nov 20, 2024
4922c43
Run ./gradlew :spotlessApply
butterman0423 Nov 20, 2024
724bacb
Merge branch 'main' into feature/npos
butterman0423 Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions initdb/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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;

@GetMapping("all")
public List<NPO> getAllNPOs() { return npoService.getAllNPOs(); }

@GetMapping
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GetMapping("/{id}")

public NPO getNPOById(@Param("npoId") 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)); }
}
33 changes: 33 additions & 0 deletions src/main/java/com/sitblueprint/admin/model/npos/NPO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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;

import java.time.LocalDate;

@Entity
@Table(name = "npos")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class NPO {
@Id
@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)
private LocalDate dateOfRecruitment;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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;

@Repository
public interface NPORepository extends JpaRepository<NPO, Long> {
}
18 changes: 18 additions & 0 deletions src/main/java/com/sitblueprint/admin/service/users/NPOService.java
Original file line number Diff line number Diff line change
@@ -0,0 +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<NPO> getAllNPOs();

NPO getNPOById(Long id);

NPO createNPO(NPO npo);

NPO updateNPO(NPO npo);

void deleteNPOById(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.sitblueprint.admin.service.users;

import com.sitblueprint.admin.model.npos.NPO;
import com.sitblueprint.admin.repository.users.NPORepository;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class NPOServiceImpl implements NPOService {

NPORepository npoRepository;

public NPOServiceImpl(NPORepository npoRepository) {
this.npoRepository = npoRepository;
}

@Override
public List<NPO> 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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean you want us to remove the function or when it saves the time created?

return npoRepository.save(npo);
}

@Override
public NPO updateNPO(NPO npo) {
return npoRepository.saveAndFlush(npo);
}

@Override
public void deleteNPOById(Long id) {
npoRepository.deleteById(id);
}
}