feat: add profile
This commit is contained in:
parent
3a8c2886a2
commit
2e4fadab0d
13
src/ru/charm/back/controller/ProfileController.java
Normal file
13
src/ru/charm/back/controller/ProfileController.java
Normal file
@ -0,0 +1,13 @@
|
||||
package ru.charm.back.controller;
|
||||
|
||||
import ru.charm.back.service.ProfileService;
|
||||
|
||||
public class ProfileController {
|
||||
private final ProfileService service;
|
||||
|
||||
public ProfileController(ProfileService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String work(String request) {}
|
||||
}
|
||||
47
src/ru/charm/back/dao/ProfileDao.java
Normal file
47
src/ru/charm/back/dao/ProfileDao.java
Normal file
@ -0,0 +1,47 @@
|
||||
package ru.charm.back.dao;
|
||||
|
||||
import ru.charm.back.model.Profile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class ProfileDao {
|
||||
private final ConcurrentHashMap<Long, Profile> storage;
|
||||
private final AtomicLong idStorage;
|
||||
|
||||
public ProfileDao() {
|
||||
this.storage = new ConcurrentHashMap<>();
|
||||
this.idStorage = new AtomicLong();
|
||||
}
|
||||
|
||||
public Profile save(Profile profile) {
|
||||
long id = idStorage.incrementAndGet();
|
||||
profile.setId(id);
|
||||
storage.put(id, profile);
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
public Optional<Profile> findById(Long id) {
|
||||
return Optional.ofNullable(storage.get(id));
|
||||
}
|
||||
|
||||
public void update(Profile profile) {
|
||||
Long id = profile.getId();
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
storage.put(id, profile);
|
||||
}
|
||||
|
||||
public List<Profile> findAll() {
|
||||
return new ArrayList<>(storage.values());
|
||||
}
|
||||
|
||||
public Boolean delete(Long id) {
|
||||
return storage.remove(id) != null;
|
||||
}
|
||||
}
|
||||
49
src/ru/charm/back/model/Profile.java
Normal file
49
src/ru/charm/back/model/Profile.java
Normal file
@ -0,0 +1,49 @@
|
||||
package ru.charm.back.model;
|
||||
|
||||
public class Profile {
|
||||
private Long id;
|
||||
private String email;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String about;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public String getAbout() {
|
||||
return about;
|
||||
}
|
||||
|
||||
public void setAbout(String about) {
|
||||
this.about = about;
|
||||
}
|
||||
}
|
||||
43
src/ru/charm/back/service/ProfileService.java
Normal file
43
src/ru/charm/back/service/ProfileService.java
Normal file
@ -0,0 +1,43 @@
|
||||
package ru.charm.back.service;
|
||||
|
||||
import ru.charm.back.dao.ProfileDao;
|
||||
import ru.charm.back.model.Profile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ProfileService {
|
||||
private ProfileDao dao;
|
||||
|
||||
public ProfileService(ProfileDao dao) {
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
public Profile save(Profile profile) {
|
||||
return dao.save(profile);
|
||||
}
|
||||
|
||||
public Optional<Profile> findById(Long id) {
|
||||
if (id == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return dao.findById(id);
|
||||
}
|
||||
|
||||
public Boolean delete(Long id) {
|
||||
if (id == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return dao.delete(id);
|
||||
}
|
||||
|
||||
public void update(Profile profile) {
|
||||
dao.update(profile);
|
||||
}
|
||||
|
||||
public List<Profile> findAll() {
|
||||
return dao.findAll();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user