ip project fixes/additions
This commit is contained in:
@@ -2,9 +2,7 @@ package ru.ip.example.config;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.springdoc.core.customizers.OpenApiCustomizer;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
@@ -20,9 +18,6 @@ public class SwaggerConfig {
|
||||
private static final String title = "Фильмы";
|
||||
private static final String description = "Тестовый сервис";
|
||||
private static final String version = "0.0.1";
|
||||
private static final String contactEmail = "email";
|
||||
private static final String contactName = "developer";
|
||||
private static final String taskLink = "http://TO-BE-INSERTED";
|
||||
private static final String openApiGroup = "public-api-v1";
|
||||
private static final String pathsToMatch = "/**";
|
||||
|
||||
@@ -43,16 +38,12 @@ public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public OpenAPI api() {
|
||||
final var bearerSecuritySchema = new SecurityScheme()
|
||||
.type(SecurityScheme.Type.HTTP);
|
||||
|
||||
return new OpenAPI()
|
||||
.openapi("3.0.1")
|
||||
.info(new Info()
|
||||
.title(title)
|
||||
.description(description)
|
||||
.version(version)
|
||||
.contact(new Contact().email(contactEmail).name(contactName).url(taskLink))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package ru.ip.example.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ip.example.domain.AddSeazonDto;
|
||||
import ru.ip.example.domain.FilmDto;
|
||||
import ru.ip.example.service.FilmService;
|
||||
@@ -15,7 +19,7 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "FilmsController")
|
||||
@Tag(name = "FilmsAPI", description = "Контроллер для работы с фильмами")
|
||||
public class FilmController {
|
||||
|
||||
private final FilmService filmService;
|
||||
@@ -52,6 +56,6 @@ public class FilmController {
|
||||
|
||||
@PutMapping("/films/seazons")
|
||||
public FilmDto addSeazon(@RequestBody AddSeazonDto addSeazonDto) {
|
||||
return filmService.
|
||||
return filmService.addSeazon(addSeazonDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,13 @@ package ru.ip.example.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ip.example.domain.AddSeriesDto;
|
||||
import ru.ip.example.domain.SeazonDto;
|
||||
import ru.ip.example.service.SeazonService;
|
||||
|
||||
@@ -27,4 +33,9 @@ public class SeazonController {
|
||||
public void delete(@PathVariable("id") Integer id) {
|
||||
seazonService.delete(id);
|
||||
}
|
||||
|
||||
@PutMapping("/seazons/series")
|
||||
public SeazonDto addSeries(@RequestBody AddSeriesDto dto) {
|
||||
return seazonService.addSeries(dto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package ru.ip.example.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ip.example.domain.SeriesDto;
|
||||
import ru.ip.example.service.SeriesService;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "SeriesAPI", description = "API для работы с сериями")
|
||||
public class SeriesController {
|
||||
|
||||
private final SeriesService seriesService;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package ru.ip.example.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ip.example.domain.SubscribeDto;
|
||||
import ru.ip.example.service.SubscribeService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "SubscribeAPI", description = "API для работы с подписками")
|
||||
public class SubscribeController {
|
||||
|
||||
private final SubscribeService subscribeService;
|
||||
|
||||
@GetMapping("/subscribes")
|
||||
@Operation(description = "Возвращает список всех подписок")
|
||||
public List<SubscribeDto> getAll() {
|
||||
return subscribeService.findAllSubscribes();
|
||||
}
|
||||
|
||||
@GetMapping("/subscribes/{id}")
|
||||
@Operation(description = "Возвращает подписку по id")
|
||||
public SubscribeDto getById(@PathVariable("id") Integer id) {
|
||||
return subscribeService.findSubscribeById(id);
|
||||
}
|
||||
|
||||
@PostMapping("/subscribes")
|
||||
@Operation(description = "Сохраняет подписку")
|
||||
public SubscribeDto save(@RequestBody SubscribeDto subscribeDto) {
|
||||
return subscribeService.saveSubscribe(subscribeDto);
|
||||
}
|
||||
|
||||
@PutMapping("/subscribes/{id}")
|
||||
@Operation(description = "Обновляет подписку")
|
||||
public SubscribeDto update(@Schema(description = "Id подписки") @PathVariable("id") Integer id, @RequestBody SubscribeDto subscribeDto) {
|
||||
return subscribeService.updateSubscribe(id, subscribeDto);
|
||||
}
|
||||
|
||||
@DeleteMapping("/subscribes/{id}")
|
||||
@Operation(description = "Удаляет подписку")
|
||||
public void deleteById(@PathVariable("id") Integer id) {
|
||||
subscribeService.deleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
package ru.ip.example.domain;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "Данные для связки сериала с сезоном")
|
||||
public class AddSeazonDto {
|
||||
|
||||
@Schema(description = "Id фильма")
|
||||
private Integer filmId;
|
||||
|
||||
@Schema(description = "Id сезона")
|
||||
private Integer seazonId;
|
||||
}
|
||||
|
||||
15
src/main/java/ru/ip/example/domain/AddSeriesDto.java
Normal file
15
src/main/java/ru/ip/example/domain/AddSeriesDto.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package ru.ip.example.domain;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "Данные для связки сезона с серией")
|
||||
public class AddSeriesDto {
|
||||
|
||||
@Schema(description = "Id сезона")
|
||||
private Integer seazonId;
|
||||
|
||||
@Schema(description = "Id серии")
|
||||
private Integer seriesId;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import lombok.ToString;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Schema(description = "Данные сезона")
|
||||
public class SeazonDto {
|
||||
|
||||
@Schema(description = "Номер сезона")
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "Информация о серии")
|
||||
public class SeriesDto {
|
||||
|
||||
@Schema(description = "Название серии")
|
||||
|
||||
15
src/main/java/ru/ip/example/domain/SubscribeDto.java
Normal file
15
src/main/java/ru/ip/example/domain/SubscribeDto.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package ru.ip.example.domain;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "Информация о подписке")
|
||||
public class SubscribeDto {
|
||||
|
||||
@Schema(description = "Месячная плата")
|
||||
private Integer sum;
|
||||
|
||||
@Schema(description = "Название подписки")
|
||||
private String name;
|
||||
}
|
||||
@@ -20,5 +20,5 @@ public class FilmEntity {
|
||||
private Integer releaseYear;
|
||||
|
||||
@ToString.Exclude
|
||||
private List<SeazonEntity> seasons;
|
||||
private List<SeazonEntity> seazons;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package ru.ip.example.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class SubscribeEntity {
|
||||
|
||||
@EqualsAndHashCode.Include
|
||||
private Integer id;
|
||||
|
||||
private Integer sum;
|
||||
|
||||
private String name;
|
||||
}
|
||||
@@ -1,14 +1,22 @@
|
||||
package ru.ip.example.mapper;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import ru.ip.example.domain.FilmDto;
|
||||
import ru.ip.example.domain.SeazonDto;
|
||||
import ru.ip.example.domain.entity.FilmEntity;
|
||||
import ru.ip.example.domain.entity.SeazonEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//чтобы spring инициализировал маппер
|
||||
@Mapper(componentModel = "spring")
|
||||
@Mapper(componentModel = "spring", uses = SeazonMapper.class)
|
||||
public interface FilmMapper {
|
||||
|
||||
@Mapping(source = "entity.seazons", target = "seazons")
|
||||
FilmDto toDto(FilmEntity entity);
|
||||
|
||||
List<SeazonDto> toSeazonsList(List<SeazonEntity> seazonEntities);
|
||||
|
||||
FilmEntity toEntity(FilmDto dto);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
package ru.ip.example.mapper;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import ru.ip.example.domain.SeazonDto;
|
||||
import ru.ip.example.domain.SeriesDto;
|
||||
import ru.ip.example.domain.entity.SeazonEntity;
|
||||
import ru.ip.example.domain.entity.SeriesEntity;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
import java.util.List;
|
||||
|
||||
@Mapper(componentModel = "spring", uses = SeriesMapper.class)
|
||||
public interface SeazonMapper {
|
||||
|
||||
@Mapping(source = "entity.series", target = "series")
|
||||
SeazonDto toDto(SeazonEntity entity);
|
||||
|
||||
List<SeriesDto> toSeriesList(List<SeriesEntity> seriesEntities);
|
||||
|
||||
SeazonEntity toEntity(SeazonDto dto);
|
||||
}
|
||||
|
||||
13
src/main/java/ru/ip/example/mapper/SubscribeMapper.java
Normal file
13
src/main/java/ru/ip/example/mapper/SubscribeMapper.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.ip.example.mapper;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import ru.ip.example.domain.SubscribeDto;
|
||||
import ru.ip.example.domain.entity.SubscribeEntity;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface SubscribeMapper {
|
||||
|
||||
SubscribeDto toDto(SubscribeEntity entity);
|
||||
|
||||
SubscribeEntity toEntity(SubscribeDto dto);
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import ru.ip.example.domain.entity.SeriesEntity;
|
||||
|
||||
public interface SeriesRepository {
|
||||
|
||||
SeriesEntity findById(int id);
|
||||
|
||||
SeriesEntity save(SeriesEntity entity);
|
||||
|
||||
void delete(Integer id);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package ru.ip.example.repository;
|
||||
|
||||
import ru.ip.example.domain.entity.SubscribeEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SubscribeRepository {
|
||||
|
||||
SubscribeEntity save(SubscribeEntity entity);
|
||||
|
||||
List<SubscribeEntity> findAll();
|
||||
|
||||
SubscribeEntity findById(Integer id);
|
||||
|
||||
void deleteById(Integer id);
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package ru.ip.example.repository.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ip.example.domain.FilmDto;
|
||||
import ru.ip.example.domain.entity.FilmEntity;
|
||||
import ru.ip.example.domain.entity.SeazonEntity;
|
||||
import ru.ip.example.repository.FilmRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -19,11 +17,15 @@ public class FilmRepositoryDao implements FilmRepository {
|
||||
@Override
|
||||
public FilmEntity save(FilmEntity entity) {
|
||||
if (entity.getId() == null) {
|
||||
entity.setSeazons(new ArrayList<>());
|
||||
entity.setId(idSequence++);
|
||||
} else if (films.contains(entity)) {
|
||||
films.remove(entity);
|
||||
}
|
||||
films.add(entity);
|
||||
} else if (films.contains(entity)) {
|
||||
FilmEntity film = findById(entity.getId());
|
||||
film.setCategory(entity.getCategory());
|
||||
film.setTitle(entity.getTitle());
|
||||
film.setReleaseYear(entity.getReleaseYear());
|
||||
}
|
||||
System.out.println("save/upd film: " + entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package ru.ip.example.repository.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ip.example.domain.entity.SeazonEntity;
|
||||
import ru.ip.example.domain.entity.SeriesEntity;
|
||||
import ru.ip.example.repository.SeazonRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -30,15 +29,14 @@ public class SeazonRepositoryDao implements SeazonRepository {
|
||||
@Override
|
||||
public SeazonEntity save(SeazonEntity entity) {
|
||||
if (entity.getId() == null) {
|
||||
entity.setSeries(new ArrayList<>());
|
||||
entity.setId(SEAZON_SEQ++);
|
||||
} else if (seazons.contains(entity)) {
|
||||
int persistEntityIndex = seazons.indexOf(entity);
|
||||
SeazonEntity savedSeazon = seazons.get(persistEntityIndex);
|
||||
entity.setSeries(savedSeazon.getSeries());
|
||||
seazons.remove(entity);
|
||||
}
|
||||
seazons.add(entity);
|
||||
System.out.println("save/upd film: " + entity);
|
||||
} else if (seazons.contains(entity)) {
|
||||
SeazonEntity seazon = findById(entity.getId());
|
||||
seazon.setNumber(entity.getNumber());
|
||||
}
|
||||
System.out.println("save/upd seazon: " + entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,15 +14,29 @@ public class SerialRepositoryDao implements SeriesRepository {
|
||||
|
||||
private static Integer SERIES_SEQ = 0;
|
||||
|
||||
@Override
|
||||
public SeriesEntity findById(int id) {
|
||||
SeriesEntity seriesEntity = new SeriesEntity();
|
||||
seriesEntity.setId(id);
|
||||
for (SeriesEntity ser : series) {
|
||||
if (ser.equals(seriesEntity)) {
|
||||
return ser;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SeriesEntity save(SeriesEntity entity) {
|
||||
if (entity.getId() == null) {
|
||||
entity.setId(SERIES_SEQ++);
|
||||
} else if (series.contains(entity)) {
|
||||
series.remove(entity);
|
||||
}
|
||||
series.add(entity);
|
||||
System.out.println("save/upd film: " + entity);
|
||||
} else if (series.contains(entity)) {
|
||||
SeriesEntity series1 = findById(entity.getId());
|
||||
series1.setName(entity.getName());
|
||||
series1.setNumber(entity.getNumber());
|
||||
}
|
||||
System.out.println("save/upd series: " + entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package ru.ip.example.repository.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ip.example.domain.entity.SubscribeEntity;
|
||||
import ru.ip.example.repository.SubscribeRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SubscribeRepositoryDao implements SubscribeRepository {
|
||||
|
||||
private static Integer idSequence = 0;
|
||||
|
||||
private static List<SubscribeEntity> subscribes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public SubscribeEntity save(SubscribeEntity entity) {
|
||||
if (entity.getId() == null) {
|
||||
entity.setId(idSequence++);
|
||||
subscribes.add(entity);
|
||||
} else if (subscribes.contains(entity)) {
|
||||
SubscribeEntity film = findById(entity.getId());
|
||||
film.setName(entity.getName());
|
||||
film.setSum(entity.getSum());
|
||||
}
|
||||
System.out.println("save/upd film: " + entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubscribeEntity> findAll() {
|
||||
return subscribes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscribeEntity findById(Integer id) {
|
||||
for (SubscribeEntity sub : subscribes) {
|
||||
if (sub.getId().equals(id)) {
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//equals реализован только с id, поэтому для remove в entity проставляем только id
|
||||
@Override
|
||||
public void deleteById(Integer id) {
|
||||
SubscribeEntity SubscribeEntity = new SubscribeEntity();
|
||||
SubscribeEntity.setId(id);
|
||||
subscribes.remove(SubscribeEntity);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package ru.ip.example.service;
|
||||
|
||||
import ru.ip.example.domain.AddSeriesDto;
|
||||
import ru.ip.example.domain.SeazonDto;
|
||||
|
||||
public interface SeazonService {
|
||||
|
||||
SeazonDto findById(Integer id);
|
||||
|
||||
SeazonDto save(SeazonDto dto);
|
||||
|
||||
SeazonDto update(Integer id, SeazonDto dto);
|
||||
|
||||
void delete(Integer id);
|
||||
|
||||
SeazonDto addSeries(AddSeriesDto dto);
|
||||
}
|
||||
|
||||
18
src/main/java/ru/ip/example/service/SubscribeService.java
Normal file
18
src/main/java/ru/ip/example/service/SubscribeService.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package ru.ip.example.service;
|
||||
|
||||
import ru.ip.example.domain.SubscribeDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SubscribeService {
|
||||
|
||||
SubscribeDto saveSubscribe(SubscribeDto dto);
|
||||
|
||||
SubscribeDto updateSubscribe(Integer id, SubscribeDto dto);
|
||||
|
||||
List<SubscribeDto> findAllSubscribes();
|
||||
|
||||
SubscribeDto findSubscribeById(Integer id);
|
||||
|
||||
void deleteById(Integer id);
|
||||
}
|
||||
@@ -1,22 +1,19 @@
|
||||
package ru.ip.example.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ip.example.domain.AddSeazonDto;
|
||||
import ru.ip.example.domain.FilmDto;
|
||||
import ru.ip.example.domain.SeazonDto;
|
||||
import ru.ip.example.domain.entity.FilmEntity;
|
||||
import ru.ip.example.domain.entity.SeazonEntity;
|
||||
import ru.ip.example.mapper.FilmMapper;
|
||||
import ru.ip.example.repository.FilmRepository;
|
||||
import ru.ip.example.repository.SeazonRepository;
|
||||
import ru.ip.example.service.FilmService;
|
||||
import ru.ip.example.service.SeazonService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static ru.ip.example.repository.impl.SeazonRepositoryDao.seazons;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class FilmServiceImpl implements FilmService {
|
||||
@@ -25,7 +22,7 @@ public class FilmServiceImpl implements FilmService {
|
||||
|
||||
private final FilmMapper filmMapper;
|
||||
|
||||
private final SeazonService seazonService;
|
||||
private final SeazonRepository seazonRepository;
|
||||
|
||||
@Override
|
||||
public FilmDto saveFilm(FilmDto dto) {
|
||||
@@ -66,8 +63,13 @@ public class FilmServiceImpl implements FilmService {
|
||||
|
||||
@Override
|
||||
public FilmDto addSeazon(AddSeazonDto addSeazonDto) {
|
||||
SeazonDto seazonDto = seazonService.findById(addSeazonDto.getSeazonId());
|
||||
SeazonEntity seazonEntity = seazonRepository.findById(addSeazonDto.getSeazonId());
|
||||
FilmEntity film = filmRepository.findById(addSeazonDto.getFilmId());
|
||||
List<SeazonEntity> seasons = film.getSeazons();
|
||||
|
||||
return null;
|
||||
if (!seasons.contains(seazonEntity)) {
|
||||
seasons.add(seazonEntity);
|
||||
}
|
||||
return filmMapper.toDto(film);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package ru.ip.example.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ip.example.domain.AddSeriesDto;
|
||||
import ru.ip.example.domain.SeazonDto;
|
||||
import ru.ip.example.domain.entity.SeazonEntity;
|
||||
import ru.ip.example.domain.entity.SeriesEntity;
|
||||
import ru.ip.example.mapper.SeazonMapper;
|
||||
import ru.ip.example.repository.SeazonRepository;
|
||||
import ru.ip.example.repository.SeriesRepository;
|
||||
import ru.ip.example.service.SeazonService;
|
||||
|
||||
@Service
|
||||
@@ -16,13 +19,7 @@ public class SeazonServiceImpl implements SeazonService {
|
||||
|
||||
private final SeazonMapper seazonMapper;
|
||||
|
||||
@Override
|
||||
public SeazonDto findById(Integer id) {
|
||||
SeazonEntity seazon = new SeazonEntity();
|
||||
seazon.setId(id);
|
||||
s
|
||||
return null;
|
||||
}
|
||||
private final SeriesRepository seriesRepository;
|
||||
|
||||
@Override
|
||||
public SeazonDto save(SeazonDto dto) {
|
||||
@@ -43,4 +40,15 @@ public class SeazonServiceImpl implements SeazonService {
|
||||
public void delete(Integer id) {
|
||||
seazonRepository.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SeazonDto addSeries(AddSeriesDto dto) {
|
||||
SeriesEntity series = seriesRepository.findById(dto.getSeriesId());
|
||||
SeazonEntity seazon = seazonRepository.findById(dto.getSeazonId());
|
||||
|
||||
if (!seazon.getSeries().contains(series)) {
|
||||
seazon.getSeries().add(series);
|
||||
}
|
||||
return seazonMapper.toDto(seazon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package ru.ip.example.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ip.example.domain.SubscribeDto;
|
||||
import ru.ip.example.domain.entity.SubscribeEntity;
|
||||
import ru.ip.example.mapper.SubscribeMapper;
|
||||
import ru.ip.example.repository.SubscribeRepository;
|
||||
import ru.ip.example.service.SubscribeService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SubscribeServiceImpl implements SubscribeService {
|
||||
|
||||
private final SubscribeRepository subscribeRepository;
|
||||
|
||||
private final SubscribeMapper subscribeMapper;
|
||||
|
||||
@Override
|
||||
public SubscribeDto saveSubscribe(SubscribeDto dto) {
|
||||
SubscribeEntity entity = subscribeMapper.toEntity(dto);
|
||||
SubscribeEntity savedSubscribe = subscribeRepository.save(entity);
|
||||
return subscribeMapper.toDto(savedSubscribe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscribeDto updateSubscribe(Integer id, SubscribeDto dto) {
|
||||
SubscribeEntity subscribeEntity = subscribeMapper.toEntity(dto);
|
||||
subscribeEntity.setId(id);
|
||||
SubscribeEntity updatedEntity = subscribeRepository.save(subscribeEntity);
|
||||
return subscribeMapper.toDto(updatedEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SubscribeDto> findAllSubscribes() {
|
||||
List<SubscribeEntity> subscribeEntities = subscribeRepository.findAll();
|
||||
List<SubscribeDto> subscribes = new ArrayList<>();
|
||||
for (SubscribeEntity entity : subscribeEntities) {
|
||||
SubscribeDto dto = subscribeMapper.toDto(entity);
|
||||
subscribes.add(dto);
|
||||
}
|
||||
return subscribes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscribeDto findSubscribeById(Integer id) {
|
||||
SubscribeEntity subscribe = subscribeRepository.findById(id);
|
||||
return subscribeMapper.toDto(subscribe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(Integer id) {
|
||||
subscribeRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user