Stephan Richter
3 years ago
5 changed files with 73 additions and 14 deletions
@ -0,0 +1,46 @@ |
|||||||
|
package de.srsoftware.widerhall.data; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import javax.validation.constraints.Email; |
||||||
|
|
||||||
|
import static de.srsoftware.widerhall.Constants.*; |
||||||
|
import static de.srsoftware.widerhall.data.Database.HASHED_PASS; |
||||||
|
import static de.srsoftware.widerhall.data.Database.SALT; |
||||||
|
|
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class MailingList { |
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(MailingList.class); |
||||||
|
private final String name; |
||||||
|
private final String email; |
||||||
|
public static final String TABLE_NAME = "Lists"; |
||||||
|
|
||||||
|
public MailingList(String email, String name){ |
||||||
|
this.email = email; |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public static MailingList create(String email, String name) throws SQLException { |
||||||
|
return new MailingList(email,name).save(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void createTable() throws SQLException { |
||||||
|
var sql = new StringBuilder() |
||||||
|
.append("CREATE TABLE ").append(TABLE_NAME) |
||||||
|
.append(" (") |
||||||
|
.append(EMAIL).append(" ").append(VARCHAR).append(" NOT NULL PRIMARY KEY, ") |
||||||
|
.append(NAME).append(" ").append(VARCHAR) |
||||||
|
.append(");"); |
||||||
|
Database.open().query(sql.toString()).run(); |
||||||
|
} |
||||||
|
|
||||||
|
private MailingList save() throws SQLException { |
||||||
|
Database.open().insertInto(TABLE_NAME) |
||||||
|
.values(Map.of(EMAIL,email,NAME,name)) |
||||||
|
.run(); |
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue