-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VKT(Backend&Frontend): Change backend to match frontend requirements
- Loading branch information
Showing
15 changed files
with
260 additions
and
96 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
backend/vkt/src/main/java/fi/oph/vkt/api/dto/MunicipalityDTO.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package fi.oph.vkt.api.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public record MunicipalityDTO(@NonNull @NotNull String code) {} |
11 changes: 0 additions & 11 deletions
11
backend/vkt/src/main/java/fi/oph/vkt/api/dto/examiner/ExaminerDetailsCreateDTO.java
This file was deleted.
Oops, something went wrong.
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
17 changes: 17 additions & 0 deletions
17
backend/vkt/src/main/java/fi/oph/vkt/api/dto/examiner/ExaminerDetailsUpsertDTO.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package fi.oph.vkt.api.dto.examiner; | ||
|
||
import fi.oph.vkt.api.dto.MunicipalityDTO; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public record ExaminerDetailsUpsertDTO( | ||
@NonNull String email, | ||
@NonNull String phoneNumber, | ||
@NonNull Boolean examLanguageFinnish, | ||
@NonNull Boolean examLanguageSwedish, | ||
@NonNull Boolean isPublic, | ||
@NonNull @NotEmpty List<MunicipalityDTO> municipalities | ||
) {} |
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
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
38 changes: 0 additions & 38 deletions
38
backend/vkt/src/main/java/fi/oph/vkt/model/ExaminerMunicipality.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
backend/vkt/src/main/java/fi/oph/vkt/model/Municipality.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package fi.oph.vkt.model; | ||
|
||
import jakarta.persistence.*; | ||
import java.util.List; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "municipality") | ||
public class Municipality extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "municipality_id", nullable = false) | ||
private long id; | ||
|
||
// Code should match the koodiArvo of an entry in koodisto | ||
@Column(name = "code", nullable = false, unique = true) | ||
private String code; | ||
|
||
@Column(name = "name_fi", nullable = false) | ||
private String nameFI; | ||
|
||
@Column(name = "name_sv", nullable = false) | ||
private String nameSV; | ||
|
||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "municipalities") | ||
private List<Examiner> examiners; | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/vkt/src/main/java/fi/oph/vkt/repository/MunicipalityRepository.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package fi.oph.vkt.repository; | ||
|
||
import fi.oph.vkt.model.Municipality; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MunicipalityRepository extends BaseRepository<Municipality> { | ||
Optional<Municipality> findByCode(String code); | ||
} |
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
68 changes: 68 additions & 0 deletions
68
backend/vkt/src/main/java/fi/oph/vkt/service/MunicipalityService.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package fi.oph.vkt.service; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import fi.oph.vkt.model.Municipality; | ||
import fi.oph.vkt.repository.MunicipalityRepository; | ||
import jakarta.annotation.PostConstruct; | ||
import jakarta.transaction.Transactional; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MunicipalityService { | ||
|
||
private final MunicipalityRepository municipalityRepository; | ||
private Map<String, String> codeToFi; | ||
private Map<String, String> codeToSv; | ||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | ||
private static final String KOODISTO_MUNICIPALITIES_JSON = "koodisto/koodisto_kunnat.json"; | ||
|
||
@PostConstruct | ||
public void init() { | ||
codeToFi = new HashMap<>(); | ||
codeToSv = new HashMap<>(); | ||
|
||
try (final InputStream is = new ClassPathResource(KOODISTO_MUNICIPALITIES_JSON).getInputStream()) { | ||
final List<KoodistoEntry> koodisto = deserializeJson(is); | ||
koodisto.forEach(koodistoEntry -> { | ||
codeToFi.put(koodistoEntry.koodiArvo(), koodistoEntry.fi()); | ||
codeToSv.put(koodistoEntry.koodiArvo(), koodistoEntry.sv()); | ||
}); | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Transactional | ||
public Municipality getOrCreateByCode(final String code) { | ||
Optional<Municipality> existingMunicipality = municipalityRepository.findByCode(code); | ||
if (existingMunicipality.isPresent()) { | ||
return existingMunicipality.get(); | ||
} else { | ||
Municipality municipality = new Municipality(); | ||
municipality.setCode(code); | ||
municipality.setNameFI(codeToFi.get(code)); | ||
municipality.setNameSV(codeToSv.get(code)); | ||
municipalityRepository.saveAndFlush(municipality); | ||
return municipality; | ||
} | ||
} | ||
|
||
private List<KoodistoEntry> deserializeJson(final InputStream is) throws IOException { | ||
return OBJECT_MAPPER.readValue(is, new TypeReference<>() {}); | ||
} | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
private record KoodistoEntry(@NonNull String koodiArvo, @NonNull String fi, @NonNull String sv) {} | ||
} |
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
Oops, something went wrong.