Checkpoint kinda workls. Ill take a nap and go bacjk to work
This commit is contained in:
		@@ -19,6 +19,8 @@ public class Assignment {
 | 
			
		||||
    @JoinColumn(name = "commision_id")
 | 
			
		||||
    private Commision commision;
 | 
			
		||||
 | 
			
		||||
    public Assignment() {
 | 
			
		||||
    public Assignment(Groups group, Commision commision) {
 | 
			
		||||
        this.commision = commision;
 | 
			
		||||
        this.group = group;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,25 +1,36 @@
 | 
			
		||||
package com.plannaplan.entities;
 | 
			
		||||
 | 
			
		||||
import java.sql.Timestamp;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import javax.persistence.Entity;
 | 
			
		||||
import javax.persistence.GeneratedValue;
 | 
			
		||||
import javax.persistence.GenerationType;
 | 
			
		||||
import javax.persistence.Id;
 | 
			
		||||
import javax.persistence.JoinColumn;
 | 
			
		||||
import javax.persistence.ManyToOne;
 | 
			
		||||
import javax.persistence.OneToMany;
 | 
			
		||||
import javax.persistence.OneToOne;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
public class Commision {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
    private Long id;
 | 
			
		||||
    @ManyToOne
 | 
			
		||||
    @OneToOne
 | 
			
		||||
    @JoinColumn(name = "owner_id")
 | 
			
		||||
    private User commisionOwner;
 | 
			
		||||
    private Timestamp commisionDate;
 | 
			
		||||
 | 
			
		||||
    public Commision() {
 | 
			
		||||
    @OneToMany(mappedBy = "commision")
 | 
			
		||||
    private List<Assignment> assignments;
 | 
			
		||||
 | 
			
		||||
    public Commision(User user) {
 | 
			
		||||
        this.commisionDate = new Timestamp(System.currentTimeMillis());
 | 
			
		||||
        this.commisionOwner = user;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Long getId() {
 | 
			
		||||
        return this.id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Timestamp getCommisionDate() {
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
package com.plannaplan.repositories;
 | 
			
		||||
 | 
			
		||||
import com.plannaplan.entities.Commision;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
			
		||||
import org.springframework.stereotype.Repository;
 | 
			
		||||
 | 
			
		||||
@Repository
 | 
			
		||||
public interface CommisionRepository extends JpaRepository<Commision, Long> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package com.plannaplan.services;
 | 
			
		||||
 | 
			
		||||
import com.plannaplan.abstracts.EventWatcher;
 | 
			
		||||
import com.plannaplan.entities.Assignment;
 | 
			
		||||
import com.plannaplan.repositories.AssignmentRepository;
 | 
			
		||||
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
@@ -14,4 +15,8 @@ public class AssignmentService extends EventWatcher {
 | 
			
		||||
    public AssignmentService() {
 | 
			
		||||
        super();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void save(Assignment assignment) {
 | 
			
		||||
        this.repo.save(assignment);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
package com.plannaplan.services;
 | 
			
		||||
 | 
			
		||||
import com.plannaplan.entities.Commision;
 | 
			
		||||
import com.plannaplan.repositories.CommisionRepository;
 | 
			
		||||
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class CommisionService {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private CommisionRepository repo;
 | 
			
		||||
 | 
			
		||||
    public CommisionService() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Commision save(Commision commision) {
 | 
			
		||||
        this.repo.save(commision);
 | 
			
		||||
        return commision;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package com.plannaplan.services;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
import com.plannaplan.entities.Groups;
 | 
			
		||||
import com.plannaplan.repositories.GroupRepository;
 | 
			
		||||
@@ -28,11 +29,15 @@ public class GroupService {
 | 
			
		||||
        this.repo.save(group);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void delete(Groups groups){
 | 
			
		||||
    public void delete(Groups groups) {
 | 
			
		||||
        this.repo.delete(groups);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getGroupsAmmount(){
 | 
			
		||||
        return (int)this.repo.count();
 | 
			
		||||
    public int getGroupsAmmount() {
 | 
			
		||||
        return (int) this.repo.count();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<Groups> getGroupById(Long id) {
 | 
			
		||||
        return this.repo.findById(id);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,58 @@
 | 
			
		||||
package com.plannaplan.controllers;
 | 
			
		||||
 | 
			
		||||
import org.springframework.web.bind.annotation.CrossOrigin;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
import com.plannaplan.App;
 | 
			
		||||
import com.plannaplan.Controller;
 | 
			
		||||
import com.plannaplan.entities.Assignment;
 | 
			
		||||
import com.plannaplan.entities.Commision;
 | 
			
		||||
import com.plannaplan.entities.Groups;
 | 
			
		||||
import com.plannaplan.models.ConfigData;
 | 
			
		||||
import com.plannaplan.services.AssignmentService;
 | 
			
		||||
import com.plannaplan.services.CommisionService;
 | 
			
		||||
import com.plannaplan.services.GroupService;
 | 
			
		||||
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.http.HttpStatus;
 | 
			
		||||
import org.springframework.http.ResponseEntity;
 | 
			
		||||
import org.springframework.web.bind.annotation.PostMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestParam;
 | 
			
		||||
import org.springframework.web.multipart.MultipartFile;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin
 | 
			
		||||
@RequestMapping("/api/" + App.API_VERSION + "/commisions")
 | 
			
		||||
public class CommisionController {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private CommisionService commisionService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private GroupService groupServcicxe;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private AssignmentService assignmentService;
 | 
			
		||||
 | 
			
		||||
    public CommisionController() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/add")
 | 
			
		||||
    public String addCommision(@RequestParam("id") Long id) {
 | 
			
		||||
        Groups group = this.groupServcicxe.getGroupById(id).orElseThrow(() -> new NullPointerException());
 | 
			
		||||
        Commision com = new Commision(null);
 | 
			
		||||
        // Object principal =
 | 
			
		||||
        // SecurityContextHolder.getContext().getAuthentication().getPrincipal();
 | 
			
		||||
 | 
			
		||||
        Assignment a = new Assignment(group, com);
 | 
			
		||||
 | 
			
		||||
        this.commisionService.save(com);
 | 
			
		||||
        this.assignmentService.save(a);
 | 
			
		||||
 | 
			
		||||
        return "Success";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user