Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadym-Ozi committed Jul 8, 2024
1 parent 49011dd commit aff9792
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package mate.academy.mapstruct.mapper;
package mate.academy.mapstruct.controller;

import java.util.Optional;
import mate.academy.mapstruct.config.MapperConfig;
import java.util.List;
import lombok.RequiredArgsConstructor;
import mate.academy.mapstruct.dto.group.CreateGroupRequestDto;
import mate.academy.mapstruct.dto.group.GroupDto;
import mate.academy.mapstruct.model.Group;
import org.mapstruct.Mapper;
import org.mapstruct.Named;
import mate.academy.mapstruct.service.group.GroupService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Mapper(config = MapperConfig.class)
public interface GroupMapper {
GroupDto toDto(Group group);
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/groups")
public class GroupController {

Group toModel(CreateGroupRequestDto requestDto);
private final GroupService groupService;

@Named("groupGetById")
default Group groupGetById(Long id) {
return Optional.ofNullable(id)
.map(Group::new)
.orElse(null);
@GetMapping
public List<GroupDto> findAll() {
return groupService.findAll();
}

@PostMapping
public GroupDto save(@RequestBody CreateGroupRequestDto requestDto) {
return groupService.save(requestDto);
}
}
12 changes: 12 additions & 0 deletions src/main/java/mate/academy/mapstruct/mapper/GroupMapper.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package mate.academy.mapstruct.mapper;

import java.util.Optional;
import mate.academy.mapstruct.config.MapperConfig;
import mate.academy.mapstruct.dto.group.CreateGroupRequestDto;
import mate.academy.mapstruct.dto.group.GroupDto;
import mate.academy.mapstruct.model.Group;
import org.mapstruct.Mapper;
import org.mapstruct.Named;

@Mapper(config = MapperConfig.class)
public interface GroupMapper {
GroupDto toDto(Group group);

Group toModel(CreateGroupRequestDto requestDto);

@Named("groupGetById")
default Group groupGetById(Long id) {
return Optional.ofNullable(id)
.map(Group::new)
.orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package mate.academy.mapstruct.mapper;

import mate.academy.mapstruct.config.MapperConfig;
import mate.academy.mapstruct.dto.subject.CreateSubjectRequestDto;
import mate.academy.mapstruct.dto.subject.SubjectDto;
import mate.academy.mapstruct.model.Subject;
import org.mapstruct.Mapper;

@Mapper(config = MapperConfig.class)
public interface SubjectMapper {
SubjectDto toDto(Subject subject);

Expand Down

0 comments on commit aff9792

Please sign in to comment.