-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
15 deletions.
There are no files selected for viewing
37 changes: 22 additions & 15 deletions
37
src/main/java/mate/academy/mapstruct/controller/GroupController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/main/java/mate/academy/mapstruct/mapper/GroupMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/mate/academy/mapstruct/mapper/SubjectMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters