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

Feature/blogs #17

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c36897f
created blogs interface
sofia-m12 Oct 4, 2024
e72d2c0
created blog model, moved blogsService to service/blogs
sofia-m12 Oct 8, 2024
3d67ced
Merge branch 'main' of https://github.com/stevensblueprint/blueprint_…
sofia-m12 Oct 9, 2024
463e117
created blogs controller, repository, serviceImpl
sofia-m12 Oct 9, 2024
19c97b4
updated BlogsServiceImpl
sofia-m12 Oct 11, 2024
9de67e5
Merge branch 'main' of https://github.com/stevensblueprint/blueprint_…
sofia-m12 Oct 22, 2024
0a4fcd3
added CRUD logic in blog service
sofia-m12 Oct 22, 2024
2fcb544
added attendance user endpoints
Oct 30, 2024
9370976
created attendance class
Nov 6, 2024
b2851b4
moved attendance service and controller to user service and controller
Nov 6, 2024
0599ee5
created attendance endpoints by team ID
Nov 6, 2024
195f6a9
added optional parameters to multiple-attendance retrieving endpoints…
Nov 6, 2024
b2d50db
Added mock data set to init
Nov 6, 2024
f1baf7c
Merge branch 'main' of github.com:stevensblueprint/blueprint_admin_ba…
miguel-merlin Nov 14, 2024
1931db2
created user-attendance table for testing attendance
Nov 22, 2024
87b5416
modified attendance endpoints to change attendance value rather than …
Nov 22, 2024
ea3d4da
Merge branch 'main' of https://github.com/stevensblueprint/blueprint_…
Nov 22, 2024
1ff6598
Merge branch 'main' of github.com:stevensblueprint/blueprint_admin_ba…
miguel-merlin Nov 23, 2024
df9e1ac
changed constructor of TeamService
miguel-merlin Nov 23, 2024
a21922b
formatting
miguel-merlin Nov 23, 2024
bba6fdf
Added MemberService testing
miguel-merlin Nov 23, 2024
254394f
added test for team
miguel-merlin Nov 23, 2024
a42dde7
fix formatting
miguel-merlin Nov 23, 2024
926c1b3
lowered test code verification
miguel-merlin Nov 23, 2024
96ef934
Merge branch 'feature/blogs' of https://github.com/stevensblueprint/b…
sofia-m12 Nov 23, 2024
2e6ef08
added mappings for blogs endpoints
sofia-m12 Nov 23, 2024
ca13461
Merge branch 'main' of github.com:stevensblueprint/blueprint_admin_ba…
miguel-merlin Dec 4, 2024
8e95736
Merge branch 'feature/blogs' of github.com:stevensblueprint/blueprint…
miguel-merlin Dec 4, 2024
d999355
Merge branch 'feature/attendance' of github.com:stevensblueprint/blue…
miguel-merlin Dec 4, 2024
8da48f0
removed attendance
miguel-merlin Dec 4, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.sitblueprint.admin.controller.blogs;

