더북(TheBook)

다음 코드는 컨트롤러 클래스에서 만들 여러 서비스 로직을 개발하는 데 사용될 서비스 클래스를 보여 준다.

코드 3-3 LicenseService 클래스

package com.optimagrowth.license.service; 
import java.util.Random; 
import org.springframework.stereotype.Service; 
import org.springframework.util.StringUtils; 
import com.optimagrowth.license.model.License;
 
@Service
public class LicenseService {
    public License getLicense(String licenseId, String organizationId) { 
        License license = new License();
        license.setId(new Random().nextInt(1000)); 
        license.setLicenseId(licenseId); 
        license.setOrganizationId(organizationId); 
        license.setDescription("Software product");
        license.setProductName("Ostock"); 
        license.setLicenseType("full"); 
        return license;
    }

    public String createLicense(License license, String organizationId) {
        String responseMessage = null;
        if (license != null) {
            license.setOrganizationId(organizationId);
            responseMessage = String.format("This is the post and the 
                    object is: %s", license.toString()); 
        }
        return responseMessage;
    } 

    public String updateLicense(License license, String organizationId) {
        String responseMessage = null;
        if (license != null) {
            license.setOrganizationId(organizationId); 
            responseMessage = String.format("This is the put and 
                    the object is: %s", license.toString()); 
        } 
        return responseMessage;
    }

    public String deleteLicense(String licenseId, String organizationId) { 
        String responseMessage = null;
        responseMessage = String.format("Deleting license with id %s for 
                       the organization %s", licenseId, organizationId);
        return responseMessage;
    } 
}
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.