I wrote a project where I want to display domain info. In my project, it displays information like this. But this is not correct, I want him to display full information
He takes information about domains from the database. I kind of wrote code, but it doesn't display information like this
My code
import java.sql.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;
@Data
@AllArgsConstructor
@ToString
public class TemporaryModel {
Long id;
Long oid;
String name;
Long tld;
String registrant;
String c_admin;
String c_tech;
String c_bill;
Date expired;
}
WhoisResponse
@Data
public class WhoisResponse {
private DomainInfo info;
private Agent agent;
private List<NameServerInfo> nameServerInfos;
public WhoisResponse(DomainInfo info, Agent agent, List<NameServerInfo> nameServerInfos) {
this.info = info;
this.agent = agent;
this.nameServerInfos = nameServerInfos;
}
}
Agent
@Data
public class Agent {
String NIC;
String name;
String phone;
String fax;
String email;
}
DomainInfo
@Data
@AllArgsConstructor
public class DomainInfo {
String domainName;
String name;
String organizationName;
String streetAddress;
String city;
String state;
String postalCode;
String country;
LocalDateTime domainCreated;
LocalDateTime lastModified;
String status;
String registarCreated;
String currentRegistar;
}
Repository
@org.springframework.stereotype.Repository
public class Repository {
private static Logger logger = Logger.getLogger(Repository.class.getName());
@Autowired
private JdbcTemplate template;
private String findDomainInfo = "select * from r_domain where name = ?";
public TemporaryModel findDomainInfo(String domain) {
logger.log(Level.INFO, "searching by domain: " + domain);
try {
TemporaryModel temporaryModel = template.queryForObject(
findDomainInfo,
new Object[]{domain},
new DomainRowMapper()
);
logger.log(Level.INFO, "found: " + temporaryModel);
return temporaryModel;
} catch (EmptyResultDataAccessException e) {
logger.log(Level.INFO, "not found by domain: " + domain);
return null;
}
}
}
class DomainRowMapper implements RowMapper<TemporaryModel> {
@Override
public TemporaryModel mapRow(ResultSet rs, int i) throws SQLException {
return new TemporaryModel(
rs.getLong("id"),
rs.getLong("oid"),
rs.getString("name"),
rs.getLong("tld"),
rs.getString("registrant"),
rs.getString("c_admin"),
rs.getString("c_tech"),
rs.getString("c_bill"),
rs.getDate("expired")
);
}
}
Controller
@RestController
@RequestMapping("api/whois")
public class Controller {
@Autowired
Repository repository;
@PostMapping
public TemporaryModel whois(@RequestBody Request request) {
return repository.findDomainInfo(request.domain);
}
}
Aucun commentaire:
Enregistrer un commentaire