import com.sitblueprint.admin.model.blogs.Blog;
import com.sitblueprint.admin.service.blogs.BlogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/api/v1/blog/")
public class BlogController {
@Autowired
BlogsService blogsService;

@GetMapping("all")
public List<Blog> getAllBlogs(){
return blogsService.getAllBlogs();
}

@GetMapping("/{blogId}")
public ResponseEntity<?> getBlog(@PathVariable("blogId") Long blogId) {
try {
Blog blog = blogsService.getBlogById(blogId);
return ResponseEntity.ok(blog);
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().body("Invalid blog id format");
}
}

@PostMapping("/create")
public Blog createBlog(@RequestBody Blog blog) {
return blogsService.createBlog(blog);
}

@PutMapping("/update")
public Blog updateBlog(@RequestBody Blog blog) {
return blogsService.updateBlog(blog);
}

@DeleteMapping("/{blogId}")
public void deleteBlog(String blogId) {
blogsService.deleteBlogById(Long.parseLong(blogId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,4 @@ public Member getProductManagerById(@PathVariable("teamId") String teamId) {
public Member getDesignerById(@PathVariable("teamId") String teamId) {
return teamService.getDesignerById(Long.parseLong(teamId));
}

@PostMapping("attendance")
public List<Attendance> markTeamAttendance(@RequestParam Long teamId, @RequestParam LocalDateTime date) {
return teamService.markTeamAttendance(teamId, date);
}

@GetMapping("attendance")
public List<Attendance> getTeamAttendance(@RequestParam Long teamId, @RequestParam LocalDateTime date) {
return teamService.getTeamAttendance(teamId, date);
}

@GetMapping("attendance/all")
public List<Attendance> getTeamAllAttendance(@RequestParam Long teamId,
@RequestParam(required = false) LocalDateTime startDate,
@RequestParam(required = false) LocalDateTime endDate) {
return teamService.getTeamAllAttendance(teamId, startDate, endDate);
}

@PutMapping("attendance")
public List<Attendance> updateTeamAttendance(@RequestParam Long teamId, @RequestParam LocalDateTime date) {
return teamService.updateTeamAttendance(teamId, date);
}

@DeleteMapping("attendance")
public void deleteTeamAttendance(@RequestParam Long teamId, @RequestParam LocalDateTime date) {
teamService.deleteTeamAttendance(teamId, date);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sitblueprint.admin.repository.blogs;

import com.sitblueprint.admin.model.blogs.Blog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BlogRepository extends JpaRepository<Blog, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,4 @@

@Repository
public interface AttendanceRepository extends JpaRepository<Attendance, Long> {
List<Attendance> findAllByUserId(Long userId);
Optional<Attendance> findByUserIdAndDate(Long userId, LocalDateTime date);
List<Attendance> findAllByUserIdAndDateBetween(Long userId, LocalDateTime startDate, LocalDateTime endDate);
List<Attendance> findAllByUserIdAndDateAfter(Long userId, LocalDateTime startDate);
List<Attendance> findAllByUserIdAndDateBefore(Long userId, LocalDateTime endDate);
List<Attendance> findAllByTeamId(Long teamId);
List<Attendance> findAllByTeamIdAndDate(Long teamId, LocalDateTime date);
List<Attendance> findAllByTeamIdAndDateBetween(Long teamId, LocalDateTime startDate, LocalDateTime endDate);
List<Attendance> findAllByTeamIdAndDateAfter(Long teamId, LocalDateTime startDate);
List<Attendance> findAllByTeamIdAndDateBefore(Long teamId, LocalDateTime endDate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sitblueprint.admin.service.blogs;

import com.sitblueprint.admin.model.blogs.Blog;

import java.util.List;
public interface BlogsService {
List<Blog> getAllBlogs();

Blog getBlogById(Long blogId);

Blog createBlog(Blog blog);

Blog updateBlog(Blog blog);

void deleteBlogById(Long blogId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.sitblueprint.admin.service.blogs;

import com.sitblueprint.admin.model.blogs.Blog;
import com.sitblueprint.admin.repository.blogs.BlogRepository;
import jakarta.transaction.Transactional;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;

@Service
public class BlogsServiceImpl implements BlogsService {
private static final Logger log = LoggerFactory.getLogger(BlogsServiceImpl.class);
private final BlogRepository blogRepository;

public BlogsServiceImpl(BlogRepository blogRepository) {
this.blogRepository = blogRepository;
}

@Override
public List<Blog> getAllBlogs() {
return blogRepository.findAll();
}

@Override
public Blog getBlogById(Long blogId){
return blogRepository.findById(blogId).orElseThrow(
() -> new NoSuchElementException("Blog with id " + blogId + " was not found")
);
}

@Override
public Blog createBlog(Blog blog){
blog.setDateCreated(LocalDateTime.now());
return blogRepository.save(blog);
}

@Override
public Blog updateBlog(Blog blog){
return blogRepository.saveAndFlush(blog);
}

@Override
public void deleteBlogById(Long blogId){
Optional<Blog> optionalBlogToDelete = blogRepository.findById(blogId);
if(optionalBlogToDelete.isEmpty()){
throw new RuntimeException("Blog with id " + blogId + " was not found");
}
blogRepository.deleteById(blogId);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.sitblueprint.admin.service.users;

import com.sitblueprint.admin.model.users.Attendance;
import com.sitblueprint.admin.model.users.Team;
import com.sitblueprint.admin.model.users.Member;

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

public interface TeamService {
Expand All @@ -23,14 +21,4 @@ public interface TeamService {
Member getProjectManagerById(Long teamId);

Member getDesignerById(Long teamId);

List<Attendance> markTeamAttendance(Long teamId, LocalDateTime date);

List<Attendance> getTeamAttendance(Long teamId, LocalDateTime date);

List<Attendance> getTeamAllAttendance(Long teamId, LocalDateTime startDate, LocalDateTime endDate);

List<Attendance> updateTeamAttendance(Long teamId, LocalDateTime date);

void deleteTeamAttendance(Long teamId, LocalDateTime date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,21 @@

import com.sitblueprint.admin.model.users.Team;
import com.sitblueprint.admin.model.users.Member;
import com.sitblueprint.admin.model.users.Attendance;
import com.sitblueprint.admin.repository.users.MemberRepository;
import com.sitblueprint.admin.repository.users.TeamRepository;
import java.time.LocalDate;
import com.sitblueprint.admin.repository.users.AttendanceRepository;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class TeamServiceImpl implements TeamService {
private final TeamRepository teamRepository;
private final AttendanceRepository attendanceRepository;

public TeamServiceImpl(TeamRepository teamRepository, AttendanceRepository attendanceRepository) {
@Autowired
public TeamServiceImpl(TeamRepository teamRepository) {
this.teamRepository = teamRepository;
this.attendanceRepository = attendanceRepository;
}

@Override
Expand Down Expand Up @@ -78,71 +72,4 @@ public Member getDesignerById(Long teamId) {
return optionalTeam.get().getDesigner();
}

@Override
public List<Attendance> markTeamAttendance(Long teamId, LocalDateTime date) {
Team team = teamRepository.findById(teamId).orElseThrow(() -> new NoSuchElementException("Team not found"));

List<Member> teamMembers = new ArrayList<>(team.getMembers());
List<Attendance> attendanceList = new ArrayList<>();

for (Member member : teamMembers) {
Optional<Attendance> existingAttendance = attendanceRepository.findByUserIdAndDate(member.getId(), date);

if (existingAttendance.isEmpty()) {
// Attendance attendance = new Attendance(null, date, member);
// attendanceList.add(attendanceRepository.save(attendance));
}
}
return attendanceList;
}

@Override
public List<Attendance> getTeamAttendance(Long teamId, LocalDateTime date) {
return attendanceRepository.findAllByTeamIdAndDate(teamId, date);
}

@Override
public List<Attendance> getTeamAllAttendance(Long teamId, LocalDateTime startDate, LocalDateTime endDate) {
if (startDate != null && endDate != null) {
return attendanceRepository.findAllByTeamIdAndDateBetween(teamId, startDate, endDate);
} else if (startDate != null) {
return attendanceRepository.findAllByTeamIdAndDateAfter(teamId, startDate);
} else if (endDate != null) {
return attendanceRepository.findAllByTeamIdAndDateBefore(teamId, endDate);
} else {
return attendanceRepository.findAllByTeamId(teamId);
}
}

@Override
public List<Attendance> updateTeamAttendance(Long teamId, LocalDateTime date) {
Team team = teamRepository.findById(teamId).orElseThrow(() -> new NoSuchElementException("Team not found"));

List<Member> teamMembers = new ArrayList<>(team.getMembers());
List<Attendance> attendanceList = new ArrayList<>();

for (Member member : teamMembers) {
Optional<Attendance> existingAttendance = attendanceRepository.findByUserIdAndDate(member.getId(), date);

if (existingAttendance.isEmpty()) {
// Attendance attendance = new Attendance(null, date, member);
// attendanceList.add(attendanceRepository.save(attendance));
} else {
attendanceRepository.delete(existingAttendance.get());
}
}

return attendanceList;
}

@Override
public void deleteTeamAttendance(Long teamId, LocalDateTime date) {
List<Attendance> attendances = attendanceRepository.findAllByTeamIdAndDate(teamId, date);

if (attendances.isEmpty()) {
throw new NoSuchElementException("No attendance records found.");
}

attendanceRepository.deleteAll(attendances);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sitblueprint.admin.service.users;

import com.sitblueprint.admin.model.users.Team;
import com.sitblueprint.admin.repository.users.AttendanceRepository;
import com.sitblueprint.admin.repository.users.TeamRepository;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class TeamServiceTest {
@Mock
TeamRepository teamRepository;

@Mock
AttendanceRepository attendanceRepository;

private TeamService teamService;
private Team testTeam;
}
Loading