package org.cmh.backend.OrganizationManagement.service;

import org.cmh.backend.OrganizationManagement.model.Organization;
import org.cmh.backend.OrganizationManagement.repository.OrganizationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrganizationService {
    @Autowired
    private OrganizationRepository organizationRepository;

    public List<Organization> listAll(){
        return organizationRepository.findAll();
    }

    public Organization add(Organization organization){
        return organizationRepository.save(organization);
    }
    public Organization update(Organization organization){
        return organizationRepository.save(organization);
    }
    public String delete(Long id){
        organizationRepository.deleteById(id);
        return "success";
    }
    public Organization getById(Long organizationId){
        return organizationRepository.findByOrganizationId(organizationId);
    }
    public Organization getByName(String name){
        return organizationRepository.findByOrganizationName(name);
    }

}
